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:
Tyler Veness
2022-08-17 13:42:36 -07:00
committed by GitHub
parent 151dabb2af
commit ac9be78e27
139 changed files with 547 additions and 593 deletions

View File

@@ -7,10 +7,10 @@
namespace DriveConstants {
const frc::MecanumDriveKinematics kDriveKinematics{
frc::Translation2d(kWheelBase / 2, kTrackWidth / 2),
frc::Translation2d(kWheelBase / 2, -kTrackWidth / 2),
frc::Translation2d(-kWheelBase / 2, kTrackWidth / 2),
frc::Translation2d(-kWheelBase / 2, -kTrackWidth / 2)};
frc::Translation2d{kWheelBase / 2, kTrackWidth / 2},
frc::Translation2d{kWheelBase / 2, -kTrackWidth / 2},
frc::Translation2d{-kWheelBase / 2, kTrackWidth / 2},
frc::Translation2d{-kWheelBase / 2, -kTrackWidth / 2}};
} // namespace DriveConstants

View File

@@ -57,11 +57,11 @@ frc2::Command* RobotContainer::GetAutonomousCommand() {
// An example trajectory to follow. All units in meters.
auto exampleTrajectory = frc::TrajectoryGenerator::GenerateTrajectory(
// Start at the origin facing the +X direction
frc::Pose2d(0_m, 0_m, frc::Rotation2d(0_deg)),
frc::Pose2d{0_m, 0_m, 0_deg},
// Pass through these two interior waypoints, making an 's' curve path
{frc::Translation2d(1_m, 1_m), frc::Translation2d(2_m, -1_m)},
{frc::Translation2d{1_m, 1_m}, frc::Translation2d{2_m, -1_m}},
// End 3 meters straight ahead of where we started, facing forward
frc::Pose2d(3_m, 0_m, frc::Rotation2d(0_deg)),
frc::Pose2d{3_m, 0_m, 0_deg},
// Pass the config
config);
@@ -71,8 +71,8 @@ frc2::Command* RobotContainer::GetAutonomousCommand() {
frc::SimpleMotorFeedforward<units::meters>(ks, kv, ka),
DriveConstants::kDriveKinematics,
frc2::PIDController(AutoConstants::kPXController, 0, 0),
frc2::PIDController(AutoConstants::kPYController, 0, 0),
frc2::PIDController{AutoConstants::kPXController, 0, 0},
frc2::PIDController{AutoConstants::kPYController, 0, 0},
frc::ProfiledPIDController<units::radians>(
AutoConstants::kPThetaController, 0, 0,
AutoConstants::kThetaControllerConstraints),
@@ -81,18 +81,18 @@ frc2::Command* RobotContainer::GetAutonomousCommand() {
[this]() {
return frc::MecanumDriveWheelSpeeds{
units::meters_per_second_t(m_drive.GetFrontLeftEncoder().GetRate()),
units::meters_per_second_t(
m_drive.GetFrontRightEncoder().GetRate()),
units::meters_per_second_t(m_drive.GetRearLeftEncoder().GetRate()),
units::meters_per_second_t(
m_drive.GetRearRightEncoder().GetRate())};
units::meters_per_second_t{m_drive.GetFrontLeftEncoder().GetRate()},
units::meters_per_second_t{
m_drive.GetFrontRightEncoder().GetRate()},
units::meters_per_second_t{m_drive.GetRearLeftEncoder().GetRate()},
units::meters_per_second_t{
m_drive.GetRearRightEncoder().GetRate()}};
},
frc2::PIDController(DriveConstants::kPFrontLeftVel, 0, 0),
frc2::PIDController(DriveConstants::kPRearLeftVel, 0, 0),
frc2::PIDController(DriveConstants::kPFrontRightVel, 0, 0),
frc2::PIDController(DriveConstants::kPRearRightVel, 0, 0),
frc2::PIDController{DriveConstants::kPFrontLeftVel, 0, 0},
frc2::PIDController{DriveConstants::kPRearLeftVel, 0, 0},
frc2::PIDController{DriveConstants::kPFrontRightVel, 0, 0},
frc2::PIDController{DriveConstants::kPRearRightVel, 0, 0},
[this](units::volt_t frontLeft, units::volt_t rearLeft,
units::volt_t frontRight, units::volt_t rearRight) {

View File

@@ -28,7 +28,7 @@ DriveSubsystem::DriveSubsystem()
m_rearRightEncoder{kRearRightEncoderPorts[0], kRearRightEncoderPorts[1],
kRearRightEncoderReversed},
m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d()} {
m_odometry{kDriveKinematics, m_gyro.GetRotation2d(), frc::Pose2d{}} {
// Set the distance per pulse for the encoders
m_frontLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
m_rearLeftEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
@@ -46,10 +46,10 @@ void DriveSubsystem::Periodic() {
m_odometry.Update(
m_gyro.GetRotation2d(),
frc::MecanumDriveWheelSpeeds{
units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
units::meters_per_second_t(m_rearLeftEncoder.GetRate()),
units::meters_per_second_t(m_frontRightEncoder.GetRate()),
units::meters_per_second_t(m_rearRightEncoder.GetRate())});
units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
units::meters_per_second_t{m_rearLeftEncoder.GetRate()},
units::meters_per_second_t{m_frontRightEncoder.GetRate()},
units::meters_per_second_t{m_rearRightEncoder.GetRate()}});
}
void DriveSubsystem::Drive(double xSpeed, double ySpeed, double rot,
@@ -96,10 +96,10 @@ frc::Encoder& DriveSubsystem::GetRearRightEncoder() {
frc::MecanumDriveWheelSpeeds DriveSubsystem::getCurrentWheelSpeeds() {
return (frc::MecanumDriveWheelSpeeds{
units::meters_per_second_t(m_frontLeftEncoder.GetRate()),
units::meters_per_second_t(m_rearLeftEncoder.GetRate()),
units::meters_per_second_t(m_frontRightEncoder.GetRate()),
units::meters_per_second_t(m_rearRightEncoder.GetRate())});
units::meters_per_second_t{m_frontLeftEncoder.GetRate()},
units::meters_per_second_t{m_rearLeftEncoder.GetRate()},
units::meters_per_second_t{m_frontRightEncoder.GetRate()},
units::meters_per_second_t{m_rearRightEncoder.GetRate()}});
}
void DriveSubsystem::SetMaxOutput(double maxOutput) {

View File

@@ -7,6 +7,7 @@
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/acceleration.h>
#include <units/angle.h>
#include <units/angular_acceleration.h>
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/time.h>
@@ -70,15 +71,10 @@ constexpr double kPRearRightVel = 0.5;
} // namespace DriveConstants
namespace AutoConstants {
using radians_per_second_squared_t =
units::compound_unit<units::radians,
units::inverse<units::squared<units::second>>>;
constexpr auto kMaxSpeed = units::meters_per_second_t(3);
constexpr auto kMaxAcceleration = units::meters_per_second_squared_t(3);
constexpr auto kMaxAngularSpeed = units::radians_per_second_t(3);
constexpr auto kMaxAngularAcceleration =
units::unit_t<radians_per_second_squared_t>(3);
constexpr auto kMaxSpeed = 3_mps;
constexpr auto kMaxAcceleration = 3_mps_sq;
constexpr auto kMaxAngularSpeed = 3_rad_per_s;
constexpr auto kMaxAngularAcceleration = 3_rad_per_s_sq;
constexpr double kPXController = 0.5;
constexpr double kPYController = 0.5;