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 diff --git a/MotorControl/low_level.c b/MotorControl/low_level.c index 6f799f4c..ebf1b232 100755 --- a/MotorControl/low_level.c +++ b/MotorControl/low_level.c @@ -995,36 +995,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) { 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: