I am driving this device (Pololu item #: 207) from a Linux system to control a standard, generic servo (also purchased from Pololu) using 8-bit Pololu mode. When I apply power to the board the servo jiggles momentarily and the yellow LED goes on. When I send a speed and position command the board/servo seems to go into one of two states:
- The servo moves about 90 degrees at full speed no matter what position or speed was specified and the yellow LED goes off momentarily and then back on. Sending the same commands again causes the servo to move about 90 degrees in the opposite direction. Subsequent commands have the same effect with the servo moving back and forth with each command set (speed and position). It stays in this state until power is removed from the board or the servo is unplugged.
OR
- The servo moves to the commanded position at the selected speed and the yellow LED goes off. Subsequent position and speed commands work correctly and all LEDs remain off. It stays in this state until power is removed from the board.
Which state the device goes into seems to be random, with state 1 occurring about 80% of the time and state 2 about 20%. It looks like it has something to do with a random state that the board and/or servo go into when power is first applied because the state doesn’t change until power is removed and then restored. I am driving the board via a USB to serial adapter into the RS-232 pins on the board. The board is being powered from the same 5v supply that is powering the servo with the power jumper in place.
I have also tried absolute positioning (command 4) and get similar results.
Any help would be appreciated.
Allen
Here is the C program I am using:
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <termios.h>
/* Main program. */
int main(int argc, char **argv)
{
int fd;
char data[6];
int set_bits = 4; /* bits to set DTR=0, RTS=1 */
int com_setspeed = 1; /* command to set servo speed */
int com_setpos = 3; /* command to set servo position */
int servono, pos, speed ;
if ( argc != 5 ) {
fprintf(stderr, "Usage: %s device servo-number position speed\n", argv[0]);
exit(1);
}
servono = atoi(argv[2]);
pos = atoi(argv[3]);
speed = atoi(argv[4]);
if ( servono < 0 || servono > 7 || pos < 20 || pos > 240 || speed > 127) {
fprintf(stderr, "Ranges: servo-number 0-7, position 20-240, seed 1-127\n");
exit(1);
}
if ((fd = open(argv[1], O_WRONLY | O_NOCTTY)) < 0) {
fprintf(stderr, "Can't open device %s\n", argv[1]);
exit(1);
}
ioctl(fd, TIOCMSET, &set_bits);
data[0] = 0x80; /* start */
data[1] = 0x1; /* device id */
data[2] = 0x1;
data[3] = servono; /* servo number */
data[4] = speed; /* servo speed */
write(fd, data, 5); /* write speed command to controller */
data[2] = 0x3; /* servo position command*/
if( pos > 127) {
data[4] = 1;
data[5] = pos - 128;
}
else {
data[4] = 0;
data[5] = pos;
}
write(fd, data, 6); /* write position command to controller */
close(fd);
exit(0);
}