Asked — Edited

Reading And Using Servo Values In Tracking

Hello,

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


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

#1  

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.

#2  

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

#3  

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

#4  

I totally understand. I dont know if it is possible in ARC 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.

#5  

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)

#6  

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

Thanks Alan

#7  

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

#8  

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 ARC or without using the Servo() command then this variable may be useless.

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

Hope this helps. ;)

#9  

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

PRO
Synthiam
#10  

You're over thinking how to do it :)

Simply enable and customize servo or movement tracking in the camera config dialogue. The work is already done for you, just turn it on and tweak the values. The learn section has an activity course. Press learn from the top menu of this website. There is a lesson which demonstrates how to make a robot move toward an object.

I'm on my phone at the moment, so unable to give you a direct link this time. But I know you've been there before because I have told you :). Navigate to the activities course through the learn section. You will find the lesson in there.

Also, each control has a ? (Question mark) next to the X (close). If you press it on the camera control, it will bring you to the help page for that control, which included written explanations of the control and tutorials.

#11  

Hi DJ,

Thanks for the reminder. My goal is to load x and y variables, to send the robot to a location. It will use the principles you are pointing me to in the camera tracking tutorial, but I want a voice command (example: go to the door) to load the x,y information. The robot will then go to that set of coordinates. I will mess with the camera tracking script and see which variables run the movement panel, so I can use that script location for the coordinates I want. The two cameras tell me where I am so I can compare to where I want to go. This will be my primitive navigation script.

I'm a slow learner but having fun.

Ron R

#12  

Lets see if I have this right. You have two cameras mounted at an initial position 90 degrees apart. You use the cameras to track the robot. As they track it, and move via servos to keep it in view, you use the amount of movement to determine the robot's position. Is that correct?

#13  

Hello WBS00001,

Yes, that is what I have so far. I haven't loaded this into my Adventure Bot yet because I stole the continuous servos, LOL. Once I build new servos, my next step is to load the program DJ reminded me of, and I will watch the variables it uses to load into the motion panel to make the robot track to a target. I will place a red ball, for now, on the top of the Bot and check to see if the tracking servos will gather the info correctly. Once I have these test done, I will see how to use the two sets of information to track to coordinates I load.

Just trying an idea.

Ron R

#14  

I had discussions with Dave C. and Dave S. about this type of idea in the past. Their thoughts were more complex. They are looking at a much more autonomous robot. My idea is simple, and with an ultra sound avoidance script, which overrides the direct line track if something gets in the way, may work.

My script ability is very, very minimal. I do have a concept in mind and will try to develop the needed software.

Ron R

#15  

The calculations would have to take into account the size of the robot or object from each camera image to be used to estimate the distance that the object is from the camera. From there, using the position that each servo is pointing to get the object centered in the camera view should allow you to get an idea of the location of the robot.

#16  

Hi Dave,

I am only looking at position for now. The area I want to track in is relatively small so the error of distance shouldn't screw it up to much for the test. Later maybe 3 ultra sonic pings and more math will have to be considered, especially when object avoidance is used.

Thanks,

Ron R

#17  

Ok, interesting method. I like it. Gets my gears turning. Just thinking out loud here but ... thinking about mounting both cameras on the robot and glyphs or solid color cards in the center of each of two adjoining walls . Could even be lights. Most cameras are sensitive to infrared so it could be invisible to boot.

When the robot wants to get a fix on it's coordinates it sets the cameras to 0,0 and each sweeps until it finds the objects on each wall. The distance it moves to find it would be related to where it is in the room. In the dead center of the room, it should find both objects at it's 0,0 initial point. That would also be a way to calibrate it. Mounting the cameras on the robot would also make it more autonomous and mean that all you need is to put cards, or whatever, in each room to be navigated. That, as opposed to a set of cameras in each room. Maybe different colors or glyphs for different rooms so it knows what room it is in.

Just a thought. Don't mean to impugn your strategy in any way or worm my way into your project. For all I know that has already been suggested to you and rejected for reasons of which I have not realized. :D

Anyway, good luck and if you need help with the scripting, let me know.

#18  

Hi WBS00001, Opinions and help is always accepted. Thank you.

@jstearns had built something like you mentioned in the past but, I don't know if he went any further with it. I hadn't seen him on the forum for quite a while.

