Skip to content

Commit

Permalink
Merge pull request #341 from tinymovr/configurable_sensor_rate
Browse files Browse the repository at this point in the history
Configurable sensor rate
  • Loading branch information
yconst authored Apr 21, 2024
2 parents d589813 + 2d5fa50 commit fa968ce
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 132 deletions.
93 changes: 58 additions & 35 deletions docs/protocol/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ Type: uint8



The type of external sensor type. Either MA7XX, AS5047 or AMT22.
The type of the external sensor.

Options:

Expand All @@ -856,11 +856,34 @@ Options:

- AMT22

sensors.setup.external_spi.calibrated
sensors.setup.external_spi.rate
-------------------------------------------------------------------

ID: 62

Type: uint8



The rate of the external sensor.

Options:

- 1_5Mbps

- 3Mbps

- 6Mbps

- 8Mbps

- 12Mbps

sensors.setup.external_spi.calibrated
-------------------------------------------------------------------

ID: 63

Type: bool


Expand All @@ -872,7 +895,7 @@ Whether the sensor has been calibrated.
sensors.setup.external_spi.errors
-------------------------------------------------------------------

ID: 63
ID: 64

Type: uint8

Expand All @@ -889,7 +912,7 @@ Flags:
sensors.setup.hall.calibrated
-------------------------------------------------------------------

ID: 64
ID: 65

Type: bool

Expand All @@ -902,7 +925,7 @@ Whether the sensor has been calibrated.
sensors.setup.hall.errors
-------------------------------------------------------------------

ID: 65
ID: 66

Type: uint8

Expand All @@ -919,7 +942,7 @@ Flags:
sensors.select.position_sensor.connection
-------------------------------------------------------------------

ID: 66
ID: 67

Type: uint8

Expand All @@ -938,7 +961,7 @@ Options:
sensors.select.position_sensor.bandwidth
-------------------------------------------------------------------

ID: 67
ID: 68

Type: float

Expand All @@ -951,7 +974,7 @@ The position sensor observer bandwidth.
sensors.select.position_sensor.raw_angle
-------------------------------------------------------------------

ID: 68
ID: 69

Type: int32

Expand All @@ -964,7 +987,7 @@ The raw position sensor angle.
sensors.select.position_sensor.position_estimate
-------------------------------------------------------------------

ID: 69
ID: 70

Type: float

Expand All @@ -977,7 +1000,7 @@ The filtered position estimate in the position sensor reference frame.
sensors.select.position_sensor.velocity_estimate
-------------------------------------------------------------------

ID: 70
ID: 71

Type: float

Expand All @@ -990,7 +1013,7 @@ The filtered velocity estimate in the position sensor reference frame.
sensors.select.commutation_sensor.connection
-------------------------------------------------------------------

ID: 71
ID: 72

Type: uint8

Expand All @@ -1009,7 +1032,7 @@ Options:
sensors.select.commutation_sensor.bandwidth
-------------------------------------------------------------------

ID: 72
ID: 73

Type: float

Expand All @@ -1022,7 +1045,7 @@ The commutation sensor observer bandwidth.
sensors.select.commutation_sensor.raw_angle
-------------------------------------------------------------------

ID: 73
ID: 74

Type: int32

Expand All @@ -1035,7 +1058,7 @@ The raw commutation sensor angle.
sensors.select.commutation_sensor.position_estimate
-------------------------------------------------------------------

ID: 74
ID: 75

Type: float

Expand All @@ -1048,7 +1071,7 @@ The filtered position estimate in the commutation sensor reference frame.
sensors.select.commutation_sensor.velocity_estimate
-------------------------------------------------------------------

ID: 75
ID: 76

Type: float

Expand All @@ -1061,7 +1084,7 @@ The filtered velocity estimate in the commutation sensor reference frame.
traj_planner.max_accel
-------------------------------------------------------------------

ID: 76
ID: 77

Type: float

Expand All @@ -1074,7 +1097,7 @@ The max allowed acceleration of the generated trajectory.
traj_planner.max_decel
-------------------------------------------------------------------

ID: 77
ID: 78

Type: float

Expand All @@ -1087,7 +1110,7 @@ The max allowed deceleration of the generated trajectory.
traj_planner.max_vel
-------------------------------------------------------------------

