Merge branch 'devel' into sam_dfu

This commit is contained in:
Oskar Weigl
2018-03-04 02:58:40 -08:00
176 changed files with 1749 additions and 499 deletions
+133 -22
View File
@@ -8,9 +8,11 @@
#include "commands.h"
#include "low_level.h"
#include "axis.h"
#include "protocol.hpp"
#include "freertos_vars.h"
#include "utils.h"
#include "config.h"
#ifdef ENABLE_LEGACY_PROTOCOL
#include "legacy_commands.h"
@@ -87,6 +89,14 @@ void motors_1_set_current_setpoint_func(void) {
set_current_setpoint(&motors[1],
motors[1].set_current_setpoint_args.current_setpoint);
}
void motors_run_anticogging_calibration_func() {
for (uint8_t i = 0; i < num_motors; i++) {
// Ensure the cogging map was correctly allocated earlier and that the motor is capable of calibrating
if (motors[i].anticogging.cogging_map != NULL && motors[i].error == ERROR_NO_ERROR) {
motors[i].anticogging.calib_anticogging = true;
}
}
}
void enter_dfu_mode() {
*((unsigned long *)0x2001C000) = 0xDEADBEEF;
@@ -98,36 +108,56 @@ void enter_dfu_mode() {
// clang-format off
const Endpoint endpoints[] = {
Endpoint::make_property("vbus_voltage", const_cast<const float*>(&vbus_voltage)),
Endpoint::make_property("elec_rad_per_enc", const_cast<const float*>(&elec_rad_per_enc)),
Endpoint::make_property("UUID_0", (const uint32_t*)(ID_UNIQUE_ADDRESS + 0*4)),
Endpoint::make_property("UUID_1", (const uint32_t*)(ID_UNIQUE_ADDRESS + 1*4)),
Endpoint::make_property("UUID_2", (const uint32_t*)(ID_UNIQUE_ADDRESS + 2*4)),
Endpoint::make_function("run_anticogging_calibration", &motors_run_anticogging_calibration_func),
// No parameters, but still requires a close_tree()
Endpoint::close_tree(),
Endpoint::make_object("config"),
Endpoint::make_property("brake_resistance", &brake_resistance),
Endpoint::close_tree(),
Endpoint::make_object("axis0"),
Endpoint::make_object("config"),
Endpoint::make_property("enable_control_at_start", &axis_configs[0].enable_control_at_start),
Endpoint::make_property("do_calibration_at_start", &axis_configs[0].do_calibration_at_start),
Endpoint::close_tree(),
Endpoint::close_tree(),
Endpoint::make_object("motor0"),
Endpoint::make_property("control_mode", reinterpret_cast<int32_t*>(&motors[0].control_mode)),
Endpoint::make_object("config"),
Endpoint::make_property("control_mode", reinterpret_cast<int32_t*>(&motors[0].control_mode)),
Endpoint::make_property("counts_per_step", &motors[0].counts_per_step),
Endpoint::make_property("pole_pairs", &motors[0].pole_pairs),
Endpoint::make_property("pos_gain", &motors[0].pos_gain),
Endpoint::make_property("vel_gain", &motors[0].vel_gain),
Endpoint::make_property("vel_integrator_gain", &motors[0].vel_integrator_gain),
Endpoint::make_property("vel_limit", &motors[0].vel_limit),
Endpoint::make_property("calibration_current", &motors[0].calibration_current),
Endpoint::make_property("resistance_calib_max_voltage", &motors[0].resistance_calib_max_voltage),
Endpoint::make_property("phase_inductance", &motors[0].phase_inductance),
Endpoint::make_property("phase_resistance", &motors[0].phase_resistance),
Endpoint::make_property("motor_type", reinterpret_cast<int32_t*>(&motors[0].motor_type)),
Endpoint::make_property("rotor_mode", reinterpret_cast<int32_t*>(&motors[0].rotor_mode)),
Endpoint::close_tree(),
Endpoint::make_property("error", reinterpret_cast<int32_t*>(&motors[0].error)),
Endpoint::make_property("pos_setpoint", &motors[0].pos_setpoint),
Endpoint::make_property("pos_gain", &motors[0].pos_gain),
Endpoint::make_property("vel_setpoint", &motors[0].vel_setpoint),
Endpoint::make_property("vel_gain", &motors[0].vel_gain),
Endpoint::make_property("vel_integrator_gain", &motors[0].vel_integrator_gain),
Endpoint::make_property("vel_integrator_current", &motors[0].vel_integrator_current),
Endpoint::make_property("vel_limit", &motors[0].vel_limit),
Endpoint::make_property("current_setpoint", &motors[0].current_setpoint),
Endpoint::make_property("calibration_current", &motors[0].calibration_current),
Endpoint::make_property("phase_inductance", const_cast<const float*>(&motors[0].phase_inductance)),
Endpoint::make_property("phase_resistance", const_cast<const float*>(&motors[0].phase_resistance)),
Endpoint::make_property("current_meas_phB", const_cast<const float*>(&motors[0].current_meas.phB)),
Endpoint::make_property("current_meas_phC", const_cast<const float*>(&motors[0].current_meas.phC)),
Endpoint::make_property("DC_calib.phB", &motors[0].DC_calib.phB),
Endpoint::make_property("DC_calib.phC", &motors[0].DC_calib.phC),
Endpoint::make_property("shunt_conductance", &motors[0].shunt_conductance),
Endpoint::make_property("phase_current_rev_gain", &motors[0].phase_current_rev_gain),
Endpoint::make_property("thread_ready", reinterpret_cast<uint8_t*>(&motors[0].thread_ready)),
Endpoint::make_property("thread_ready", &motors[0].thread_ready),
Endpoint::make_property("control_deadline", &motors[0].control_deadline),
Endpoint::make_property("last_cpu_time", &motors[0].last_cpu_time),
Endpoint::make_property("loop_counter", &motors[0].loop_counter),
Endpoint::make_object("current_control"),
Endpoint::make_property("current_lim", &motors[0].current_control.current_lim),
Endpoint::make_object("config"),
Endpoint::make_property("current_lim", &motors[0].current_control.current_lim),
Endpoint::close_tree(),
Endpoint::make_property("p_gain", &motors[0].current_control.p_gain),
Endpoint::make_property("i_gain", &motors[0].current_control.i_gain),
Endpoint::make_property("v_current_control_integral_d", &motors[0].current_control.v_current_control_integral_d),
@@ -136,7 +166,22 @@ const Endpoint endpoints[] = {
Endpoint::make_property("Iq_measured", &motors[0].current_control.Iq_measured),
Endpoint::make_property("Ibus", const_cast<const float*>(&motors[0].current_control.Ibus)),
Endpoint::close_tree(),
Endpoint::make_object("gate_driver"),
Endpoint::make_property("drv_fault", reinterpret_cast<int32_t*>(&motors[0].drv_fault)),
Endpoint::make_property("status_reg_1", (&motors[0].gate_driver_regs.Stat_Reg_1_Value)),
Endpoint::make_property("status_reg_2", (&motors[0].gate_driver_regs.Stat_Reg_2_Value)),
Endpoint::make_property("ctrl_reg_1", (&motors[0].gate_driver_regs.Ctrl_Reg_1_Value)),
Endpoint::make_property("ctrl_reg_2", (&motors[0].gate_driver_regs.Ctrl_Reg_2_Value)),
Endpoint::close_tree(),
Endpoint::make_object("encoder"),
Endpoint::make_object("config"),
Endpoint::make_property("use_index", &motors[0].encoder.use_index),
Endpoint::make_property("manually_calibrated", &motors[0].encoder.manually_calibrated),
Endpoint::make_property("idx_search_speed", &motors[0].encoder.idx_search_speed),
Endpoint::make_property("cpr", &motors[0].encoder.encoder_cpr),
Endpoint::make_property("offset", &motors[0].encoder.encoder_offset),
Endpoint::make_property("motor_dir", &motors[0].encoder.motor_dir),
Endpoint::close_tree(),
Endpoint::make_property("phase", const_cast<const float*>(&motors[0].encoder.phase)),
Endpoint::make_property("pll_pos", &motors[0].encoder.pll_pos),
Endpoint::make_property("pll_vel", &motors[0].encoder.pll_vel),
@@ -158,33 +203,61 @@ const Endpoint endpoints[] = {
Endpoint::make_function("set_current_setpoint", &motors_0_set_current_setpoint_func),
Endpoint::make_property("current_setpoint", &motors[0].set_current_setpoint_args.current_setpoint),
Endpoint::close_tree(),
Endpoint::make_object("timing_log"),
Endpoint::make_property("TIMING_LOG_GENERAL", &motors[0].timing_log[TIMING_LOG_GENERAL]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M0_I", &motors[0].timing_log[TIMING_LOG_ADC_CB_M0_I]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M0_DC", &motors[0].timing_log[TIMING_LOG_ADC_CB_M0_DC]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M1_I", &motors[0].timing_log[TIMING_LOG_ADC_CB_M1_I]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M1_DC", &motors[0].timing_log[TIMING_LOG_ADC_CB_M1_DC]),
Endpoint::make_property("TIMING_LOG_MEAS_R", &motors[0].timing_log[TIMING_LOG_MEAS_R]),
Endpoint::make_property("TIMING_LOG_MEAS_L", &motors[0].timing_log[TIMING_LOG_MEAS_L]),
Endpoint::make_property("TIMING_LOG_ENC_CALIB", &motors[0].timing_log[TIMING_LOG_ENC_CALIB]),
Endpoint::make_property("TIMING_LOG_IDX_SEARCH", &motors[0].timing_log[TIMING_LOG_IDX_SEARCH]),
Endpoint::make_property("TIMING_LOG_FOC_VOLTAGE", &motors[0].timing_log[TIMING_LOG_FOC_VOLTAGE]),
Endpoint::make_property("TIMING_LOG_FOC_CURRENT", &motors[0].timing_log[TIMING_LOG_FOC_CURRENT]),
Endpoint::close_tree(),
Endpoint::close_tree(), // motor0
Endpoint::make_object("axis1"),
Endpoint::make_object("config"),
Endpoint::make_property("enable_control_at_start", &axis_configs[1].enable_control_at_start),
Endpoint::make_property("do_calibration_at_start", &axis_configs[1].do_calibration_at_start),
Endpoint::close_tree(),
Endpoint::close_tree(),
Endpoint::make_object("motor1"),
Endpoint::make_property("control_mode", reinterpret_cast<int32_t*>(&motors[1].control_mode)),
Endpoint::make_object("config"),
Endpoint::make_property("control_mode", reinterpret_cast<int32_t*>(&motors[1].control_mode)),
Endpoint::make_property("counts_per_step", &motors[1].counts_per_step),
Endpoint::make_property("pole_pairs", &motors[1].pole_pairs),
Endpoint::make_property("pos_gain", &motors[1].pos_gain),
Endpoint::make_property("vel_gain", &motors[1].vel_gain),
Endpoint::make_property("vel_integrator_gain", &motors[1].vel_integrator_gain),
Endpoint::make_property("vel_limit", &motors[1].vel_limit),
Endpoint::make_property("calibration_current", &motors[1].calibration_current),
Endpoint::make_property("resistance_calib_max_voltage", &motors[1].resistance_calib_max_voltage),
Endpoint::make_property("phase_inductance", &motors[1].phase_inductance),
Endpoint::make_property("phase_resistance", &motors[1].phase_resistance),
Endpoint::make_property("motor_type", reinterpret_cast<int32_t*>(&motors[1].motor_type)),
Endpoint::make_property("rotor_mode", reinterpret_cast<int32_t*>(&motors[1].rotor_mode)),
Endpoint::close_tree(),
Endpoint::make_property("error", reinterpret_cast<int32_t*>(&motors[1].error)),
Endpoint::make_property("pos_setpoint", &motors[1].pos_setpoint),
Endpoint::make_property("pos_gain", &motors[1].pos_gain),
Endpoint::make_property("vel_setpoint", &motors[1].vel_setpoint),
Endpoint::make_property("vel_gain", &motors[1].vel_gain),
Endpoint::make_property("vel_integrator_gain", &motors[1].vel_integrator_gain),
Endpoint::make_property("vel_integrator_current", &motors[1].vel_integrator_current),
Endpoint::make_property("vel_limit", &motors[1].vel_limit),
Endpoint::make_property("current_setpoint", &motors[1].current_setpoint),
Endpoint::make_property("calibration_current", &motors[1].calibration_current),
Endpoint::make_property("phase_inductance", const_cast<const float*>(&motors[1].phase_inductance)),
Endpoint::make_property("phase_resistance", const_cast<const float*>(&motors[1].phase_resistance)),
Endpoint::make_property("current_meas_phB", const_cast<const float*>(&motors[1].current_meas.phB)),
Endpoint::make_property("current_meas_phC", const_cast<const float*>(&motors[1].current_meas.phC)),
Endpoint::make_property("DC_calib.phB", &motors[1].DC_calib.phB),
Endpoint::make_property("DC_calib.phC", &motors[1].DC_calib.phC),
Endpoint::make_property("shunt_conductance", &motors[1].shunt_conductance),
Endpoint::make_property("phase_current_rev_gain", &motors[1].phase_current_rev_gain),
Endpoint::make_property("thread_ready", reinterpret_cast<uint8_t*>(&motors[1].thread_ready)),
Endpoint::make_property("thread_ready", &motors[1].thread_ready),
Endpoint::make_property("control_deadline", &motors[1].control_deadline),
Endpoint::make_property("last_cpu_time", &motors[1].last_cpu_time),
Endpoint::make_property("loop_counter", &motors[1].loop_counter),
Endpoint::make_object("current_control"),
Endpoint::make_property("current_lim", &motors[1].current_control.current_lim),
Endpoint::make_object("config"),
Endpoint::make_property("current_lim", &motors[1].current_control.current_lim),
Endpoint::close_tree(),
Endpoint::make_property("p_gain", &motors[1].current_control.p_gain),
Endpoint::make_property("i_gain", &motors[1].current_control.i_gain),
Endpoint::make_property("v_current_control_integral_d", &motors[1].current_control.v_current_control_integral_d),
@@ -193,7 +266,22 @@ const Endpoint endpoints[] = {
Endpoint::make_property("Iq_measured", &motors[1].current_control.Iq_measured),
Endpoint::make_property("Ibus", const_cast<const float*>(&motors[1].current_control.Ibus)),
Endpoint::close_tree(),
Endpoint::make_object("gate_driver"),
Endpoint::make_property("drv_fault", reinterpret_cast<int32_t*>(&motors[1].drv_fault)),
Endpoint::make_property("status_reg_1", (&motors[1].gate_driver_regs.Stat_Reg_1_Value)),
Endpoint::make_property("status_reg_2", (&motors[1].gate_driver_regs.Stat_Reg_2_Value)),
Endpoint::make_property("ctrl_reg_1", (&motors[1].gate_driver_regs.Ctrl_Reg_1_Value)),
Endpoint::make_property("ctrl_reg_2", (&motors[1].gate_driver_regs.Ctrl_Reg_2_Value)),
Endpoint::close_tree(),
Endpoint::make_object("encoder"),
Endpoint::make_object("config"),
Endpoint::make_property("use_index", &motors[1].encoder.use_index),
Endpoint::make_property("manually_calibrated", &motors[1].encoder.manually_calibrated),
Endpoint::make_property("idx_search_speed", &motors[1].encoder.idx_search_speed),
Endpoint::make_property("cpr", &motors[1].encoder.encoder_cpr),
Endpoint::make_property("offset", &motors[1].encoder.encoder_offset),
Endpoint::make_property("motor_dir", &motors[1].encoder.motor_dir),
Endpoint::close_tree(),
Endpoint::make_property("phase", const_cast<const float*>(&motors[1].encoder.phase)),
Endpoint::make_property("pll_pos", &motors[1].encoder.pll_pos),
Endpoint::make_property("pll_vel", &motors[1].encoder.pll_vel),
@@ -216,8 +304,31 @@ const Endpoint endpoints[] = {
Endpoint::make_property("current_setpoint", &motors[1].set_current_setpoint_args.current_setpoint),
Endpoint::close_tree(),
Endpoint::close_tree(), // motor1
Endpoint::make_function("save_configuration", &save_configuration),
// no arguments
Endpoint::close_tree(),
Endpoint::make_function("erase_configuration", &erase_configuration),
// no arguments
Endpoint::close_tree(),
Endpoint::make_function("reboot", &NVIC_SystemReset),
// no arguments
Endpoint::close_tree(),
Endpoint::make_function("enter_dfu_mode", &enter_dfu_mode),
Endpoint::close_tree() // enter_dfu_mode
// no arguments
Endpoint::close_tree(),
Endpoint::make_object("timing_log"),
Endpoint::make_property("TIMING_LOG_GENERAL", &motors[1].timing_log[TIMING_LOG_GENERAL]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M0_I", &motors[1].timing_log[TIMING_LOG_ADC_CB_M0_I]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M0_DC", &motors[1].timing_log[TIMING_LOG_ADC_CB_M0_DC]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M1_I", &motors[1].timing_log[TIMING_LOG_ADC_CB_M1_I]),
Endpoint::make_property("TIMING_LOG_ADC_CB_M1_DC", &motors[1].timing_log[TIMING_LOG_ADC_CB_M1_DC]),
Endpoint::make_property("TIMING_LOG_MEAS_R", &motors[1].timing_log[TIMING_LOG_MEAS_R]),
Endpoint::make_property("TIMING_LOG_MEAS_L", &motors[1].timing_log[TIMING_LOG_MEAS_L]),
Endpoint::make_property("TIMING_LOG_ENC_CALIB", &motors[1].timing_log[TIMING_LOG_ENC_CALIB]),
Endpoint::make_property("TIMING_LOG_IDX_SEARCH", &motors[1].timing_log[TIMING_LOG_IDX_SEARCH]),
Endpoint::make_property("TIMING_LOG_FOC_VOLTAGE", &motors[1].timing_log[TIMING_LOG_FOC_VOLTAGE]),
Endpoint::make_property("TIMING_LOG_FOC_CURRENT", &motors[1].timing_log[TIMING_LOG_FOC_CURRENT]),
Endpoint::close_tree(),
};
// clang-format on