|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#11
|
||||
|
||||
|
Re: Help Needed with some Simple Programming
Here is how you apply the deadband:
I assume that you already have the Joystick created, I am just gonna call it joystickcontroller. And I am going to throw it all inside a method for functionality. #include "math.h" // Make sure you have that ^^^^ float DriverController::GetSpeedAxis() { float val = -joystickcontroller->GetY(); if( fabs(val) <= SPEED_AXIS_DEADBAND) val = 0; return val; }//GetSpeedAxis SPEED_AXIS_DEADBAND is a constant.... can be replaced by any number The fabs call is the call for absolute value. This only works if the deadband that you want to set is the same for both the positive and negative values on the joystick. Since the deadband is the same in both the positive and negative direction, then by using the fabs call we can eliminate some needless code. The motor code that you would want: I am going to use Victor for this example, can be easily switched to work with a Jaguar just by changing the words Victor to Jaguar. I am going to call the joystick method that I gave to you earlier on this comment to get the value from the joystick. Lets just pretend they are in the same class for now. Victor *vic = new Victor(VICTOR_PORT); vic->Set(GetSpeedAxis()); Now what that did is take the value from the joystick and assign that -1 to 1 value to the Victor which then controls the motor itself. To assign it a value as to whether a button is pressed: Victor *vic = new Victor(VICTOR_PORT); if(joystickcontroller->GetRawButton(1)) vic->Set(1); else vic->Set(0); the value 1 when I called GetRawButton is the button that you wish to get, the button configuration are different for each different type of controller. If you need any more help just message me. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|