ID: 78
ID: 79

Type: float

Expand All @@ -1100,7 +1123,7 @@ The max allowed cruise velocity of the generated trajectory.
traj_planner.t_accel
-------------------------------------------------------------------

ID: 79
ID: 80

Type: float

Expand All @@ -1113,7 +1136,7 @@ In time mode, the acceleration time of the generated trajectory.
traj_planner.t_decel
-------------------------------------------------------------------

ID: 80
ID: 81

Type: float

Expand All @@ -1126,7 +1149,7 @@ In time mode, the deceleration time of the generated trajectory.
traj_planner.t_total
-------------------------------------------------------------------

ID: 81
ID: 82

Type: float

Expand All @@ -1139,7 +1162,7 @@ In time mode, the total time of the generated trajectory.
move_to(float pos_setpoint) -> void
--------------------------------------------------------------------------------------------

ID: 82
ID: 83

Return Type: void

Expand All @@ -1150,7 +1173,7 @@ Move to target position in the user reference frame respecting velocity and acce
move_to_tlimit(float pos_setpoint) -> void
--------------------------------------------------------------------------------------------

ID: 83
ID: 84

Return Type: void

Expand All @@ -1161,7 +1184,7 @@ Move to target position in the user reference frame respecting time limits for e
traj_planner.errors
-------------------------------------------------------------------

ID: 84
ID: 85

Type: uint8

Expand All @@ -1178,7 +1201,7 @@ Flags:
homing.velocity
-------------------------------------------------------------------

ID: 85
ID: 86

Type: float

Expand All @@ -1191,7 +1214,7 @@ The velocity at which the motor performs homing.
homing.max_homing_t
-------------------------------------------------------------------

ID: 86
ID: 87

Type: float

Expand All @@ -1204,7 +1227,7 @@ The maximum time the motor is allowed to travel before homing times out and abor
homing.retract_dist
-------------------------------------------------------------------

ID: 87
ID: 88

Type: float

Expand All @@ -1217,7 +1240,7 @@ The retraction distance the motor travels after the endstop has been found.
homing.warnings
-------------------------------------------------------------------

ID: 88
ID: 89

Type: uint8

Expand All @@ -1232,7 +1255,7 @@ Flags:
homing.stall_detect.velocity
-------------------------------------------------------------------

ID: 89
ID: 90

Type: float

Expand All @@ -1245,7 +1268,7 @@ The velocity below which (and together with `stall_detect.delta_pos`) stall dete
homing.stall_detect.delta_pos
-------------------------------------------------------------------

ID: 90
ID: 91

Type: float

Expand All @@ -1258,7 +1281,7 @@ The velocity below which (and together with `stall_detect.delta_pos`) stall dete
homing.stall_detect.t
-------------------------------------------------------------------

ID: 91
ID: 92

Type: float

Expand All @@ -1271,7 +1294,7 @@ The time to remain in stall detection mode before the motor is considered stalle
home() -> void
--------------------------------------------------------------------------------------------

ID: 92
ID: 93

Return Type: void

Expand All @@ -1282,7 +1305,7 @@ Perform the homing operation.
watchdog.enabled
-------------------------------------------------------------------

ID: 93
ID: 94

Type: bool

Expand All @@ -1295,7 +1318,7 @@ Whether the watchdog is enabled or not.
watchdog.triggered
-------------------------------------------------------------------

ID: 94
ID: 95

Type: bool

Expand All @@ -1308,7 +1331,7 @@ Whether the watchdog has been triggered or not.
watchdog.timeout
-------------------------------------------------------------------

ID: 95
ID: 96

Type: float

Expand Down
20 changes: 19 additions & 1 deletion firmware/src/can/can_endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <src/can/can_endpoints.h>


