View Single Post
  #2   Spotlight this post!  
Unread 02-02-2015, 07:39
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: Help with implementing Joysticks into C++ command based code

Assuming you already have the joystick defined in your OI class you can access joystick axis in a command like this.

Code:
#ifndef DriveCommand_H
#define DriveCommand_H

#include "../CommandBase.h"
#include "WPILib.h"

class DriveCommand: public CommandBase
{
public:
	DriveCommand();
	void Initialize();
	void Execute() {
		driveTrain->Crab(oi->GetDriverStick()->GetRawAxis(1),
				         oi->GetDriverStick()->GetRawAxis(2),
						 oi->GetDriverStick()->GetRawAxis(3));
	}
	bool IsFinished(){
		return false;
	}
	void End();
	void Interrupted();
};

#endif
In this particular command, driveTrain has been defined in CommandBase as a static. DriveTrain has a method defined called Crab that is passed float parameters. In this case we are passing in 3 joystick axis.

Optionally you may want this command to be running on the subsystem as the default behavior when no other command is running. To achieve this ensure you have an InitDefaultCommand() method defined in your subsystem that calls SetDefaultCommand(new DriveCommand);

Code:
void DriveTrain::InitDefaultCommand() {
	SetDefaultCommand(new DriveCommand());
}
You might want to read through http://wpilib.screenstepslive.com/s/.../13810/c/88685. It tells you everything you need to know about command based programming.
__________________
"May the coms be with you"

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

Reply With Quote