Modbus - Servo Bricklet 2.0

This is the description of the Modbus protocol for the Servo Bricklet 2.0. General information and technical specifications for the Servo Bricklet 2.0 are summarized in its hardware description.

API

A general description of the Modbus protocol structure can be found here.

Every function of the Servo Brick API that has a servo_channel parameter can address a servo with the servo channel (0 to 9). If it is a setter function then multiple servos can be addressed at once with a bitmask for the servos, if the highest bit is set. For example: 1 will address servo 1, (1 << 1) | (1 << 5) | (1 << 15) will address servos 1 and 5. This allows to set configurations to several servos with one function call. It is guaranteed that the changes will take effect in the same PWM period for all servos you specified in the bitmask.

Basic Functions

BrickletServoV2.get_status
Function ID:
  • 1
Request:
  • empty payload
Response:
  • enabled – Type: bool[10]
  • current_position – Type: int16[10], Unit: 1/100 °, Range: ?
  • current_velocity – Type: int16[10], Unit: 1/100 °/s, Range: [0 to 500000]
  • current – Type: uint16[10], Unit: 1 mA, Range: [0 to 216 - 1]
  • input_voltage – Type: uint16, Unit: 1 mV, Range: [0 to 216 - 1]

Returns the status information of the Servo Bricklet 2.0.

The status includes

  • for each channel if it is enabled or disabled,
  • for each channel the current position,
  • for each channel the current velocity,
  • for each channel the current usage and
  • the input voltage.

Please note that the position and the velocity is a snapshot of the current position and velocity of the servo in motion.

BrickletServoV2.set_enable
Function ID:
  • 2
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • enable – Type: bool, Default: false
Response:
  • no response

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

BrickletServoV2.get_enabled
Function ID:
  • 3
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • enable – Type: bool, Default: false

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

BrickletServoV2.set_position
Function ID:
  • 4
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • position – Type: int16, Unit: 1/100 °, Range: ?
Response:
  • no response

Sets the position in °/100 for the specified servo channel.

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

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 set_degree.

BrickletServoV2.get_position
Function ID:
  • 5
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • position – Type: int16, Unit: 1/100 °, Range: ?

Returns the position of the specified servo channel as set by set_position.

BrickletServoV2.get_current_position
Function ID:
  • 6
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • position – Type: int16, Unit: 1/100 °, Range: ?

Returns the current position of the specified servo channel. This may not be the value of set_position if the servo is currently approaching a position goal.

BrickletServoV2.get_current_velocity
Function ID:
  • 7
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • velocity – Type: uint16, Unit: 1/100 °/s, Range: [0 to 500000]

Returns the current velocity of the specified servo channel. This may not be the velocity specified by set_motion_configuration. if the servo is currently approaching a velocity goal.

BrickletServoV2.set_motion_configuration
Function ID:
  • 8
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • velocity – Type: uint32, Unit: 1/100 °/s, Range: [0 to 500000], Default: 100000
  • acceleration – Type: uint32, Unit: 1/100 °/s², Range: [0 to 500000], Default: 50000
  • deceleration – Type: uint32, Unit: 1/100 °/s², Range: [0 to 500000], Default: 50000
Response:
  • no response

Sets the maximum velocity of the specified servo channel in °/100s as well as the acceleration and deceleration in °/100s²

With a velocity of 0 °/100s the position will be set immediately (no velocity).

With an acc-/deceleration of 0 °/100s² the velocity will be set immediately (no acc-/deceleration).

BrickletServoV2.get_motion_configuration
Function ID:
  • 9
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • velocity – Type: uint32, Unit: 1/100 °/s, Range: [0 to 500000], Default: 100000
  • acceleration – Type: uint32, Unit: 1/100 °/s², Range: [0 to 500000], Default: 50000
  • deceleration – Type: uint32, Unit: 1/100 °/s², Range: [0 to 500000], Default: 50000

Returns the motion configuration as set by set_motion_configuration.

BrickletServoV2.set_pulse_width
Function ID:
  • 10
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • min – Type: uint32, Unit: 1 µs, Range: [0 to 232 - 1], Default: 1000
  • max – Type: uint32, Unit: 1 µs, Range: [0 to 232 - 1], Default: 2000
Response:
  • no response

Sets the minimum and maximum pulse width of the specified servo channel in µs.

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.

Both values have a range from 1 to 65535 (unsigned 16-bit integer). The minimum must be smaller than the maximum.

The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and maximum pulse width.

