mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
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:
@@ -125,13 +125,17 @@ void RobotDrive::Drive(double outputMagnitude, double curve) {
|
||||
if (curve < 0) {
|
||||
double value = std::log(-curve);
|
||||
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
||||
if (ratio == 0) ratio = 0.0000000001;
|
||||
if (ratio == 0) {
|
||||
ratio = 0.0000000001;
|
||||
}
|
||||
leftOutput = outputMagnitude / ratio;
|
||||
rightOutput = outputMagnitude;
|
||||
} else if (curve > 0) {
|
||||
double value = std::log(curve);
|
||||
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
||||
if (ratio == 0) ratio = 0.0000000001;
|
||||
if (ratio == 0) {
|
||||
ratio = 0.0000000001;
|
||||
}
|
||||
leftOutput = outputMagnitude;
|
||||
rightOutput = outputMagnitude / ratio;
|
||||
} else {
|
||||
@@ -339,12 +343,14 @@ void RobotDrive::SetLeftRightMotorOutputs(double leftOutput,
|
||||
double rightOutput) {
|
||||
wpi_assert(m_rearLeftMotor != nullptr && m_rearRightMotor != nullptr);
|
||||
|
||||
if (m_frontLeftMotor != nullptr)
|
||||
if (m_frontLeftMotor != nullptr) {
|
||||
m_frontLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
||||
}
|
||||
m_rearLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
||||
|
||||
if (m_frontRightMotor != nullptr)
|
||||
if (m_frontRightMotor != nullptr) {
|
||||
m_frontRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
||||
}
|
||||
m_rearRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
||||
|
||||
Feed();
|
||||
@@ -375,21 +381,33 @@ void RobotDrive::SetSensitivity(double sensitivity) {
|
||||
m_sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
void RobotDrive::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
|
||||
void RobotDrive::SetMaxOutput(double maxOutput) {
|
||||
m_maxOutput = maxOutput;
|
||||
}
|
||||
|
||||
void RobotDrive::GetDescription(wpi::raw_ostream& desc) const {
|
||||
desc << "RobotDrive";
|
||||
}
|
||||
|
||||
void RobotDrive::StopMotor() {
|
||||
if (m_frontLeftMotor != nullptr) m_frontLeftMotor->StopMotor();
|
||||
if (m_frontRightMotor != nullptr) m_frontRightMotor->StopMotor();
|
||||
if (m_rearLeftMotor != nullptr) m_rearLeftMotor->StopMotor();
|
||||
if (m_rearRightMotor != nullptr) m_rearRightMotor->StopMotor();
|
||||
if (m_frontLeftMotor != nullptr) {
|
||||
m_frontLeftMotor->StopMotor();
|
||||
}
|
||||
if (m_frontRightMotor != nullptr) {
|
||||
m_frontRightMotor->StopMotor();
|
||||
}
|
||||
if (m_rearLeftMotor != nullptr) {
|
||||
m_rearLeftMotor->StopMotor();
|
||||
}
|
||||
if (m_rearRightMotor != nullptr) {
|
||||
m_rearRightMotor->StopMotor();
|
||||
}
|
||||
Feed();
|
||||
}
|
||||
|
||||
void RobotDrive::InitRobotDrive() { SetSafetyEnabled(true); }
|
||||
void RobotDrive::InitRobotDrive() {
|
||||
SetSafetyEnabled(true);
|
||||
}
|
||||
|
||||
double RobotDrive::Limit(double number) {
|
||||
if (number > 1.0) {
|
||||
@@ -405,7 +423,9 @@ void RobotDrive::Normalize(double* wheelSpeeds) {
|
||||
double maxMagnitude = std::fabs(wheelSpeeds[0]);
|
||||
for (int i = 1; i < kMaxNumberOfMotors; i++) {
|
||||
double temp = std::fabs(wheelSpeeds[i]);
|
||||
if (maxMagnitude < temp) maxMagnitude = temp;
|
||||
if (maxMagnitude < temp) {
|
||||
maxMagnitude = temp;
|
||||
}
|
||||
}
|
||||
if (maxMagnitude > 1.0) {
|
||||
for (int i = 0; i < kMaxNumberOfMotors; i++) {
|
||||
|
||||
Reference in New Issue
Block a user