Getting the position

I found a few threads with similar subject, but I couldn’t find the answer I was looking for.

It isn’t hard to set the target of a channel with the Maestro SDK using VC++. But it seems impossible to me, to receive the position, when the given channel is used as an input.

I have tried a lot now, but nothing worked.
I found promising values in the ServoStatus structure, “position” and “target”. But i don’t know how to use them. I can’t set the channel and device.

ServoStatus status;
short pos = status.position;

Of course is ‘pos’ useless and btw ‘0’.

So, how do I recieve the position of a channel?

Hello.

UscCmd has an option for printing out the positions of the servos so you can look at its source code.

In general, if you want to get or send some information to the Maestro, you should call one of the instance methods available in the Usc class. If you are using Visual Studio and have a Usc object (which represents a connection to a Maestro), you can use the autocomplete feature to get a list of those methods: type the name of the object (e.g. ‘usc’), then type a period (or ‘->’ in VC++), and Visual Studio will show you all the methods and their documentation. In this case you want to use one of the overloads of the getVariables method.

I think with these tips you will be able to figure it out, but let me know if you want an actual code example.

Edit: I just realized you were using VC++. Are you comfortable with translating code from C# to VC++?

–David

Also, you should note that because of basic limitations of servos, this position variable reported by the Maestro may not be the actual position of your servo; it is just the width of the pulses that the Maestro is currently sending to the servo. Unless you have speed or acceleration limits enabled on a channel, getting the position over USB is not very useful because it will always just be whatever value was passed in the last setTarget command.

–David

I know, it’s just the target, not the actual position. But, as said, I want to use this for Inputs.

I tried finding the values using IntelliSense ( I guess that’s how it’s called ), but couldn’t find the right value.

Well, now I took a look at the C# source of the advanced example and found this:

ServoStatus[] servos;
usc.getVariables(out servos);
pos = servos[channel].position;

But I’m not comfortable with converting C# to VC++.

So, the first thing I had tried was

ServoStatus status;
device->getVariables( status );

This seemed to be the right way after having read what IntelliSense told me. But if that would have worked, I wouldn’t post my problem here :slight_smile:

The compiler claims, that I can’t convert ServoStatus to MaestroVariables. ( the argument of getVariables() ).

In C#, “ServoStatus[]” represents a managed array of ServoStatus structs. But you wrote “ServoStatus status;” which just represents one struct.

Try something like this, (I’m not totally confident in it):

cli::array<ServoStatus^>^ servos;
device->getVariables(servos);

You might need to remove the first caret character and you might need to do something special to pass in servos as a “out” parameter.

–David

Thanks a lot!

cli::array<ServoStatus>^ status;
device->getVariables( status );
return status[channel].position;

Works fine :smiley: