Asked — Edited

Keyboard Control Questions.

Hey everybody,

I have my cameras pan and tilt servos set to be controlled by 'w,a,s,d' and I have 'x' set to a "snap to" position and then return to the previous position on release of the 'x' key. I started doing some trouble shooting with the 'w' key. I've put my code below. I've described my problem beneath the code.

#'w down'
#get original servo position
$preTiltPos = GetServo(D0)

#Printing for test purposes
Print("PreTilt = $preTiltPos")

#Move servo
Move (D0,reverse)

#get current servo position
$postTiltPos = GetServo(D0) 
#print new servo position
Print("PostTilt = $postTiltPos")

#'x down'
#get current servo positions
$PanPos = GetServo(D2)
$TiltPos = GetServo(D0)

#set servos to desired positions

#'x up'
#return to previous postion

The problem seems to be that when I use a keyboard command it registers the positions as either 1 or 100. The function works if I move the camera servos with any of the control panels because they are reporting their positions accurately.

Why do the servos throw these signals when I use the keyboard controls? Is it because I'm using 'Move'? I can see how that may be the problem. I want the servo to move as long as I'm pressing the key. I don't want to have to use multiple 'taps'. I like the analogue feel. How can I do this without using 'Move'? Some sort of loop with ServoUp, ServoDown?

Thanks in advance

Skip to comments


Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

United Kingdom

I haven't tested it but I would assume a ServoUp and ServoDown would be the way to go.

If holding a key down simply repeats the command then no loop would be needed, just a simple




But I'm not sure how keyboard control works since I haven't used it much.

Also, and you may have already done it but set your servo positions in an init script otherwise the first time it runs it wont know where the servos are.


Thanks for the tip Rich. Up and Down do require multiple strokes per increment:( I tried it first then went to move. It isn't having problems reading the positions, it reads whatever is in my servo panel. The problem seems to be that Move sends either 1 or 100. I just got home but, I'll play with it later (if not tomorrow) and see what I come up with. I have some ideas. I'm still open to suggestions though;) I'll post my results when I get them.

United Kingdom

Move isn't the correct command since it's for modified servos not standard servos. Which is why it's either 1 or 100.

What you need to do is write the scrips and have them loop around a ServoUp or ServoDown command...


So you have that in your script manager. Then you use the keyboard control and set the On Key Down command as a ControlCommand() to start the above script. While you hold down the key it will loop.

To stop it on release, you need another ControlCommand() on the On Key Up command, to stop the script.

Hopefully that makes sense, if not I'll try and explain better.


Nope, makes perfect sense. Thanks, I haven't gotten to the ezb yet. Later today:) I'll let you know how it went. Thanks again Rich!


Quick update, using loops like suggested now and it works, kinda. There seems to be a delay using the ControlCommand() for some reason. I'll try putting the code in spot where I'm calling the functions and see if that helps. If not I may go back to Move() and then ServoDown/Up(Dx,1) to see if that will trick it into reading something besides 1 & 100. (I have IFs preventing them from over exerting or hitting a part of the body) This guy's short lived anyway but I'd still like to crack this for future use. Thanks again for your help @Rich:)