8 servo controller + linux

I’m having a weird problem w/ the 8 servo controller.

I’m using a serial->usb converter which seems to be recognized by the system, as /dev/ttyUSB0 is created when you plug it in.

I’m running a test program that just opens the port, moves a servo, and closes the port. When I run the program, the yellow light will blink off, and then blink on again when the program is done running, but will not actually move the servo. The green light never comes on.

I’m using code from one of the example projects, and also from Adam(nexisnet). Here is my code:

    #include <stdio.h>   /* Standard input/output definitions */
    #include <string.h>  /* String function definitions */
    #include <unistd.h>  /* UNIX standard function definitions */
    #include <fcntl.h>   /* File control definitions */
    #include <errno.h>   /* Error number definitions */
    #include <termios.h> /* POSIX terminal control definitions */
#include <iostream>
using namespace std;
int open_port();
int put(int servo, int angle, int port);
int input;

int main() {

	struct termios options;

	int count,ret;



	int fd;

	fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);

	if (fd == -1) {
		cout<<"Failed to open device";
		return 0;
	}

	else 
		fcntl(fd, F_SETFL, 0);



	tcgetattr(fd, &options);


	cfsetospeed(&options, B9600);

	cfsetispeed(&options, B9600);

	options.c_oflag = 0;
	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(fd, TCSANOW, &options);

	int servo=7;
	int angle=3000;
	unsigned char buff[6];
	unsigned short int temp;
	unsigned char pos_hi,pos_low;
	temp=angle&0x1f80;
	pos_hi=temp>>7;
	pos_low=angle & 0x7f;
	buff[0]=0x80;//start byte
	buff[1]=0x01;//device id
	buff[2]=0x04;//command number
	buff[3]=servo;//servo number
	buff[4]=pos_hi;//data1
	buff[5]=pos_low;//data2
	int result=write(fd,&buff,6);
	cout<<endl<<"Result of write operation: "<<result<<endl;
	int closereturns = close(fd);
	cout<<"Result of port closing: "<<closereturns<<endl;
	return 0;
}

The code returns 6 at output, and 0 at port close… neither one is an error code. The output of the program is always the same… 6 - 0.

The weird thing is… the only time it HAS worked, was when it was plugged in through a non-powered USB hub. And it worked erratically then… it would move the servos into position, but would sometimes result in the red error light… i could run the same code 10 times and get about 3 different results…

I’m running ubuntu 7.1 gutsy.

Thanks,
Colin

Fixed the problem. Turns out it wasn’t linux, my code, or the converter. About 5 months ago I removed the metal plate on the outside of the serial port connector of the servo controller. For whatever reason it worked like this in windows, but not in linux.

I figured it out by touching a wire from where the metal connector would have been to the shielding of the serial cable. Et Voila!

I had recorded the output of the serial port w/ an ADC, however I don’t want anyone to waste anymore brain power on this than I did. I may have spent 12+ hours fooling w/ it this weekend. Theres a lot of unknown factors when you’re in a new operating system on a new machine.