mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
@@ -15,19 +15,20 @@ using namespace frc::sim;
|
||||
ElevatorSim::ElevatorSim(const LinearSystem<2, 1, 1>& plant,
|
||||
const DCMotor& gearbox, double gearing,
|
||||
units::meter_t drumRadius, units::meter_t minHeight,
|
||||
units::meter_t maxHeight,
|
||||
units::meter_t maxHeight, bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: LinearSystemSim(plant, measurementStdDevs),
|
||||
m_gearbox(gearbox),
|
||||
m_drumRadius(drumRadius),
|
||||
m_minHeight(minHeight),
|
||||
m_maxHeight(maxHeight),
|
||||
m_gearing(gearing) {}
|
||||
m_gearing(gearing),
|
||||
m_simulateGravity(simulateGravity) {}
|
||||
|
||||
ElevatorSim::ElevatorSim(const DCMotor& gearbox, double gearing,
|
||||
units::kilogram_t carriageMass,
|
||||
units::meter_t drumRadius, units::meter_t minHeight,
|
||||
units::meter_t maxHeight,
|
||||
units::meter_t maxHeight, bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: LinearSystemSim(LinearSystemId::ElevatorSystem(gearbox, carriageMass,
|
||||
drumRadius, gearing),
|
||||
@@ -36,7 +37,8 @@ ElevatorSim::ElevatorSim(const DCMotor& gearbox, double gearing,
|
||||
m_drumRadius(drumRadius),
|
||||
m_minHeight(minHeight),
|
||||
m_maxHeight(maxHeight),
|
||||
m_gearing(gearing) {}
|
||||
m_gearing(gearing),
|
||||
m_simulateGravity(simulateGravity) {}
|
||||
|
||||
bool ElevatorSim::WouldHitLowerLimit(units::meter_t elevatorHeight) const {
|
||||
return elevatorHeight < m_minHeight;
|
||||
@@ -87,8 +89,12 @@ Eigen::Vector<double, 2> ElevatorSim::UpdateX(
|
||||
auto updatedXhat = RKDP(
|
||||
[&](const Eigen::Vector<double, 2>& x,
|
||||
const Eigen::Vector<double, 1>& u_) -> Eigen::Vector<double, 2> {
|
||||
return m_plant.A() * x + m_plant.B() * u_ +
|
||||
Eigen::Vector<double, 2>{0.0, -9.8};
|
||||
Eigen::Vector<double, 2> xdot = m_plant.A() * x + m_plant.B() * u;
|
||||
|
||||
if (m_simulateGravity) {
|
||||
xdot += Eigen::Vector<double, 2>{0.0, -9.8};
|
||||
}
|
||||
return xdot;
|
||||
},
|
||||
currentXhat, u, dt);
|
||||
// Check for collision after updating x-hat.
|
||||
|
||||
@@ -18,13 +18,13 @@ using namespace frc::sim;
|
||||
SingleJointedArmSim::SingleJointedArmSim(
|
||||
const LinearSystem<2, 1, 1>& system, const DCMotor& gearbox, double gearing,
|
||||
units::meter_t armLength, units::radian_t minAngle,
|
||||
units::radian_t maxAngle, units::kilogram_t mass, bool simulateGravity,
|
||||
units::radian_t maxAngle, units::kilogram_t armMass, bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: LinearSystemSim<2, 1, 1>(system, measurementStdDevs),
|
||||
m_r(armLength),
|
||||
m_minAngle(minAngle),
|
||||
m_maxAngle(maxAngle),
|
||||
m_mass(mass),
|
||||
m_armMass(armMass),
|
||||
m_gearbox(gearbox),
|
||||
m_gearing(gearing),
|
||||
m_simulateGravity(simulateGravity) {}
|
||||
@@ -32,11 +32,11 @@ SingleJointedArmSim::SingleJointedArmSim(
|
||||
SingleJointedArmSim::SingleJointedArmSim(
|
||||
const DCMotor& gearbox, double gearing, units::kilogram_square_meter_t moi,
|
||||
units::meter_t armLength, units::radian_t minAngle,
|
||||
units::radian_t maxAngle, units::kilogram_t mass, bool simulateGravity,
|
||||
units::radian_t maxAngle, units::kilogram_t armMass, bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: SingleJointedArmSim(
|
||||
LinearSystemId::SingleJointedArmSystem(gearbox, moi, gearing),
|
||||
gearbox, gearing, armLength, minAngle, maxAngle, mass,
|
||||
gearbox, gearing, armLength, minAngle, maxAngle, armMass,
|
||||
simulateGravity, measurementStdDevs) {}
|
||||
|
||||
bool SingleJointedArmSim::WouldHitLowerLimit(units::radian_t armAngle) const {
|
||||
@@ -94,7 +94,7 @@ Eigen::Vector<double, 2> SingleJointedArmSim::UpdateX(
|
||||
|
||||
if (m_simulateGravity) {
|
||||
xdot += Eigen::Vector<double, 2>{
|
||||
0.0, (m_mass * m_r * -9.8 * 3.0 / (m_mass * m_r * m_r) *
|
||||
0.0, (m_armMass * m_r * -9.8 * 3.0 / (m_armMass * m_r * m_r) *
|
||||
std::cos(x(0)))
|
||||
.value()};
|
||||
}
|
||||
|
||||
@@ -31,11 +31,13 @@ class ElevatorSim : public LinearSystemSim<2, 1, 1> {
|
||||
* wrapped around.
|
||||
* @param minHeight The minimum allowed height of the elevator.
|
||||
* @param maxHeight The maximum allowed height of the elevator.
|
||||
* @param simulateGravity Whether gravity should be simulated or not.
|
||||
* @param measurementStdDevs The standard deviation of the measurements.
|
||||
*/
|
||||
ElevatorSim(const LinearSystem<2, 1, 1>& plant, const DCMotor& gearbox,
|
||||
double gearing, units::meter_t drumRadius,
|
||||
units::meter_t minHeight, units::meter_t maxHeight,
|
||||
bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
|
||||
/**
|
||||
@@ -50,11 +52,13 @@ class ElevatorSim : public LinearSystemSim<2, 1, 1> {
|
||||
* wrapped around.
|
||||
* @param minHeight The minimum allowed height of the elevator.
|
||||
* @param maxHeight The maximum allowed height of the elevator.
|
||||
* @param simulateGravity Whether gravity should be simulated or not.
|
||||
* @param measurementStdDevs The standard deviation of the measurements.
|
||||
*/
|
||||
ElevatorSim(const DCMotor& gearbox, double gearing,
|
||||
units::kilogram_t carriageMass, units::meter_t drumRadius,
|
||||
units::meter_t minHeight, units::meter_t maxHeight,
|
||||
bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
|
||||
/**
|
||||
@@ -133,5 +137,6 @@ class ElevatorSim : public LinearSystemSim<2, 1, 1> {
|
||||
units::meter_t m_minHeight;
|
||||
units::meter_t m_maxHeight;
|
||||
double m_gearing;
|
||||
bool m_simulateGravity;
|
||||
};
|
||||
} // namespace frc::sim
|
||||
|
||||
@@ -30,14 +30,14 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 1> {
|
||||
* @param armLength The length of the arm.
|
||||
* @param minAngle The minimum angle that the arm is capable of.
|
||||
* @param maxAngle The maximum angle that the arm is capable of.
|
||||
* @param mass The mass of the arm.
|
||||
* @param measurementStdDevs The standard deviations of the measurements.
|
||||
* @param armMass The mass of the arm.
|
||||
* @param simulateGravity Whether gravity should be simulated or not.
|
||||
* @param measurementStdDevs The standard deviations of the measurements.
|
||||
*/
|
||||
SingleJointedArmSim(const LinearSystem<2, 1, 1>& system,
|
||||
const DCMotor& gearbox, double gearing,
|
||||
units::meter_t armLength, units::radian_t minAngle,
|
||||
units::radian_t maxAngle, units::kilogram_t mass,
|
||||
units::radian_t maxAngle, units::kilogram_t armMass,
|
||||
bool simulateGravity,
|
||||
const std::array<double, 1>& measurementStdDevs = {0.0});
|
||||
/**
|
||||
@@ -52,8 +52,8 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 1> {
|
||||
* @param minAngle The minimum angle that the arm is capable of.
|
||||
* @param maxAngle The maximum angle that the arm is capable of.
|
||||
* @param mass The mass of the arm.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
* @param simulateGravity Whether gravity should be simulated or not.
|
||||
* @param measurementStdDevs The standard deviation of the measurement noise.
|
||||
*/
|
||||
SingleJointedArmSim(const DCMotor& gearbox, double gearing,
|
||||
units::kilogram_square_meter_t moi,
|
||||
@@ -150,7 +150,7 @@ class SingleJointedArmSim : public LinearSystemSim<2, 1, 1> {
|
||||
units::meter_t m_r;
|
||||
units::radian_t m_minAngle;
|
||||
units::radian_t m_maxAngle;
|
||||
units::kilogram_t m_mass;
|
||||
units::kilogram_t m_armMass;
|
||||
const DCMotor m_gearbox;
|
||||
double m_gearing;
|
||||
bool m_simulateGravity;
|
||||
|
||||
Reference in New Issue
Block a user