1- #include " ctre/phoenix6/TalonFX.hpp"
1+ #include < ctre/phoenix6/TalonFX.hpp>
22#include " RobotBase.hpp"
3- #include " Joystick .hpp"
3+ #include " GameController .hpp"
44
55using namespace ctre ::phoenix6;
66
@@ -25,11 +25,12 @@ class Robot : public RobotBase {
2525 controls::DutyCycleOut rightOut{0 };
2626
2727 /* joystick */
28- Joystick joy{0 };
28+ GameController joy{0 };
2929
3030public:
31+ Robot ();
32+
3133 /* main robot interface */
32- void RobotInit () override ;
3334 void RobotPeriodic () override ;
3435
3536 bool IsEnabled () override ;
@@ -40,10 +41,8 @@ class Robot : public RobotBase {
4041 void DisabledPeriodic () override ;
4142};
4243
43- /* *
44- * Runs once at code initialization.
45- */
46- void Robot::RobotInit ()
44+ Robot::Robot ()
45+ // : RobotBase{20_ms} // optionally specify loop time for periodic calls
4746{
4847 configs::TalonFXConfiguration fx_cfg{};
4948
@@ -74,10 +73,8 @@ void Robot::RobotPeriodic()
7473 */
7574bool Robot::IsEnabled ()
7675{
77- /* enable while joystick is an Xbox controller (6 axes),
78- * and we are holding the right bumper */
79- if (joy.GetNumAxes () < 6 ) return false ;
80- return joy.GetButton (5 ); // SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
76+ /* enable while holding the right bumper */
77+ return joy.GetButton (SDL_CONTROLLER_BUTTON_RIGHTSHOULDER );
8178}
8279
8380/* *
@@ -91,11 +88,11 @@ void Robot::EnabledInit() {}
9188void Robot::EnabledPeriodic ()
9289{
9390 /* arcade drive */
94- double speed = -joy.GetAxis (1 ); // SDL_CONTROLLER_AXIS_LEFTY
95- double turn = joy.GetAxis (4 ); // SDL_CONTROLLER_AXIS_RIGHTX
91+ double speed = -joy.GetAxis (SDL_CONTROLLER_AXIS_LEFTY );
92+ double turn = - joy.GetAxis (SDL_CONTROLLER_AXIS_RIGHTX );
9693
97- leftOut.Output = speed + turn;
98- rightOut.Output = speed - turn;
94+ leftOut.Output = speed - turn;
95+ rightOut.Output = speed + turn;
9996
10097 leftLeader.SetControl (leftOut);
10198 rightLeader.SetControl (rightOut);
@@ -120,7 +117,5 @@ void Robot::DisabledPeriodic()
120117int main ()
121118{
122119 /* create and run robot */
123- Robot robot{};
124- // robot.SetLoopTime(20_ms); // optionally change loop time for periodic calls
125- return robot.Run ();
120+ return RobotBase::StartRobot<Robot>();
126121}
0 commit comments