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.