From c5f06845c2b5eb3242654451ca640d615ac8362e Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Mon, 25 Mar 2019 20:04:45 +0100 Subject: [PATCH 1/3] Allow for regen current before braking --- Firmware/MotorControl/low_level.cpp | 8 ++++---- Firmware/MotorControl/odrive_main.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Firmware/MotorControl/low_level.cpp b/Firmware/MotorControl/low_level.cpp index 82e54049..2b834e55 100644 --- a/Firmware/MotorControl/low_level.cpp +++ b/Firmware/MotorControl/low_level.cpp @@ -585,10 +585,10 @@ void update_brake_current() { Ibus_sum += axes[i]->motor_.current_control_.Ibus; } } - float brake_current = -Ibus_sum; - // Clip negative values to 0.0f - if (brake_current < 0.0f) brake_current = 0.0f; - float brake_duty = brake_current * board_config.brake_resistance / vbus_voltage; + + // Don't start braking until -Ibus > regen_current_allowed + float brake_current = std::max(-Ibus_sum - board_config.max_regen_current, 0.0f); + float brake_duty = std::max(brake_current * std::abs(board_config.brake_resistance) / vbus_voltage, 0.0f); // Duty limit at 90% to allow bootstrap caps to charge // If brake_duty is NaN, this expression will also evaluate to false diff --git a/Firmware/MotorControl/odrive_main.h b/Firmware/MotorControl/odrive_main.h index 8bff6d81..d8e569da 100644 --- a/Firmware/MotorControl/odrive_main.h +++ b/Firmware/MotorControl/odrive_main.h @@ -71,6 +71,7 @@ struct BoardConfig_t { bool enable_uart = true; bool enable_i2c_instead_of_can = false; bool enable_ascii_protocol_on_usb = true; + float max_regen_current = 0.0f; #if HW_VERSION_MAJOR == 3 && HW_VERSION_MINOR >= 5 && HW_VERSION_VOLTAGE >= 48 float brake_resistance = 2.0f; // [ohm] #else From a7dfb6ca060b6d3a483426797d0cdee2bec9f4f9 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Thu, 30 Jan 2020 13:31:20 -0800 Subject: [PATCH 2/3] add max regen current to protocl --- Firmware/communication/communication.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/communication/communication.cpp b/Firmware/communication/communication.cpp index 79982e64..fe426a9d 100644 --- a/Firmware/communication/communication.cpp +++ b/Firmware/communication/communication.cpp @@ -152,6 +152,7 @@ static inline auto make_obj_tree() { ), make_protocol_object("config", make_protocol_property("brake_resistance", &board_config.brake_resistance), + make_protocol_property("max_regen_current ", &board_config.max_regen_current ), // TODO: changing this currently requires a reboot - fix this make_protocol_property("enable_uart", &board_config.enable_uart), make_protocol_property("enable_i2c_instead_of_can" , &board_config.enable_i2c_instead_of_can), // requires a reboot From 8cbc09e168186ccd1454daf5111727d027b6f11f Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Thu, 30 Jan 2020 16:16:39 -0800 Subject: [PATCH 3/3] feed watchdog on enter closed loop --- Firmware/MotorControl/axis.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index 8ed9a4a3..6a3d0444 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -419,6 +419,7 @@ void Axis::run_state_machine_loop() { goto invalid_state_label; if (!encoder_.is_ready_) goto invalid_state_label; + watchdog_feed(); status = run_closed_loop_control_loop(); } break;