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

@@ -9,12 +9,13 @@
#include "Robot.h"
DriveStraight::DriveStraight(double distance, Drivetrain& drivetrain)
: frc2::CommandHelper<frc2::PIDCommand, DriveStraight>(
frc2::PIDController(4, 0, 0),
[&drivetrain] { return drivetrain.GetDistance(); }, distance,
: frc2::CommandHelper<frc2::PIDCommand, DriveStraight>{
frc2::PIDController{4, 0, 0},
[&drivetrain] { return drivetrain.GetDistance(); },
distance,
[&drivetrain](double output) { drivetrain.Drive(output, output); },
{&drivetrain}),
m_drivetrain(&drivetrain) {
{&drivetrain}},
m_drivetrain{&drivetrain} {
m_controller.SetTolerance(0.01);
}

View File

@@ -9,13 +9,13 @@
#include "Robot.h"
SetDistanceToBox::SetDistanceToBox(double distance, Drivetrain& drivetrain)
: frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>(
frc2::PIDController(-2, 0, 0),
: frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>{
frc2::PIDController{-2, 0, 0},
[&drivetrain] { return drivetrain.GetDistanceToObstacle(); },
distance,
[&drivetrain](double output) { drivetrain.Drive(output, output); },
{&drivetrain}),
m_drivetrain(&drivetrain) {
{&drivetrain}},
m_drivetrain{&drivetrain} {
m_controller.SetTolerance(0.01);
}

View File

@@ -9,7 +9,7 @@
#include <frc/smartdashboard/SmartDashboard.h>
Elevator::Elevator()
: frc2::PIDSubsystem(frc2::PIDController(kP_real, kI_real, 0)) {
: frc2::PIDSubsystem{frc2::PIDController{kP_real, kI_real, 0}} {
#ifdef SIMULATION // Check for simulation and update PID values
GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0);
#endif

View File

@@ -7,7 +7,7 @@
#include <frc/controller/PIDController.h>
#include <frc/smartdashboard/SmartDashboard.h>
Wrist::Wrist() : frc2::PIDSubsystem(frc2::PIDController(kP, 0, 0)) {
Wrist::Wrist() : frc2::PIDSubsystem{frc2::PIDController{kP, 0, 0}} {
m_controller.SetTolerance(2.5);
SetName("Wrist");