YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Member Functions | List of all members
yams::motorcontrollers::simulation::DCMotorSimSupplier Class Reference

#include <DCMotorSimSupplier.hpp>

Inheritance diagram for yams::motorcontrollers::simulation::DCMotorSimSupplier:
Inheritance graph
[legend]
Collaboration diagram for yams::motorcontrollers::simulation::DCMotorSimSupplier:
Collaboration graph
[legend]

Public Member Functions

 DCMotorSimSupplier (wpi::sim::DCMotorSim &sim, SmartMotorController &smc)
 
void UpdateSim () override
 
bool GetUpdatedSim () override
 
void FeedUpdateSim () override
 
void StarveUpdateSim () override
 
bool IsInputFed () override
 
void FeedInput () override
 
void StarveInput () override
 
void SetMechanismStatorDutyCycle (double dutyCycle) override
 
wpi::units::volt_t GetMechanismSupplyVoltage () override
 
wpi::units::volt_t GetMechanismStatorVoltage () override
 
void SetMechanismStatorVoltage (wpi::units::volt_t volts) override
 
wpi::units::turn_t GetMechanismPosition () override
 
wpi::units::turns_per_second_t GetMechanismVelocity () override
 
wpi::units::turns_per_second_squared_t GetMechanismAcceleration () override
 
wpi::units::turn_t GetRotorPosition () override
 
wpi::units::turns_per_second_t GetRotorVelocity () override
 
wpi::units::turns_per_second_squared_t GetRotorAcceleration () override
 
void SetMechanismPosition (wpi::units::turn_t angle) override
 
void SetMechanismVelocity (wpi::units::turns_per_second_t velocity) override
 
void SetRotorPosition (wpi::units::turn_t angle) override
 
void SetRotorVelocity (wpi::units::turns_per_second_t velocity) override
 
wpi::units::ampere_t GetStatorCurrent () override
 
wpi::units::ampere_t GetSupplyCurrent () override
 
- Public Member Functions inherited from yams::motorcontrollers::SimSupplier
virtual ~SimSupplier ()=default
 

Detailed Description

SimSupplier backed by a WPILib DCMotorSim.

Suitable for flywheel- and pivot-style mechanisms that use a simple DC motor physics model. The duty cycle is read from the motor controller each iteration unless an input voltage has been fed this loop.

Constructor & Destructor Documentation

◆ DCMotorSimSupplier()

yams::motorcontrollers::simulation::DCMotorSimSupplier::DCMotorSimSupplier ( wpi::sim::DCMotorSim &  sim,
SmartMotorController &  smc 
)

Create a DCMotorSimSupplier.

The duty cycle, gearing, simulation period and DC motor are read from smc and its config. The supplier's current draw is tracked in BatterySim under smc.

Parameters
simWPILib simulation to advance each loop (must outlive this supplier).
smcSmartMotorController driving the simulation (must outlive this supplier).

Member Function Documentation

◆ FeedInput()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::FeedInput ( )
overridevirtual

Mark the input as supplied directly for this loop.

Implements yams::motorcontrollers::SimSupplier.

◆ FeedUpdateSim()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::FeedUpdateSim ( )
overridevirtual

Mark the simulation as stepped for this loop.

Implements yams::motorcontrollers::SimSupplier.

◆ GetMechanismAcceleration()

wpi::units::turns_per_second_squared_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetMechanismAcceleration ( )
overridevirtual

Get the simulated mechanism angular acceleration.

Returns
Mechanism acceleration in turns per second squared.

Implements yams::motorcontrollers::SimSupplier.

◆ GetMechanismPosition()

wpi::units::turn_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetMechanismPosition ( )
overridevirtual

Get the simulated mechanism position.

Returns
Mechanism position in turns.

Implements yams::motorcontrollers::SimSupplier.

◆ GetMechanismStatorVoltage()

wpi::units::volt_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetMechanismStatorVoltage ( )
overridevirtual

Get the voltage applied to the simulated motor.

Returns
Stator voltage in volts.

Implements yams::motorcontrollers::SimSupplier.

◆ GetMechanismSupplyVoltage()

wpi::units::volt_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetMechanismSupplyVoltage ( )
overridevirtual

Get the supply voltage available to the simulated motor controller (bus voltage).

Returns
Supply voltage in volts.

Implements yams::motorcontrollers::SimSupplier.

◆ GetMechanismVelocity()

wpi::units::turns_per_second_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetMechanismVelocity ( )
overridevirtual

Get the simulated mechanism velocity.

Returns
Mechanism velocity in turns per second.

Implements yams::motorcontrollers::SimSupplier.

◆ GetRotorAcceleration()

