Hello,
i have a 8 Port mini servo controller, working in Pololu mode, connected to a USB to Serial converter. My system is Opensuse, i use C for developing the controller software.
Everything seems pretty fine so far, communication works properly and so on…
My only problem is:
I wrote a demo program which starts moving the servo at a value of 120…and then goes up to 160 (range is about 50 degrees), one step per second.
The servo seems to move fine so far…but if i send the values 139, 140, the servo moves one step backward instead of forward…at 141 and above…everything continues fine until the servo reaches position corresponding to value 160.
here is my code…i use 8 bit command, just read 120-160 for the “pos” variable.
int setpos8bit(struct sc *sc, char servo, unsigned int pos) {
unsigned char buf[6];
unsigned int temp;
unsigned char hi_byte;
unsigned char lo_byte;
temp = pos & 0x1f80;
hi_byte = temp>>7;
lo_byte = pos & 0x7f;
buf[0]=0x80;//start byte
buf[1]=0x01;//device id
buf[2]=0x03;//command number
buf[3]=servo;//servo number
buf[4]=hi_byte;//data1
buf[5]=lo_byte;//data2
printf("hi-byte: %X | lo-byte: %X\n",buf[4],buf[5]);
write(sc->fd,buf,6);
return 1;
}
this is just the command for transmitting data… i use a loop with 1 sec usleep in order to generate the values & send them via the setpos8bit function.
i initialize the serial interface via
int connect(struct sc *sc) {
struct termios options;
sc->connected=0; /* reset in case we fail to connect */
sc->fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
if (sc->fd == -1)
{
printf("unable to open /dev/ttyUSB0\n");
return 0;
}
else fcntl(sc->fd, F_SETFL, 0);
tcgetattr(sc->fd, &options);
/* go to 9600 baud */
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD); /* enable */
options.c_cflag &= ~PARENB; /* 8N1 */
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
/* set all of the options */
tcsetattr(sc->fd, TCSANOW, &options);
sc->connected=1;
return 1;
}
the strange thing is…if i try the same (increasing servo position step by step) using the absolute command…there is no problem! the servo moves straight from the beginning to the end.
i have tried several servos on different ports…the behaviour is just the same.
is it possible that this is a firmware bug in the servo controller?
thank you very much for help!
chris