View Full Version : C++ Functions
01-30-2009, 02:41 PM
Is there a function in the WindRiver language that allows me to take the value of the joystick (speed of motor) and make it into a variable so that you can compare how fast you are intending to go based on joystick location and compare it to the actual speed?
01-30-2009, 03:38 PM
There's not a WPI library function for what you want, but there is a simple feature of the C language called an "assignment". It is implemented using the equals sign = character.
variable = retrieve_value();
This takes the value returned by the retrieve_value() function and assigns it to the variable named variable. In order to make it work properly, the variable and the function must have the same type. (For joystick axis values, I think that type is float.)
If you didn't already know this, you should probably find and follow a basic C/C++ programming tutorial. Finding and following a knowledgeable mentor would be a good idea as well.
I'm focusing on LabVIEW this season, so I'm not confident in my ability to give correct examples using the C++ classes to an insufficiently experienced programmer. Would someone else please answer specific questions about reading Joystick data?
01-30-2009, 06:05 PM
Thank you very much. So if I use the float variable of the retrieve_value() function I can get the joystick speed?
01-30-2009, 07:06 PM
No, I don't believe that there's a function called retrieve_value() function. Try looking at WPILib and seeing what functions there are for the joystick class.
01-31-2009, 12:40 AM
If you're using the SimpleRobot demo, then you would use the instance of the Joystick class to retrieve the value of the Joystick.
// assuming that there is an instance of the Joystick class called 'stick' in the current scope
float some_X = stick.GetX();
float some_Y = stick.GetY();
However, if you glance at how the joystick values are translated to motor speed (see RobotDrive.cpp), its probably not the stick values you want to look at, you'll want to look at the motor values -- which is harder if you use their RobotDrive class, which doesn't allow you to easily access the motor values unless you create the speed controller classes outside the RobotDrive class and pass it in through the constructor of RobotDrive. For this reason, we chose to write our own RobotDrive-like class.
Reading the WPILib source code is the best way to understand how things work underneath.
01-31-2009, 12:45 PM
Okay I'll try that. Thank you very much.
vBulletin® v3.6.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.