Pybricks I/O
Classes | Typedefs | Functions
pbio/observer: Servo state observer

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...
 

Detailed Description

Luenberger state observer implementation to estimate motor speed.

Typedef Documentation

◆ pbio_observer_model_t

Device-type specific constants that describe the motor model.

◆ pbio_observer_settings_t

Configurable observer settings.

◆ pbio_observer_t

Motor state observer object.

Function Documentation

◆ pbio_observer_get_estimated_state()

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.

Parameters
[in]obsThe observer instance.
[out]speed_numSpeed in millidegrees/second as numeric derivative of angle.
[out]angle_estModel estimate of angle in millidegrees.
[out]speed_estModel estimate of speed in millidegrees/second.

Definition at line 58 of file observer.c.

◆ pbio_observer_get_feedback_voltage()

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.

Parameters
[in]obsThe observer instance.
[in]angleMeasured angle used to correct the model.
Returns
Feedback voltage in mV.

Definition at line 132 of file observer.c.

◆ pbio_observer_get_feedforward_torque()

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.

Parameters
[in]modelThe observer model instance.
[in]rate_refThe reference rate in mdeg/s.
[in]acceleration_refThe reference acceleration in mdeg/s/s.
Returns
The feedforward torque in uNm.

Definition at line 250 of file observer.c.

◆ pbio_observer_get_max_torque()

int32_t pbio_observer_get_max_torque ( void  )

Gets the maximum torque for use by user input validators.

Returns
The maximum torque in uNm.

Definition at line 236 of file observer.c.

◆ pbio_observer_is_stalled()

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.

Parameters
[in]obsThe observer instance.
[in]timeWall time.
[out]stall_durationFor how long it has been stalled.
Returns
True if stalled, false if not.

Definition at line 220 of file observer.c.

◆ pbio_observer_reset()

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.

Parameters
[in]obsThe observer instance.
[in]angleAngle to which the observer should be reset.

Definition at line 36 of file observer.c.

◆ pbio_observer_torque_to_voltage()

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.

Parameters
[in]modelThe observer model instance.
[in]desired_torqueThe torque in uNm.
Returns
The voltage in mV.

Definition at line 267 of file observer.c.

◆ pbio_observer_update()

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.

Parameters
[in]obsThe observer instance.
[in]timeWall time.
[in]angleMeasured angle used to correct the model.
[in]actuationActuation type currently applied to the motor.
[in]voltageIf actuation type is voltage, this is the payload in mV.

Definition at line 153 of file observer.c.

◆ pbio_observer_voltage_to_torque()

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.

Parameters
[in]modelThe observer model instance.
[in]voltageThe voltage in mV.
Returns
The torque in uNm.

Definition at line 278 of file observer.c.