mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add C++20 std::math constants shim (#1788)
Based on http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0631r7.pdf
This commit is contained in:
committed by
Peter Johnson
parent
dd43109596
commit
37d316aa09
@@ -10,14 +10,13 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/HAL.h>
|
||||
#include <wpi/math>
|
||||
|
||||
#include "frc/DriverStation.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
|
||||
Joystick::Joystick(int port) : GenericHID(port) {
|
||||
m_axes[Axis::kX] = kDefaultXChannel;
|
||||
m_axes[Axis::kY] = kDefaultYChannel;
|
||||
@@ -91,5 +90,5 @@ double Joystick::GetDirectionRadians() const {
|
||||
}
|
||||
|
||||
double Joystick::GetDirectionDegrees() const {
|
||||
return (180 / kPi) * GetDirectionRadians();
|
||||
return (180 / wpi::math::pi) * GetDirectionRadians();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -11,14 +11,13 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/HAL.h>
|
||||
#include <wpi/math>
|
||||
|
||||
#include "frc/SpeedController.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
|
||||
KilloughDrive::KilloughDrive(SpeedController& leftMotor,
|
||||
SpeedController& rightMotor,
|
||||
SpeedController& backMotor)
|
||||
@@ -30,12 +29,12 @@ KilloughDrive::KilloughDrive(SpeedController& leftMotor,
|
||||
SpeedController& backMotor, double leftMotorAngle,
|
||||
double rightMotorAngle, double backMotorAngle)
|
||||
: m_leftMotor(leftMotor), m_rightMotor(rightMotor), m_backMotor(backMotor) {
|
||||
m_leftVec = {std::cos(leftMotorAngle * (kPi / 180.0)),
|
||||
std::sin(leftMotorAngle * (kPi / 180.0))};
|
||||
m_rightVec = {std::cos(rightMotorAngle * (kPi / 180.0)),
|
||||
std::sin(rightMotorAngle * (kPi / 180.0))};
|
||||
m_backVec = {std::cos(backMotorAngle * (kPi / 180.0)),
|
||||
std::sin(backMotorAngle * (kPi / 180.0))};
|
||||
m_leftVec = {std::cos(leftMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(leftMotorAngle * (wpi::math::pi / 180.0))};
|
||||
m_rightVec = {std::cos(rightMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(rightMotorAngle * (wpi::math::pi / 180.0))};
|
||||
m_backVec = {std::cos(backMotorAngle * (wpi::math::pi / 180.0)),
|
||||
std::sin(backMotorAngle * (wpi::math::pi / 180.0))};
|
||||
AddChild(&m_leftMotor);
|
||||
AddChild(&m_rightMotor);
|
||||
AddChild(&m_backMotor);
|
||||
@@ -84,8 +83,9 @@ void KilloughDrive::DrivePolar(double magnitude, double angle,
|
||||
reported = true;
|
||||
}
|
||||
|
||||
DriveCartesian(magnitude * std::sin(angle * (kPi / 180.0)),
|
||||
magnitude * std::cos(angle * (kPi / 180.0)), zRotation, 0.0);
|
||||
DriveCartesian(magnitude * std::sin(angle * (wpi::math::pi / 180.0)),
|
||||
magnitude * std::cos(angle * (wpi::math::pi / 180.0)),
|
||||
zRotation, 0.0);
|
||||
}
|
||||
|
||||
void KilloughDrive::StopMotor() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <hal/HAL.h>
|
||||
#include <wpi/math>
|
||||
|
||||
#include "frc/SpeedController.h"
|
||||
#include "frc/drive/Vector2d.h"
|
||||
@@ -18,8 +19,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
|
||||
MecanumDrive::MecanumDrive(SpeedController& frontLeftMotor,
|
||||
SpeedController& rearLeftMotor,
|
||||
SpeedController& frontRightMotor,
|
||||
@@ -81,8 +80,9 @@ void MecanumDrive::DrivePolar(double magnitude, double angle,
|
||||
reported = true;
|
||||
}
|
||||
|
||||
DriveCartesian(magnitude * std::sin(angle * (kPi / 180.0)),
|
||||
magnitude * std::cos(angle * (kPi / 180.0)), zRotation, 0.0);
|
||||
DriveCartesian(magnitude * std::sin(angle * (wpi::math::pi / 180.0)),
|
||||
magnitude * std::cos(angle * (wpi::math::pi / 180.0)),
|
||||
zRotation, 0.0);
|
||||
}
|
||||
|
||||
bool MecanumDrive::IsRightSideInverted() const {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace frc;
|
||||
#include <wpi/math>
|
||||
|
||||
constexpr double kPi = 3.14159265358979323846;
|
||||
using namespace frc;
|
||||
|
||||
Vector2d::Vector2d(double x, double y) {
|
||||
this->x = x;
|
||||
@@ -19,8 +19,8 @@ Vector2d::Vector2d(double x, double y) {
|
||||
}
|
||||
|
||||
void Vector2d::Rotate(double angle) {
|
||||
double cosA = std::cos(angle * (kPi / 180.0));
|
||||
double sinA = std::sin(angle * (kPi / 180.0));
|
||||
double cosA = std::cos(angle * (wpi::math::pi / 180.0));
|
||||
double sinA = std::sin(angle * (wpi::math::pi / 180.0));
|
||||
double out[2];
|
||||
out[0] = x * cosA - y * sinA;
|
||||
out[1] = x * sinA + y * cosA;
|
||||
|
||||
Reference in New Issue
Block a user