RIG InMoov Project
|
Documentation for the servo_demo.py script. More...
Functions | |
def | connect (port) |
Sets the global ser variable. More... | |
def | sweep (initial, servos, starts, ends, steps) |
Produces complex command chains. More... | |
def | unsweep (servos, ends, steps) |
Produces a command chain that resets all servos to 0. More... | |
def | servowrite (commands, delay) |
Writes commands to the serial port. More... | |
def | gesture (initial, servos, starts, ends, steps, delay) |
Sets the servos to a position, waits for input, then resets them to 0. More... | |
def | reset () |
Immediately sets the servos to 0. More... | |
def | cmd () |
Sends the input to the serial port until a blank line is given. More... | |
def | dump (servos=6) |
Retrieves information about the board. More... | |
def | peace (delay=0) |
Makes a peace sign. More... | |
def | ok (delay=0.01) |
Makes an ok sign. More... | |
def | grab (delay=0.02) |
Makes a fist. More... | |
def | rockon (delay=0.01) |
Makes a rock on sign. More... | |
def | wiggle (n=90, delay=0.01, wiggles=1) |
Wiggles the fingers. More... | |
def | count () |
Counts to 5 on the fingers. More... | |
def | demo () |
Performs all movements. More... | |
def | getarrow () |
def | calibrate (s=1) |
Calibrate a servo. More... | |
def | calibrate_all () |
Variables | |
int | CANCEL_SIGNAL = 255 |
int | DUMP_SIGNAL = 253 |
int | START_RESPONSE = 252 |
int | END_RESPONSE = 251 |
int | RHAND_ID = 181 |
The identification byte of the right hand board. | |
ser = serial.Serial() | |
The serial connection for input and output. More... | |
Documentation for the servo_demo.py script.
An example script for controlling the right hand. This script can also be used to calibrate the bot. Please see connect, cmd, and calibrate. This script requires python with a library called pyserial. After instally python 3, pyserial can be installed by calling
Or through your package manager. Example:
Once you have the library installed, you must have your PYTHONPATH variable set to the location of the library.
Replace 2.7 with your version of python (type in /usr/lib/python and press tab once or twice).
This may vary from system to system. See the python and pyserial websites for help.
To run the script, execute
or in python
This will allow you to call the functions from a command interpreter. It is recommended you experiment with all functions and view the source to understand how you might produce commands. Also try demo() while connected.
The movements included are quickly written and for demo purposes only.
def servo_demo.calibrate | ( | s = 1 | ) |
Calibrate a servo.
Takes one argument, which is the id of a server. Introduction has the servo codes.
Use the left and right arrow keys to adjust the value of the servo. Use any other key to exit.
Enter the maximum values into the limit array in your settings file.
Note that if a servo isn't moving the correct way, for example if a finger isn't flat at 0 and curved at 180, you must set reverse to 1 at the servo index.
Definition at line 375 of file servo_demo.py.
def servo_demo.cmd | ( | ) |
Sends the input to the serial port until a blank line is given.
Must enter integers between 0-255.
Definition at line 229 of file servo_demo.py.
def servo_demo.connect | ( | port | ) |
Sets the global ser variable.
Call this to connect to the board.
Replace /dev/ttyUSB0 with the name of the port your board is connected to. Usually this is /dev/ttyUSB* for the arduino nano or /dev/ttyACM* for the arduino uno. This is the same port used in Installation.
Note that you must be part of the dialout group in Linux. Enter this command to add yourself to a group.
You must logout to apply group changes. If you cannot logout, you can run the script as root.
Definition at line 72 of file servo_demo.py.
def servo_demo.count | ( | ) |
def servo_demo.demo | ( | ) |
Performs all movements.
Definition at line 329 of file servo_demo.py.
def servo_demo.dump | ( | servos = 6 | ) |
Retrieves information about the board.
The command sends the DUMP_SIGNAL to the serial port and reads back the response. The response is described in servo.ino.
When you write your own similar function, timing is important.
We may need to increase the response delay on the Arduino if you are unable to recieve a response. View the source of this function to understand how it works, but keep in mind it is untested. Also keep in mind that the function is very non-general as it always reads the same amount of bytes instead of looking for the end signal.
Definition at line 241 of file servo_demo.py.
def servo_demo.gesture | ( | initial, | |
servos, | |||
starts, | |||
ends, | |||
steps, | |||
delay | |||
) |
Sets the servos to a position, waits for input, then resets them to 0.
Definition at line 212 of file servo_demo.py.
def servo_demo.grab | ( | delay = 0.02 | ) |
def servo_demo.ok | ( | delay = 0.01 | ) |
def servo_demo.peace | ( | delay = 0 | ) |
def servo_demo.reset | ( | ) |
Immediately sets the servos to 0.
Definition at line 225 of file servo_demo.py.
def servo_demo.rockon | ( | delay = 0.01 | ) |
def servo_demo.servowrite | ( | commands, | |
delay | |||
) |
Writes commands to the serial port.
If delay is 0, immediately writes a list of ints to ser as bytes. Otherwise, writes a list of ints to ser as bytes one at a time.
Inserting a delay controls the speed of the movements.
Definition at line 195 of file servo_demo.py.
def servo_demo.sweep | ( | initial, | |
servos, | |||
starts, | |||
ends, | |||
steps | |||
) |
Produces complex command chains.
The output returned from the function is formatted in such a way that the commands can be transmitted to the serial port at variable speeds.
The parameters must all be lists of the same length whose indexes correspond with servos.
initial | An array of initial commands to append to. |
servos | The servos to control. |
starts | The current positions of the servos. |
ends | The desired end positions. |
steps | The values to use to decrement/increment. Converted to absolute value. |
Definition at line 103 of file servo_demo.py.
def servo_demo.unsweep | ( | servos, | |
ends, | |||
steps | |||
) |
Produces a command chain that resets all servos to 0.
Definition at line 187 of file servo_demo.py.
def servo_demo.wiggle | ( | n = 90 , |
|
delay = 0.01 , |
|||
wiggles = 1 |
|||
) |
servo_demo.ser = serial.Serial() |
The serial connection for input and output.
Must be initialized.
Definition at line 70 of file servo_demo.py.