Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Help with implementing Joysticks into C++ command based code (http://www.chiefdelphi.com/forums/showthread.php?t=133854)

Ebslgpy 02-02-2015 00:55

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.

kylelanman 02-02-2015 07:39

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.

JohnSmooth42 03-02-2015 22:13

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.


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

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