Skip to content

Commit

Permalink
Use Robot constructor instead of robotInit in Java/C++
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre committed Oct 31, 2024
1 parent aab7300 commit 55038a9
Show file tree
Hide file tree
Showing 42 changed files with 43 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cpp/ArcadeDrive/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {
Robot::Robot() {
/* Configure devices */
configs::TalonFXConfiguration leftConfiguration{};
configs::TalonFXConfiguration rightConfiguration{};
Expand Down
2 changes: 1 addition & 1 deletion cpp/ArcadeDrive/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Robot : public frc::TimedRobot {
int printCount{};

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/BasicLatencyCompensation/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {}
Robot::Robot() {}
void Robot::RobotPeriodic() {
/* Perform basic latency compensation based on latency and current derivative */
/* First refresh the signal */
Expand Down
2 changes: 1 addition & 1 deletion cpp/BasicLatencyCompensation/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Robot : public frc::TimedRobot {
ctre::phoenix6::StatusSignal<units::degrees_per_second_t> &m_p2yawRate = m_p2.GetAngularVelocityZWorld();

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
3 changes: 2 additions & 1 deletion cpp/CANcoder/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace ctre::phoenix6;

constexpr units::time::second_t print_period{500_ms};

void Robot::RobotInit() {
Robot::Robot() {
/* Configure CANcoder */
configs::CANcoderConfiguration toApply{};

Expand All @@ -20,6 +20,7 @@ void Robot::RobotInit() {
/* Speed up signals to an appropriate rate */
BaseStatusSignal::SetUpdateFrequencyForAll(100_Hz, cancoder.GetPosition(), cancoder.GetVelocity());
}

void Robot::RobotPeriodic() {
/* Every print_period get the CANcoder position/velocity and report it */
if (frc::Timer::GetFPGATimestamp() - currentTime >= print_period) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/CANcoder/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Robot : public frc::TimedRobot {
units::time::second_t currentTime{frc::Timer::GetFPGATimestamp()};

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/CommandBasedDrive/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down
2 changes: 1 addition & 1 deletion cpp/CommandBasedDrive/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/ControlRequestLimits/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using namespace ctre::phoenix;
using namespace ctre::phoenix6;

void Robot::RobotInit()
Robot::Robot()
{
configs::TalonFXConfiguration configs{};

Expand Down
2 changes: 1 addition & 1 deletion cpp/ControlRequestLimits/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/CurrentLimits/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {
Robot::Robot() {
/* Configure the Talon to use a supply limit of 70 A, and
* lower to 40 A if we're at 70 A for over 1 second */
configs::TalonFXConfiguration toConfigure{};
Expand Down
2 changes: 1 addition & 1 deletion cpp/CurrentLimits/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Robot : public frc::TimedRobot {
int printCount = 0;

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/FusedCANcoder/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {
Robot::Robot() {
/* Configure CANcoder to zero the magnet appropriately */
configs::CANcoderConfiguration cc_cfg{};
cc_cfg.MagnetSensor.AbsoluteSensorRange = signals::AbsoluteSensorRangeValue::Signed_PlusMinusHalf;
Expand Down
2 changes: 1 addition & 1 deletion cpp/FusedCANcoder/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Robot : public frc::TimedRobot {
int printCount = 0;

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/MotionMagic/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Robot::SimulationPeriodic() {
PhysicsSim::GetInstance().Run();
}

void Robot::RobotInit() {
Robot::Robot() {
configs::TalonFXConfiguration cfg{};

/* Configure gear ratio */
Expand Down
2 changes: 1 addition & 1 deletion cpp/MotionMagic/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Robot : public frc::TimedRobot {
int m_printCount = 0;

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/PhoenixSysId/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <frc2/command/CommandScheduler.h>

void Robot::RobotInit() {}
Robot::Robot() {}

void Robot::RobotPeriodic() {
frc2::CommandScheduler::GetInstance().Run();
Expand Down
2 changes: 1 addition & 1 deletion cpp/PhoenixSysId/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/Pigeon2/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace ctre::phoenix6;

constexpr units::time::second_t print_period{500_ms};

void Robot::RobotInit() {
Robot::Robot() {
/* Configure Pigeon2 */
configs::Pigeon2Configuration toApply{};

Expand Down
2 changes: 1 addition & 1 deletion cpp/Pigeon2/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Robot : public frc::TimedRobot {
units::time::second_t currentTime{frc::Timer::GetFPGATimestamp()};

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/PositionClosedLoop/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {
Robot::Robot() {
configs::TalonFXConfiguration configs{};
configs.Slot0.kP = 2.4; // An error of 1 rotations results in 1.2 V output
configs.Slot0.kI = 0; // No output for integrated error
Expand Down
2 changes: 1 addition & 1 deletion cpp/PositionClosedLoop/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Robot : public frc::TimedRobot {
frc::XboxController m_joystick{0};

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/Simulation/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit()
Robot::Robot()
{
ctre::phoenix::StatusCode returnCode;

Expand Down
2 changes: 1 addition & 1 deletion cpp/Simulation/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Robot : public frc::TimedRobot {
units::turns_per_second_t metersToRotationsVel(units::meters_per_second_t meters);

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/VelocityClosedLoop/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using namespace ctre::phoenix6;

void Robot::RobotInit() {
Robot::Robot() {
configs::TalonFXConfiguration configs{};

/* Voltage-based velocity requires a feed forward to account for the back-emf of the motor */
Expand Down
2 changes: 1 addition & 1 deletion cpp/VelocityClosedLoop/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Robot : public frc::TimedRobot {
frc::XboxController m_joystick{0};

public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
2 changes: 1 addition & 1 deletion cpp/WaitForAll/src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Robot.h"
#include <iostream>

void Robot::RobotInit() {}
Robot::Robot() {}
void Robot::RobotPeriodic() {
if (m_joystick.GetLeftBumperButton()) {
m_waitForAllTimeout = 0.1_s;
Expand Down
2 changes: 1 addition & 1 deletion cpp/WaitForAll/src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Robot : public frc::TimedRobot {
public:
void RobotInit() override;
Robot();
void RobotPeriodic() override;

void AutonomousInit() override;
Expand Down
3 changes: 1 addition & 2 deletions java/ArcadeDrive/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
/* Configure the devices */
var leftConfiguration = new TalonFXConfiguration();
var rightConfiguration = new TalonFXConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {

}

Expand Down
3 changes: 1 addition & 2 deletions java/CANcoder/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
/* Configure CANcoder */
var toApply = new CANcoderConfiguration();

Expand Down
3 changes: 1 addition & 2 deletions java/CommandBasedDrive/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
Expand Down
3 changes: 1 addition & 2 deletions java/ControlRequestLimits/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
TalonFXConfiguration configs = new TalonFXConfiguration();

configs.MotorOutput.Inverted = InvertedValue.Clockwise_Positive;
Expand Down
3 changes: 1 addition & 2 deletions java/CurrentLimits/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
/* Configure the Talon to use a supply limit of 70 A, and
* lower to 40 A if we're at 70 A for over 1 second */
TalonFXConfiguration toConfigure = new TalonFXConfiguration();
Expand Down
3 changes: 1 addition & 2 deletions java/FusedCANcoder/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
/* Configure CANcoder to zero the magnet appropriately */
CANcoderConfiguration cc_cfg = new CANcoderConfiguration();
cc_cfg.MagnetSensor.AbsoluteSensorRange = AbsoluteSensorRangeValue.Signed_PlusMinusHalf;
Expand Down
3 changes: 1 addition & 2 deletions java/MotionMagic/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public void simulationPeriodic() {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
TalonFXConfiguration cfg = new TalonFXConfiguration();

/* Configure gear ratio */
Expand Down
3 changes: 1 addition & 2 deletions java/PhoenixSysId/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class Robot extends TimedRobot {

private RobotContainer m_robotContainer;

@Override
public void robotInit() {
public Robot() {
m_robotContainer = new RobotContainer();
}

Expand Down
3 changes: 1 addition & 2 deletions java/Pigeon2/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
/* Configure Pigeon2 */
var toApply = new Pigeon2Configuration();

Expand Down
3 changes: 1 addition & 2 deletions java/PositionClosedLoop/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
TalonFXConfiguration configs = new TalonFXConfiguration();
configs.Slot0.kP = 2.4; // An error of 1 rotation results in 2.4 V output
configs.Slot0.kI = 0; // No output for integrated error
Expand Down
3 changes: 1 addition & 2 deletions java/Simulation/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public class Robot extends TimedRobot {
* for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
StatusCode returnCode;

TalonFXConfiguration fxCfg = new TalonFXConfiguration();
Expand Down
3 changes: 1 addition & 2 deletions java/VelocityClosedLoop/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
public Robot() {
TalonFXConfiguration configs = new TalonFXConfiguration();

/* Voltage-based velocity requires a velocity feed forward to account for the back-emf of the motor */
Expand Down
3 changes: 1 addition & 2 deletions java/WaitForAll/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public class Robot extends TimedRobot {
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {}
public Robot() {}

@Override
public void robotPeriodic() {
Expand Down

0 comments on commit 55038a9

Please sign in to comment.