|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Help with implementing Joysticks into C++ command based code
Hello, I am one of the two programmers in a rookie team starting out this year. We have never programmed for a robot before, but did have experience with C++. We successfully connected commands to joystick buttons, but do not know how to declare the axis of the joysticks in our code (we are using 2 joysticks). Any help in regards of that and how to code the joystick to control the drive train would be appreciated.
P.S. Please do ask if the above paragraph was not clear enough. I hope we can learn more through communicating with experienced programmers. |
|
#2
|
||||
|
||||
|
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
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());
}
|
|
#3
|
|||
|
|||
|
Re: Help with implementing Joysticks into C++ command based code
The GearsBot example project also has some very good examples on how to do this.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|