Thread: Deadband Help
View Single Post
  #4   Spotlight this post!  
Unread 13-02-2013, 20:15
kylelanman's Avatar
kylelanman kylelanman is offline
Programming Mentor
AKA: Kyle
FRC #2481 (Roboteers)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Tremont Il
Posts: 186
kylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to allkylelanman is a name known to all
Re: Deadband Help

Give the following a try. I have a more object oriented version but don't have a robot to test it on so I don't want to distribute it yet. If it gives you any problems you can't figure out let me know. I don't have WindRiver handy to compile it but it should build.

In order to apply a dead band to a given axis you just need to pass the result of get axis method into InputShape. Then use the result that InputShape returns where you were using the get axis methods.

ex.
float x = InputShape(stick->GetX());

Code:
#include "WPILib.h"

// Team 1721 mecanum code 2013 By: Zakary Tobine at 2/11/13 10:33am

// Needs to add 2 relays; one for motor for shooter; one for frishbee pusher 

const char inputShape[255] = {0,1,3,4,5,6,7,9,10,11,12,13,15,16,17,18,19,21,22,23,24,25,27,28,29,30,31,
	        33,34,35,36,37,38,40,41,42,43,44,46,47,48,49,50,52,53,54,55,56,58,59,60,61,62,
	        64,65,66,67,68,70,71,72,73,74,76,77,78,79,80,82,83,84,85,86,88,89,90,91,92,94,
	        95,96,97,98,100,101,102,103,104,106,107,108,109,110,112,113,114,115,116,117,
	        118,119,120,121,121,122,123,123,124,124,125,125,125,126,126,126,126,126,127,
	        127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
	        128,128,128,128,128,129,129,129,130,130,131,131,132,133,133,134,135,136,
	        137,138,139,140,141,142,144,145,146,147,148,150,151,152,153,154,156,157,158,
	        159,160,162,163,164,165,166,168,169,170,171,172,174,175,176,177,178,180,181,
	        182,183,184,186,187,188,189,190,192,193,194,195,196,198,199,200,201,202,204,
	        205,206,207,208,210,211,212,213,214,216,217,218,219,220,221,223,224,225,226,
	        227,229,230,231,232,233,235,236,237,238,239,241,242,243,244,245,247,248,249,
	        250,251,253,254,255};

float InputShape(float userValue)
	{
		int iUserValue;

		iUserValue = (int)(userValue * 127);
		iUserValue += 127;
		iUserValue = inputShape[iUserValue];
		userValue = iUserValue - 127;
		userValue /= 127;
		return userValue;
	}

class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick; // only joystick

public:
	RobotDemo(void):
		myRobot(1, 2, 3, 4),	// these must be initialized in the same order
		stick(1)		// as they are declared above.
	{
		
		
		stick.SetAxisChannel(Joystick::kTwistAxis, 3);// Add the 3rd axis 
		myRobot.SetExpiration(0.1);// The time the motors stop moving after a value is sent  
	}

	
	void Autonomous(void)
	{
		// Commented out till a later date 
		
		//myRobot.SetSafetyEnabled(false);
		//myRobot.Drive(-0.5, 0.0); 	// drive forwards half speed
		//Wait(2.0); 				//    for 2 seconds
		//myRobot.Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with one joystick mecanum. 
	 */
	void OperatorControl(void)
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
		
			float x = InputShape(stick->GetX());
			float y = InputShape(stick->GetY());
			float t = InputShape(stick->GetTwist()); 
		
			myRobot.MecanumDrive_Cartesian(x, y, t);// Mecanum drive single joystick drive 
			
		
		
		
			Wait(0.005);				// wait for a motor update time
		}
	}
	
	/**
	 * Runs during test mode
	 */
	void Test() {

	}
};

START_ROBOT_CLASS(RobotDemo);
__________________
"May the coms be with you"

Is this a "programming error" or a "programmer error"?

Reply With Quote