How to control three servos connected to Maestro micro 6 servo controller from MATLAB

Dear all

I need to control three servos at a time from MATLAB, I have used the following code and read through some of related posts and I changed the settings as required but unfortunately, I was not successful.
s2 = serial(‘COM7’,…
‘Baudrate’,9600, …
‘DataBits’,8, …
‘Parity’,‘none’, …
‘InputBufferSize’,16384)
fopen(s2)
fwrite(s2,[132, 0, 112, 46],‘uint8’)
fclose(s2)

My questions as follows if somebody could kindly help me please.
1- Which servo the above code will deal with?
2- In my case, which I have three servos need to be controlled, so what do I need to add for the other two servo in MATLAB code.
3- Sometimes, I need to rotate the servo a specific angle e.g 45 degree, how I could do that please.

Many thanks in advance
Fawaz

Hello, Fawaz.

It sounds like you are not sure what the command you are sending is supposed to do. From the bytes in the command of the code you listed (132, 0, 112, 46), it looks like it is sending the Set Target command specified by the first byte (132, or 0x84 in hex). Details about this command can be found under the “Set Target (Pololu/Compact protocol)” heading of the “Serial Servo Commands” section of the Maestro controller’s user’s guide. From that information, you can see that the second byte (0) is specifying which servo channel to control, and the third and fourth bytes are specifying the target.

To send a Set Target command to a different servo channel, you can change the second byte in this command. For example, sending [132, 1, 112, 46] (or [0x84, 0x01, 0x70, 2E] in hex) will set the target of servo channel 2 to the same target value.

Alternatively, if you are using a Mini Maestro, you can use the Set Multiple Targets command (also described in the “Serial Servo Commands” section of the Maestro controller’s user’s guide), to simultaneously set the targets for a contiguous block of channels (e.g. servo channels 0-2).

As for commanding your servo to rotate to a specific angle, it will depend on your servo; some servos have datasheets that specify the range of travel over a specific pulse width range, but if you do not have a datasheet for your servo, you will likely need to test to see what pulse width values correspond to the motion you want. You might consider using the sliders in the “Status” tab of the Maestro Control Center software to help determine these values.

By the way, the Maestro’s serial mode is set to “UART, detect baud rate” by default. In this serial mode, the Maestro will only react to serial signals received through its TX and RX pins. Since you are trying to communicate with it over USB via the virtual COM port, you will need to change this setting to one of the two USB modes (USB Dual Port or USB Chained) for these commands to work if you have not done so already. This setting can be changed in the “Serial Settings” tab of the Maestro Control Center software.

Brandon

By the way, the Maestro’s serial mode is set to “UART, detect baud rate” by default. In this serial mode, the Maestro will only react to serial signals received through its TX and RX pins.

The confusing part was the maestro app says it’s in UART mode but it’s communicating over a USB port so not sure what that means. Changing to USB mode fixed it, but it was a pain to find this out.