From 0882c71beb1ecef858f4e021fe31852503c0dada Mon Sep 17 00:00:00 2001 From: Shaun Meehan Date: Thu, 3 Sep 2020 18:59:14 -0700 Subject: [PATCH] Removed apply_config and enable functions, removed automatic gpio swap, fixed readme and odrive-interface to match --- Firmware/MotorControl/main.cpp | 1 - Firmware/MotorControl/mechanical_brake.cpp | 21 ++++++--------------- Firmware/MotorControl/mechanical_brake.hpp | 6 +----- Firmware/odrive-interface.yaml | 1 - docs/mechanical-brakes.md | 19 ++++++++----------- 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/Firmware/MotorControl/main.cpp b/Firmware/MotorControl/main.cpp index 09838764..65609497 100644 --- a/Firmware/MotorControl/main.cpp +++ b/Firmware/MotorControl/main.cpp @@ -103,7 +103,6 @@ static bool config_apply_all() { && axes[i].controller_.apply_config() && axes[i].min_endstop_.apply_config() && axes[i].max_endstop_.apply_config() - && axes[i].mechanical_brake_.apply_config() && motors[i].apply_config() && axes[i].apply_config(); } diff --git a/Firmware/MotorControl/mechanical_brake.cpp b/Firmware/MotorControl/mechanical_brake.cpp index 21a98881..c9d3602f 100644 --- a/Firmware/MotorControl/mechanical_brake.cpp +++ b/Firmware/MotorControl/mechanical_brake.cpp @@ -1,22 +1,13 @@ #include -bool MechanicalBrake::apply_config() { - config_.parent = this; - set_enabled(config_.enabled); - return true; -} - void MechanicalBrake::engage() { - get_gpio(config_.gpio_num).write(config_.is_active_low ? 0 : 1); + if (odrv.config_.gpio_modes[config_.gpio_num] == ODriveIntf::GPIO_MODE_MECH_BRAKE){ + get_gpio(config_.gpio_num).write(config_.is_active_low ? 0 : 1); + } } void MechanicalBrake::release() { - get_gpio(config_.gpio_num).write(config_.is_active_low ? 1 : 0); + if (odrv.config_.gpio_modes[config_.gpio_num] == ODriveIntf::GPIO_MODE_MECH_BRAKE){ + get_gpio(config_.gpio_num).write(config_.is_active_low ? 1 : 0); + } } - -void MechanicalBrake::set_enabled(bool enable) { - if (enable) { - // We need this flag to alert the system to the configuration on boot - odrv.config_.gpio_modes[config_.gpio_num] = ODriveIntf::GPIO_MODE_MECH_BRAKE; - } -} \ No newline at end of file diff --git a/Firmware/MotorControl/mechanical_brake.hpp b/Firmware/MotorControl/mechanical_brake.hpp index ae8373fd..26362ce5 100644 --- a/Firmware/MotorControl/mechanical_brake.hpp +++ b/Firmware/MotorControl/mechanical_brake.hpp @@ -7,13 +7,11 @@ class MechanicalBrake : public ODriveIntf::MechanicalBrakeIntf { public: struct Config_t { uint16_t gpio_num = 0; - bool enabled = false; bool is_active_low = true; // custom setters MechanicalBrake* parent = nullptr; - void set_gpio_num(uint16_t value) { gpio_num = value; parent->apply_config(); } - void set_enabled(uint32_t value) { enabled = value; parent->apply_config(); } + void set_gpio_num(uint16_t value) { gpio_num = value; } }; MechanicalBrake() {} @@ -21,8 +19,6 @@ class MechanicalBrake : public ODriveIntf::MechanicalBrakeIntf { MechanicalBrake::Config_t config_; Axis* axis_ = nullptr; - bool apply_config(); - void set_enabled(bool enabled); void release(); void engage(); }; diff --git a/Firmware/odrive-interface.yaml b/Firmware/odrive-interface.yaml index 8c527d04..3d31d252 100644 --- a/Firmware/odrive-interface.yaml +++ b/Firmware/odrive-interface.yaml @@ -924,7 +924,6 @@ interfaces: c_is_class: False attributes: gpio_num: {type: uint16, c_setter: set_gpio_num} - enabled: {type: bool, c_setter: set_enabled} is_active_low: bool functions: engage: diff --git a/docs/mechanical-brakes.md b/docs/mechanical-brakes.md index 3dde1e18..ab2164e1 100644 --- a/docs/mechanical-brakes.md +++ b/docs/mechanical-brakes.md @@ -14,7 +14,6 @@ Each axis supports one mechanical brake. The following properties are accessible Name | Type | Default --- | -- | -- gpio_num | int | 0 -enabled | boolean | false is_active_low | boolean | true ### gpio_num @@ -24,26 +23,24 @@ The GPIO pin number, according to the silkscreen labels on ODrive. Set with thes ``` After GPIO pin number is changed, you'll need to run `.save_configuration()` and `.reboot()` for changes to take effect. -### enabled -Enables/disables the operation of the mechanical brake. -``` -..mechanical_brake.config.enabled = -``` -After mechanical brake is enabled or disabled, you'll need to run `.save_configuration()` and `.reboot()` for changes to take effect. - ### is_active_low Most safety braking systems are active low, e.g. when the power is off, the brake is on. If the system uses brake drive electronics which use active high logic, flip this bit then reconsider the safety implications of your design... +### Enabling +The configuration of the mechanical brake will enable the brake functionality. There's no need to specifically 'enable' this feature. + + ### Example Let's say we're hacking away on an old ABB robotic arm. We've wired a 24V brake drive circuit triggered by GPIO5. When GPIO5 is driven, it will release the brakes on the axis we're moving. +We need to notify the axis of the GPIO number we've attached our brake to, and configure the ODrive pin mode to `GPIO_MODE_MECH_BRAKE`: ``` ..mechanical_brake.config.gpio_num = 5 -..mechanical_brake.config.enabled = True +.config.gpio5_mode = GPIO_MODE_MECH_BRAKE ``` -Don't forget to save and reboot: +Pin configurations only take effect after a save/reboot so don't forget to run: ``` .save_configuration() .reboot() @@ -55,7 +52,7 @@ Depending on your system this could be a dangerous experiment. Ensure that you h ``` ..mechanical_brake.release() ``` -Note: If a brake is enabled, it will be engaged/disengaged during the next state machine step. +Note: If a brake is configured, it will be automatically engaged/disengaged during the next state machine step. After you're satisfied with the testing, you can re-enable the brake using the command