Servo controller and Raspberry Pi

Hi,

I have a Raspberry Pi ( Rasbin Wheazy ) and would like to use it with my servo controller ( Mini Maestro 18 ).

  1. Is it possible using USB
  2. What software/drivers do I need
  3. Is there any sample program code I could look at

any info would be great.

Thanx Leo

Hello, Leo.

Yes, you can control the Maestro over USB from a Raspberry Pi and several people have done it before. There are two main ways to do this: you can use the Maestro’s native USB interface or you can use the virtual serial port. You can find more information and example code in Maestro User’s Guide. The relevant sections are named “Writing PC Software to Control the Maestro” and “Related Resources”.

–David

I’ve done exactly that! Except with a Micro Maestro. It works great.
I control it using the virtual serial port.
Here’s some code:

int fd = -1;


bool open_servos(char const *n) {
    fd = open(n, O_RDWR, 0600);
    if (fd < 0) {
        perror("open");
        return false;
    }
    struct termios tio;
    if (tcgetattr(fd, &tio) < 0) {
        perror("tcgetattr");
        return false;
    }
    cfmakeraw(&tio);
    cfsetspeed(&tio, B9600);
    if (tcsetattr(fd, TCSAFLUSH, &tio) < 0) {
        perror("tcsetattr");
        return false;
    }
    return true;
}


void update(double d, unsigned char *b) {
    if (d < -1) { d = -1; }
    if (d > 1) { d = 1; }
    unsigned short t = (unsigned short)((1500 + d * 500) * 4);
    if (t > 16363) {
        fprintf(stderr, "rmaestro: steer %f generates value %d which is too big\n", d, t);
        return;
    }
    b[0] = (unsigned char)(t & 0x7f);
    b[1] = (unsigned char)((t >> 7) & 0x7f);
}


void write_servos() {
    unsigned char cmds[16] = {
        0x84, 0x00, 0x00, 0x00,
        0x84, 0x01, 0x00, 0x00,
        0x84, 0x02, 0x00, 0x00,
        0x84, 0x03, 0x00, 0x00,
    };
    update(fr + d_fr, &cmds[2]);
    update(fl + d_fl, &cmds[6]);
    update(rr + d_rr, &cmds[10]);
    update(rl + d_rl, &cmds[14]);
    int w = write(fd, cmds, 16);
    if (w != 16) {
        perror("write");
        fprintf(stderr, "rmaestro: short write: %d/16\n", w);
        exit(1);
    }
}

The “fr + d_fr” calculate the steering I want for each of the four channels I use, between -1 and 1.
You can change it to whatever you need.