Go to Post IMHO, [the driver's] job is to drive the robot. The coaches job is to monitor everything in a match that isn't your robot. - CalTran [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Spotlight this post!  
Unread 26-01-2012, 00:15
Tommy.Brown's Avatar
Tommy.Brown Tommy.Brown is offline
Lead Programmer
FRC #1477 (Texas Torque)
Team Role: Programmer
 
Join Date: Jul 2011
Rookie Year: 2011
Location: The Woodlands
Posts: 27
Tommy.Brown is an unknown quantity at this point
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.
__________________
FRC Team 1477 - Texas Torque
The Woodlands, Texas
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi