loading
 
Joystick => Servo controller
bigkahuna from United States  [14 posts]
15 year
Hi,
I'm new to RR and just started my 30 day demo.  Before buying RR one of the first things I want to try is controlling a servo with a joystick.  I plugged in my servo controller (a Parallax USB Servo Controller) and my joystick (a Logitech RumblePad II) and tested both appropriate RR Modules.  Happily, everything worked perfectly.  Now comes the hard part, I want to turn joystick input into servo motion.  Basically the input range for a joystick axis is 0 to 1000 and for the servo it is 128 (center) to 255 (end), so if I move the joystick to a value of 500, the servo should move to a value of 194.  How do I set this up in RR?  I'm guessing it has to be done through code some how, but what would the code look like?  I checked the tutorials and although the rocket launcher tutorial came close, I'm still a bit confused.
Anonymous 15 year
NCUI,

Its actually very similar to the red object tracking example.

You use the VBScript module and use the follow one line to create a variable that scales accordingly. Assume that you use the variable JOY_X to represent the joystick value. This has to be added into the right place in the joystick module first. Then add a VBScript module after that with

SetVariable "SERVO_VALUE", Cint((GetVariable("JOY_X") * 255)/1000)

which will scale the JOY_X value from 0 - 1000 to 0 - 255 meant for the servo. After this module add the Parallax module and use the variable SERVO_VALUE (that's what you just created in the VB module) as the value to send to the controller.

STeven.
bigkahuna from United States  [14 posts] 15 year
Ok, thanks Steven.  With a bit of experimenting I was able to get it to work perfectly.  Interesting that you can declare variables in the modules and not in script and I gather that variables must be in ALL_CAPS with no spaces?    I'm not familiar with VBScript syntax, is it based on Visual Basic?  I'll have to do some reading up on it.
Anonymous 15 year
NCUI,

Good to hear. No, all variables need not be in all caps ... that's just a convention we use to distinguish what is a variable and what is not. You can use lower case variables too .. in fact, VBScript sees THIS_TEXT and this_text as being the same variable unlike other languages like c++ which do not.

Yes, VBScript is a simpler form of Visual Basic.

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