Reading And Using Servo Values In Tracking



I have two cameras mounted on servos. They are set it up in tracking color mode (red). I have an 10 foot square area. The cameras are mounted in two locations (5 feet from a corner), 90 degrees from each other, against the outside wall . While tracking, I want to read the values the servos are at, and display the value. I know I can only read the information sent, not the true value.

I want to take these values and compare them to a preset value or coordinates.

My end goal is to track a Movement Panel to these two values.

My scripting skills are minimal to say the least, but can someone point me in a direction to find examples of these concepts?

I search around and know the "servo read" is somewhere, but I can't remember where.

Rich, Dave and Richard R, posted some information about this. Any ideas?

Ron R


Normally you can't query the location that a servo is at. You would have to do this in one of three ways that I can think of.

1. Take the servo apart and attach wire leads to the pot that is in the servo. These leads would connect to an analog port on the ezb. I haven't done it this way but you should be able to read the location of the pot. The concern would be that the power or volts going to the ezb from the servo would be too high and cause damage. I dink know.

2. Use a script for your movement of the camera and set a variable for where you told the servo to stop

3. Use an arduino or pic to drive the motor in the servo and read the pot to know when to stop. Serial commands can be used to query the location of the pot, which would cause the arduino or pic to read the location of the pot. This is the far more difficult approach but the one that offers the most options. This is the path that I choose to go down.

Someone else might have some other suggestions that would be easier to impliment.


Hello Dave,
I really want to stay on the simpler side. I want to read the value I.e. 0 to 180 degrees or the numeric values being sent to the servo by the ezb.

Ron R


Your number 2 answer is the way I want to go for now. My future idea will be to get actual feedback from another ezb.

We had a discussion about a similar concept in the past. This test is a very simple idea I want to try. I have the hardware, but need to learn more about the scripting to make it work.

Ron R


I totally understand. I dont know if it is possible in EZ-Builder to catch the locations being set to the servos from the tracking piece of the camera control. If it isnt being set to variables from the control, you would probably not be able to get it. DJ would have to make a code change to make this happen for you I think. I think it could be done. To know where the servo is at though, you would need to query the pot. I dont think this is essential to what you are doing (querying the pot) as I think that it would probably be fine to just know where the servo was told to go last instead of a "Where am I now" type of query.


The script command you are looking for is GetServo(port)

From the script manual:


GetServo( Port )
#Returns the last specified Servo Position value of the servo port.
#Servo position is between 1 and 180
#Example: $x = GetServo(d0)


There you go Smile. I haven't been scripting much at all lately so I have become rusty on all of the commands.

Thanks Alan


Thanks Dave, Alan found what I am looking for. I warned everyone, Im not rusty, I am unknowing.. LOL .. With this information I can start playing around. My next step is to compare the servo value to a preset value and figure how to track to it. This way as I move it updates my current location by the servo/camera values, both in an x and y axis.

Any ideas will be appreciated.

Thanks Alan.. I knew it was somewhere.

Ron R


I'm pretty rusty Ron also but this may be what you're looking for. This is untested:


Servo( D1, 100 ) #moves servo attached to port D1 to position 100
Sleep( 500 ) #pause to move servo - value must be adjusted to your needs
$Servopostion = GetServo(D1) #sets the variable $Servopostion form servo command :GetServo"

You can now use the $Servopostion variable in your next script or command to reference where the servo attached to D1 should be. If that servo moves by some other means outside of EZ Builder or without using the Servo() command then this variable may be useless.

Also each time you move the servo using EZ Builder with the Servo() command you need to use the "$Servopostion = GetServo(D1)" again to get the new position.

Hope this helps. Winky


Has anyone ever made or have seen a script where you describe a set point and track to it? An example is to have a robot fetch an item on the floor, or get a ball.
Another idea is if I have a "green frog" seen in the camera, I want to track to it. (My real goal is to load two variables, an x and y, and go to that point).

I am able to read the servo values discussed above which tells me where I am, and updates every 500 ms.

Ron R