mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add setting to invert the right side of the drive (#1045)
This commit is contained in:
committed by
Peter Johnson
parent
73439d8213
commit
17401e10f0
@@ -94,7 +94,8 @@ void DifferentialDrive::ArcadeDrive(double xSpeed, double zRotation,
|
||||
}
|
||||
|
||||
m_leftMotor.Set(Limit(leftMotorOutput) * m_maxOutput);
|
||||
m_rightMotor.Set(-Limit(rightMotorOutput) * m_maxOutput);
|
||||
m_rightMotor.Set(Limit(rightMotorOutput) * m_maxOutput *
|
||||
m_rightSideInvertMultiplier);
|
||||
|
||||
m_safetyHelper.Feed();
|
||||
}
|
||||
@@ -181,7 +182,8 @@ void DifferentialDrive::CurvatureDrive(double xSpeed, double zRotation,
|
||||
}
|
||||
|
||||
m_leftMotor.Set(leftMotorOutput * m_maxOutput);
|
||||
m_rightMotor.Set(-rightMotorOutput * m_maxOutput);
|
||||
m_rightMotor.Set(rightMotorOutput * m_maxOutput *
|
||||
m_rightSideInvertMultiplier);
|
||||
|
||||
m_safetyHelper.Feed();
|
||||
}
|
||||
@@ -218,7 +220,7 @@ void DifferentialDrive::TankDrive(double leftSpeed, double rightSpeed,
|
||||
}
|
||||
|
||||
m_leftMotor.Set(leftSpeed * m_maxOutput);
|
||||
m_rightMotor.Set(-rightSpeed * m_maxOutput);
|
||||
m_rightMotor.Set(rightSpeed * m_maxOutput * m_rightSideInvertMultiplier);
|
||||
|
||||
m_safetyHelper.Feed();
|
||||
}
|
||||
@@ -256,6 +258,26 @@ void DifferentialDrive::SetQuickStopAlpha(double alpha) {
|
||||
m_quickStopAlpha = alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the power sent to the right side of the drivetrain is multipled by
|
||||
* -1.
|
||||
*
|
||||
* @return true if the right side is inverted
|
||||
*/
|
||||
bool DifferentialDrive::IsRightSideInverted() const {
|
||||
return m_rightSideInvertMultiplier == -1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the power sent to the right side of the drivetrain should be
|
||||
* multipled by -1.
|
||||
*
|
||||
* @param rightSideInverted true if right side power should be multipled by -1
|
||||
*/
|
||||
void DifferentialDrive::SetRightSideInverted(bool rightSideInverted) {
|
||||
m_rightSideInvertMultiplier = rightSideInverted ? -1.0 : 1.0;
|
||||
}
|
||||
|
||||
void DifferentialDrive::StopMotor() {
|
||||
m_leftMotor.StopMotor();
|
||||
m_rightMotor.StopMotor();
|
||||
@@ -271,7 +293,10 @@ void DifferentialDrive::InitSendable(SendableBuilder& builder) {
|
||||
builder.AddDoubleProperty("Left Motor Speed",
|
||||
[=]() { return m_leftMotor.Get(); },
|
||||
[=](double value) { m_leftMotor.Set(value); });
|
||||
builder.AddDoubleProperty("Right Motor Speed",
|
||||
[=]() { return -m_rightMotor.Get(); },
|
||||
[=](double value) { m_rightMotor.Set(-value); });
|
||||
builder.AddDoubleProperty(
|
||||
"Right Motor Speed",
|
||||
[=]() { return m_rightMotor.Get() * m_rightSideInvertMultiplier; },
|
||||
[=](double value) {
|
||||
m_rightMotor.Set(value * m_rightSideInvertMultiplier);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user