wpi::units::turns_per_second_squared_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetRotorAcceleration ( )
overridevirtual

Get the simulated rotor angular acceleration.

Returns
Rotor acceleration in turns per second squared.

Implements yams::motorcontrollers::SimSupplier.

◆ GetRotorPosition()

wpi::units::turn_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetRotorPosition ( )
overridevirtual

Get the simulated rotor position.

Returns
Rotor position in turns.

Implements yams::motorcontrollers::SimSupplier.

◆ GetRotorVelocity()

wpi::units::turns_per_second_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetRotorVelocity ( )
overridevirtual

Get the simulated rotor velocity.

Returns
Rotor velocity in turns per second.

Implements yams::motorcontrollers::SimSupplier.

◆ GetStatorCurrent()

wpi::units::ampere_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetStatorCurrent ( )
overridevirtual

Get the simulated stator (motor) current.

Returns
Stator current in amperes.

Implements yams::motorcontrollers::SimSupplier.

◆ GetSupplyCurrent()

wpi::units::ampere_t yams::motorcontrollers::simulation::DCMotorSimSupplier::GetSupplyCurrent ( )
overridevirtual

Get the simulated supply (battery) current: duty cycle times stator current, filtered by a 0.1 s single-pole IIR filter.

Returns
Supply current in amperes.

Implements yams::motorcontrollers::SimSupplier.

◆ GetUpdatedSim()

bool yams::motorcontrollers::simulation::DCMotorSimSupplier::GetUpdatedSim ( )
overridevirtual

Whether the simulation has already been stepped this loop.

Returns
true if UpdateSim() stepped the physics since the last StarveUpdateSim().

Implements yams::motorcontrollers::SimSupplier.

◆ IsInputFed()

bool yams::motorcontrollers::simulation::DCMotorSimSupplier::IsInputFed ( )
overridevirtual

Whether an input voltage was supplied directly this loop (e.g. from a hardware sim state).

Returns
true if the input was fed since the simulation last stepped.

Implements yams::motorcontrollers::SimSupplier.

◆ SetMechanismPosition()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetMechanismPosition ( wpi::units::turn_t  angle)
overridevirtual

Set the simulated mechanism position.

Parameters
angleMechanism position to inject.

Implements yams::motorcontrollers::SimSupplier.

◆ SetMechanismStatorDutyCycle()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetMechanismStatorDutyCycle ( double  dutyCycle)
overridevirtual

Apply a duty cycle of the supply voltage as the motor input (feeds the input).

Parameters
dutyCycleDuty cycle in [-1, 1].

Implements yams::motorcontrollers::SimSupplier.

◆ SetMechanismStatorVoltage()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetMechanismStatorVoltage ( wpi::units::volt_t  volts)
overridevirtual

Set the motor input voltage directly, e.g. from a hardware sim state (feeds the input).

Parameters
voltsVoltage to apply.

Implements yams::motorcontrollers::SimSupplier.

◆ SetMechanismVelocity()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetMechanismVelocity ( wpi::units::turns_per_second_t  velocity)
overridevirtual

Set the simulated mechanism velocity.

Parameters
velocityMechanism velocity to inject.

Implements yams::motorcontrollers::SimSupplier.

◆ SetRotorPosition()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetRotorPosition ( wpi::units::turn_t  angle)
overridevirtual

Set the simulated rotor position.

Parameters
angleRotor position to inject.

Implements yams::motorcontrollers::SimSupplier.

◆ SetRotorVelocity()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::SetRotorVelocity ( wpi::units::turns_per_second_t  velocity)
overridevirtual

Set the simulated rotor velocity.

Parameters
velocityRotor velocity to inject.

Implements yams::motorcontrollers::SimSupplier.

◆ StarveInput()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::StarveInput ( )
overridevirtual

Clear the input-fed flag so UpdateSim() falls back to the duty-cycle supplier.

Implements yams::motorcontrollers::SimSupplier.

◆ StarveUpdateSim()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::StarveUpdateSim ( )
overridevirtual

Clear the stepped flag so the next UpdateSim() steps the physics again.

Implements yams::motorcontrollers::SimSupplier.

◆ UpdateSim()

void yams::motorcontrollers::simulation::DCMotorSimSupplier::UpdateSim ( )
overridevirtual

Advance the simulation by one loop iteration.

When the input has not been fed this loop (see FeedInput()), the motor duty cycle times the supply voltage is applied as the input and the battery voltage is updated. The physics are only stepped if the simulation has not already been updated this loop (see GetUpdatedSim()); stepping marks it updated, so a mechanism and its motor controller calling UpdateSim() in the same loop step the physics once.

Implements yams::motorcontrollers::SimSupplier.


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