LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::FlywheelSimulator Class Reference

#include <flywheelSimulator.hpp>

Public Member Functions

 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.
 
virtual ~FlywheelSimulator ()
 
double step ()
 Step the simulation by the timestep.
 
double step (double itorque)
 Step the simulation by the timestep.
 
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 setTorque (double itorque)
 Sets the input torque.
 
void setMaxTorque (double imaxTorque)
 Sets the max torque.
 
void setAngle (double iangle)
 Sets the current angle.
 
void setMass (double imass)
 Sets the mass (kg).
 
void setLinkLength (double ilinkLen)
 Sets the link length (m).
 
void setStaticFriction (double imuStatic)
 Sets the static friction (N*m).
 
void setDynamicFriction (double imuDynamic)
 Sets the dynamic friction (N*m).
 
void setTimestep (double itimestep)
 Sets the timestep (sec).
 
double getAngle () const
 Returns the current angle (angle in rad).
 
double getOmega () const
 Returns the current omgea (angular velocity in rad / sec).
 
double getAcceleration () const
 Returns the current acceleration (angular acceleration in rad / sec^2).
 
double getMaxTorque () const
 Returns the maximum torque input.
 

Protected Member Functions

virtual double stepImpl ()
 

Protected Attributes

double inputTorque = 0
 
double maxTorque = 0.5649
 
double angle = 0
 
double omega = 0
 
double accel = 0
 
double mass
 
double linkLen
 
double muStatic
 
double muDynamic
 
double timestep
 
double I = 0
 
std::function< double(double, double, double)> torqueFunc
 
const double minTimestep = 0.000001
 

Detailed Description

Definition at line 11 of file flywheelSimulator.hpp.

Constructor & Destructor Documentation

◆ FlywheelSimulator()

okapi::FlywheelSimulator::FlywheelSimulator ( double  imass = 0.01,
double  ilinkLen = 1,
double  imuStatic = 0.1,
double  imuDynamic = 0.9,
double  itimestep = 0.01 
)
explicit

A simulator for an inverted pendulum.

The center of mass of the system changes as the link rotates (by default, you can set a new torque function with setExternalTorqueFunction()).

◆ ~FlywheelSimulator()

virtual okapi::FlywheelSimulator::~FlywheelSimulator ( )
virtual

Member Function Documentation

◆ getAcceleration()

double okapi::FlywheelSimulator::getAcceleration ( ) const

Returns the current acceleration (angular acceleration in rad / sec^2).

Returns
the current acceleration

◆ getAngle()

double okapi::FlywheelSimulator::getAngle ( ) const

Returns the current angle (angle in rad).

Returns
the current angle

◆ getMaxTorque()

double okapi::FlywheelSimulator::getMaxTorque ( ) const

Returns the maximum torque input.

Returns
the max torque input

◆ getOmega()

double okapi::FlywheelSimulator::getOmega ( ) const

Returns the current omgea (angular velocity in rad / sec).

Returns
the current omega

◆ setAngle()

void okapi::FlywheelSimulator::setAngle ( double  iangle)

Sets the current angle.

Parameters
ianglenew angle

◆ setDynamicFriction()

void okapi::FlywheelSimulator::setDynamicFriction ( double  imuDynamic)

Sets the dynamic friction (N*m).

Parameters
imuDynamicnew dynamic friction

◆ setExternalTorqueFunction()

void okapi::FlywheelSimulator::setExternalTorqueFunction ( std::function< double(double angle, double mass, double linkLength)>  itorqueFunc)

Sets the torque function used to calculate the torque due to external forces.

This torque gets summed with the input torque.

For example, the default torque function has the torque due to gravity vary as the link swings: [](double angle, double mass, double linkLength) { return (linkLength * std::cos(angle)) * (mass * -1 * gravity); }

Parameters
itorqueFuncthe torque function. The return value is the torque due to external forces

◆ setLinkLength()

void okapi::FlywheelSimulator::setLinkLength ( double  ilinkLen)

Sets the link length (m).

Parameters
ilinkLennew link length

◆ setMass()

void okapi::FlywheelSimulator::setMass ( double  imass)

Sets the mass (kg).

Parameters
imassnew mass

◆ setMaxTorque()

void okapi::FlywheelSimulator::setMaxTorque ( double  imaxTorque)

Sets the max torque.

The input torque cannot exceed this maximum torque.

Parameters
imaxTorquenew maximum torque

◆ setStaticFriction()

void okapi::FlywheelSimulator::setStaticFriction ( double  imuStatic)

Sets the static friction (N*m).

Parameters
imuStaticnew static friction

◆ setTimestep()

void okapi::FlywheelSimulator::setTimestep ( double  itimestep)

Sets the timestep (sec).

Parameters
itimestepnew timestep

◆ setTorque()

void okapi::FlywheelSimulator::setTorque ( double  itorque)

Sets the input torque.

The input will be bounded by the max torque.

Parameters
itorquenew input torque

◆ step() [1/2]

double okapi::FlywheelSimulator::step ( )

Step the simulation by the timestep.

Returns
the current angle

◆ step() [2/2]

double okapi::FlywheelSimulator::step ( double  itorque)

Step the simulation by the timestep.

Parameters
itorquenew input torque
Returns
the current angle

◆ stepImpl()

virtual double okapi::FlywheelSimulator::stepImpl ( )
protectedvirtual

Member Data Documentation

◆ accel

double okapi::FlywheelSimulator::accel = 0
protected

Definition at line 143 of file flywheelSimulator.hpp.

◆ angle

double okapi::FlywheelSimulator::angle = 0
protected

Definition at line 141 of file flywheelSimulator.hpp.

◆ I

double okapi::FlywheelSimulator::I = 0
protected

Definition at line 149 of file flywheelSimulator.hpp.

◆ inputTorque

double okapi::FlywheelSimulator::inputTorque = 0
protected

Definition at line 139 of file flywheelSimulator.hpp.

◆ linkLen

double okapi::FlywheelSimulator::linkLen
protected

Definition at line 145 of file flywheelSimulator.hpp.

◆ mass

double okapi::FlywheelSimulator::mass
protected

Definition at line 144 of file flywheelSimulator.hpp.

◆ maxTorque

double okapi::FlywheelSimulator::maxTorque = 0.5649
protected

Definition at line 140 of file flywheelSimulator.hpp.

◆ minTimestep

const double okapi::FlywheelSimulator::minTimestep = 0.000001
protected

Definition at line 152 of file flywheelSimulator.hpp.

◆ muDynamic

double okapi::FlywheelSimulator::muDynamic
protected

Definition at line 147 of file flywheelSimulator.hpp.

◆ muStatic

double okapi::FlywheelSimulator::muStatic
protected

Definition at line 146 of file flywheelSimulator.hpp.

◆ omega

double okapi::FlywheelSimulator::omega = 0
protected

Definition at line 142 of file flywheelSimulator.hpp.

◆ timestep

double okapi::FlywheelSimulator::timestep
protected

Definition at line 148 of file flywheelSimulator.hpp.

◆ torqueFunc

std::function<double(double, double, double)> okapi::FlywheelSimulator::torqueFunc
protected

Definition at line 150 of file flywheelSimulator.hpp.


The documentation for this class was generated from the following file: