LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
flywheelSimulator.hpp
Go to the documentation of this file.
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6#pragma once
7
8#include <functional>
9
10namespace okapi {
12 public:
17 explicit FlywheelSimulator(double imass = 0.01,
18 double ilinkLen = 1,
19 double imuStatic = 0.1,
20 double imuDynamic = 0.9,
21 double itimestep = 0.01);
22
24
30 double step();
31
38 double step(double itorque);
39
52 std::function<double(double angle, double mass, double linkLength)> itorqueFunc);
53
59 void setTorque(double itorque);
60
66 void setMaxTorque(double imaxTorque);
67
73 void setAngle(double iangle);
74
80 void setMass(double imass);
81
87 void setLinkLength(double ilinkLen);
88
94 void setStaticFriction(double imuStatic);
95
101 void setDynamicFriction(double imuDynamic);
102
108 void setTimestep(double itimestep);
109
115 double getAngle() const;
116
122 double getOmega() const;
123
129 double getAcceleration() const;
130
136 double getMaxTorque() const;
137
138 protected:
139 double inputTorque = 0; // N*m
140 double maxTorque = 0.5649; // N*m
141 double angle = 0; // rad
142 double omega = 0; // rad / sec
143 double accel = 0; // rad / sec^2
144 double mass; // kg
145 double linkLen; // m
146 double muStatic; // N*m
147 double muDynamic; // N*m
148 double timestep; // sec
149 double I = 0; // moment of inertia
150 std::function<double(double, double, double)> torqueFunc;
151
152 const double minTimestep = 0.000001; // 1 us
153
154 virtual double stepImpl();
155};
156} // namespace okapi
double getMaxTorque() const
Returns the maximum torque input.
double step()
Step the simulation by the timestep.
void setMass(double imass)
Sets the mass (kg).
void setTorque(double itorque)
Sets the input torque.
double getOmega() const
Returns the current omgea (angular velocity in rad / sec).
void setExternalTorqueFunction(std::function< double(double angle, double mass, double linkLength)> itorqueFunc)
Sets the torque function used to calculate the torque due to external forces.
void setMaxTorque(double imaxTorque)
Sets the max torque.
double getAngle() const
Returns the current angle (angle in rad).
void setLinkLength(double ilinkLen)
Sets the link length (m).
double step(double itorque)
Step the simulation by the timestep.
void setStaticFriction(double imuStatic)
Sets the static friction (N*m).
virtual double stepImpl()
std::function< double(double, double, double)> torqueFunc
FlywheelSimulator(double imass=0.01, double ilinkLen=1, double imuStatic=0.1, double imuDynamic=0.9, double itimestep=0.01)
A simulator for an inverted pendulum.
void setTimestep(double itimestep)
Sets the timestep (sec).
void setDynamicFriction(double imuDynamic)
Sets the dynamic friction (N*m).
void setAngle(double iangle)
Sets the current angle.
double getAcceleration() const
Returns the current acceleration (angular acceleration in rad / sec^2).