I really don't want to use any external cards or markers. My final wish is an Infra red or other invisible beacon on the robot. The other issue is items in the room may block the targets on the walls. That is why I want the robot to be tracked. The cameras would be mounted where they would not be blocked tracking the robot. I am also waiting for the possibility of an ez robot wireless cameras once spoke of, coming out again. My plan is to mount cameras in the rooms I want to navigate. I would send the go-to coordinates to the robot to track to. I have an inexpensive wifi camera and I will try it once I get the initial testing done.

Between the Holidays, my R2D2 project and my poor servo-less Adventure Bot, it may be a while before this really gets going. The tests with the two servos works, so now I need to build the continuous servos for the Adventure Bot and try the tracking script Dj mentioned.

I will post my progress.

Ron R

#19  

I have returned to the correct posting for my idea for a very simple navigation script. I wanted to find out if I could look at the program for the camera tracking, but found it isn't a script, but a program.

I have written a conceptual script for moving and tracking to one coordinate. I tried to load it, but due to my lack of knowledge, I wasn't able to have it work or load. It is as follows:

GetDigital(D10) #Data, taken from tracking camera servo to show current location $doorxcoordinate #variable, input of location desired (desired track servo value) $minusdestination #variable, a minus value calculated from current location to desired location. Information determines travel direction and speed. $plusdestination #variable, a plus value calculated from current location to desired location. Information determines travel direction and speed. ClearVariables() #set all to 0

:loop

GetDigital(D10) # camera is mounted on servo D10 which is tracking the robot. Data is servo position value. ( this worked in a trial script)

GetAsByte($doorxcoordinate) # coordinate loaded from speech recognition. (this worked in a trial script)

if (GetDigital(D10) => $doorxcoordinate) # do math, equal more than goto (math1) Sleep(500)

if GetDigital(D10) <= $doorxcoordinate) #do math, equal less than goto (math2)
Sleep(500)

endif

math1: $plusdestination = (GetDigital(D10) - $doorxcoordinate #do math to find coordinate error on plus from location $minusdestination = $doorxcoordinate - (Getdigital (D10) #do math to find coordinate error on minus from location

if $plusdestination => 10 Forward, 200 # a near target value and speed

if $plusdestination =>1,<=9 forward, 50 # a near target value and speed

 if $plusdestination = 0, Stop # a target value and stop command

math2: # same description as math 1

if $minusdestination => 10 reverse, 200

if $minusdestination =>1,<=9 reverse, 50

if $minusdestination = 0, Stop

goto (loop)

I really want to continue this idea to see if it will work. Any advice would be appreciated. I want to keep this as simple as possible.

The first goal is to use Omni wheels on two continuous servos to track to locations in an Auto Position file. These files will be called on from speech recognition. The above is only 1/2 the needed script (X coordinate) for the testing. I will add the Y coordinate, if, and once this is working.

Ron R

#20  

@ANDY ROID can you please post using the proper UBB tags.... It's really hard to read your code in a plain post....

#21  

Hi Richard,

I never got it to load. Can I still copy if it has a bunch of syntax errors?

Ron R

#22  

GetDigital(D10) #Data, taken from tracking camera servo to show current location
$doorxcoordinate #variable, input of location desired (desired track servo value)
$minusdestination #variable, a minus value calculated from current location to desired location. Information determines travel direction and speed. 
$plusdestination #variable, a plus value calculated from current location to desired location. Information determines travel direction and speed. 
ClearVariables() #set all to 0

:loop

GetDigital(D10) # camera is mounted on servo D10 which is tracking the robot. Data is servo position value. ( this worked in a trial script)

GetAsByte($doorxcoordinate) # coordinate loaded from speech recognition. (this worked in a trial script)

if (GetDigital(D10) =&gt; $doorxcoordinate) # do math, equal more than
goto (math1)
 Sleep(500)

if GetDigital(D10) &lt;= $doorxcoordinate) #do math, equal less than 
 goto (math2) 
Sleep(500)

endif 

 math1: 