BrickletServoV2.get_pulse_width
Function ID:
  • 11
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • min – Type: uint32, Unit: 1 µs, Range: [0 to 232 - 1], Default: 1000
  • max – Type: uint32, Unit: 1 µs, Range: [0 to 232 - 1], Default: 2000

Returns the minimum and maximum pulse width for the specified servo channel as set by set_pulse_width.

BrickletServoV2.set_degree
Function ID:
  • 12
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • min – Type: int16, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: -9000
  • max – Type: int16, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: 9000
Response:
  • no response

Sets the minimum and maximum degree for the specified servo channel (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 set_position 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 set_position 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. set_position now controls the rpm.

Both values have a possible range from -32767 to 32767 (signed 16-bit integer). The minimum must be smaller than the maximum.

The default values are -9000 and 9000 for the minimum and maximum degree.

BrickletServoV2.get_degree
Function ID:
  • 13
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • min – Type: int16, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: -9000
  • max – Type: int16, Unit: 1/100 °, Range: [-215 to 215 - 1], Default: 9000

Returns the minimum and maximum degree for the specified servo channel as set by set_degree.

BrickletServoV2.set_period
Function ID:
  • 14
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • period – Type: uint32, Unit: 1 µs, Range: [1 to 1000000], Default: 19500
Response:
  • no response

Sets the period of the specified servo channel in µs.

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 (19.5ms) will most likely work fine.

The minimum possible period is 1µs and the maximum is 1000000µs.

The default value is 19.5ms (19500µs).

BrickletServoV2.get_period
Function ID:
  • 15
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • period – Type: uint32, Unit: 1 µs, Range: [1 to 1000000], Default: 19500

Returns the period for the specified servo channel as set by set_period.

BrickletServoV2.get_servo_current
Function ID:
  • 16
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • current – Type: uint16, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the current consumption of the specified servo channel in mA.

BrickletServoV2.set_servo_current_configuration
Function ID:
  • 17
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • averaging_duration – Type: uint8, Unit: 1 ms, Range: [1 to 255], Default: 255
Response:
  • no response

Sets the averaging duration of the current measurement for the specified servo channel in ms.

BrickletServoV2.get_servo_current_configuration
Function ID:
  • 18
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • averaging_duration – Type: uint8, Unit: 1 ms, Range: [1 to 255], Default: 255

Returns the servo current configuration for the specified servo channel as set by set_servo_current_configuration.

BrickletServoV2.set_input_voltage_configuration
Function ID:
  • 19
Request:
  • averaging_duration – Type: uint8, Unit: 1 ms, Range: [1 to 255], Default: 255
Response:
  • no response

Sets the averaging duration of the input voltage measurement for the specified servo channel in ms.

BrickletServoV2.get_input_voltage_configuration
Function ID:
  • 20
Request:
  • empty payload
Response:
  • averaging_duration – Type: uint8, Unit: 1 ms, Range: [1 to 255], Default: 255

Returns the input voltage configuration as set by set_input_voltage_configuration.

BrickletServoV2.get_overall_current
Function ID:
  • 21
Request:
  • empty payload
Response:
  • current – Type: uint16, Unit: 1 mA, Range: [0 to 216 - 1]

Returns the current consumption of all servos together in mA.

BrickletServoV2.get_input_voltage
Function ID:
  • 22
Request:
  • empty payload
Response:
  • voltage – Type: uint16, Unit: 1 mV, Range: [0 to 216 - 1]

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

Advanced Functions

BrickletServoV2.set_current_calibration
Function ID:
  • 23
Request:
  • offset – Type: int16[10], Unit: 1 mA, Range: [-215 to 215 - 1]
Response:
  • no response

Sets an offset value (in mA) for each channel.

Note: On delivery the Servo Bricklet 2.0 is already calibrated.

BrickletServoV2.get_current_calibration
Function ID:
  • 24
Request:
  • empty payload
Response:
  • offset – Type: int16[10], Unit: 1 mA, Range: [-215 to 215 - 1]

Returns the current calibration as set by set_current_calibration.

BrickletServoV2.get_spitfp_error_count
Function ID:
  • 234
Request:
  • empty payload
Response:
  • error_count_ack_checksum – Type: uint32, Range: [0 to 232 - 1]
  • error_count_message_checksum – Type: uint32, Range: [0 to 232 - 1]
  • error_count_frame – Type: uint32, Range: [0 to 232 - 1]
  • error_count_overflow – Type: uint32, 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 Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

BrickletServoV2.set_status_led_config
Function ID:
  • 239
Request:
  • config – Type: uint8, Range: See meanings, Default: 3
Response:
  • no response

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Status
BrickletServoV2.get_status_led_config
Function ID:
  • 240
Request:
  • empty payload
Response:
  • config – Type: uint8, Range: See meanings, Default: 3

Returns the configuration as set by set_status_led_config

The following meanings are defined for the elements of this function:

For config:

  • 0 = Off
  • 1 = On
  • 2 = Show Heartbeat
  • 3 = Show Status
BrickletServoV2.get_chip_temperature
Function ID:
  • 242
Request:
  • empty payload
Response:
  • temperature – Type: int16, Unit: 1 °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 bad accuracy. Practically it is only useful as an indicator for temperature changes.

BrickletServoV2.reset
Function ID:
  • 243
Request:
  • empty payload
Response:
  • no response

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

BrickletServoV2.get_identity
Function ID:
  • 255
Request:
  • empty payload
Response:
  • uid – Type: char[8]
  • connected_uid – Type: char[8]
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • firmware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • device_identifier – Type: uint16, Range: [0 to 216 - 1]

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

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here

Callback Configuration Functions

BrickletServoV2.set_position_reached_callback_configuration
Function ID:
  • 25
Request:
  • servo_channel – Type: uint16, Range: [0 to 9, 215 to 33791]
  • enabled – Type: bool, Default: false
Response:
  • no response

Enable/Disable CALLBACK_POSITION_REACHED callback.

BrickletServoV2.get_position_reached_callback_configuration
Function ID:
  • 26
Request:
  • servo_channel – Type: uint16, Range: [0 to 9]
Response:
  • enabled – Type: bool, Default: false

Returns the callback configuration as set by set_position_reached_callback_configuration.

Callbacks

BrickletServoV2.CALLBACK_POSITION_REACHED
Function ID:
  • 27
Response:
  • servo_channel – Type: uint16, Range: [0 to 9]
  • position – Type: int16, Unit: 1/100 °, Range: ?

This callback is triggered when a position set by set_position is reached. If the new position matches the current position then the callback is not triggered, because the servo didn't move. The response values are the servo and the position that is reached.

You can enable this callback with set_position_reached_callback_configuration.

Note

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

Internal Functions

Internal functions are used for maintenance tasks such as flashing a new firmware of changing the UID of a Bricklet. These task should be performed using Brick Viewer instead of using the internal functions directly.

BrickletServoV2.set_bootloader_mode
Function ID:
  • 235
Request:
  • mode – Type: uint8, Range: See meanings
Response:
  • status – Type: uint8, Range: See meanings

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

The following meanings are defined for the elements of this function:

For mode:

  • 0 = Bootloader
  • 1 = Firmware
  • 2 = Bootloader Wait For Reboot
  • 3 = Firmware Wait For Reboot
  • 4 = Firmware Wait For Erase And Reboot

For status:

  • 0 = OK
  • 1 = Invalid Mode
  • 2 = No Change
  • 3 = Entry Function Not Present
  • 4 = Device Identifier Incorrect
  • 5 = CRC Mismatch
BrickletServoV2.get_bootloader_mode
Function ID:
  • 236
Request:
  • empty payload
Response:
  • mode – Type: uint8, Range: See meanings

Returns the current bootloader mode, see set_bootloader_mode.

The following meanings are defined for the elements of this function:

For mode:

  • 0 = Bootloader
  • 1 = Firmware
  • 2 = Bootloader Wait For Reboot
  • 3 = Firmware Wait For Reboot
  • 4 = Firmware Wait For Erase And Reboot
BrickletServoV2.set_write_firmware_pointer
Function ID:
  • 237
Request:
  • pointer – Type: uint32, Unit: 1 B, Range: [0 to 232 - 1]
Response:
  • no response

Sets the firmware pointer for write_firmware. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

BrickletServoV2.write_firmware
Function ID:
  • 238
Request:
  • data – Type: uint8[64], Range: [0 to 255]
Response:
  • status – Type: uint8, Range: [0 to 255]

Writes 64 Bytes of firmware at the position as written by set_write_firmware_pointer before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

BrickletServoV2.write_uid
Function ID:
  • 248
Request:
  • uid – Type: uint32, Range: [0 to 232 - 1]
Response:
  • no response

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

BrickletServoV2.read_uid
Function ID:
  • 249
Request:
  • empty payload
Response:
  • uid – Type: uint32, Range: [0 to 232 - 1]

Returns the current UID as an integer. Encode as Base58 to get the usual string version.