mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Use stricter C++ type conversions (#4357)
Now, implicit narrowing conversions are only used with wpi::Now(). This
also fixes clang-tidy warnings about C-style casts. For example:
```
== clang-tidy /__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc ==
/__w/allwpilib/allwpilib/wpilibNewCommands/src/main/native/include/frc2/command/SwerveControllerCommand.inc:95:18: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting]
auto curTime = units::second_t(m_timer.Get());
^
```
In that case at least, the cast was removed entirely since Get() already
returns a units::second_t.
This commit is contained in:
@@ -44,8 +44,8 @@ ChassisSpeeds HolonomicDriveController::Calculate(
|
||||
// Calculate feedforward velocities (field-relative)
|
||||
auto xFF = linearVelocityRef * poseRef.Rotation().Cos();
|
||||
auto yFF = linearVelocityRef * poseRef.Rotation().Sin();
|
||||
auto thetaFF = units::radians_per_second_t(m_thetaController.Calculate(
|
||||
currentPose.Rotation().Radians(), angleRef.Radians()));
|
||||
auto thetaFF = units::radians_per_second_t{m_thetaController.Calculate(
|
||||
currentPose.Rotation().Radians(), angleRef.Radians())};
|
||||
|
||||
m_poseError = poseRef.RelativeTo(currentPose);
|
||||
m_rotationError = angleRef - currentPose.Rotation();
|
||||
@@ -56,10 +56,10 @@ ChassisSpeeds HolonomicDriveController::Calculate(
|
||||
}
|
||||
|
||||
// Calculate feedback velocities (based on position error).
|
||||
auto xFeedback = units::meters_per_second_t(
|
||||
m_xController.Calculate(currentPose.X().value(), poseRef.X().value()));
|
||||
auto yFeedback = units::meters_per_second_t(
|
||||
m_yController.Calculate(currentPose.Y().value(), poseRef.Y().value()));
|
||||
auto xFeedback = units::meters_per_second_t{
|
||||
m_xController.Calculate(currentPose.X().value(), poseRef.X().value())};
|
||||
auto yFeedback = units::meters_per_second_t{
|
||||
m_yController.Calculate(currentPose.Y().value(), poseRef.Y().value())};
|
||||
|
||||
// Return next output.
|
||||
return ChassisSpeeds::FromFieldRelativeSpeeds(
|
||||
|
||||
@@ -65,7 +65,7 @@ double PIDController::GetD() const {
|
||||
}
|
||||
|
||||
units::second_t PIDController::GetPeriod() const {
|
||||
return units::second_t(m_period);
|
||||
return m_period;
|
||||
}
|
||||
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
|
||||
@@ -29,8 +29,8 @@ RamseteController::RamseteController(units::unit_t<b_unit> b,
|
||||
: m_b{b}, m_zeta{zeta} {}
|
||||
|
||||
RamseteController::RamseteController()
|
||||
: RamseteController(units::unit_t<b_unit>{2.0},
|
||||
units::unit_t<zeta_unit>{0.7}) {}
|
||||
: RamseteController{units::unit_t<b_unit>{2.0},
|
||||
units::unit_t<zeta_unit>{0.7}} {}
|
||||
|
||||
bool RamseteController::AtReference() const {
|
||||
const auto& eTranslate = m_poseError.Translation();
|
||||
|
||||
@@ -65,9 +65,9 @@ void DifferentialDrivePoseEstimator::ResetPosition(
|
||||
}
|
||||
|
||||
Pose2d DifferentialDrivePoseEstimator::GetEstimatedPosition() const {
|
||||
return Pose2d(units::meter_t(m_observer.Xhat(0)),
|
||||
units::meter_t(m_observer.Xhat(1)),
|
||||
Rotation2d(units::radian_t(m_observer.Xhat(2))));
|
||||
return Pose2d{units::meter_t{m_observer.Xhat(0)},
|
||||
units::meter_t{m_observer.Xhat(1)},
|
||||
units::radian_t{m_observer.Xhat(2)}};
|
||||
}
|
||||
|
||||
void DifferentialDrivePoseEstimator::AddVisionMeasurement(
|
||||
|
||||
@@ -66,8 +66,8 @@ void frc::MecanumDrivePoseEstimator::ResetPosition(
|
||||
}
|
||||
|
||||
Pose2d frc::MecanumDrivePoseEstimator::GetEstimatedPosition() const {
|
||||
return Pose2d(m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m,
|
||||
Rotation2d(units::radian_t{m_observer.Xhat(2)}));
|
||||
return Pose2d{m_observer.Xhat(0) * 1_m, m_observer.Xhat(1) * 1_m,
|
||||
units::radian_t{m_observer.Xhat(2)}};
|
||||
}
|
||||
|
||||
void frc::MecanumDrivePoseEstimator::AddVisionMeasurement(
|
||||
@@ -96,8 +96,8 @@ Pose2d frc::MecanumDrivePoseEstimator::UpdateWithTime(
|
||||
|
||||
auto chassisSpeeds = m_kinematics.ToChassisSpeeds(wheelSpeeds);
|
||||
auto fieldRelativeVelocities =
|
||||
Translation2d(chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s)
|
||||
.RotateBy(angle);
|
||||
Translation2d{chassisSpeeds.vx * 1_s, chassisSpeeds.vy * 1_s}.RotateBy(
|
||||
angle);
|
||||
|
||||
Vectord<3> u{fieldRelativeVelocities.X().value(),
|
||||
fieldRelativeVelocities.Y().value(), omega.value()};
|
||||
|
||||
@@ -22,7 +22,7 @@ Pose2d Pose2d::operator+(const Transform2d& other) const {
|
||||
|
||||
Transform2d Pose2d::operator-(const Pose2d& other) const {
|
||||
const auto pose = this->RelativeTo(other);
|
||||
return Transform2d(pose.Translation(), pose.Rotation());
|
||||
return Transform2d{pose.Translation(), pose.Rotation()};
|
||||
}
|
||||
|
||||
bool Pose2d::operator==(const Pose2d& other) const {
|
||||
@@ -87,7 +87,7 @@ Twist2d Pose2d::Log(const Pose2d& end) const {
|
||||
{halfThetaByTanOfHalfDtheta, -halfDtheta}) *
|
||||
std::hypot(halfThetaByTanOfHalfDtheta, halfDtheta);
|
||||
|
||||
return {translationPart.X(), translationPart.Y(), units::radian_t(dtheta)};
|
||||
return {translationPart.X(), translationPart.Y(), units::radian_t{dtheta}};
|
||||
}
|
||||
|
||||
void frc::to_json(wpi::json& json, const Pose2d& pose) {
|
||||
|
||||
@@ -43,7 +43,7 @@ Pose3d Pose3d::operator+(const Transform3d& other) const {
|
||||
|
||||
Transform3d Pose3d::operator-(const Pose3d& other) const {
|
||||
const auto pose = this->RelativeTo(other);
|
||||
return Transform3d(pose.Translation(), pose.Rotation());
|
||||
return Transform3d{pose.Translation(), pose.Rotation()};
|
||||
}
|
||||
|
||||
bool Pose3d::operator==(const Pose3d& other) const {
|
||||
|
||||
@@ -31,7 +31,7 @@ Rotation2d::Rotation2d(double x, double y) {
|
||||
m_sin = 0.0;
|
||||
m_cos = 1.0;
|
||||
}
|
||||
m_value = units::radian_t(std::atan2(m_sin, m_cos));
|
||||
m_value = units::radian_t{std::atan2(m_sin, m_cos)};
|
||||
}
|
||||
|
||||
Rotation2d Rotation2d::operator+(const Rotation2d& other) const {
|
||||
@@ -43,11 +43,11 @@ Rotation2d Rotation2d::operator-(const Rotation2d& other) const {
|
||||
}
|
||||
|
||||
Rotation2d Rotation2d::operator-() const {
|
||||
return Rotation2d(-m_value);
|
||||
return Rotation2d{-m_value};
|
||||
}
|
||||
|
||||
Rotation2d Rotation2d::operator*(double scalar) const {
|
||||
return Rotation2d(m_value * scalar);
|
||||
return Rotation2d{m_value * scalar};
|
||||
}
|
||||
|
||||
bool Rotation2d::operator==(const Rotation2d& other) const {
|
||||
|
||||
@@ -20,10 +20,10 @@ std::vector<CubicHermiteSpline> SplineHelper::CubicSplinesFromControlVectors(
|
||||
|
||||
if (waypoints.size() > 1) {
|
||||
waypoints.emplace(waypoints.begin(),
|
||||
Translation2d{units::meter_t(xInitial[0]),
|
||||
units::meter_t(yInitial[0])});
|
||||
Translation2d{units::meter_t{xInitial[0]},
|
||||
units::meter_t{yInitial[0]}});
|
||||
waypoints.emplace_back(
|
||||
Translation2d{units::meter_t(xFinal[0]), units::meter_t(yFinal[0])});
|
||||
Translation2d{units::meter_t{xFinal[0]}, units::meter_t{yFinal[0]}});
|
||||
|
||||
// Populate tridiagonal system for clamped cubic
|
||||
/* See:
|
||||
|
||||
@@ -30,7 +30,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory(
|
||||
Spline<3>::ControlVector initial,
|
||||
const std::vector<Translation2d>& interiorWaypoints,
|
||||
Spline<3>::ControlVector end, const TrajectoryConfig& config) {
|
||||
const Transform2d flip{Translation2d(), Rotation2d(180_deg)};
|
||||
const Transform2d flip{Translation2d{}, 180_deg};
|
||||
|
||||
// Make theta normal for trajectory generation if path is reversed.
|
||||
// Flip the headings.
|
||||
@@ -76,7 +76,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory(
|
||||
Trajectory TrajectoryGenerator::GenerateTrajectory(
|
||||
std::vector<Spline<5>::ControlVector> controlVectors,
|
||||
const TrajectoryConfig& config) {
|
||||
const Transform2d flip{Translation2d(), Rotation2d(180_deg)};
|
||||
const Transform2d flip{Translation2d{}, 180_deg};
|
||||
// Make theta normal for trajectory generation if path is reversed.
|
||||
if (config.IsReversed()) {
|
||||
for (auto& vector : controlVectors) {
|
||||
@@ -112,7 +112,7 @@ Trajectory TrajectoryGenerator::GenerateTrajectory(
|
||||
Trajectory TrajectoryGenerator::GenerateTrajectory(
|
||||
const std::vector<Pose2d>& waypoints, const TrajectoryConfig& config) {
|
||||
auto newWaypoints = waypoints;
|
||||
const Transform2d flip{Translation2d(), Rotation2d(180_deg)};
|
||||
const Transform2d flip{Translation2d{}, 180_deg};
|
||||
if (config.IsReversed()) {
|
||||
for (auto& waypoint : newWaypoints) {
|
||||
waypoint = waypoint + flip;
|
||||
|
||||
@@ -23,7 +23,7 @@ DifferentialDriveVoltageConstraint::DifferentialDriveVoltageConstraint(
|
||||
units::meters_per_second_t DifferentialDriveVoltageConstraint::MaxVelocity(
|
||||
const Pose2d& pose, units::curvature_t curvature,
|
||||
units::meters_per_second_t velocity) const {
|
||||
return units::meters_per_second_t(std::numeric_limits<double>::max());
|
||||
return units::meters_per_second_t{std::numeric_limits<double>::max()};
|
||||
}
|
||||
|
||||
TrajectoryConstraint::MinMax
|
||||
|
||||
Reference in New Issue
Block a user