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. 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
Servo(D0,54)
Servo(D2,50)
#'x up'
#return to previous postion
Servo(D0,$TiltPos)
Servo(D2,$PanPos)
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
Asked
— Edited
If holding a key down simply repeats the command then no loop would be needed, just a simple
orCode:
Code:
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.
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
What you need to do is write the scrips and have them loop around a ServoUp or ServoDown command...
Code:
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.