Get position

Hello every one.
Not long ago i have bought Pololu’s 6 channels servo controller.
The controller works fine but when i looked in the documentation section i noticed the “Get position” ability.
1)i would like to make sure: this allows me to get the current position of the servo when not controlled by PC?
2)If so, i did not understand the way i should write the program…can i get an example somewhere?

Thanks a lot for helping, please let me know if this is not the correct place to write such a topic

**of course i didn’t inform you, i am using C# for the program

  1. Yes.
  2. To get the position of a channel on the Maestro from C#, you can use the “public void getVariables(out ServoStatus[] servos)” function of the Usc class. Look at the source code of UscCmd in the Pololu USB SDK for an example of how to read channel positions.

–David

Hello David, thanks for your response.
Each time I try to get the servo’s position when it’s disabled, I get zero as a result.
However, as long as the servo is locked on one target by the computer and is not physically changeable,
I have no problem getting the number representing the servo’s position.
Is there any way to get the servo’s position while its state is set to “disabled”?
Thanks in advance, Ori.

Hello,

Do you understand that servos do not provide a way to measure their actual position? The “position” value is just an indication of the signal that the Maestro is sending to the servo at a given time. To the Maestro, a position of 0 means that the servo is disabled. It does not keep track of any other position while the servo is off.

-Paul

didnt know that, thanks

this means that when my servo reach a position and then stop moving the value of position will be 0??
if i send an array of postions to the mastro to move an specific servo, would they move one after the other or is it going to be an overlaping or something crazy?

or just by comparing the target and the position will I know that the servo is not moving?

something like this:

if(servos[0].position == servos[0].target)
//servo is not moving and i have reached the target position.

Hello,

No, servos do not report any data at all back to the Maestro. So when the servo physically stops moving nothing will change on the Maestro. All servos channels are independent, so if you set the positions for a bunch of servos simultaneously, they will all start moving simultaneously, and they will reach their destinations at times that depend on their motors and gearing.

The position information in the Maestro is only an indication of the signal that the Maestro is currently sending, not of what the servo is actually doing. Now, if you change position slowly enough, you can be reasonable certain that the servo has had time to reach the indicated position - that is when it is useful to use the get_position command.

I highly recommend taking a look at Jan’s blog, which has an in-depth series of articles on servos that should clear some of this up.

-Paul

Great blog. thanks.

What I really want to achieve is to move a series of servos in an specific way. Let me explain more in deep.

I have 3 servos that move an aluminum segment, and each servo is placed at the end of the segment, so moving servo1 will cause the segment 1 to displace the segment 2 and the servos that are placed on those segments, like this:

Sv1 = servo1
Sv2 = servo2
Sv3 = servo3

Seg1 = Segment1 (30 cms of alluminium)
Seg2 = Segment2 (30 cms of alluminium)
Seg3 = Segment3 (30 cms of alluminium)

Sv3 ------------------- Object
------------------- Sv2
Sv1 -------------------

Is like a robotic arm or an extension. Sv1 will move the 3 segments and Sv2 will move only the 2 segments above, the Sv3 will only move the last segment. by moving the servos we can extend the arm to reach some point (height), after an analysis made by someone else, he recommend that the servos should move in stages, not just moving the servo to the needed position, so if we need to extend the arm 46 cms we need to past through 2 stages, first move Sv1 13°, Sv2 46° and Sv3 0°, second move Sv1 24°, Sv2 15° and Sv3 14°. The analyst said that if we don’t move this way the forces in the segments could damage the servos or something like that.

So, since I need to move the servos in this way, I was thinking to wait for some time before sending the next position to the servos, to make sure they had arrived to the previous target. Something like this (values are not accurate, they are just to represent that the servo will move to some position):

usc.setTarget(0,1000);
usc.setTarget(1,1250);
usc.setTarget(2,0);
Sleep(2000);//Sleep 2secs
usc.setTarget(0,2500);
usc.setTarget(1,3050);
usc.setTarget(2,1570);

Then I found that the ServoStatus class provides the Position and the Target of the servos, now things change and I can create a more elaborated work. Something like this:

ServoStatus[] servos;
           using (var usc = new Usc(deviceList[0]))
                {
                    for (int stage = 0; stage < 2; stage++)//move through stages
                    {
                        usc.getVariables(out servos);
                        var targets = GetTargets(stage);//this method calculates the target using the stage

                        while (servos[0].position != servos[0].target)
                            Sleep(someTime);//or maybe just do nothing
                        usc.setTarget(0, targets[0]);// command the servo to move target 1

                        while (servos[1].position != servos[1].target)
                            Sleep(someTime);
                        usc.setTarget(1, targets[1]);

                        while (servos[2].position != servos[2].target)
                            Sleep(someTime);
                        usc.setTarget(2, targets[2]);
                    }
                }

what is the best way to solve this?? any ideas?