RIG InMoov Project
Enumerations | Functions | Variables
servo.ino File Reference
#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.
 

Detailed Description

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.

Enumeration Type Documentation

anonymous enum
Enumerator
DUMP_RESPONSE_LEN 

The length of the response to the dump signal.

Definition at line 44 of file servo.ino.

Function Documentation

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.

See also
Arduino Protocol, START_RESPONSE, END_RESPONSE, current_pos, getServoIDFromIndex()

Definition at line 265 of file servo.ino.

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.

Definition at line 100 of file servo.ino.

int serialGetByte ( )

Retrieves a byte from the serial port.

Returns
If a normal value is recieved, returns that value as an integer. If CANCEL_SIGNAL is recieved, returns -1.

Definition at line 180 of file servo.ino.

void serialPrint ( const char *  s)

Prints a string to the serial port if VERBOSE is enabled.

Definition at line 142 of file servo.ino.

void serialPrintInt ( uint8_t  i)

Prints an integer to the serial port as a string if VERBOSE is enabled.

Definition at line 153 of file servo.ino.

void serialPrintIntPretty ( const char *  pre,
uint8_t  i,
const char *  post 
)

Prints an integer as a string surrounded by two strings to the serial port if VERBOSE is enabled.

Definition at line 165 of file servo.ino.

void serialWait ( )

Waits for serial input to become available then returns.

Definition at line 291 of file servo.ino.

void setServoFromID ( int  servo_id,
uint8_t  servo_angle 
)

Writes an angle to a pin associated with a servo ID.

See also
setServoFromIndex(), getServoIndexFromID()

Definition at line 244 of file servo.ino.

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.

Parameters
servo_indexThe servo to write to.
servo_angleThe angle to write after adjusting. It may be reversed.
See also
reverse

Definition at line 205 of file servo.ino.

void setup ( )

The setup function is called at the beginning of the program. In it, we assign a pin to each servo.

Definition at line 61 of file servo.ino.

Variable Documentation

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.

Definition at line 39 of file servo.ino.

Servo servo[SERVOS]

The representation of the servos. Used to keep track of pin assignments and send output.

See also
getServoIndexFromID(), Arduino

Definition at line 33 of file servo.ino.