23 static const uint8_t empty_msg = 0x00;
24 static const uint8_t get_controller_params = 0x01;
25 static const uint8_t update_controller_params = 0x02;
26 static const uint8_t get_status = 0x03;
27 static const uint8_t update_status = 0x04;
28 static const uint8_t get_config = 0x05;
29 static const uint8_t update_config = 0x06;
30 static const uint8_t get_cal_trq_sensor = 0x07;
31 static const uint8_t update_cal_trq_sensor = 0x08;
32 static const uint8_t get_cal_fsr = 0x09;
33 static const uint8_t update_cal_fsr = 0x0A;
34 static const uint8_t get_refine_fsr = 0x0B;
35 static const uint8_t update_refine_fsr = 0x0C;
36 static const uint8_t get_motor_enable_disable = 0x0D;
37 static const uint8_t update_motor_enable_disable = 0x0E;
38 static const uint8_t get_motor_zero = 0x0F;
39 static const uint8_t update_motor_zero = 0x10;
40 static const uint8_t get_real_time_data = 0x11;
41 static const uint8_t update_real_time_data = 0x12;
42 static const uint8_t get_controller_param = 0x13;
43 static const uint8_t update_controller_param = 0x14;
44 static const uint8_t get_error_code = 0x15;
45 static const uint8_t update_error_code = 0x16;
46 static const uint8_t get_FSR_thesholds = 0x17;
47 static const uint8_t update_FSR_thesholds = 0x18;
123 logger::println(
"UART_command_handlers::get_controller_params->No joint with id = "); logger::print(msg.joint_id); logger::println(
" found");
127 msg.command = UART_command_names::update_controller_params;
133 for (
int i=0; i<param_length; i++)
149 logger::println(
"UART_command_handlers::update_controller_params->No joint with id = " + String(msg.joint_id) +
" found");
153 #if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
165 tx_msg.
command = UART_command_names::update_status;
177 #if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)
189 tx_msg.
command = UART_command_names::update_config;
192 tx_msg.
data[config_defs::board_name_idx] = exo_data->
config[config_defs::board_name_idx];
193 tx_msg.
data[config_defs::battery_idx] = exo_data->
config[config_defs::battery_idx];
194 tx_msg.
data[config_defs::board_version_idx] = exo_data->
config[config_defs::board_version_idx];
195 tx_msg.
data[config_defs::exo_name_idx] = exo_data->
config[config_defs::exo_name_idx];
196 tx_msg.
data[config_defs::exo_side_idx] = exo_data->
config[config_defs::exo_side_idx];
197 tx_msg.
data[config_defs::hip_idx] = exo_data->
config[config_defs::hip_idx];
198 tx_msg.
data[config_defs::knee_idx] = exo_data->
config[config_defs::knee_idx];
199 tx_msg.
data[config_defs::ankle_idx] = exo_data->
config[config_defs::ankle_idx];
200 tx_msg.
data[config_defs::hip_gear_idx] = exo_data->
config[config_defs::hip_gear_idx];
201 tx_msg.
data[config_defs::knee_gear_idx] = exo_data->
config[config_defs::knee_gear_idx];
202 tx_msg.
data[config_defs::ankle_gear_idx] = exo_data->
config[config_defs::ankle_gear_idx];
203 tx_msg.
data[config_defs::exo_hip_default_controller_idx] = exo_data->
config[config_defs::exo_hip_default_controller_idx];
204 tx_msg.
data[config_defs::exo_knee_default_controller_idx] = exo_data->
config[config_defs::exo_knee_default_controller_idx];
205 tx_msg.
data[config_defs::exo_ankle_default_controller_idx] = exo_data->
config[config_defs::exo_ankle_default_controller_idx];
206 tx_msg.
data[config_defs::hip_flip_dir_idx] = exo_data->
config[config_defs::hip_flip_dir_idx];
207 tx_msg.
data[config_defs::knee_flip_dir_idx] = exo_data->
config[config_defs::knee_flip_dir_idx];
208 tx_msg.
data[config_defs::ankle_flip_dir_idx] = exo_data->
config[config_defs::ankle_flip_dir_idx];
216 UART_msg_t_utils::print_msg(msg);
217 exo_data->
config[config_defs::board_name_idx] = msg.data[config_defs::board_name_idx];
218 exo_data->
config[config_defs::battery_idx] = msg.data[config_defs::battery_idx];
219 exo_data->
config[config_defs::board_version_idx] = msg.data[config_defs::board_version_idx];
220 exo_data->
config[config_defs::exo_name_idx] = msg.data[config_defs::exo_name_idx];
221 exo_data->
config[config_defs::exo_side_idx] = msg.data[config_defs::exo_side_idx];
222 exo_data->
config[config_defs::hip_idx] = msg.data[config_defs::hip_idx];
223 exo_data->
config[config_defs::knee_idx] = msg.data[config_defs::knee_idx];
224 exo_data->
config[config_defs::ankle_idx] = msg.data[config_defs::ankle_idx];
225 exo_data->
config[config_defs::hip_gear_idx] = msg.data[config_defs::hip_gear_idx];
226 exo_data->
config[config_defs::knee_gear_idx] = msg.data[config_defs::knee_gear_idx];
227 exo_data->
config[config_defs::ankle_gear_idx] = msg.data[config_defs::ankle_gear_idx];
228 exo_data->
config[config_defs::exo_hip_default_controller_idx] = msg.data[config_defs::exo_hip_default_controller_idx];
229 exo_data->
config[config_defs::exo_knee_default_controller_idx] = msg.data[config_defs::exo_knee_default_controller_idx];
230 exo_data->
config[config_defs::exo_ankle_default_controller_idx] = msg.data[config_defs::exo_ankle_default_controller_idx];
231 exo_data->
config[config_defs::hip_flip_dir_idx] = msg.data[config_defs::hip_flip_dir_idx];
232 exo_data->
config[config_defs::knee_flip_dir_idx] = msg.data[config_defs::knee_flip_dir_idx];
233 exo_data->
config[config_defs::ankle_flip_dir_idx] = msg.data[config_defs::ankle_flip_dir_idx];
298 rx_msg.
command = UART_command_names::update_real_time_data;
300 rx_msg.
len = (uint8_t)rt_data::BILATERAL_ANKLE_RT_LEN;
305 switch (config[config_defs::exo_name_idx])
308 rx_msg.
len = (uint8_t)rt_data::BILATERAL_ANKLE_RT_LEN;
332 rx_msg.
len = (uint8_t)rt_data::BILATERAL_HIP_RT_LEN;
344 rx_msg.
len = (uint8_t)rt_data::BILATERAL_ANKLE_RT_LEN;
357 rx_msg.
len = (uint8_t)rt_data::RIGHT_KNEE;
372 rx_msg.
len = (uint8_t)rt_data::BILATERAL_ANKLE_RT_LEN;
399 get_real_time_data(handler, exo_data, msg, empty_config);
410 if (rt_data::len != msg.len)
414 for (
int i = 0; i < rt_data::len; i++)
416 rt_data::float_values[i] = msg.data[i];
418 rt_data::new_rt_msg =
true;
433 logger::println(
"UART_command_handlers::update_controller_param->No joint with id = "); logger::print(msg.joint_id); logger::println(
" found");
465 tx_msg.
command = UART_command_names::update_error_code;
476 tx_msg.
command = UART_command_names::update_FSR_thesholds;
504 uint8_t searching = 1;
506 float start_time = millis();
512 rx_msg = handler->
poll(200000);
513 searching = (rx_msg.
command != (msg.command+1));
515 if (millis() - start_time > timeout)
522 UART_msg_t_utils::print_msg(rx_msg);
526 static uint8_t get_config(
UARTHandler* handler, uint8_t* config,
float timeout)
529 float start_time = millis();
532 msg.command = UART_command_names::get_config;
534 msg = call_and_response(handler, msg, timeout);
536 if ((millis() - start_time) > timeout)
538 logger::println(
"UART_command_utils::get_config->timed out");
545 logger::println(
"UART_command_utils::get_config->msg.len != number_of_keys");
549 for (
int i=0; i<msg.len; i++)
554 logger::print(
"UART_command_utils::get_config->Config contained a zero at index ");
561 logger::println(
"UART_command_utils::get_config->got good config");
566 for (
int i=0; i<msg.len; i++)
568 config[i] = msg.data[i];
576 float start_time = millis();
579 logger::println(
"UART_command_utils::wait_for_config->Polling for config");
580 rx_msg = handler->
poll(100000);
581 if (rx_msg.
command == UART_command_names::get_config)
583 logger::println(
"UART_command_utils::wait_for_config->Got config request");
584 UART_command_handlers::get_config(handler, data, rx_msg);
587 delayMicroseconds(500);
589 if ((millis() - start_time) > timeout)
591 logger::println(
"UART_command_utils::wait_for_config->Timed out");
595 logger::println(
"UART_command_utils::wait_for_config->Sent config");
602 if (msg.command == UART_command_names::empty_msg)
607 logger::println(
"UART_command_utils::handle_message->got message: ");
608 UART_msg_t_utils::print_msg(msg);
612 case UART_command_names::empty_msg:
613 logger::println(
"UART_command_utils::handle_message->Empty Message!");
616 case UART_command_names::get_controller_params:
617 UART_command_handlers::get_controller_params(handler, exo_data, msg);
619 case UART_command_names::update_controller_params:
620 UART_command_handlers::update_controller_params(handler, exo_data, msg);
623 case UART_command_names::get_status:
624 UART_command_handlers::get_status(handler, exo_data, msg);
626 case UART_command_names::update_status:
627 UART_command_handlers::update_status(handler, exo_data, msg);
630 case UART_command_names::get_config:
631 UART_command_handlers::get_config(handler, exo_data, msg);
633 case UART_command_names::update_config:
634 UART_command_handlers::update_config(handler, exo_data, msg);
637 case UART_command_names::get_cal_trq_sensor:
638 UART_command_handlers::get_cal_trq_sensor(handler, exo_data, msg);
640 case UART_command_names::update_cal_trq_sensor:
641 UART_command_handlers::update_cal_trq_sensor(handler, exo_data, msg);
644 case UART_command_names::get_cal_fsr:
645 UART_command_handlers::get_cal_fsr(handler, exo_data, msg);
647 case UART_command_names::update_cal_fsr:
648 UART_command_handlers::update_cal_fsr(handler, exo_data, msg);
651 case UART_command_names::get_refine_fsr:
652 UART_command_handlers::get_refine_fsr(handler, exo_data, msg);
654 case UART_command_names::update_refine_fsr:
655 UART_command_handlers::update_refine_fsr(handler, exo_data, msg);
658 case UART_command_names::get_motor_enable_disable:
659 UART_command_handlers::get_motor_enable_disable(handler, exo_data, msg);
661 case UART_command_names::update_motor_enable_disable:
662 UART_command_handlers::update_motor_enable_disable(handler, exo_data, msg);
665 case UART_command_names::get_motor_zero:
666 UART_command_handlers::get_motor_zero(handler, exo_data, msg);
668 case UART_command_names::update_motor_zero:
669 UART_command_handlers::update_motor_zero(handler, exo_data, msg);
672 case UART_command_names::get_real_time_data:
673 UART_command_handlers::get_real_time_data(handler, exo_data, msg);
675 case UART_command_names::update_real_time_data:
676 UART_command_handlers::update_real_time_data(handler, exo_data, msg);
679 case UART_command_names::update_controller_param:
680 UART_command_handlers::update_controller_param(handler, exo_data, msg);
683 case UART_command_names::get_error_code:
684 UART_command_handlers::get_error_code(handler, exo_data, msg);
686 case UART_command_names::update_error_code:
687 UART_command_handlers::update_error_code(handler, exo_data, msg);
690 case UART_command_names::get_FSR_thesholds:
691 UART_command_handlers::get_FSR_thesholds(handler, exo_data, msg);
693 case UART_command_names::update_FSR_thesholds:
694 UART_command_handlers::update_FSR_thesholds(handler, exo_data, msg);
699 logger::println(
"UART_command_utils::handle_message->Unknown Message!",
LogLevel::Error);
700 UART_msg_t_utils::print_msg(msg);
Declares a class used to store data for the Exo to access.
Declares a class used to store data for joint to access.
Declares the functions to pull controller parameters from the SD card and defines the mapping to the ...
Declares the functions needed and defines mapping between the INI keys and the exo components.
Singleton class that manages the UART data. NOT THREAD SAFE. The class queues recieved messages.
float setpoint
Definition ControllerData.h:323
uint8_t controller
Definition ControllerData.h:320
float ff_setpoint
Definition ControllerData.h:324
uint8_t get_parameter_length()
Get the parameter length for the current controller.
Definition ControllerData.cpp:80
float parameters[controller_defs::max_parameters]
Definition ControllerData.h:325
float filtered_torque_reading
Definition ControllerData.h:328
Class to store all the data related to the exo.
Definition ExoData.h:38
void set_default_parameters()
Set the default controller parameters for the current controller. These are the first row in the cont...
Definition ExoData.cpp:103
void for_each_joint(F &&func)
performs a function for each joint
Definition ExoData.h:55
bool user_paused
Definition ExoData.h:131
LegData right_leg
Definition ExoData.h:122
int error_joint_id
Definition ExoData.h:130
int error_code
Definition ExoData.h:129
JointData * get_joint_with(uint8_t id)
Get the joint pointer for a joint id.
Definition ExoData.cpp:56
uint16_t get_status(void)
Get the status object.
Definition ExoData.cpp:98
void start_pretrial_cal()
Start the pretrial calibration process.
Definition ExoData.cpp:116
uint8_t * config
Definition ExoData.h:126
LegData left_leg
Definition ExoData.h:121
void set_status(uint16_t status_to_set)
Set the status object.
Definition ExoData.cpp:88
class to store information related to joint.
Definition JointData.h:33
bool is_used
Definition JointData.h:50
ControllerData controller
Definition JointData.h:46
MotorData motor
Definition JointData.h:45
bool do_calibration_refinement_toe_fsr
Definition LegData.h:76
bool toe_stance
Definition LegData.h:69
bool do_calibration_toe_fsr
Definition LegData.h:75
float toe_fsr_upper_threshold
Definition LegData.h:60
JointData knee
Definition LegData.h:43
bool do_calibration_heel_fsr
Definition LegData.h:77
JointData ankle
Definition LegData.h:44
JointData hip
Definition LegData.h:42
float toe_fsr_lower_threshold
Definition LegData.h:61
float toe_fsr
Definition LegData.h:59
bool do_calibration_refinement_heel_fsr
Definition LegData.h:78
float percent_gait
Definition LegData.h:47
float i
Definition MotorData.h:41
bool enabled
Definition MotorData.h:50
Singleton Class to handle the UART Work.
Definition UARTHandler.h:54
void UART_msg(uint8_t msg_id, uint8_t len, uint8_t joint_id, float *buffer)
Packs and sends a UART message.
Definition UARTHandler.cpp:35
UART_msg_t poll(float timeout_us=RX_TIMEOUT_US)
Check for incoming data. If there is data read the message, timing out if it takes too long.
Definition UARTHandler.cpp:73
Holds all of the enums for the UART commands. The enums are used to properly index the data.
Definition uart_commands.h:55
FSR_thresholds
Definition uart_commands.h:99
cal_trq_sensor
Definition uart_commands.h:66
motor_zero
Definition uart_commands.h:82
motor_enable_disable
Definition uart_commands.h:78
error_code
Definition uart_commands.h:95
controller_params
Definition uart_commands.h:56
controller_param
Definition uart_commands.h:86
real_time_data
Definition uart_commands.h:92
cal_fsr
Definition uart_commands.h:70
status
Definition uart_commands.h:62
refine_fsr
Definition uart_commands.h:74
Holds the handlers for all of the commands. The handler function types should be the same....
Definition uart_commands.h:114
Type to associate a command with an ammount of data.
Definition uart_commands.h:21
Definition uart_commands.h:499
const float SCHMITT_DELTA
Definition Config.h:43
const int number_of_keys
Definition ParseIni.h:25
void msg(float *data, int len)
Definition RealTimeI2C.cpp:55
const uint16_t trial_on
Definition StatusDefs.h:31
Definition UART_msg_t.h:9
float data[UART_MSG_T_MAX_DATA_LEN]
Definition UART_msg_t.h:12
uint8_t len
Definition UART_msg_t.h:13
uint8_t joint_id
Definition UART_msg_t.h:11
uint8_t command
Definition UART_msg_t.h:10