loading
 
Spark_Fun Mega Pan/Tilt camera: Pan going in wrong direction!
techdetect from United States  [27 posts]
5 years
I am trying to use the Sparkfun Arduino mega as downloaded from Roborealm website.  I believe the VBscript code i am using is the issue.  I am totally new to this and only wanted to do this as a hobby.  I have everything working fine, very fast and stable movement but when I move left the pan moves right, move right the pan moves left.  What can i do,  I tried to put a "-" on the pan variable but that don't work.  Again i have no coding exp. but would love some help.  I added the files that i am using.  Many thanks in advance.
techdetect from United States  [27 posts] 5 years
Here is a picture of the VBscript,  the robo file is the exact same as on the roborealm website.

 
Anonymous 5 years
You can replace

SetVariable "servo_position_x", x

with


SetVariable "servo_position_x", 2000 - x

which is effectively using a negative sign but the "center" is 1000 and not 0.

Or you can also use

http://www.roborealm.com/help/Scale_Variable.php

which was created after that script was designed. Either technique will work fine.

STeven.

techdetect from United States  [27 posts] 5 years
Thanks Steve,  It did work.  Now all I have to do is get rid of the jitters when i attach my webcam to the homemade brackets my servos are attached to.  They seem to make the camera shake a little extra and the pan/tilt goes crazy.  I am wondering if purchasing the brackets would make the difference or if it is a power thing.  i don't think it is a powe issue because if i remove the camera and allow it to set stationary the tilt/pan works fine.  HMMM..  Is there a way to slow down the reaction to the object tracking so that the extra movement from the poorly built brackets don't hove such a profound effect.  Or am i going to be shopping for some brackets.  By the way, i am using two futaba S3003 hobby servos running directly from the arduino mega and USB from PC.  Again thanks for your response and the coaching.
Anonymous 5 years
Try removing the camera from the pan/tilt but keep it plugged into the PC. Often lower power USB can cause the behavior you are seeing. Removing the webcam would give the Arduino more power to work with and may be the reason the problem goes away.

If not you can slow down the changes by using the Filter_variable module. This will smooth the changes but will also make it much less reactive.

STeven.
MOHD ADAM from Malaysia  [19 posts] 5 years
Hi,

I try your code but error: division by zero

x=CInt((x/width)*2000-x)
Anonymous 5 years
Most likely that error is occurring since width is not set to anything. Be sure you have the line

width = GetVariable("IMAGE_WIDTH")

somewhere before that line.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index