Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -17,7 +17,9 @@ void Robot::RobotInit() {}
* <p> This runs after the mode specific periodic functions, but before
* LiveWindow and SmartDashboard integrated updating.
*/
void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); }
void Robot::RobotPeriodic() {
frc2::CommandScheduler::GetInstance().Run();
}
/**
* This function is called once each time the robot enters Disabled mode. You
@@ -64,5 +66,7 @@ void Robot::TeleopPeriodic() {}
void Robot::TestPeriodic() {}
#ifndef RUNNING_FRC_TESTS
int main() { return frc::StartRobot<Robot>(); }
int main() {
return frc::StartRobot<Robot>();
}
#endif

View File

@@ -12,10 +12,14 @@ CloseClaw::CloseClaw(Claw* claw) : m_claw(claw) {
}
// Called just before this Command runs the first time
void CloseClaw::Initialize() { m_claw->Close(); }
void CloseClaw::Initialize() {
m_claw->Close();
}
// Make this return true when this Command no longer needs to run execute()
bool CloseClaw::IsFinished() { return m_claw->IsGripping(); }
bool CloseClaw::IsFinished() {
return m_claw->IsGripping();
}
// Called once after isFinished returns true
void CloseClaw::End(bool) {

View File

@@ -25,4 +25,6 @@ void DriveStraight::Initialize() {
frc2::PIDCommand::Initialize();
}
bool DriveStraight::IsFinished() { return m_controller.AtSetpoint(); }
bool DriveStraight::IsFinished() {
return m_controller.AtSetpoint();
}

View File

@@ -19,4 +19,6 @@ void OpenClaw::Initialize() {
}
// Called once after isFinished returns true
void OpenClaw::End(bool) { m_claw->Stop(); }
void OpenClaw::End(bool) {
m_claw->Stop();
}

View File

@@ -25,4 +25,6 @@ void SetDistanceToBox::Initialize() {
frc2::PIDCommand::Initialize();
}
bool SetDistanceToBox::IsFinished() { return m_controller.AtSetpoint(); }
bool SetDistanceToBox::IsFinished() {
return m_controller.AtSetpoint();
}

View File

@@ -14,10 +14,16 @@ TankDrive::TankDrive(std::function<double()> left,
}
// Called repeatedly when this Command is scheduled to run
void TankDrive::Execute() { m_drivetrain->Drive(m_left(), m_right()); }
void TankDrive::Execute() {
m_drivetrain->Drive(m_left(), m_right());
}
// Make this return true when this Command no longer needs to run execute()
bool TankDrive::IsFinished() { return false; }
bool TankDrive::IsFinished() {
return false;
}
// Called once after isFinished returns true
void TankDrive::End(bool) { m_drivetrain->Drive(0, 0); }
void TankDrive::End(bool) {
m_drivetrain->Drive(0, 0);
}

View File

@@ -12,16 +12,26 @@ Claw::Claw() {
AddChild("Motor", &m_motor);
}
void Claw::Open() { m_motor.Set(-1); }
void Claw::Open() {
m_motor.Set(-1);
}
void Claw::Close() { m_motor.Set(1); }
void Claw::Close() {
m_motor.Set(1);
}
void Claw::Stop() { m_motor.Set(0); }
void Claw::Stop() {
m_motor.Set(0);
}
bool Claw::IsGripping() { return m_contact.Get(); }
bool Claw::IsGripping() {
return m_contact.Get();
}
void Claw::Log() {
frc::SmartDashboard::PutBoolean("Claw switch", IsGripping());
}
void Claw::Periodic() { Log(); }
void Claw::Periodic() {
Log();
}

View File

@@ -50,7 +50,9 @@ void DriveTrain::Drive(double left, double right) {
m_robotDrive.TankDrive(left, right);
}
double DriveTrain::GetHeading() { return m_gyro.GetAngle(); }
double DriveTrain::GetHeading() {
return m_gyro.GetAngle();
}
void DriveTrain::Reset() {
m_gyro.Reset();
@@ -67,4 +69,6 @@ double DriveTrain::GetDistanceToObstacle() {
return m_rangefinder.GetAverageVoltage();
}
void DriveTrain::Periodic() { Log(); }
void DriveTrain::Periodic() {
Log();
}

View File

@@ -21,12 +21,18 @@ Elevator::Elevator()
AddChild("Pot", &m_pot);
}
void Elevator::Log() { frc::SmartDashboard::PutData("Wrist Pot", &m_pot); }
void Elevator::Log() {
frc::SmartDashboard::PutData("Wrist Pot", &m_pot);
}
double Elevator::GetMeasurement() { return m_pot.Get(); }
double Elevator::GetMeasurement() {
return m_pot.Get();
}
void Elevator::UseOutput(double output, double setpoint) {
m_motor.Set(output);
}
void Elevator::Periodic() { Log(); }
void Elevator::Periodic() {
Log();
}

View File

@@ -23,8 +23,14 @@ void Wrist::Log() {
frc::SmartDashboard::PutNumber("Wrist Angle", GetMeasurement());
}
double Wrist::GetMeasurement() { return m_pot.Get(); }
double Wrist::GetMeasurement() {
return m_pot.Get();
}
void Wrist::UseOutput(double output, double setpoint) { m_motor.Set(output); }
void Wrist::UseOutput(double output, double setpoint) {
m_motor.Set(output);
}
void Wrist::Periodic() { Log(); }
void Wrist::Periodic() {
Log();
}