From 09daacda9f4c34873a4e7de927d1d72b357b1bd0 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 19 Jul 2020 18:49:50 +0200 Subject: [PATCH 1/7] Changed bash shebang to more a general version. --- Firmware/build.sh | 2 +- Firmware/find_programmer.sh | 2 +- tools/odrive/tests/test_runner.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/build.sh b/Firmware/build.sh index 8f3a0730..88570b15 100755 --- a/Firmware/build.sh +++ b/Firmware/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Builds the firmware with the configuration specified by # environment variables named CONFIG_... # If DEPLOY is set, the deliverables are copied to Firmware/deploy/* diff --git a/Firmware/find_programmer.sh b/Firmware/find_programmer.sh index 4b184b6a..cea57038 100755 --- a/Firmware/find_programmer.sh +++ b/Firmware/find_programmer.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash openocd -d3 -f board/stm32f4discovery.cfg -c "hla_serial wrong_serial" 2>&1 | \ xxd -p | \ tr -d '\n' | \ diff --git a/tools/odrive/tests/test_runner.py b/tools/odrive/tests/test_runner.py index 8295a1af..9633b92f 100644 --- a/tools/odrive/tests/test_runner.py +++ b/tools/odrive/tests/test_runner.py @@ -794,7 +794,7 @@ if args.setup_host: if not os.path.isfile('/usr/share/arduino/hardware/tools/teensy_post_compile_old'): os.rename('/usr/share/arduino/hardware/tools/teensy_post_compile', '/usr/share/arduino/hardware/tools/teensy_post_compile_old') with open('/usr/share/arduino/hardware/tools/teensy_post_compile', 'w') as scr: - scr.write('#!/bin/bash\n') + scr.write('#!/usr/bin/env bash\n') scr.write('if [ "$ARDUINO_COMPILE_DESTINATION" != "" ]; then\n') scr.write(' cp -r ${2#-path=}/*.ino.hex ${ARDUINO_COMPILE_DESTINATION}\n') scr.write('fi\n') From deb4a68d896a6acd2a6739bcdee266ff70bcfc2c Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Mon, 20 Jul 2020 11:12:01 +0200 Subject: [PATCH 2/7] remove build.sh This script was used by Travis CI which got disabled in a4e03ffd077eae11f1d3cdc62d3c20ef38f9fb3f in favor of GitHub Workflows. Developers should use `make` instead of this script. --- Firmware/build.sh | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100755 Firmware/build.sh diff --git a/Firmware/build.sh b/Firmware/build.sh deleted file mode 100755 index 88570b15..00000000 --- a/Firmware/build.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Builds the firmware with the configuration specified by -# environment variables named CONFIG_... -# If DEPLOY is set, the deliverables are copied to Firmware/deploy/* -# with the suffix $DEPLOY -set -euo pipefail - -THIS_DIR="$(dirname "$0")" -cd "$THIS_DIR" - -# Treat warnings as errors -export CONFIG_STRICT=true - -# Write all environment variables that start with "CONFIG_" to tup.config -rm -rdf build -mkdir -p build -env | grep ^CONFIG > tup.config -tup init -tup generate ./tup_build.sh -bash -xe ./tup_build.sh - -# Deploy -if ! [ -z ${DEPLOY+x} ]; then - mkdir -p deploy - cp build/ODriveFirmware.elf deploy/ODriveFirmware_"$DEPLOY".elf - cp build/ODriveFirmware.hex deploy/ODriveFirmware_"$DEPLOY".hex -fi From ff6146f05516d915ee42f8eed6e33c20312f3625 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Mon, 20 Jul 2020 11:47:18 +0200 Subject: [PATCH 3/7] Fix bugs in protocol code - Fix incorrect use of snprintf. - Fix TreatPacketSinkAsStreamSink::process_bytes() quitting when being passed more than 64 bytes. Reported in https://github.com/madcowswe/ODrive/issues/438 These bugs are not known to have an effect currently but could have one if code somewhere else is changed. --- Firmware/communication/ascii_protocol.cpp | 4 +++- Firmware/communication/interface_usb.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/communication/ascii_protocol.cpp b/Firmware/communication/ascii_protocol.cpp index c8cc3299..5efbed46 100644 --- a/Firmware/communication/ascii_protocol.cpp +++ b/Firmware/communication/ascii_protocol.cpp @@ -36,14 +36,16 @@ static Introspectable root_obj = ODriveTypeInfo::make_introspectable(odr // @brief Sends a line on the specified output. template void respond(StreamSink& output, bool include_checksum, const char * fmt, TArgs&& ... args) { - char response[64]; + char response[64]; // Hardcoded max buffer size. We silently truncate the output if it's too long for the buffer. size_t len = snprintf(response, sizeof(response), fmt, std::forward(args)...); + len = std::min(len, sizeof(response)); output.process_bytes((uint8_t*)response, len, nullptr); // TODO: use process_all instead if (include_checksum) { uint8_t checksum = 0; for (size_t i = 0; i < len; ++i) checksum ^= response[i]; len = snprintf(response, sizeof(response), "*%u", checksum); + len = std::min(len, sizeof(response)); output.process_bytes((uint8_t*)response, len, nullptr); } output.process_bytes((const uint8_t*)"\r\n", 2, nullptr); diff --git a/Firmware/communication/interface_usb.cpp b/Firmware/communication/interface_usb.cpp index 83632bcd..bbdabb3d 100644 --- a/Firmware/communication/interface_usb.cpp +++ b/Firmware/communication/interface_usb.cpp @@ -61,7 +61,7 @@ public: // Loop to ensure all bytes get sent while (length) { size_t chunk = length < USB_TX_DATA_SIZE ? length : USB_TX_DATA_SIZE; - if (output_.process_packet(buffer, length) != 0) + if (output_.process_packet(buffer, chunk) != 0) return -1; buffer += chunk; length -= chunk; From 4cc9b16077de431eeb1429302b2af2362328eac6 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Mon, 20 Jul 2020 12:24:21 +0200 Subject: [PATCH 4/7] Fix motor subtree being unreachable from ASCII protocol When get_direct_child() was invoked on an Axis Instrospectable with the string "motor" it instead returned an Introspectable for "motor_thermistor". This is because strncmp("motor", "motor_thermistor", 5) compares to 0. --- Firmware/fibre/cpp/include/fibre/introspection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/fibre/cpp/include/fibre/introspection.hpp b/Firmware/fibre/cpp/include/fibre/introspection.hpp index f52b73a8..f7e43f68 100644 --- a/Firmware/fibre/cpp/include/fibre/introspection.hpp +++ b/Firmware/fibre/cpp/include/fibre/introspection.hpp @@ -96,7 +96,7 @@ public: private: Introspectable get_direct_child(const char * name, size_t length) const { for (size_t i = 0; i < type_info_->property_table_length_; ++i) { - if (!strncmp(name, type_info_->property_table_[i].name, length)) { + if (!strncmp(name, type_info_->property_table_[i].name, length) && (length == strlen(type_info_->property_table_[i].name))) { Introspectable result; result.storage_ = type_info_->get_child(storage_, i); result.type_info_ = type_info_->property_table_[i].type_info; From aa73bc907e109ea1359c549e8fe96001534d826a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 25 Jul 2020 23:27:08 -0400 Subject: [PATCH 5/7] Add simple analysis --- analysis/Simulation/TranslationalMass.py | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 analysis/Simulation/TranslationalMass.py diff --git a/analysis/Simulation/TranslationalMass.py b/analysis/Simulation/TranslationalMass.py new file mode 100644 index 00000000..3cb1a4aa --- /dev/null +++ b/analysis/Simulation/TranslationalMass.py @@ -0,0 +1,35 @@ +import os +import matplotlib.pyplot as plt +from control.matlab import * + +# Input: Current (A) +# Output: Torque (Nm) +# Params: Kt (Nm/A) +def motor(Kt): + return tf(Kt, 1) + +# Mass-Spring-Damper +# Input: Force +# Output: Position +# Params: m (kg) +# b +# k (N/m) +def mass(m, b, k): + A = [[0, 1.], [-k/m, -b/m]] + B = [[0], [1/m]] + C = [[1., 0]] + return ss(A, B, C, 0) + +# Input: Torque (Nm) +# Output: Force (N) +# Params: r (m) +def pulley(r): + return tf(r, 1) + +sys = series(motor(2.5), pulley(0.015), mass(0.10, 0, 0)) +yout, T, xout = step(sys, return_x=True) +print(yout) +# plt.plot(T, yout) +plt.plot(T, xout) +plt.legend(['Displacement', 'Velocity']) +plt.show() \ No newline at end of file From 88b3ed42606f2d4eb909bec893c55e4a39472038 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 26 Jul 2020 16:16:10 -0400 Subject: [PATCH 6/7] Optimize step/dir callback --- Firmware/.vscode/c_cpp_properties.json | 6 +++--- Firmware/MotorControl/axis.cpp | 10 ++++------ Firmware/MotorControl/controller.cpp | 3 --- Firmware/MotorControl/controller.hpp | 5 ++++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Firmware/.vscode/c_cpp_properties.json b/Firmware/.vscode/c_cpp_properties.json index 9c1aec97..1d5ab7cf 100644 --- a/Firmware/.vscode/c_cpp_properties.json +++ b/Firmware/.vscode/c_cpp_properties.json @@ -3,7 +3,7 @@ { "name": "Win32", "includePath": [ - "${workspaceRoot}/**" + "${workspaceFolder}/**" ], "defines": [ "STM32F405xx", @@ -24,7 +24,7 @@ { "name": "Linux", "includePath": [ - "${workspaceRoot}/**" + "${workspaceFolder}/**" ], "defines": [ "STM32F405xx", @@ -44,7 +44,7 @@ { "name": "Mac", "includePath": [ - "${workspaceRoot}/**" + "${workspaceFolder}/**" ], "defines": [ "STM32F405xx", diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index f66f8f32..bc11d1e4 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -118,12 +118,10 @@ bool Axis::wait_for_current_meas() { // step/direction interface void Axis::step_cb() { - if (step_dir_active_) { - GPIO_PinState dir_pin = HAL_GPIO_ReadPin(dir_port_, dir_pin_); - float dir = (dir_pin == GPIO_PIN_SET) ? 1.0f : -1.0f; - controller_.input_pos_ += dir * config_.counts_per_step; - controller_.input_pos_updated(); - } + const GPIO_PinState dir_pin = (GPIO_PinState)(dir_port_->IDR & dir_pin_); + const int32_t dir = (1 - 2 * (int32_t)dir_pin) * step_dir_active_; + controller_.input_pos_ += dir * config_.counts_per_step; + controller_.input_pos_updated(); }; void Axis::load_default_step_dir_pin_config( diff --git a/Firmware/MotorControl/controller.cpp b/Firmware/MotorControl/controller.cpp index c15b1cbe..7b3fe8ef 100644 --- a/Firmware/MotorControl/controller.cpp +++ b/Firmware/MotorControl/controller.cpp @@ -26,9 +26,6 @@ void Controller::set_error(Error error) { // Command Handling //-------------------------------- -void Controller::input_pos_updated() { - input_pos_updated_ = true; -} bool Controller::select_encoder(size_t encoder_num) { if (encoder_num < AXIS_COUNT) { diff --git a/Firmware/MotorControl/controller.hpp b/Firmware/MotorControl/controller.hpp index 0b692450..b1f687dc 100644 --- a/Firmware/MotorControl/controller.hpp +++ b/Firmware/MotorControl/controller.hpp @@ -52,7 +52,10 @@ public: void reset(); void set_error(Error error); - void input_pos_updated(); + constexpr void input_pos_updated() { + input_pos_updated_ = true; + } + bool select_encoder(size_t encoder_num); // Trajectory-Planned control From 7d94b6c7866201397f0fb9ac418d47bb2ac3b2ad Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 27 Jul 2020 18:20:14 -0400 Subject: [PATCH 7/7] Fix step_cb per @PAJohnson --- Firmware/MotorControl/axis.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index bc11d1e4..375d75b8 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -118,8 +118,8 @@ bool Axis::wait_for_current_meas() { // step/direction interface void Axis::step_cb() { - const GPIO_PinState dir_pin = (GPIO_PinState)(dir_port_->IDR & dir_pin_); - const int32_t dir = (1 - 2 * (int32_t)dir_pin) * step_dir_active_; + const bool dir_pin = dir_port_->IDR & dir_pin_; + const int32_t dir = (-1 + 2 * dir_pin) * step_dir_active_; controller_.input_pos_ += dir * config_.counts_per_step; controller_.input_pos_updated(); };