I’m having some trouble with my usb 16 servo controller. When I send a command, the yellow LED goes out, but nothing else happens. I don’t have a servo hooked in, but I’m trying to get it to blink out the current number of servos.
I’m running on Mac OSX.
Here’s my code:
#include <iostream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <cmath>
#include <math.h>
#include <time.h>
int fdIMU_;
/******************************************************************************
*
*****************************************************************************/
bool connect() {
struct termios term_info;
fdIMU_ = open("/dev/cu.Pololu", O_RDWR | O_NOCTTY);
if(fdIMU_ < 0) {
perror(NULL);
return false;
} else fcntl(fdIMU_, F_SETFL, 0);
if (tcgetattr(fdIMU_,&term_info) < 0){
return false;
}
cfmakeraw(&term_info);
if(tcsetattr(fdIMU_,TCSAFLUSH,&term_info) < 0){
return false;
}
if(cfsetospeed(&term_info, B9600) &&
cfsetispeed(&term_info, B9600)) {
return false;
}
term_info.c_cflag |= (CLOCAL | CREAD); /* enable */
term_info.c_cflag &= ~PARENB;
term_info.c_cflag &= ~CSTOPB;
term_info.c_cflag &= ~CSIZE;
term_info.c_cflag |= CS8;
if(tcsetattr(fdIMU_,TCSANOW,&term_info) < 0){
return false;
}
printf("Set attr\n");
return true;
}
/******************************************************************************
*
*****************************************************************************/
bool disconnect() {
close(fdIMU_);
return true;
}
/******************************************************************************
*
*****************************************************************************/
bool moveServo() {
std::cout << "Attempting to send...";
//static const unsigned char cmd[] = {0x80,0x01,0x01,0x00,0x40};
static const unsigned char cmd[] = {0x80,0x02,0x08};
//static const uint8_t cmd[] = {0x80, 0x01, 0x02, 0x00, 0xFE};
ssize_t bytesWrote = write(fdIMU_, cmd, 3);
if(bytesWrote < 0) {
perror(NULL);
printf("Bytes wrote: %d\n", bytesWrote);
printf("Errno: %d\n", errno);
return false;
}
return true;
}
int main (int argc, char * const argv[]) {
printf("Time to work\n");
connect();
moveServo();
printf("Done.\n");
return 0;
}