From cd4ec0aeb985b0d12b42418b934b866e4b2c83f2 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Sun, 1 Oct 2017 22:32:03 -0700 Subject: [PATCH 1/5] add vscode intellisense --- .vscode/c_cpp_properties.json | 4 +++- MotorControl/low_level.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index bd8d33ee..2fb3414a 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -15,7 +15,9 @@ "${workspaceRoot}/Drivers/CMSIS/Device/ST/STM32F4xx/Include", "${workspaceRoot}/Drivers/CMSIS/Include", "${workspaceRoot}/Inc", - "${workspaceRoot}/MotorControl" + "${workspaceRoot}/MotorControl", + "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/arm-none-eabi/include", + "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/lib/gcc/arm-none-eabi/6.3.1/include" ], "defines": [ "_DEBUG", diff --git a/MotorControl/low_level.c b/MotorControl/low_level.c index 1d1da1b6..a7cf7fa2 100755 --- a/MotorControl/low_level.c +++ b/MotorControl/low_level.c @@ -2,12 +2,14 @@ // Because of broken cmsis_os.h, we need to include arm_math first, // otherwise chip specific defines are ommited +#include #include // Sets up the correct chip specifc defines required by arm_math #define ARM_MATH_CM4 #include #include +#include #include #include #include From 6dfc499f4f204b74c5b542399e978048374672be Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Thu, 5 Oct 2017 17:22:02 -0700 Subject: [PATCH 2/5] cleaner rotor mode decode --- MotorControl/low_level.c | 55 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/MotorControl/low_level.c b/MotorControl/low_level.c index a7cf7fa2..db44c3b8 100755 --- a/MotorControl/low_level.c +++ b/MotorControl/low_level.c @@ -1214,36 +1214,39 @@ static void update_rotor(Motor_t* motor) { } } +static bool using_encoder(Motor_t* motor) { + if (motor->rotor_mode == ROTOR_MODE_ENCODER || + motor->rotor_mode == ROTOR_MODE_RUN_ENCODER_TEST_SENSORLESS) + return true; + else + return false; +} + +static bool using_sensorless(Motor_t* motor) { + if (motor->rotor_mode == ROTOR_MODE_SENSORLESS) + return true; + else + return false; +} + static float get_rotor_phase(Motor_t* motor) { - switch (motor->rotor_mode) { - case ROTOR_MODE_ENCODER: - case ROTOR_MODE_RUN_ENCODER_TEST_SENSORLESS: - return motor->encoder.phase; - break; - case ROTOR_MODE_SENSORLESS: - return motor->sensorless.phase; - break; - default: - //TODO error handling - return 0.0f; - break; - } + if (using_encoder(motor)) + return motor->encoder.phase; + else if (using_sensorless(motor)) + return motor->sensorless.phase; + else + //TODO error handling + return 0.0f; } static float get_pll_vel(Motor_t* motor) { - switch (motor->rotor_mode) { - case ROTOR_MODE_ENCODER: - case ROTOR_MODE_RUN_ENCODER_TEST_SENSORLESS: - return motor->encoder.pll_vel; - break; - case ROTOR_MODE_SENSORLESS: - return motor->sensorless.pll_vel; - break; - default: - //TODO error handling - return 0.0f; - break; - } + if (using_encoder(motor)) + return motor->encoder.pll_vel; + else if (using_sensorless(motor)) + return motor->sensorless.pll_vel; + else + //TODO error handling + return 0.0f; } static bool spin_up_timestep(Motor_t* motor, float phase, float I_mag) { From c8ff9e7e6da95b00b15ec091a29dd5ccd4e7c0f1 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Wed, 11 Oct 2017 13:31:15 -0700 Subject: [PATCH 3/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b0c8ec1..11438531 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Like this (click for video): [![Servo motor control demo](https://img.youtube.com/vi/WT4E5nb3KtY/0.jpg)](https://www.youtube.com/watch?v=WT4E5nb3KtY) This repository contains the firmware that runs on the board. The other related repositories are: -* [ODriveHardware](https://github.com/madcowswe/ODriveHardware): Circuit board design. Also, the pinout from the microcontroller to the board is documented [here](https://docs.google.com/spreadsheets/d/1QXDCs1IRtUyG__M_9WruWOheywb-GhOwFtfPcHuN2Fg/edit?usp=sharing). +* [ODriveHardware](https://github.com/madcowswe/ODriveHardware): Circuit board design. Also, the pinout from the microcontroller to the board is documented [here](https://docs.google.com/spreadsheets/d/1QXDCs1IRtUyG__M_9WruWOheywb-GhOwFtfPcHuN2Fg/edit#gid=404444347). * [ODrive](https://github.com/madcowswe/ODrive): Configuration and analysis scripts that runs on a PC. There is also [ODriveFPGA](https://github.com/madcowswe/ODriveFPGA), which contains the FPGA logic and software that runs on the FPGA based ODrive. This is not currently in development, but may be resumed at some later date. @@ -44,7 +44,7 @@ You must set: ### Tuning parameters The most important parameters are the limits: -* The current limit: `.current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain`. The default current limit, for safety reasons, is set to 10A. This is quite weak, and good for making sure the drive is stable. Once you have tuned the drive, you should increase this to 75A to get some performance. Note that above 75A, you must change the current amplifier gains. +* The current limit: `.current_lim = 75.0f, //[A] // Note: consistent with 40v/v gain`. The default current limit, for safety reasons, is set to 10A. This is quite weak, and good for making sure the drive is stable. Once you have tuned the drive, you can increase this to 75A to get some performance. Note that above 75A, you must change the current amplifier gains. * The velocity limit: `.vel_limit = 20000.0f, // [counts/s]`. Does what it says on the tin. The motion control gains are currently manually tuned: From 99b9840455468b8da5bcf84684e669d261d83df7 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Wed, 11 Oct 2017 13:42:59 -0700 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62e96abb..1b9b4455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -## [0.1] - UNRELEASED +## [0.1.0] - 2017-08-26 ### Added * Step/Dir interface * this Changelog From 8b70924b41643c8a7af4beb21a536b78533ccf53 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Sat, 14 Oct 2017 14:45:38 -0700 Subject: [PATCH 5/5] unsafe modification outside buffer fixed --- MotorControl/low_level.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MotorControl/low_level.c b/MotorControl/low_level.c index db44c3b8..d5c18bff 100755 --- a/MotorControl/low_level.c +++ b/MotorControl/low_level.c @@ -414,7 +414,7 @@ void motor_parse_cmd(uint8_t* buffer, int len) { // TODO very hacky way of terminating sscanf at end of buffer: // We should do some proper struct packing instead of using sscanf altogether - buffer[len] = 0; + buffer[len-1] = 0; // check incoming packet type if (buffer[0] == 'p') {