Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Getting started - Maestro Micro 6 Servo Controller in Matlab

I’d like to use Matlab to do some simple control of a single servo via a Maestro Micro 6 Servo controller, but I’m having trouble getting started, and I’d be very grateful for some help.

I have a Power HB 3001HB servo connected to port 0 of a Maestro Micro 6 Servo Controller, which is connected to a USB port on a PC running Windows XP (SP3).

In device manager I can see the controller command port is COM4, and the controller TTL port is COM3.

If I use the Pololu Maestro Control Center GUI I can control the servo fine, and it responds to changes in target, speed and acceleration exactly as I’d expect. (mode = USB Dual Port mode, device number = 12, mini ssc offset = 0, timeout = 0)

If I change to Matlab though, I can’t get the servo to move at all. I’ve read about the three different serial modes, and different command protocols, and tried some of the sample code from the forum, but not had any luck getting it going.

Would you be able to suggest the simplest combination of serial mode and command protocol I should be using please? I just need to control the one servo, and be able to set the position, speed and acceleration.

This is some code I copied from a forum post, but couldn’t get to work. Perhaps, if you are able to suggest the best serial mode and command protocol to use, you could suggest how I might modify this code to get it going please?

function moveServo(s,x)
 
port = 'COM4';
 
ser1 = serial(port);
set(ser1, 'InputBufferSize', 2048);
set(ser1, 'BaudRate', 9600);
set(ser1, 'DataBits', 8);
set(ser1, 'Parity', 'none');
set(ser1, 'StopBits', 1);
 
fopen(ser1);
fwrite(ser1, [128, 1, 4, s, binvec2dec(bitget(x,8:13)), binvec2dec(bitget(x,1:7))]);
 
fclose(ser1);
delete(ser1);
 
end

Any help would be very gratefully received!!

Hello.

You should be able to use USB Dual Port mode and the compact protocol. It looks like you probably copied some code for controlling one of our old servo controllers that is not a Maestro. If you look carefully in the Maestro user’s guide you will find that there is no serial command that starts with 128 (0x80). I recommend reading the user’s guide to find out exactly what bytes you need to send, and also checking out this post I made about Matlab.

–David

It moves!! I swapped the command code sequence for one in your previous post beginning 132 and it works fine.

Many thanks for your help David!

Andy