Phidgets1 example

In this mix, SPARKL intermediates between a rotation sensor and a motor service.

Explaining the mix

Figure: Phidgets1 - The mix


The mix itself is a fairly simple one, comprising of a notify and a consume operation.

The notify is triggered by rotating the sensor and the consume is used to set the position of the motor.

Tip: Get the code from the SPARKL public repository.
Table 1. Phidgets1 - The markup
Example Description
<folder name="Phidgets1">
  <field name="position" 
  type="integer"/>
  <service name="Sequencer" 
    provision="sequencer">
  <service name="Rotary" 
    provision="phidget">
    <prop name="phidget.spec" 
      kind="PhidgetInterfaceKit" 
      domains="domain.local"/>
    <prop name="phidget.params" 
      sensor0="position"/>
  </service>
  <service name="Servo" 
    provision="phidget">
    <prop name="phidget.spec" 
      kind="PhidgetAdvancedServo" 
      domains="domain.local"/>
    <prop name="phidget.params" 
      position0="position"/>
  </service>
  <mix name="Mix">
  ...
  </mix>
</folder>
The Rotary service, which we defined as a client for the Turn operation, is a phidget service. It comprises an interface kit and a rotation sensor connected to it.

In the properties of the Rotary service we mapped the sensor to the field position ("position0=position").

The value of the field position, therefore, depends on the position of the rotation sensor.

The Servo service is a phidget service. It comprises a motor controller and a servo motor connected to it. In the properties of Servo we mapped the position of the servo motor to the field position.

The Servo service, therefore, moves the servo motor to the position that corresponds to the value of the field position.

<notify name="Turn" 
    service="Sequencer" 
    clients="Rotary" 
    fields="position"/>
Once the rotation sensor is moved, the Rotary service fires the Turn notify. The interface kit measures the rotation (on a scale of 1 to 999).

Turn outputs the field position with a value that corresponds to the position of the rotation sensor.

<consume name="SetPosition" 
    service="Servo" 
    fields="position"/>
The SetPosition consume forms a goal which SPARKL tries to satisfy.

Servo, the service implementing the consume, wants to collect the field position, which SPARKL already has.