servos object is used to control a collection of Servo Boards.
servos can be used like a list.
To do something with the first Servo Board, you would use:
…because indexes are 0-based (counting starts from 0, not 1).
When you have more than one Servo Board connected to your kit they will be ordered based upon their serial number.
The SR Part Code of each detected motor board is also printed to the log when your robot starts. It will look something like this:
Found the following devices: - Servos: 0: Servo( serialnum = "SR0LG31" )
servos is actually a dictionary.
As a result, in
servos you can also use the SR Part Code of the Servo Board as a key.
For example, if you had a board that was labelled “SR0LG31”,
you could do this instead:
Setting servo positions
The position of servos can range from
# R.servos[SERVO_BOARD_ID][SERVO_NUMBER] = POS # set servo 1's position (on the first Servo Board connected, board 0) to 20 R.servos = 20 # Set servo 2's position (on the Servo Board with part code SRABC) to -55 R.servos["SRABC"] = -55
It is important that you use integers (whole numbers, such as
10 instead of
10.0) when specifying servo positions.
You can read the last value a servo was set to using similar code:
# get the last setting of the second servo on the first Servo Board lastSetting = R.servos
While it is possible to retrieve the last position a servo was set to, this does not guarantee that the servo is currently in that position.
The angle of an RC servo is controlled by the width of a pulse supplied to it periodically. There is no standard for the width of this pulse and there are differences between manufacturers as to what angle the servo will turn to for a given pulse width. To be able to handle the widest range of all servos our hardware outputs a very wide range of pulse widths which in some cases will force the servo to try and turn past its internal end-stops. You should experiment and find what the actual limit of your servos are (it almost certainly won’t be -100 and 100) and not drive them past that.