[wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)

The constants were moved from std::math to std::numbers before
ratification in C++20.
This commit is contained in:
Tyler Veness
2021-05-26 00:09:36 -07:00
committed by GitHub
parent 393bf23c0c
commit a238cec12b
73 changed files with 322 additions and 284 deletions

View File

@@ -8,7 +8,7 @@
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -34,7 +34,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ArmConstants {
@@ -54,7 +55,8 @@ constexpr auto kMaxAcceleration = 10_rad / (1_s * 1_s);
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
constexpr auto kEncoderDistancePerPulse = 2.0_rad * wpi::math::pi / kEncoderPPR;
constexpr auto kEncoderDistancePerPulse =
2.0_rad * wpi::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal

View File

@@ -8,7 +8,7 @@
#include <units/angular_velocity.h>
#include <units/time.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -34,7 +34,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ArmConstants {
@@ -54,7 +55,8 @@ constexpr auto kMaxAcceleration = 10_rad / (1_s * 1_s);
constexpr int kEncoderPorts[]{4, 5};
constexpr int kEncoderPPR = 256;
constexpr auto kEncoderDistancePerPulse = 2.0_rad * wpi::math::pi / kEncoderPPR;
constexpr auto kEncoderDistancePerPulse =
2.0_rad * wpi::numbers::pi / kEncoderPPR;
// The offset of the arm from the horizontal in its neutral position,
// measured from the horizontal

View File

@@ -17,7 +17,7 @@
#include <frc/system/plant/LinearSystemId.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -35,7 +35,7 @@ class Robot : public frc::TimedRobot {
// distance per pulse = (angle per revolution) / (pulses per revolution)
// = (2 * PI rads) / (4096 pulses)
static constexpr double kArmEncoderDistPerPulse =
2.0 * wpi::math::pi / 4096.0;
2.0 * wpi::numbers::pi / 4096.0;
// The arm gearbox represents a gerbox containing two Vex 775pro motors.
frc::DCMotor m_armGearbox = frc::DCMotor::Vex775Pro(2);

View File

@@ -16,7 +16,7 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -28,9 +28,9 @@ class Drivetrain {
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_leftEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -40,7 +40,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,

View File

@@ -16,7 +16,7 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -29,9 +29,9 @@ class Drivetrain {
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_leftEncoder.SetDistancePerPulse(
2 * wpi::math::pi * kWheelRadius.to<double>() / kEncoderResolution);
2 * wpi::numbers::pi * kWheelRadius.to<double>() / kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(
2 * wpi::math::pi * kWheelRadius.to<double>() / kEncoderResolution);
2 * wpi::numbers::pi * kWheelRadius.to<double>() / kEncoderResolution);
m_leftEncoder.Reset();
m_rightEncoder.Reset();
@@ -40,7 +40,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,

View File

@@ -9,7 +9,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide

View File

@@ -12,14 +12,14 @@
#include <units/length.h>
#include <units/time.h>
#include <units/velocity.h>
#include <wpi/math>
#include <wpi/numbers>
class Robot : public frc::TimedRobot {
public:
static constexpr units::second_t kDt = 20_ms;
Robot() {
m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::math::pi * 1.5);
m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
}
void TeleopPeriodic() override {

View File

@@ -17,7 +17,7 @@
#include <frc/system/plant/LinearSystemId.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -40,7 +40,7 @@ class Robot : public frc::TimedRobot {
// distance per pulse = (distance per revolution) / (pulses per revolution)
// = (Pi * D) / ppr
static constexpr double kArmEncoderDistPerPulse =
2.0 * wpi::math::pi * kElevatorDrumRadius.to<double>() / 4096.0;
2.0 * wpi::numbers::pi * kElevatorDrumRadius.to<double>() / 4096.0;
// This gearbox represents a gearbox containing 4 Vex 775pro motors.
frc::DCMotor m_elevatorGearbox = frc::DCMotor::Vex775Pro(4);

View File

@@ -11,7 +11,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
#include "ExampleSmartMotorController.h"

View File

@@ -5,7 +5,7 @@
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Sample program displaying the value of a quadrature encoder on the
@@ -40,7 +40,7 @@ class Robot : public frc::TimedRobot {
* inch diameter (1.5inch radius) wheel, and that we want to measure
* distance in inches.
*/
m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::math::pi * 1.5);
m_encoder.SetDistancePerPulse(1.0 / 360.0 * 2.0 * wpi::numbers::pi * 1.5);
/* Defines the lowest rate at which the encoder will not be considered
* stopped, for the purposes of the GetStopped() method. Units are in

View File

@@ -7,7 +7,7 @@
#include <units/angle.h>
#include <units/time.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -33,7 +33,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace ShooterConstants {

View File

@@ -7,7 +7,7 @@
#include <frc/Joystick.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <units/length.h>
#include <wpi/math>
#include <wpi/numbers>
DriveTrain::DriveTrain() {
// Encoders may measure differently in the real world and in
@@ -21,9 +21,9 @@ DriveTrain::DriveTrain() {
#else
// Circumference = diameter * pi. 360 tick simulated encoders.
m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.to<double>() *
wpi::math::pi / 360.0);
wpi::numbers::pi / 360.0);
m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.to<double>() *
wpi::math::pi / 360.0);
wpi::numbers::pi / 360.0);
#endif
SetName("DriveTrain");
// Let's show everything on the LiveWindow

View File

@@ -6,7 +6,7 @@
#include <units/angle.h>
#include <units/angular_velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -32,7 +32,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
constexpr bool kGyroReversed = true;

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -30,7 +30,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace HatchConstants {

View File

@@ -4,7 +4,7 @@
#pragma once
#include <wpi/math>
#include <wpi/numbers>
/**
* The Constants header provides a convenient place for teams to hold robot-wide
@@ -30,7 +30,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
} // namespace DriveConstants
namespace HatchConstants {

View File

@@ -13,7 +13,7 @@
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a mecanum drive style drivetrain.
@@ -32,7 +32,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
private:
frc::PWMSparkMax m_frontLeftMotor{1};

View File

@@ -12,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
#pragma once
@@ -51,7 +51,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterMeters = .15;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterMeters * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterMeters * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
// These characterization values MUST be determined either experimentally or

View File

@@ -14,7 +14,7 @@
#include <frc/kinematics/MecanumDriveOdometry.h>
#include <frc/kinematics/MecanumDriveWheelSpeeds.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a mecanum drive style drivetrain.
@@ -32,7 +32,7 @@ class Drivetrain {
static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
private:
frc::PWMSparkMax m_frontLeftMotor{1};

View File

@@ -7,7 +7,7 @@
#include <frc/TimedRobot.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This sample program shows how to control a motor using a joystick. In the
@@ -35,7 +35,7 @@ class Robot : public frc::TimedRobot {
void RobotInit() override {
// Use SetDistancePerPulse to set the multiplier for GetDistance
// This is set up assuming a 6 inch wheel with a 360 CPR encoder.
m_encoder.SetDistancePerPulse((wpi::math::pi * 6) / 360.0);
m_encoder.SetDistancePerPulse((wpi::numbers::pi * 6) / 360.0);
}
private:

View File

@@ -6,7 +6,7 @@
#include <frc/Joystick.h>
#include <units/length.h>
#include <wpi/math>
#include <wpi/numbers>
#include "commands/DriveWithJoystick.h"
@@ -31,9 +31,9 @@ DriveTrain::DriveTrain() : frc::Subsystem("DriveTrain") {
#else
// Circumference = diameter * pi. 360 tick simulated encoders.
m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.to<double>() *
wpi::math::pi / 360.0);
wpi::numbers::pi / 360.0);
m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.to<double>() *
wpi::math::pi / 360.0);
wpi::numbers::pi / 360.0);
#endif
AddChild("Right Encoder", m_rightEncoder);

View File

@@ -9,7 +9,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
#pragma once
@@ -40,7 +40,8 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterInches = 6;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterInches * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterInches * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!
// These characterization values MUST be determined either experimentally or

View File

@@ -14,7 +14,7 @@
#include <frc/motorcontrol/PWMSparkMax.h>
#include <units/angular_velocity.h>
#include <units/length.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -26,9 +26,9 @@ class Drivetrain {
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_leftEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -38,7 +38,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,

View File

@@ -5,7 +5,7 @@
#include "commands/TurnDegrees.h"
#include <units/math.h>
#include <wpi/math>
#include <wpi/numbers>
void TurnDegrees::Initialize() {
// Set motors to stop, read encoder values for starting point
@@ -26,7 +26,7 @@ bool TurnDegrees::IsFinished() {
// found here https://www.pololu.com/category/203/romi-chassis-kits, has a
// wheel placement diameter (149 mm) - width of the wheel (8 mm) = 141 mm
// or 5.551 inches. We then take into consideration the width of the tires.
static auto inchPerDegree = (5.551_in * wpi::math::pi) / 360_deg;
static auto inchPerDegree = (5.551_in * wpi::numbers::pi) / 360_deg;
// Compare distance traveled from start to distance based on degree turn.
return GetAverageTurningDistance() >= inchPerDegree * m_angle;

View File

@@ -4,7 +4,7 @@
#include "subsystems/Drivetrain.h"
#include <wpi/math>
#include <wpi/numbers>
#include "Constants.h"
@@ -16,9 +16,9 @@ using namespace DriveConstants;
// to use DIO pins 4/5 and 6/7 for the left and right
Drivetrain::Drivetrain() {
m_leftEncoder.SetDistancePerPulse(
wpi::math::pi * kWheelDiameter.to<double>() / kCountsPerRevolution);
wpi::numbers::pi * kWheelDiameter.to<double>() / kCountsPerRevolution);
m_rightEncoder.SetDistancePerPulse(
wpi::math::pi * kWheelDiameter.to<double>() / kCountsPerRevolution);
wpi::numbers::pi * kWheelDiameter.to<double>() / kCountsPerRevolution);
ResetEncoders();
}

View File

@@ -22,7 +22,7 @@
#include <units/angular_velocity.h>
#include <units/length.h>
#include <units/velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* Represents a differential drive style drivetrain.
@@ -34,9 +34,9 @@ class Drivetrain {
// Set the distance per pulse for the drive encoders. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_leftEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_leftEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_rightEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_rightEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
m_leftEncoder.Reset();
@@ -50,7 +50,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
void SetSpeeds(const frc::DifferentialDriveWheelSpeeds& speeds);
void Drive(units::meters_per_second_t xSpeed,

View File

@@ -18,7 +18,7 @@
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/angle.h>
#include <units/moment_of_inertia.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -66,7 +66,8 @@ class Robot : public frc::TimedRobot {
// qelms. Velocity error tolerance, in radians and radians per second.
// Decrease this to more heavily penalize state excursion, or make the
// controller behave more aggressively.
{1.0 * 2.0 * wpi::math::pi / 360.0, 10.0 * 2.0 * wpi::math::pi / 360.0},
{1.0 * 2.0 * wpi::numbers::pi / 360.0,
10.0 * 2.0 * wpi::numbers::pi / 360.0},
// relms. Control effort (voltage) tolerance. Decrease this to more
// heavily penalize control effort, or make the controller less
// aggressive. 12 is a good starting point because that is the
@@ -95,7 +96,7 @@ class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
void TeleopInit() override {

View File

@@ -12,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
#pragma once
@@ -43,7 +43,7 @@ constexpr int kEncoderCPR = 1024;
constexpr auto kWheelDiameter = 6_in;
constexpr double kEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameter.to<double>() * wpi::math::pi) /
(kWheelDiameter.to<double>() * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
// These are example values only - DO NOT USE THESE FOR YOUR OWN ROBOT!

View File

@@ -19,7 +19,7 @@
#include <units/length.h>
#include <units/mass.h>
#include <units/velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -92,7 +92,7 @@ class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
// Circumference = pi * d, so distance per click = pi * d / counts
m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi *
m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi *
kDrumRadius.to<double>() / 4096.0);
}

View File

@@ -16,7 +16,7 @@
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
#include <units/angular_velocity.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -83,7 +83,7 @@ class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
void TeleopInit() override {

View File

@@ -16,7 +16,7 @@
#include <frc/system/LinearSystemLoop.h>
#include <frc/system/plant/DCMotor.h>
#include <frc/system/plant/LinearSystemId.h>
#include <wpi/math>
#include <wpi/numbers>
/**
* This is a sample program to demonstrate how to use a state-space controller
@@ -84,7 +84,7 @@ class Robot : public frc::TimedRobot {
public:
void RobotInit() override {
// We go 2 pi radians per 4096 clicks.
m_encoder.SetDistancePerPulse(2.0 * wpi::math::pi / 4096.0);
m_encoder.SetDistancePerPulse(2.0 * wpi::numbers::pi / 4096.0);
}
void TeleopInit() override {

View File

@@ -5,7 +5,7 @@
#include "SwerveModule.h"
#include <frc/geometry/Rotation2d.h>
#include <wpi/math>
#include <wpi/numbers>
SwerveModule::SwerveModule(const int driveMotorChannel,
const int turningMotorChannel,
@@ -20,18 +20,19 @@ SwerveModule::SwerveModule(const int driveMotorChannel,
// Set the distance per pulse for the drive encoder. We can simply use the
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_driveEncoder.SetDistancePerPulse(2 * wpi::math::pi * kWheelRadius /
m_driveEncoder.SetDistancePerPulse(2 * wpi::numbers::pi * kWheelRadius /
kEncoderResolution);
// Set the distance (in this case, angle) per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * wpi::math::pi)
// This is the the angle through an entire rotation (2 * wpi::numbers::pi)
// divided by the encoder resolution.
m_turningEncoder.SetDistancePerPulse(2 * wpi::math::pi / kEncoderResolution);
m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
kEncoderResolution);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(-units::radian_t(wpi::math::pi),
units::radian_t(wpi::math::pi));
m_turningPIDController.EnableContinuousInput(
-units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
}
frc::SwerveModuleState SwerveModule::GetState() const {

View File

@@ -8,7 +8,7 @@
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
#include <wpi/math>
#include <wpi/numbers>
#include "SwerveModule.h"
@@ -27,7 +27,7 @@ class Drivetrain {
static constexpr units::meters_per_second_t kMaxSpeed =
3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
private:
frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};

View File

@@ -14,7 +14,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
class SwerveModule {
public:
@@ -29,9 +29,9 @@ class SwerveModule {
static constexpr int kEncoderResolution = 4096;
static constexpr auto kModuleMaxAngularVelocity =
wpi::math::pi * 1_rad_per_s; // radians per second
wpi::numbers::pi * 1_rad_per_s; // radians per second
static constexpr auto kModuleMaxAngularAcceleration =
wpi::math::pi * 2_rad_per_s / 1_s; // radians per second^2
wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
frc::PWMSparkMax m_driveMotor;
frc::PWMSparkMax m_turningMotor;

View File

@@ -67,8 +67,8 @@ frc2::Command* RobotContainer::GetAutonomousCommand() {
AutoConstants::kPThetaController, 0, 0,
AutoConstants::kThetaControllerConstraints};
thetaController.EnableContinuousInput(units::radian_t(-wpi::math::pi),
units::radian_t(wpi::math::pi));
thetaController.EnableContinuousInput(units::radian_t(-wpi::numbers::pi),
units::radian_t(wpi::numbers::pi));
frc2::SwerveControllerCommand<4> swerveControllerCommand(
exampleTrajectory, [this]() { return m_drive.GetPose(); },

View File

@@ -5,7 +5,7 @@
#include "subsystems/SwerveModule.h"
#include <frc/geometry/Rotation2d.h>
#include <wpi/math>
#include <wpi/numbers>
#include "Constants.h"
@@ -27,15 +27,15 @@ SwerveModule::SwerveModule(int driveMotorChannel, int turningMotorChannel,
ModuleConstants::kDriveEncoderDistancePerPulse);
// Set the distance (in this case, angle) per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * wpi::math::pi)
// This is the the angle through an entire rotation (2 * wpi::numbers::pi)
// divided by the encoder resolution.
m_turningEncoder.SetDistancePerPulse(
ModuleConstants::kTurningEncoderDistancePerPulse);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(units::radian_t(-wpi::math::pi),
units::radian_t(wpi::math::pi));
m_turningPIDController.EnableContinuousInput(
units::radian_t(-wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
}
frc::SwerveModuleState SwerveModule::GetState() {

View File

@@ -12,7 +12,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
#pragma once
@@ -77,11 +77,12 @@ constexpr int kEncoderCPR = 1024;
constexpr double kWheelDiameterMeters = .15;
constexpr double kDriveEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(kWheelDiameterMeters * wpi::math::pi) / static_cast<double>(kEncoderCPR);
(kWheelDiameterMeters * wpi::numbers::pi) /
static_cast<double>(kEncoderCPR);
constexpr double kTurningEncoderDistancePerPulse =
// Assumes the encoders are directly mounted on the wheel shafts
(wpi::math::pi * 2) / static_cast<double>(kEncoderCPR);
(wpi::numbers::pi * 2) / static_cast<double>(kEncoderCPR);
constexpr double kPModuleTurningController = 1;
constexpr double kPModuleDriveController = 1;

View File

@@ -11,7 +11,7 @@
#include <frc/kinematics/SwerveModuleState.h>
#include <frc/motorcontrol/Spark.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <wpi/math>
#include <wpi/numbers>
#include "Constants.h"
@@ -37,11 +37,11 @@ class SwerveModule {
// meters per second squared.
static constexpr units::radians_per_second_t kModuleMaxAngularVelocity =
units::radians_per_second_t(wpi::math::pi); // radians per second
units::radians_per_second_t(wpi::numbers::pi); // radians per second
static constexpr units::unit_t<radians_per_second_squared_t>
kModuleMaxAngularAcceleration =
units::unit_t<radians_per_second_squared_t>(
wpi::math::pi * 2.0); // radians per second squared
wpi::numbers::pi * 2.0); // radians per second squared
frc::Spark m_driveMotor;
frc::Spark m_turningMotor;

View File

@@ -5,7 +5,7 @@
#include "SwerveModule.h"
#include <frc/geometry/Rotation2d.h>
#include <wpi/math>
#include <wpi/numbers>
SwerveModule::SwerveModule(const int driveMotorChannel,
const int turningMotorChannel,
@@ -21,17 +21,18 @@ SwerveModule::SwerveModule(const int driveMotorChannel,
// distance traveled for one rotation of the wheel divided by the encoder
// resolution.
m_driveEncoder.SetDistancePerPulse(
2 * wpi::math::pi * kWheelRadius.to<double>() / kEncoderResolution);
2 * wpi::numbers::pi * kWheelRadius.to<double>() / kEncoderResolution);
// Set the distance (in this case, angle) per pulse for the turning encoder.
// This is the the angle through an entire rotation (2 * wpi::math::pi)
// This is the the angle through an entire rotation (2 * wpi::numbers::pi)
// divided by the encoder resolution.
m_turningEncoder.SetDistancePerPulse(2 * wpi::math::pi / kEncoderResolution);
m_turningEncoder.SetDistancePerPulse(2 * wpi::numbers::pi /
kEncoderResolution);
// Limit the PID Controller's input range between -pi and pi and set the input
// to be continuous.
m_turningPIDController.EnableContinuousInput(-units::radian_t(wpi::math::pi),
units::radian_t(wpi::math::pi));
m_turningPIDController.EnableContinuousInput(
-units::radian_t(wpi::numbers::pi), units::radian_t(wpi::numbers::pi));
}
frc::SwerveModuleState SwerveModule::GetState() const {

View File

@@ -9,7 +9,7 @@
#include <frc/geometry/Translation2d.h>
#include <frc/kinematics/SwerveDriveKinematics.h>
#include <frc/kinematics/SwerveDriveOdometry.h>
#include <wpi/math>
#include <wpi/numbers>
#include "SwerveModule.h"
@@ -27,7 +27,7 @@ class Drivetrain {
static constexpr auto kMaxSpeed = 3.0_mps; // 3 meters per second
static constexpr units::radians_per_second_t kMaxAngularSpeed{
wpi::math::pi}; // 1/2 rotation per second
wpi::numbers::pi}; // 1/2 rotation per second
private:
frc::Translation2d m_frontLeftLocation{+0.381_m, +0.381_m};

View File

@@ -14,7 +14,7 @@
#include <units/time.h>
#include <units/velocity.h>
#include <units/voltage.h>
#include <wpi/math>
#include <wpi/numbers>
class SwerveModule {
public:
@@ -29,9 +29,9 @@ class SwerveModule {
static constexpr int kEncoderResolution = 4096;
static constexpr auto kModuleMaxAngularVelocity =
wpi::math::pi * 1_rad_per_s; // radians per second
wpi::numbers::pi * 1_rad_per_s; // radians per second
static constexpr auto kModuleMaxAngularAcceleration =
wpi::math::pi * 2_rad_per_s / 1_s; // radians per second^2
wpi::numbers::pi * 2_rad_per_s / 1_s; // radians per second^2
frc::PWMSparkMax m_driveMotor;
frc::PWMSparkMax m_turningMotor;