Pybricks I/O
|
Luenberger state observer implementation to estimate motor speed. More...
Classes | |
struct | _pbio_observer_model_t |
Device-type specific constants that describe the motor model. More... | |
struct | _pbio_observer_settings_t |
Configurable observer settings. More... | |
struct | _pbio_observer_t |
Motor state observer object. More... | |
Typedefs | |
typedef struct _pbio_observer_model_t | pbio_observer_model_t |
Device-type specific constants that describe the motor model. More... | |
typedef struct _pbio_observer_settings_t | pbio_observer_settings_t |
Configurable observer settings. More... | |
typedef struct _pbio_observer_t | pbio_observer_t |
Motor state observer object. More... | |
Functions | |
void | pbio_observer_reset (pbio_observer_t *obs, const pbio_angle_t *angle) |
Resets the observer to a new angle. More... | |
void | pbio_observer_get_estimated_state (const pbio_observer_t *obs, int32_t *speed_num, pbio_angle_t *angle_est, int32_t *speed_est) |
Gets the observer state, which is the estimated state of the real system. More... | |
void | pbio_observer_update (pbio_observer_t *obs, uint32_t time, const pbio_angle_t *angle, pbio_dcmotor_actuation_t actuation, int32_t voltage) |
Predicts next system state and corrects the model using a measurement. More... | |
bool | pbio_observer_is_stalled (const pbio_observer_t *obs, uint32_t time, uint32_t *stall_duration) |
Checks whether system is stalled by testing how far the estimate is ahead of the measured angle, which is a measure for an unmodeled load. More... | |
int32_t | pbio_observer_get_feedback_voltage (const pbio_observer_t *obs, const pbio_angle_t *angle) |
Gets observer feedback voltage that keeps it close to measured value. More... | |
int32_t | pbio_observer_get_max_torque (void) |
Gets the maximum torque for use by user input validators. More... | |
int32_t | pbio_observer_get_feedforward_torque (const pbio_observer_model_t *model, int32_t rate_ref, int32_t acceleration_ref) |
Calculates the feedforward torque needed to achieve the requested reference rotational speed and acceleration. More... | |
int32_t | pbio_observer_torque_to_voltage (const pbio_observer_model_t *model, int32_t desired_torque) |
Converts a torque to a voltage based on the given motor model. More... | |
int32_t | pbio_observer_voltage_to_torque (const pbio_observer_model_t *model, int32_t voltage) |
Converts a voltage to a torque based on the given motor model. More... | |
Luenberger state observer implementation to estimate motor speed.
typedef struct _pbio_observer_model_t pbio_observer_model_t |
Device-type specific constants that describe the motor model.
typedef struct _pbio_observer_settings_t pbio_observer_settings_t |
Configurable observer settings.
typedef struct _pbio_observer_t pbio_observer_t |
Motor state observer object.
void pbio_observer_get_estimated_state | ( | const pbio_observer_t * | obs, |
int32_t * | speed_num, | ||
pbio_angle_t * | angle_est, | ||
int32_t * | speed_est | ||
) |
Gets the observer state, which is the estimated state of the real system.
[in] | obs | The observer instance. |
[out] | speed_num | Speed in millidegrees/second as numeric derivative of angle. |
[out] | angle_est | Model estimate of angle in millidegrees. |
[out] | speed_est | Model estimate of speed in millidegrees/second. |
Definition at line 58 of file observer.c.
int32_t pbio_observer_get_feedback_voltage | ( | const pbio_observer_t * | obs, |
const pbio_angle_t * | angle | ||
) |
Gets observer feedback voltage that keeps it close to measured value.
[in] | obs | The observer instance. |
[in] | angle | Measured angle used to correct the model. |
Definition at line 132 of file observer.c.
int32_t pbio_observer_get_feedforward_torque | ( | const pbio_observer_model_t * | model, |
int32_t | rate_ref, | ||
int32_t | acceleration_ref | ||
) |
Calculates the feedforward torque needed to achieve the requested reference rotational speed and acceleration.
[in] | model | The observer model instance. |
[in] | rate_ref | The reference rate in mdeg/s. |
[in] | acceleration_ref | The reference acceleration in mdeg/s/s. |
Definition at line 250 of file observer.c.
int32_t pbio_observer_get_max_torque | ( | void | ) |
Gets the maximum torque for use by user input validators.
Definition at line 236 of file observer.c.
bool pbio_observer_is_stalled | ( | const pbio_observer_t * | obs, |
uint32_t | time, | ||
uint32_t * | stall_duration | ||
) |
Checks whether system is stalled by testing how far the estimate is ahead of the measured angle, which is a measure for an unmodeled load.
[in] | obs | The observer instance. |
[in] | time | Wall time. |
[out] | stall_duration | For how long it has been stalled. |
Definition at line 220 of file observer.c.
void pbio_observer_reset | ( | pbio_observer_t * | obs, |
const pbio_angle_t * | angle | ||
) |
Resets the observer to a new angle.
Speed and current are reset to zero.
[in] | obs | The observer instance. |
[in] | angle | Angle to which the observer should be reset. |
Definition at line 36 of file observer.c.
int32_t pbio_observer_torque_to_voltage | ( | const pbio_observer_model_t * | model, |
int32_t | desired_torque | ||
) |
Converts a torque to a voltage based on the given motor model.
[in] | model | The observer model instance. |
[in] | desired_torque | The torque in uNm. |
Definition at line 267 of file observer.c.
void pbio_observer_update | ( | pbio_observer_t * | obs, |
uint32_t | time, | ||
const pbio_angle_t * | angle, | ||
pbio_dcmotor_actuation_t | actuation, | ||
int32_t | voltage | ||
) |
Predicts next system state and corrects the model using a measurement.
[in] | obs | The observer instance. |
[in] | time | Wall time. |
[in] | angle | Measured angle used to correct the model. |
[in] | actuation | Actuation type currently applied to the motor. |
[in] | voltage | If actuation type is voltage, this is the payload in mV. |
Definition at line 153 of file observer.c.
int32_t pbio_observer_voltage_to_torque | ( | const pbio_observer_model_t * | model, |
int32_t | voltage | ||
) |
Converts a voltage to a torque based on the given motor model.
[in] | model | The observer model instance. |
[in] | voltage | The voltage in mV. |
Definition at line 278 of file observer.c.