RIG InMoov Project
|
#include <Servo.h>
#include "settings.h"
#include <stdint.h>
Go to the source code of this file.
Enumerations | |
enum | { MIN_LIM = 0, MAX_LIM = 1, CANCEL_SIGNAL = 255, WAIT_RESPONSE = 254, DUMP_SIGNAL = 253, START_RESPONSE = 252, END_RESPONSE = 251, DUMP_RESPONSE_LEN = SERVOS * 2 + 4 } |
Functions | |
void | setup () |
void | loop () |
void | serialPrint (const char *s) |
void | serialPrintInt (uint8_t i) |
void | serialPrintIntPretty (const char *pre, uint8_t i, const char *post) |
int | serialGetByte () |
void | setServoFromIndex (uint8_t servo_index, uint8_t servo_angle) |
void | setServoFromID (int servo_id, uint8_t servo_angle) |
void | dump () |
void | serialWait () |
Variables | |
Servo | servo [SERVOS] |
uint8_t | current_pos [SERVOS] = { 0 } |
char | buf [BUFSIZE] |
The print buffer. | |
This is the common code for all Arduino servo boards.
The program is written to be a simple module that can pass values to servos. Each board needs its own settings file. Because of limitations of the Arduino command line interface, these are included as settings.h. The Makefile manages which configuration is currently located in the same directory as this file and named settings.h. A better build system in the future could use the tools avrdude or ino. Other Arduino boards in the project, such as flex sensor boards, use an identical folder structure and include process.
See rhand.h for an example of a settings header, and Arduino Protocol for information servo IDs and other relevant values.
Definition in file servo.ino.
anonymous enum |
void dump | ( | ) |
Writes various information about the board to the serial port. Triggered on reception of DUMP_SIGNAL. Transmits the ID of the board, the number of servos, each servo ID, and the current position of the servos.
void loop | ( | ) |
The loop function is called continually until the program exits. It performs actions based on Arduino Protocol. Recieves two unsigned 8-bit integers, a servo id and a servo angle, then calls setServoFromID(). If the DUMP_SIGNAL is recieved at any time, calls dump() and continues. If the CANCEL_SIGNAL is recieved, it does nothing and continues. If, at the beginning of the function, there is no pending input, it transmits WAIT_RESPONSE, then does nothing until input is available.
int serialGetByte | ( | ) |
Retrieves a byte from the serial port.
void serialPrint | ( | const char * | s | ) |
void serialPrintInt | ( | uint8_t | i | ) |
void serialPrintIntPretty | ( | const char * | pre, |
uint8_t | i, | ||
const char * | post | ||
) |
void serialWait | ( | ) |
void setServoFromID | ( | int | servo_id, |
uint8_t | servo_angle | ||
) |
Writes an angle to a pin associated with a servo ID.
void setServoFromIndex | ( | uint8_t | servo_index, |
uint8_t | servo_angle | ||
) |
Writes an angle to a pin associated with a servo index. Servos are controlled by sending varying pulse widths over their signal wire. The adjusted angle will be sent to the servo. Updates current_pos with the non-adjusted angle. If the servo index is invalid, the function does nothing and exits, but if the angle is out of range, it is changed to a valid value.
servo_index | The servo to write to. |
servo_angle | The angle to write after adjusting. It may be reversed. |
void setup | ( | ) |
uint8_t current_pos[SERVOS] = { 0 } |
The current position of each servo. These are updated whenever a servos value is changed and retrieved upon DUMP_SIGNAL.
Servo servo[SERVOS] |
The representation of the servos. Used to keep track of pin assignments and send output.