6 Channel maestro with openFrameWorks

Hello everyone,

A few months ago i purchased the 6 Channel Maestro, I started programming with Visual Basic and i succeeded in building a pretty neat movement sequencer based on timers with even intervals. The problem with VB was that it did not support the graphics (which are supposed to be synchronised with servo movements) i needed. I was using VB in combination with Flash and encoutered severe problems when it comes to the difference of timer resolution from both platforms.

So i started over with openFrameWorks which has a serial library and a LOT of graphic abillities. This is the script i am using (i ripped the numbers from https://www.pololu.com/docs/0J40/5.h.1).

.cpp

maestrodevice.listDevices();
vector <ofSerialDeviceInfo> deviceList = maestrodevice.getDeviceList();


maestrodevice.setup("COM3",9600);

maestrodevice.writeByte(0xAA);
maestrodevice.writeByte(0x0C);
maestrodevice.writeByte(0x04);
maestrodevice.writeByte(0x00);
maestrodevice.writeByte(0x20);
maestrodevice.writeByte(0x1F);

Only useful declaration in .h

ofSerial maestrodevice;

Thats for introduction; this actually sets the servo target and it worked.Though i have the following questions.

  • Maestro control center gives me the following error: Serial protocol error 0x0010. What is the cause of this error?

  • Do i need to close the serial connection for every set of bytes i wrote to the Maestro?

  • What command is meant for disabling the given channel? Im working with ‘hacked’ servos, the mechanical stops have been removed and instead of a potentiometer i soldered in two resistors. I suppose there is a command for disableing the channel, it works more accurate for me.

And off-topic (i guess); does the use of hacked servo’s cause any threat to the Maestro itself?

Greetings and thanks in advance, Tom
and oh yeah, my technical-english might be a little bit off.

In addition to my post: i’am using the ofSerial instead of Usc.dll because of linking problems within my script. I do not have any clue how i should use Usc.dll in my script. Also, I guess direct serial commands will work a bit faster than using a lot of additional linking?

Hello,

If you want our help finding the source of the error, please simplify your code to the simplest possible thing that demonstrates the problem and post your complete code. For example, if you do not send any command, do you still get an error?

You should not ever need to close the serial connection, and a hacked servo should not be dangerous for your Maestro.

-Paul

Alright, today the code is working without errors :/.
But my question about disabling a channel remains, these are the bytes from the polulu documentation:

0xAA //start byte
0x0C //device id 12
0x04 //command settarget
0x00 //channelset 0
0x20 //settarget value 1000
0x1F //endbyte?

I guessed that when i changed the third one into 0x00 the channel would be disabled. Thats when i get an error. Also i tried to change settarget value into 0x00 which results in an error and a target like 960.

Any idea which byte(s) should be changed in order to stop the servo connected to channel 0?

Hello,

Sorry I forgot to answer that question! You set the position to zero for off, but it sounds like you do not understand the Set Target command. Please take a look at the documentation for that command, which has an example totally written out. The last two bytes represent the position (0x1F*128+0x20 = 4000, which represents 1000 us). So, set both of those to zero, and you will turn the channel off.

If you set the third byte to zero, you get an error because you changed to a different, nonexistent command. (We do not have a command numbered zero because it would break the ability of the Maestro to be chained with devices using the older Pololu serial protocol that relies on byte 0x80.)

-Paul

Thanks alot Paul!

I guess i should have read a few pages further then the example script :blush: . I’m trying it out in the next half hour. And i hope i will be able to post some project results in a few days.

Greets

Of course the next problem rises;

How to split the binary in two even chunks and convert it to hexadecimal? Is there some standard function for this in c++?

Hello,

The documentation page I linked to earlier has example C code for computing the two bytes. Is that what you are looking for?

Your question makes me think that you have a fundamental misunderstanding about numbers and their representations in computer programs. Unless you are formatting numbers for human-readable output, they will (almost) always be stored as binary values. Your computer uses binary, the Maestro uses binary, and there is no need to convert to hexadecimal for them to communicate. In documentation and source code, we can write numbers a variety of different ways, using decimal, hexadecimal, binary, or even octal, but all the representations of a number refer to exactly the same data.

-Paul

True, im not understanding it.

Id like to increase the target by while it is turning. What im not understanding is how to increase those numbers when they are splitted in two bytes. Thanks anyway :slight_smile:

**Solved it with the SSC protocol though!

Hello,

What you need to do is increase the number before splitting it into two bytes. Just consider splitting it part of the process of sending it to the Maestro.

-Paul