This is the description of the Shell API bindings for the Servo Bricklet 2.0. General information and technical specifications for the Servo Bricklet 2.0 are summarized in its hardware description.
An installation guide for the Shell API bindings is part of their general description.
The example code below is Public Domain (CC0 1.0).
Download (example-callback.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this
uid=XYZ # Change XYZ to the UID of your Servo Bricklet 2.0
# Use position reached callback to swing back and forth
tinkerforge dispatch servo-v2-bricklet $uid position-reached\
--execute "if [ {position} -eq 9000 ];
then echo 'Position: 90°, going to -90°' && tinkerforge call servo-v2-bricklet $uid set-position 0 -9000;
elif [ {position} -eq -9000 ];
then echo 'Position: -90°, going to 90°' && tinkerforge call servo-v2-bricklet $uid set-position 0 9000;
else echo error; fi" &
# Enable position reached callback
tinkerforge call servo-v2-bricklet $uid set-position-reached-callback-configuration 0 true
# Set velocity to 100°/s. This has to be smaller or equal to the
# maximum velocity of the servo you are using, otherwise the position
# reached callback will be called too early
tinkerforge call servo-v2-bricklet $uid set-motion-configuration 0 10000 500000 500000
tinkerforge call servo-v2-bricklet $uid set-position 0 9000
tinkerforge call servo-v2-bricklet $uid set-enable 0 true
echo "Press key to exit"; read dummy
tinkerforge call servo-v2-bricklet $uid set-enable 0 false
kill -- -$$ # Stop callback dispatch in background
|
Download (example-configuration.sh)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/bin/sh
# Connects to localhost:4223 by default, use --host and --port to change this
uid=XYZ # Change XYZ to the UID of your Servo Bricklet 2.0
# Servo 1: Connected to port 0, period of 19.5ms, pulse width of 1 to 2ms
# and operating angle -100 to 100°
tinkerforge call servo-v2-bricklet $uid set-degree 0 -10000 10000
tinkerforge call servo-v2-bricklet $uid set-pulse-width 0 1000 2000
tinkerforge call servo-v2-bricklet $uid set-period 0 19500
tinkerforge call servo-v2-bricklet $uid set-motion-configuration 0 500000 1000 1000 # Full velocity with slow ac-/deceleration
# Servo 2: Connected to port 5, period of 20ms, pulse width of 0.95 to 1.95ms
# and operating angle -90 to 90°
tinkerforge call servo-v2-bricklet $uid set-degree 5 -9000 9000
tinkerforge call servo-v2-bricklet $uid set-pulse-width 5 950 1950
tinkerforge call servo-v2-bricklet $uid set-period 5 20000
tinkerforge call servo-v2-bricklet $uid set-motion-configuration 5 500000 500000 500000 # Full velocity with full ac-/deceleration
tinkerforge call servo-v2-bricklet $uid set-position 0 10000 # Set to most right position
tinkerforge call servo-v2-bricklet $uid set-enable 0 true
tinkerforge call servo-v2-bricklet $uid set-position 5 -9000 # Set to most left position
tinkerforge call servo-v2-bricklet $uid set-enable 5 true
echo "Press key to exit"; read dummy
tinkerforge call servo-v2-bricklet $uid set-enable 0 false
tinkerforge call servo-v2-bricklet $uid set-enable 5 false
|
Possible exit codes for all tinkerforge
commands are:
argparse
module is missingEvery 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.
The common options of the call
and dispatch
commands are documented
here. The specific command structure is shown below.
call
servo-v2-bricklet
[<option>..] <uid> <function> [<argument>..]¶Parameters: |
|
---|
The call
command is used to call a function of the Servo Bricklet 2.0. It can take several
options:
--help
shows help for the specific call
command and exits--list-functions
shows a list of known functions of the Servo Bricklet 2.0 and exitsdispatch
servo-v2-bricklet
[<option>..] <uid> <callback>¶Parameters: |
|
---|
The dispatch
command is used to dispatch a callback of the Servo Bricklet 2.0. It can
take several options:
--help
shows help for the specific dispatch
command and exits--list-callbacks
shows a list of known callbacks of the Servo Bricklet 2.0 and exitsservo-v2-bricklet
<uid> <function>
[<option>..] [<argument>..]¶Parameters: |
|
---|
The <function>
to be called can take different options depending of its
kind. All functions can take the following options:
--help
shows help for the specific function and exitsGetter functions can take the following options:
--execute <command>
shell command line to execute for each incoming
response (see section about output formatting
for details)Setter functions can take the following options:
--expect-response
requests response and waits for itThe --expect-response
option for setter functions allows to detect
timeouts and other error conditions calls of setters as well. The device will
then send a response for this purpose. If this option is not given for a
setter function then no response is sent and errors are silently ignored,
because they cannot be detected.
servo-v2-bricklet
<uid> <callback>
[<option>..]¶Parameters: |
|
---|
The <callback>
to be dispatched can take several options:
--help
shows help for the specific callback and exits--execute <command>
shell command line to execute for each incoming
response (see section about output formatting
for details)servo-v2-bricklet
<uid> get-status
¶Output: |
|
---|
Returns the status information of the Servo Bricklet 2.0.
The status includes
Please note that the position and the velocity is a snapshot of the current position and velocity of the servo in motion.
servo-v2-bricklet
<uid> set-enable
<servo-channel> <enable>¶Parameters: |
|
---|---|
Output: |
|
Enables a servo channel (0 to 9). If a servo is enabled, the configured position, velocity, acceleration, etc. are applied immediately.
servo-v2-bricklet
<uid> get-enabled
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns true if the specified servo channel is enabled, false otherwise.
servo-v2-bricklet
<uid> set-position
<servo-channel> <position>¶Parameters: |
|
---|---|
Output: |
|
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
.
servo-v2-bricklet
<uid> get-position
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the position of the specified servo channel as set by set-position
.
servo-v2-bricklet
<uid> get-current-position
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> get-current-velocity
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> set-motion-configuration
<servo-channel> <velocity> <acceleration> <deceleration>¶Parameters: |
|
---|---|
Output: |
|
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).
servo-v2-bricklet
<uid> get-motion-configuration
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the motion configuration as set by set-motion-configuration
.
servo-v2-bricklet
<uid> set-pulse-width
<servo-channel> <min> <max>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> get-pulse-width
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the minimum and maximum pulse width for the specified servo channel as set by
set-pulse-width
.
servo-v2-bricklet
<uid> set-degree
<servo-channel> <min> <max>¶Parameters: |
|
---|---|
Output: |
|
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:
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².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.
servo-v2-bricklet
<uid> get-degree
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the minimum and maximum degree for the specified servo channel as set by
set-degree
.
servo-v2-bricklet
<uid> set-period
<servo-channel> <period>¶Parameters: |
|
---|---|
Output: |
|
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).
servo-v2-bricklet
<uid> get-period
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the period for the specified servo channel as set by set-period
.
servo-v2-bricklet
<uid> get-servo-current
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the current consumption of the specified servo channel in mA.
servo-v2-bricklet
<uid> set-servo-current-configuration
<servo-channel> <averaging-duration>¶Parameters: |
|
---|---|
Output: |
|
Sets the averaging duration of the current measurement for the specified servo channel in ms.
servo-v2-bricklet
<uid> get-servo-current-configuration
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the servo current configuration for the specified servo channel as set
by set-servo-current-configuration
.
servo-v2-bricklet
<uid> set-input-voltage-configuration
<averaging-duration>¶Parameters: |
|
---|---|
Output: |
|
Sets the averaging duration of the input voltage measurement for the specified servo channel in ms.
servo-v2-bricklet
<uid> get-input-voltage-configuration
¶Output: |
|
---|
Returns the input voltage configuration as set by set-input-voltage-configuration
.
servo-v2-bricklet
<uid> get-overall-current
¶Output: |
|
---|
Returns the current consumption of all servos together in mA.
servo-v2-bricklet
<uid> get-input-voltage
¶Output: |
|
---|
Returns the input voltage in mV. The input voltage is given via the black power input connector on the Servo Brick.
servo-v2-bricklet
<uid> set-current-calibration
<offset>¶Parameters: |
|
---|---|
Output: |
|
Sets an offset value (in mA) for each channel.
Note: On delivery the Servo Bricklet 2.0 is already calibrated.
servo-v2-bricklet
<uid> get-current-calibration
¶Output: |
|
---|
Returns the current calibration as set by set-current-calibration
.
servo-v2-bricklet
<uid> get-spitfp-error-count
¶Output: |
|
---|
Returns the error count for the communication between Brick and Bricklet.
The errors are divided into
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.
servo-v2-bricklet
<uid> set-status-led-config
<config>¶Parameters: |
|
---|---|
Output: |
|
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 symbols are available for this function:
For <config>:
servo-v2-bricklet
<uid> get-status-led-config
¶Output: |
|
---|
Returns the configuration as set by set-status-led-config
The following symbols are available for this function:
For config:
servo-v2-bricklet
<uid> get-chip-temperature
¶Output: |
|
---|
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.
servo-v2-bricklet
<uid> reset
¶Output: |
|
---|
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!
servo-v2-bricklet
<uid> get-identity
¶Output: |
|
---|
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.
servo-v2-bricklet
<uid> set-position-reached-callback-configuration
<servo-channel> <enabled>¶Parameters: |
|
---|---|
Output: |
|
Enable/Disable position-reached
callback.
servo-v2-bricklet
<uid> get-position-reached-callback-configuration
<servo-channel>¶Parameters: |
|
---|---|
Output: |
|
Returns the callback configuration as set by
set-position-reached-callback-configuration
.
Callbacks can be used to receive time critical or recurring data from the device:
tinkerforge dispatch servo-v2-bricklet <uid> example
The available callbacks are described below.
Note
Using callbacks for recurring events is always preferred compared to using getters. It will use less USB bandwidth and the latency will be a lot better, since there is no round trip time.
servo-v2-bricklet
<uid> position-reached
¶Output: |
|
---|
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 parameters 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 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.
servo-v2-bricklet
<uid> set-bootloader-mode
<mode>¶Parameters: |
|
---|---|
Output: |
|
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 symbols are available for this function:
For <mode>:
For status:
servo-v2-bricklet
<uid> get-bootloader-mode
¶Output: |
|
---|
Returns the current bootloader mode, see set-bootloader-mode
.
The following symbols are available for this function:
For mode:
servo-v2-bricklet
<uid> set-write-firmware-pointer
<pointer>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> write-firmware
<data>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> write-uid
<uid>¶Parameters: |
|
---|---|
Output: |
|
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.
servo-v2-bricklet
<uid> read-uid
¶Output: |
|
---|
Returns the current UID as an integer. Encode as Base58 to get the usual string version.