openHAB - Servo Brick

This is the description of the openHAB API bindings for the Servo Brick. General information and technical specifications for the Servo Brick are summarized in its hardware description.

An installation guide for the openHAB API bindings is part of their general description.

Thing

UID:
  • tinkerforge:brickservo:[UID]
Required firmware version:
  • 2.3.4
Firmware update supported:
  • no
Channels:
Actions:
Parameters:
  • Minimum Voltage – Type: decimal, Default: 5, Unit: V, Min: 0, Max: 65.535
  • The minimum voltage in V, below which the Unter Voltage channel is triggered. The minimum possible value that works with the Servo Brick is 5V. You can use this function to detect the discharge of a battery that is used to drive the stepper motor. If you have a fixed power supply, you likely do not need this functionality. The default value is 5V.

  • Status LED Config – Type: boolean, Default: true
  • The status LED is the blue LED next to the USB connector. If enabled is is on and it flickers if data is transfered. If disabled it is always off.

  • SPITFP Enable Dynamic Baudrate – Type: boolean, Default: true
  • The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is enabled, the Brick will try to adapt the baudrate for the communication between Bricks and Bricklets according to the amount of data that is transferred. The baudrate will be increased exponentially if lots of data is sent/received and decreased linearly if little data is sent/received. This lowers the baudrate in applications where little data is transferred (e.g. a weather station) and increases the robustness. If there is lots of data to transfer (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed. In cases where some data has to transferred as fast as possible every few seconds (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn the dynamic baudrate off to get the highest possible performance. The maximum value of the baudrate can be set per port. If the dynamic baudrate is disabled, the maximum baudrate will be used statically.

  • SPITFP Minimum Dynamic Baudrate – Type: integer, Default: 400000, Min: 400000, Max: 2000000
  • See SPITFP Enable Dynamic Baudrate

  • (Maximum) SPITFP Baudrate Port A – Type: integer, Default: 1400000, Min: 400000, Max: 2000000
  • The baudrate for Bricklet port A. If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference you can decrease the baudrate. If the dynamic baudrate feature is enabled, this is the maximum baudrate. Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in you applications we recommend to not change the baudrate.

  • (Maximum) SPITFP Baudrate Port B – Type: integer, Default: 1400000, Min: 400000, Max: 2000000
  • The baudrate for Bricklet port B. If you want to increase the throughput of Bricklets you can increase the baudrate. If you get a high error count because of high interference you can decrease the baudrate. If the dynamic baudrate feature is enabled, this is the maximum baudrate. Regulatory testing is done with the default baudrate. If CE compatibility or similar is necessary in you applications we recommend to not change the baudrate.

Channels

Velocity Reached

This channel is triggered when a velocity set by the setVelocity action is reached.

Note

Since we can't get any feedback from the servo, this only works if the acceleration is set smaller or equal to the maximum acceleration of the servo. Otherwise the servo will lag behind the control value and the listener will be triggered too early.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickservo:[UID]:BrickServoVelocityReached
Read only:
  • No
Position Reached

This listener is triggered when a position set by the setPosition action is reached. If the new position matches the current position then the listener is not triggered, because the servo didn't move.

Note

Since we can't get any feedback from the servo, this only works if the velocity is set smaller or equal to the maximum velocity of the servo. Otherwise the servo will lag behind the control value and the listener will be triggered too early.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickservo:[UID]:BrickServoPositionReached
Read only:
  • No
Unter Voltage

This channel is triggered when the input voltage drops below the configured minimum voltage.

Type:
  • Trigger (system.trigger)
UID:
  • tinkerforge:brickservo:[UID]:BrickServoUnterVoltage
Read only:
  • No

Actions

Actions can be used in rules by creating an action object. All actions return a Map<String, Object>. Returned values can be accessed by name, sometimes the type deduction needs some hints, as shown below:

val actions = getActions("tinkerforge", "tinkerforge:brickservo:[UID]")
val hwVersion = actions.brickServoGetIdentity().get("hardwareVersion") as short[]
logInfo("Example", "Hardware version: " + hwVersion.get(0) + "." + hwVersion.get(1) + "." + hwVersion.get(2))

Basic Actions

brickServoEnable(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]

Enables a servo (0 to 6). If a servo is enabled, the configured position, velocity, acceleration, etc. are applied immediately.

brickServoDisable(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]

Disables a servo (0 to 6). Disabled servos are not driven at all, i.e. a disabled servo will not hold its position if a load is applied.

brickServoIsEnabled(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • enabled – Type: boolean

Returns true if the specified servo is enabled, false otherwise.

brickServoSetPosition(short servoNum, short position)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • position – Type: short, Unit: 1/100 °, Range: ?

Sets the position for the specified servo.

The default range of the position is -9000 to 9000, but it can be specified according to your servo with SetDegree().

If you want to control a linear servo or RC brushless motor controller or similar with the Servo Brick, you can also define lengths or speeds with SetDegree().

brickServoGetPosition(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • position – Type: short, Unit: 1/100 °, Range: ?

Returns the position of the specified servo as set by SetPosition().

brickServoGetCurrentPosition(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • position – Type: short, Unit: 1/100 °, Range: ?

Returns the current position of the specified servo. This may not be the value of SetPosition() if the servo is currently approaching a position goal.

brickServoSetVelocity(short servoNum, int velocity)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • velocity – Type: int, Unit: 1/100 °/s, Range: [0 to 216 - 1], Default: 216 - 1

Sets the maximum velocity of the specified servo. The velocity is accelerated according to the value set by SetAcceleration().

The minimum velocity is 0 (no movement) and the maximum velocity is 65535. With a value of 65535 the position will be set immediately (no velocity).

brickServoGetVelocity(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • velocity – Type: int, Unit: 1/100 °/s, Range: [0 to 216 - 1], Default: 216 - 1

Returns the velocity of the specified servo as set by SetVelocity().

brickServoGetCurrentVelocity(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • velocity – Type: int, Unit: 1/100 °/s, Range: [0 to 216 - 1], Default: 216 - 1

Returns the current velocity of the specified servo. This may not be the value of SetVelocity() if the servo is currently approaching a velocity goal.

brickServoSetAcceleration(short servoNum, int acceleration)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • acceleration – Type: int, Unit: 1/100 °/s², Range: [0 to 216 - 1], Default: 216 - 1

Sets the acceleration of the specified servo.

The minimum acceleration is 1 and the maximum acceleration is 65535. With a value of 65535 the velocity will be set immediately (no acceleration).

brickServoGetAcceleration(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • acceleration – Type: int, Unit: 1/100 °/s², Range: [0 to 216 - 1], Default: 216 - 1

Returns the acceleration for the specified servo as set by SetAcceleration().

brickServoSetOutputVoltage(int voltage)
Parameters:
  • voltage – Type: int, Unit: 1 mV, Range: [2000 to 9000], Default: 5000

Sets the output voltages with which the servos are driven.

Note

We recommend that you set this value to the maximum voltage that is specified for your servo, most servos achieve their maximum force only with high voltages.

brickServoGetOutputVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [2000 to 9000], Default: 5000

Returns the output voltage as specified by SetOutputVoltage().

brickServoSetPulseWidth(short servoNum, int min, int max)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • min – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 1000
  • max – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 2000

Sets the minimum and maximum pulse width of the specified servo.

Usually, servos are controlled with a PWM, whereby the length of the pulse controls the position of the servo. Every servo has different minimum and maximum pulse widths, these can be specified with this function.

If you have a datasheet for your servo that specifies the minimum and maximum pulse width, you should set the values accordingly. If your servo comes without any datasheet you have to find the values via trial and error.

The minimum must be smaller than the maximum.

brickServoGetPulseWidth(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • min – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 1000
  • max – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 2000

Returns the minimum and maximum pulse width for the specified servo as set by SetPulseWidth().

brickServoSetDegree(short servoNum, short min, short max)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • min – Type: short, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: -9000
  • max – Type: short, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: 9000

Sets the minimum and maximum degree for the specified servo (by default given as °/100).

This only specifies the abstract values between which the minimum and maximum pulse width is scaled. For example: If you specify a pulse width of 1000µs to 2000µs and a degree range of -90° to 90°, a call of SetPosition() with 0 will result in a pulse width of 1500µs (-90° = 1000µs, 90° = 2000µs, etc.).

Possible usage:

  • The datasheet of your servo specifies a range of 200° with the middle position at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.
  • You measure a range of 220° on your servo and you don't have or need a middle position. In this case you can set the minimum to 0 and the maximum to 22000.
  • You have a linear servo with a drive length of 20cm, In this case you could set the minimum to 0 and the maximum to 20000. Now you can set the Position with SetPosition() with a resolution of cm/100. Also the velocity will have a resolution of cm/100s and the acceleration will have a resolution of cm/100s².
  • You don't care about units and just want the highest possible resolution. In this case you should set the minimum to -32767 and the maximum to 32767.
  • You have a brushless motor with a maximum speed of 10000 rpm and want to control it with a RC brushless motor controller. In this case you can set the minimum to 0 and the maximum to 10000. SetPosition() now controls the rpm.

The minimum must be smaller than the maximum.

brickServoGetDegree(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • min – Type: short, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: -9000
  • max – Type: short, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: 9000

Returns the minimum and maximum degree for the specified servo as set by SetDegree().

brickServoSetPeriod(short servoNum, int period)
Parameters:
  • servoNum – Type: short, Range: [0 to 6, 128 to 255]
  • period – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 19500

Sets the period of the specified servo.

Usually, servos are controlled with a PWM. Different servos expect PWMs with different periods. Most servos run well with a period of about 20ms.

If your servo comes with a datasheet that specifies a period, you should set it accordingly. If you don't have a datasheet and you have no idea what the correct period is, the default value will most likely work fine.

brickServoGetPeriod(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • period – Type: int, Unit: 1 µs, Range: [0 to 216 - 1], Default: 19500

Returns the period for the specified servo as set by SetPeriod().

brickServoGetServoCurrent(short servoNum)
Parameters:
  • servoNum – Type: short, Range: [0 to 6]
Return Map:
  • current – Type: int, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the current consumption of the specified servo.

brickServoGetOverallCurrent()
Return Map:
  • current – Type: int, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the current consumption of all servos together.

brickServoGetStackInputVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]

Returns the stack input voltage. The stack input voltage is the voltage that is supplied via the stack, i.e. it is given by a Step-Down or Step-Up Power Supply.

brickServoGetExternalInputVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1]

Returns the external input voltage. The external input voltage is given via the black power input connector on the Servo Brick.

If there is an external input voltage and a stack input voltage, the motors will be driven by the external input voltage. If there is only a stack voltage present, the motors will be driven by this voltage.

Warning

This means, if you have a high stack voltage and a low external voltage, the motors will be driven with the low external voltage. If you then remove the external connection, it will immediately be driven by the high stack voltage

Advanced Actions

brickServoGetIdentity()
Return Map:
  • uid – Type: String, Length: up to 8
  • connectedUid – Type: String, Length: up to 8
  • position – Type: char, Range: ['0' to '8']
  • hardwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • firmwareVersion – Type: short[], Length: 3
    • 0: major – Type: short, Range: [0 to 255]
    • 1: minor – Type: short, Range: [0 to 255]
    • 2: revision – Type: short, Range: [0 to 255]
  • deviceIdentifier – Type: int, Range: [0 to 216 - 1]

Returns the UID, the UID where the Brick is connected to, the position, the hardware and firmware version as well as the device identifier.

The position is the position in the stack from '0' (bottom) to '8' (top).

The device identifier numbers can be found here

brickServoIsStatusLEDEnabled()
Return Map:
  • enabled – Type: boolean, Default: true

Returns true if the status LED is enabled, false otherwise.

New in version 2.3.1 (Firmware).

brickServoGetChipTemperature()
Return Map:
  • temperature – Type: short, Unit: 1/10 °C, Range: [-215 to 215 - 1]

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has an accuracy of ±15%. Practically it is only useful as an indicator for temperature changes.

brickServoGetSendTimeoutCount(short communicationMethod)
Parameters:
  • communicationMethod – Type: short, Range: See constants
Return Map:
  • timeoutCount – Type: long, Range: [0 to 232 - 1]

Returns the timeout count for the different communication methods.

The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.

This function is mostly used for debugging during development, in normal operation the counters should nearly always stay at 0.

The following constants are available for this function:

For communicationMethod:

  • val COMMUNICATION_METHOD_NONE = 0
  • val COMMUNICATION_METHOD_USB = 1
  • val COMMUNICATION_METHOD_SPI_STACK = 2
  • val COMMUNICATION_METHOD_CHIBI = 3
  • val COMMUNICATION_METHOD_RS485 = 4
  • val COMMUNICATION_METHOD_WIFI = 5
  • val COMMUNICATION_METHOD_ETHERNET = 6
  • val COMMUNICATION_METHOD_WIFI_V2 = 7

New in version 2.3.2 (Firmware).

brickServoGetSPITFPBaudrateConfig()
Return Map:
  • enableDynamicBaudrate – Type: boolean, Default: true
  • minimumDynamicBaudrate – Type: long, Unit: 1 Bd, Range: [400000 to 2000000], Default: 400000

Returns the baudrate config, see the thing configuration.

New in version 2.3.4 (Firmware).

brickServoGetSPITFPErrorCount(char brickletPort)
Parameters:
  • brickletPort – Type: char, Range: ['a' to 'b']
Return Map:
  • errorCountACKChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountMessageChecksum – Type: long, Range: [0 to 232 - 1]
  • errorCountFrame – Type: long, Range: [0 to 232 - 1]
  • errorCountOverflow – Type: long, Range: [0 to 232 - 1]

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Brick side. All Bricklets have a similar function that returns the errors on the Bricklet side.

New in version 2.3.2 (Firmware).

brickServoGetSPITFPBaudrate(char brickletPort)
Parameters:
  • brickletPort – Type: char, Range: ['a' to 'b']
Return Map:
  • baudrate – Type: long, Unit: 1 Bd, Range: [400000 to 2000000], Default: 1400000

Returns the baudrate for a given Bricklet port, see the thing configuration.

New in version 2.3.2 (Firmware).

Trigger Channel Configuration Actions

brickServoGetMinimumVoltage()
Return Map:
  • voltage – Type: int, Unit: 1 mV, Range: [0 to 216 - 1], Default: 5000

Returns the minimum voltage as set by the thing configuration