$plusdestination = (GetDigital(D10) - $doorxcoordinate #do math to find coordinate error on plus from location
$minusdestination = $doorxcoordinate - (Getdigital (D10) #do math to find coordinate error on minus from location

 if $plusdestination =&gt; 10 Forward, 200 # a near target value and speed

 if $plusdestination =&gt;1,&lt;=9 forward, 50 # a near target value and speed

 if $plusdestination = 0, Stop # a target value and stop command

math2: # same description as math 1

 if $minusdestination =&gt; 10 reverse, 200

 if $minusdestination =&gt;1,&lt;=9 reverse, 50

 if $minusdestination = 0, Stop

 goto (loop)

Ok I got it. I'm worst than Nomad sometimes..

#23  

For one thing you have to use a new line per command... a comma doesn't work for the next command... For example...


if($whatever&gt;10)
Reverse()
else
Forward()
endif

Quote:

Ok I got it. I'm worst than Nomad sometimes..
No your not... :)

#24  

I see I need to fix the command to set the servo for movement, forward, and set the speed which I didn't address in the script. I was more concerned about doing the math and proving it out.

#25  

I just got your reply. Do you see what I am trying to do and am I on the right track? I think, for a simple idea, it should work.

#26  

I have to go out now, but I will try to make it more basic and rewrite it. This way I will learn more and build an example to use.

Thanks for the reply

Nomad has been quiet lately... I wish him well !

Ron R

PRO
Synthiam
#27  

Sorry Andy, absolutely none of that code makes any sense.

  • IF conditions without closing ENDIFs

  • Comparing GetDigital() with integer values. As the manual states, GetDigital returns a True (1) or a False (0) only, because it is Digital. Read dictionary definition of the word Digital

  • Incorrect comparison used for Greater Than Equals, should be >= not =>

  • Random single line functions not assigned to variables (i.e. GetAsByte()). Also a bunch of variables with nothing being assigned specified on single lines.

  • ClearVariables() being used, which i don't know why that would ever be done outside of loading a new project because it clears every variable in the stack.

My advise is to visit the LEARN section and click on ACTIVITIES course. There are lessons which explain how to do basic tracking. Once you have successfully accomplished those activities, use the EXAMPLES folder in ARC to see examples of EZ-Script functions and how they work.

#28  

I will continue to work at learning more about scripting. Thanks for the constructive criticism.

Ron R

#29  

@ANDY ROID Approach ARC scripting like Lego... Get a small piece working then build from there... It's best to download other people's code or look at the built in examples in ARC....

For example


$plusdestination = GetDigital(D10)
if($plusdestination =1) #true
Reverse() #or whatever you want to do
else
Forward()
endif

#30  

Thanks Richard,

I had only wanted to post "CONCEPT" not real code. That is why I listed it in thread # 20 with labels, not using the UBB Code. Dj' s reply was code issues , not concept issues, so he replied firmly.

In the future I will build my ideas in code to the best of my ability. Your advice is well taken and I will do line by line testing of my script to be sure it works. I will then post the real scripting.

I still think my idea will do what I want.

More to come...LOL

Ron R

#31  

I got the test script working. I can load a verbal command (Goto A) which loads a coordinate. It runs the continuous servos until the camera servo value matches the coordinate.

My next problem is getting better vision/tracking. I was using a web cam, but now I think I will need to, at minimum, use the "old" Ez robot camera. I think Dj said it was better than a web cam, but not as good as the new release one. I am hoping a wireless unit once spoke of comes out soon. Otherwise I will have to buy a new one or any suggestions?

What has been found to be the best color to use for tracking? Can I use a light beacon? Any suggestions. I was thinking a maybe white because it is neutral?

I am getting closer to a full trial.

Ron R

#32  

This is the Test script. It is not fully completed but it worked for testing. I am aware it needs additional work. Posted for @castlephelps.

#Navigation Test Code 1-4-2016

# $xcoordinate is loaded from speech recognition robot go to door or robot go home


:loop

$apos = GetServo(D10)
 
if ($apos &gt;= $xcoordinate)
goto(math1)
endif 
sleep (500)

if($apos &lt;= $xcoordinate)    # for reverse test

endif 
sleep (500)



:math1
$plusdestination = ($apos - $xcoordinate)
if ($plusdestination &gt;= 0+1)
Servo(d0,119)
Servo(d1,99)
endif
if ($plusdestination = 0)
Servo (d0,109)
Servo(d1,109)
 endif 
:math2
$minusdestination = ($apos - $xcoordinate)
if ($minusdestination &lt;= 0-1)
Servo(d0,99)
Servo(d1,119)
endif
if ($minusdestination = 0)
Servo (d0,109)
Servo(d1,109)
 endif 
  
 Goto(loop)

I will be labeling the lines soon.

Ron R

#33  

I forgot to mention these are continuous servos, D0 and D1. D0 values: forward =119, stop=109. D1 values forward=99, stop=109. The camera servo is D10.

@castlephelps Maybe you could load locations? instead of numbers?

Ron R

#34  

I just want to bump the camera question from #32. I am wanting to use a reliable target or beacon. I want to determine if an onboard lamp is beter than a plain target. Lighting in the room will vary. Is Lidar the way to go?

Ron R