13#include "sylib/env.hpp"
14#include "sylib/math.hpp"
15#include "sylib/system.hpp"
16#include "sylib/sylib_apitypes.hpp"
41 uint32_t previousInternalMotorClock;
46 double motorVoltageTarget;
47 double emaFilteredVelocity;
48 double smaFilteredVelocity;
49 double smaFilteredAccel;
50 double medianFilteredVelocity;
51 double outputVelocity;
52 double preFilterAcceleration;
55 double outputAcceleration;
58 double accelCalculatedkA;
59 double maxFilteredAccel;
60 double smaFilteredJerk;
61 double smaFilteredSnap;
88 double getVelocity(
double currentMotorTicks, std::uint32_t currentInternalMotorClock);
208 const std::uint8_t smart_port;
209 const double gearing;
211 const V5_DeviceT device;
212 void set_motor_controller();
227 uint32_t internalClock;
229 double velocity_error;
231 double vexos_velocity;
237 double target_position;
238 double target_velocity;
239 std::int32_t current_draw;
240 std::int32_t direction;
241 std::int32_t efficiency;
245 std::int32_t voltage;
246 std::int32_t zero_position_flag;
247 std::int32_t stopped;
248 std::int32_t over_temp;
249 std::int32_t over_current;
250 V5MotorBrakeMode brake_mode;
251 std::int32_t current_limit;
252 std::int32_t voltage_limit;
256 double position_target;
257 double velocity_target;
258 std::int32_t voltage_target;
297 Motor(
const uint8_t smart_port,
const double gearing = 200,
const bool reverse =
false,
D Controller.
Definition: math.hpp:582
Device Parent Class.
Definition: system.hpp:238
Exponential Moving Average Filter.
Definition: math.hpp:19
I Controller.
Definition: math.hpp:469
V5 Smart Motor.
Definition: motor.hpp:206
std::int32_t get_braking_mode() const
Gets the current motor brake mode.
void stop()
Stops the motor.
void set_amps_limit(std::int32_t limit)
Sets the motor amperage limit.
std::int32_t get_tbh_voltage() const
Gets the current output of the user-provided TBH controller.
void set_volts_limit(std::int32_t limit)
Sets the motor voltage limit.
double get_position() const
Gets the current raw motor position.
double get_temperature() const
Gets the motor temperature.
std::int32_t get_volts_limit() const
Gets the user-provided motor voltage limit.
std::int32_t get_flags() const
Gets the motor-reported flags.
void set_voltage(std::int16_t new_voltage_target)
Sets the voltage sent to the motor directly.
bool is_over_temp() const
Gets if the motor is over temperature, as reported by the motor.
Motor(const uint8_t smart_port, const double gearing=200, const bool reverse=false, const SpeedControllerInfo speedController=SpeedControllerInfo())
Creates a smart motor object.
void update() override
Motor update loop.
std::int32_t get_position_and_timestamp(std::uint32_t *timestamp)
Gets the current motor tick count and timestamp value.
std::int32_t get_faults() const
Gets the motor-reported faults.
double get_velocity_error() const
Gets the current error between the motor's actual velocity and the velocity target.
double get_acceleration() const
Gets the motor acceleration.
void set_velocity_custom_controller(std::int16_t new_velocity_target)
Sets the motor velocity target and changes control modes.
std::uint32_t get_device_timestamp() const
Gets the most recent time at which the motor has updated its tick count.
void set_is_reversed(bool reverse)
Sets the motor reversed flag.
double get_position_target() const
Gets the current target motor position.
void set_braking_mode(V5MotorBrakeMode mode)
Sets the motor braking mode.
std::int32_t get_estimator_voltage() const
Gets the current output of the user-provided feedforward controller.
std::int32_t get_d_voltage() const
Gets the current output of the user-provided D controller.
void set_position_target_relative(double new_position, std::int32_t velocity_cap=200)
Sets a motor position target relative to its current position.
std::int32_t get_amps() const
Gets the motor current draw.
void tare_encoder()
Tares the motor encoder.
void set_position_target_absolute(double new_position, std::int32_t velocity_cap=200)
Sets the absolute motor position target.
std::int32_t get_smart_port() const
Gets 1-indexed smart port used by the motor.
std::int32_t get_p_voltage() const
Gets the current output of the user-provided P controller.
bool is_reversed() const
Gets if the motor reversed flag is set.
std::int32_t get_efficiency() const
Gets the motor-reported efficiency value in percent.
bool is_stopped() const
Gets if the motor is stopped.
double get_velocity_motor_reported() const
Gets the current motor velocity as reported by the motor itself.
std::int32_t get_applied_voltage() const
Gets the voltage most recently sent to the motor, when using a sylib control mode.
std::int32_t get_gearing() const
Gets the user-set motor gearing.
double get_velocity() const
Gets the current motor velocity.
void set_velocity(std::int32_t new_velocity_target)
Sets the motor velocity target.
double get_velocity_sma_filter_only() const
Gets the partially-filtered motor velocity.
double get_velocity_target() const
Gets the current motor velocity target.
double get_watts() const
Gets the motor power consumption.
std::int32_t get_i_voltage() const
Gets the current output of the user-provided I controller.
bool is_over_current() const
Gets if the motor is over current, as reported by the motor.
std::int32_t get_amps_limit() const
Gets the user-provided motor current limit.
double get_torque() const
Gets the motor torque.
void updateSpeedController(sylib::SpeedControllerInfo controller)
Sets the custom speed controller used by set_velocity_custom_controller.
double get_velocity_raw() const
Gets the unfiltered motor velocity.
P Controller.
Definition: math.hpp:363
Extrema Filter.
Definition: math.hpp:199
Simple Moving Average Filter.
Definition: math.hpp:62
Accurate Motor Velocity Estimator.
Definition: motor.hpp:23
double getSnap() const
Gets the motor snap.
double getRawPosition() const
Gets the most recent user-provided motor position.
SylviesPogVelocityEstimator(double motorGearing=200)
Creates a velocity estimator for a smart motor.
double getAcceleration() const
Gets the motor acceleration.
double getEmaFilteredVelocity() const
Gets the motor velocity put through a an exponential moving average filter.
double getRawVelocity() const
Gets the raw motor velocity.
double getSmaFilteredVelocity() const
Gets the motor velocity put through a 3-tap simple moving average.
double getPreFilterAcceleration() const
Gets the raw motor acceleration based on a partially filtered velocity calculation.
double getMedianFilteredVelocity() const
Gets the motor velocity put through a median filter.
double getMaxFilteredAcceleration() const
Gets the absolute value of the largest or smallest acceleration measurement in the last 200ms.
double getVelocity(double currentMotorTicks, std::uint32_t currentInternalMotorClock)
Calculates motor velocity.
double getJerk() const
Gets the motor jerk.
double getCalculatedkA() const
Gets the current value of the variable gain used for the velocity EMA filter.
double getVelocityNoCalculations() const
Gets the most recent calculated motor velocity.
Generic Derivative Solver.
Definition: math.hpp:253
TBH Controller.
Definition: math.hpp:664
Feedforward Controller.
Definition: math.hpp:300
Definition: addrled.hpp:20
SylibMotorControlMode
Definition: sylib_apitypes.hpp:14
Custom Velocity Controller.
Definition: math.hpp:743