uint8_t (*avlos_endpoints[96])(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd) = {&avlos_protocol_hash, &avlos_uid, &avlos_fw_version, &avlos_hw_revision, &avlos_Vbus, &avlos_Ibus, &avlos_power, &avlos_temp, &avlos_calibrated, &avlos_errors, &avlos_warnings, &avlos_save_config, &avlos_erase_config, &avlos_reset, &avlos_enter_dfu, &avlos_config_size, &avlos_scheduler_load, &avlos_scheduler_warnings, &avlos_controller_state, &avlos_controller_mode, &avlos_controller_warnings, &avlos_controller_errors, &avlos_controller_position_setpoint, &avlos_controller_position_p_gain, &avlos_controller_velocity_setpoint, &avlos_controller_velocity_limit, &avlos_controller_velocity_p_gain, &avlos_controller_velocity_i_gain, &avlos_controller_velocity_deadband, &avlos_controller_velocity_increment, &avlos_controller_current_Iq_setpoint, &avlos_controller_current_Id_setpoint, &avlos_controller_current_Iq_limit, &avlos_controller_current_Iq_estimate, &avlos_controller_current_bandwidth, &avlos_controller_current_Iq_p_gain, &avlos_controller_current_max_Ibus_regen, &avlos_controller_current_max_Ibrake, &avlos_controller_voltage_Vq_setpoint, &avlos_controller_calibrate, &avlos_controller_idle, &avlos_controller_position_mode, &avlos_controller_velocity_mode, &avlos_controller_current_mode, &avlos_controller_set_pos_vel_setpoints, &avlos_comms_can_rate, &avlos_comms_can_id, &avlos_comms_can_heartbeat, &avlos_motor_R, &avlos_motor_L, &avlos_motor_pole_pairs, &avlos_motor_type, &avlos_motor_calibrated, &avlos_motor_I_cal, &avlos_motor_errors, &avlos_sensors_user_frame_position_estimate, &avlos_sensors_user_frame_velocity_estimate, &avlos_sensors_user_frame_offset, &avlos_sensors_user_frame_multiplier, &avlos_sensors_setup_onboard_calibrated, &avlos_sensors_setup_onboard_errors, &avlos_sensors_setup_external_spi_type, &avlos_sensors_setup_external_spi_calibrated, &avlos_sensors_setup_external_spi_errors, &avlos_sensors_setup_hall_calibrated, &avlos_sensors_setup_hall_errors, &avlos_sensors_select_position_sensor_connection, &avlos_sensors_select_position_sensor_bandwidth, &avlos_sensors_select_position_sensor_raw_angle, &avlos_sensors_select_position_sensor_position_estimate, &avlos_sensors_select_position_sensor_velocity_estimate, &avlos_sensors_select_commutation_sensor_connection, &avlos_sensors_select_commutation_sensor_bandwidth, &avlos_sensors_select_commutation_sensor_raw_angle, &avlos_sensors_select_commutation_sensor_position_estimate, &avlos_sensors_select_commutation_sensor_velocity_estimate, &avlos_traj_planner_max_accel, &avlos_traj_planner_max_decel, &avlos_traj_planner_max_vel, &avlos_traj_planner_t_accel, &avlos_traj_planner_t_decel, &avlos_traj_planner_t_total, &avlos_traj_planner_move_to, &avlos_traj_planner_move_to_tlimit, &avlos_traj_planner_errors, &avlos_homing_velocity, &avlos_homing_max_homing_t, &avlos_homing_retract_dist, &avlos_homing_warnings, &avlos_homing_stall_detect_velocity, &avlos_homing_stall_detect_delta_pos, &avlos_homing_stall_detect_t, &avlos_homing_home, &avlos_watchdog_enabled, &avlos_watchdog_triggered, &avlos_watchdog_timeout };
uint8_t (*avlos_endpoints[97])(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd) = {&avlos_protocol_hash, &avlos_uid, &avlos_fw_version, &avlos_hw_revision, &avlos_Vbus, &avlos_Ibus, &avlos_power, &avlos_temp, &avlos_calibrated, &avlos_errors, &avlos_warnings, &avlos_save_config, &avlos_erase_config, &avlos_reset, &avlos_enter_dfu, &avlos_config_size, &avlos_scheduler_load, &avlos_scheduler_warnings, &avlos_controller_state, &avlos_controller_mode, &avlos_controller_warnings, &avlos_controller_errors, &avlos_controller_position_setpoint, &avlos_controller_position_p_gain, &avlos_controller_velocity_setpoint, &avlos_controller_velocity_limit, &avlos_controller_velocity_p_gain, &avlos_controller_velocity_i_gain, &avlos_controller_velocity_deadband, &avlos_controller_velocity_increment, &avlos_controller_current_Iq_setpoint, &avlos_controller_current_Id_setpoint, &avlos_controller_current_Iq_limit, &avlos_controller_current_Iq_estimate, &avlos_controller_current_bandwidth, &avlos_controller_current_Iq_p_gain, &avlos_controller_current_max_Ibus_regen, &avlos_controller_current_max_Ibrake, &avlos_controller_voltage_Vq_setpoint, &avlos_controller_calibrate, &avlos_controller_idle, &avlos_controller_position_mode, &avlos_controller_velocity_mode, &avlos_controller_current_mode, &avlos_controller_set_pos_vel_setpoints, &avlos_comms_can_rate, &avlos_comms_can_id, &avlos_comms_can_heartbeat, &avlos_motor_R, &avlos_motor_L, &avlos_motor_pole_pairs, &avlos_motor_type, &avlos_motor_calibrated, &avlos_motor_I_cal, &avlos_motor_errors, &avlos_sensors_user_frame_position_estimate, &avlos_sensors_user_frame_velocity_estimate, &avlos_sensors_user_frame_offset, &avlos_sensors_user_frame_multiplier, &avlos_sensors_setup_onboard_calibrated, &avlos_sensors_setup_onboard_errors, &avlos_sensors_setup_external_spi_type, &avlos_sensors_setup_external_spi_rate, &avlos_sensors_setup_external_spi_calibrated, &avlos_sensors_setup_external_spi_errors, &avlos_sensors_setup_hall_calibrated, &avlos_sensors_setup_hall_errors, &avlos_sensors_select_position_sensor_connection, &avlos_sensors_select_position_sensor_bandwidth, &avlos_sensors_select_position_sensor_raw_angle, &avlos_sensors_select_position_sensor_position_estimate, &avlos_sensors_select_position_sensor_velocity_estimate, &avlos_sensors_select_commutation_sensor_connection, &avlos_sensors_select_commutation_sensor_bandwidth, &avlos_sensors_select_commutation_sensor_raw_angle, &avlos_sensors_select_commutation_sensor_position_estimate, &avlos_sensors_select_commutation_sensor_velocity_estimate, &avlos_traj_planner_max_accel, &avlos_traj_planner_max_decel, &avlos_traj_planner_max_vel, &avlos_traj_planner_t_accel, &avlos_traj_planner_t_decel, &avlos_traj_planner_t_total, &avlos_traj_planner_move_to, &avlos_traj_planner_move_to_tlimit, &avlos_traj_planner_errors, &avlos_homing_velocity, &avlos_homing_max_homing_t, &avlos_homing_retract_dist, &avlos_homing_warnings, &avlos_homing_stall_detect_velocity, &avlos_homing_stall_detect_delta_pos, &avlos_homing_stall_detect_t, &avlos_homing_home, &avlos_watchdog_enabled, &avlos_watchdog_triggered, &avlos_watchdog_timeout };

uint32_t _avlos_get_proto_hash(void)
{
Expand Down Expand Up @@ -881,6 +881,24 @@ else if (AVLOS_CMD_WRITE == cmd) {
return AVLOS_RET_NOACTION;
}

uint8_t avlos_sensors_setup_external_spi_rate(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd)
{
if (AVLOS_CMD_READ == cmd) {
uint8_t v;
v = sensor_external_spi_get_rate_avlos();
*buffer_len = sizeof(v);
memcpy(buffer, &v, sizeof(v));
return AVLOS_RET_READ;
}
else if (AVLOS_CMD_WRITE == cmd) {
uint8_t v;
memcpy(&v, buffer, sizeof(v));
sensor_external_spi_set_rate_avlos(v);
return AVLOS_RET_WRITE;
}
return AVLOS_RET_NOACTION;
}

uint8_t avlos_sensors_setup_external_spi_calibrated(uint8_t * buffer, uint8_t * buffer_len, Avlos_Command cmd)
{
if (AVLOS_CMD_READ == cmd) {
Expand Down
Loading

0 comments on commit fa968ce

Please sign in to comment.