From 8302de11296d7c050578227019c5d34226531802 Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Tue, 8 Jun 2021 15:55:36 -0700 Subject: [PATCH 1/9] Added position getter function for arduino Added GetPosition function in ODriveArduino file to accompany the existing GetVelocity function. Changed arduino example file to demonstrate usage over previous verbose implementation. --- Arduino/ODriveArduino/ODriveArduino.cpp | 10 +++++++--- Arduino/ODriveArduino/ODriveArduino.h | 1 + .../examples/ODriveArduinoTest/ODriveArduinoTest.ino | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Arduino/ODriveArduino/ODriveArduino.cpp b/Arduino/ODriveArduino/ODriveArduino.cpp index cd3fcd5e..2ff9006c 100644 --- a/Arduino/ODriveArduino/ODriveArduino.cpp +++ b/Arduino/ODriveArduino/ODriveArduino.cpp @@ -1,4 +1,3 @@ - #include "Arduino.h" #include "ODriveArduino.h" @@ -42,7 +41,7 @@ void ODriveArduino::SetCurrent(int motor_number, float current) { serial_ << "c " << motor_number << " " << current << "\n"; } -void ODriveArduino::TrapezoidalMove(int motor_number, float position){ +void ODriveArduino::TrapezoidalMove(int motor_number, float position) { serial_ << "t " << motor_number << " " << position << "\n"; } @@ -50,11 +49,16 @@ float ODriveArduino::readFloat() { return readString().toFloat(); } -float ODriveArduino::GetVelocity(int motor_number){ +float ODriveArduino::GetVelocity(int motor_number) { serial_<< "r axis" << motor_number << ".encoder.vel_estimate\n"; return ODriveArduino::readFloat(); } +float ODriveArduino::GetPosition(int motor_number) { + serial_ << "r axis" << motor_number << ".encoder.pos_estimate\n"; + return ODriveArduino::readFloat(); +} + int32_t ODriveArduino::readInt() { return readString().toInt(); } diff --git a/Arduino/ODriveArduino/ODriveArduino.h b/Arduino/ODriveArduino/ODriveArduino.h index 6620f859..0824110a 100644 --- a/Arduino/ODriveArduino/ODriveArduino.h +++ b/Arduino/ODriveArduino/ODriveArduino.h @@ -30,6 +30,7 @@ public: void TrapezoidalMove(int motor_number, float position); // Getters float GetVelocity(int motor_number); + float GetPosition(int motor_number); // General params float readFloat(); int32_t readInt(); diff --git a/Arduino/ODriveArduino/examples/ODriveArduinoTest/ODriveArduinoTest.ino b/Arduino/ODriveArduino/examples/ODriveArduinoTest/ODriveArduinoTest.ino index e75a1862..186c81d6 100644 --- a/Arduino/ODriveArduino/examples/ODriveArduinoTest/ODriveArduinoTest.ino +++ b/Arduino/ODriveArduino/examples/ODriveArduinoTest/ODriveArduinoTest.ino @@ -112,8 +112,7 @@ void loop() { unsigned long start = millis(); while(millis() - start < duration) { for (int motor = 0; motor < 2; ++motor) { - odrive_serial << "r axis" << motor << ".encoder.pos_estimate\n"; - Serial << odrive.readFloat() << '\t'; + Serial << odrive.GetPosition(motor) << '\t'; } Serial << '\n'; } From ab7ed49e7b659acb862c517cf9001c75253c6056 Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Tue, 8 Jun 2021 21:02:47 -0700 Subject: [PATCH 2/9] Update ODriveArduino.cpp Added top empty line back. --- Arduino/ODriveArduino/ODriveArduino.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Arduino/ODriveArduino/ODriveArduino.cpp b/Arduino/ODriveArduino/ODriveArduino.cpp index 2ff9006c..7bedfc46 100644 --- a/Arduino/ODriveArduino/ODriveArduino.cpp +++ b/Arduino/ODriveArduino/ODriveArduino.cpp @@ -1,3 +1,4 @@ + #include "Arduino.h" #include "ODriveArduino.h" From 16aad18448fefe095e4b4a762fa06c78a39d2b7e Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Tue, 8 Jun 2021 22:54:01 -0700 Subject: [PATCH 3/9] Created jinja template to autogenerate arduino enums header Created arduino_enums_template.j2 to generate header file containing enums for arduino. Added the header file to Arduino/ODriveArduino/enums.h. This replaces the hardcoded enum defined inside the ODriveArduino class. --- Arduino/ODriveArduino/enums.h | 198 ++++++++++++++++++++++++++++++++ tools/arduino_enums_template.j2 | 22 ++++ 2 files changed, 220 insertions(+) create mode 100644 Arduino/ODriveArduino/enums.h create mode 100644 tools/arduino_enums_template.j2 diff --git a/Arduino/ODriveArduino/enums.h b/Arduino/ODriveArduino/enums.h new file mode 100644 index 00000000..3794d602 --- /dev/null +++ b/Arduino/ODriveArduino/enums.h @@ -0,0 +1,198 @@ +#ifndef arduino_enums_template_h +#define arduino_enums_template_h + +/* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. +** To regenerate this file, nagivate to the top level of the ODrive repository and run: +** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/enums.h +*/ + +// ODrive.GpioMode +enum GpioMode { + GPIO_MODE_DIGITAL = 0, + GPIO_MODE_DIGITAL_PULL_UP = 1, + GPIO_MODE_DIGITAL_PULL_DOWN = 2, + GPIO_MODE_ANALOG_IN = 3, + GPIO_MODE_UART_A = 4, + GPIO_MODE_UART_B = 5, + GPIO_MODE_UART_C = 6, + GPIO_MODE_CAN_A = 7, + GPIO_MODE_I2C_A = 8, + GPIO_MODE_SPI_A = 9, + GPIO_MODE_PWM = 10, + GPIO_MODE_ENC0 = 11, + GPIO_MODE_ENC1 = 12, + GPIO_MODE_ENC2 = 13, + GPIO_MODE_MECH_BRAKE = 14, + GPIO_MODE_STATUS = 15, +}; + +// ODrive.StreamProtocolType +enum StreamProtocolType { + STREAM_PROTOCOL_TYPE_FIBRE = 0, + STREAM_PROTOCOL_TYPE_ASCII = 1, + STREAM_PROTOCOL_TYPE_STDOUT = 2, + STREAM_PROTOCOL_TYPE_ASCII_AND_STDOUT = 3, +}; + +// ODrive.Can.Protocol +enum Protocol { + PROTOCOL_SIMPLE = 0x00000001, +}; + +// ODrive.Axis.AxisState +enum AxisState { + AXIS_STATE_UNDEFINED = 0, + AXIS_STATE_IDLE = 1, + AXIS_STATE_STARTUP_SEQUENCE = 2, + AXIS_STATE_FULL_CALIBRATION_SEQUENCE = 3, + AXIS_STATE_MOTOR_CALIBRATION = 4, + AXIS_STATE_ENCODER_INDEX_SEARCH = 6, + AXIS_STATE_ENCODER_OFFSET_CALIBRATION = 7, + AXIS_STATE_CLOSED_LOOP_CONTROL = 8, + AXIS_STATE_LOCKIN_SPIN = 9, + AXIS_STATE_ENCODER_DIR_FIND = 10, + AXIS_STATE_HOMING = 11, + AXIS_STATE_ENCODER_HALL_POLARITY_CALIBRATION = 12, + AXIS_STATE_ENCODER_HALL_PHASE_CALIBRATION = 13, +}; + +// ODrive.Encoder.Mode +enum EncoderMode { + ENCODER_MODE_INCREMENTAL = 0, + ENCODER_MODE_HALL = 1, + ENCODER_MODE_SINCOS = 2, + ENCODER_MODE_SPI_ABS_CUI = 256, + ENCODER_MODE_SPI_ABS_AMS = 257, + ENCODER_MODE_SPI_ABS_AEAT = 258, + ENCODER_MODE_SPI_ABS_RLS = 259, + ENCODER_MODE_SPI_ABS_MA732 = 260, +}; + +// ODrive.Controller.ControlMode +enum ControlMode { + CONTROL_MODE_VOLTAGE_CONTROL = 0, + CONTROL_MODE_TORQUE_CONTROL = 1, + CONTROL_MODE_VELOCITY_CONTROL = 2, + CONTROL_MODE_POSITION_CONTROL = 3, +}; + +// ODrive.Controller.InputMode +enum InputMode { + INPUT_MODE_INACTIVE = 0, + INPUT_MODE_PASSTHROUGH = 1, + INPUT_MODE_VEL_RAMP = 2, + INPUT_MODE_POS_FILTER = 3, + INPUT_MODE_MIX_CHANNELS = 4, + INPUT_MODE_TRAP_TRAJ = 5, + INPUT_MODE_TORQUE_RAMP = 6, + INPUT_MODE_MIRROR = 7, + INPUT_MODE_TUNING = 8, +}; + +// ODrive.Motor.MotorType +enum MotorType { + MOTOR_TYPE_HIGH_CURRENT = 0, + MOTOR_TYPE_GIMBAL = 2, + MOTOR_TYPE_ACIM = 3, +}; + +// ODrive.Error +enum ODriveError { + ODRIVE_ERROR_NONE = 0x00000000, + ODRIVE_ERROR_CONTROL_ITERATION_MISSED = 0x00000001, + ODRIVE_ERROR_DC_BUS_UNDER_VOLTAGE = 0x00000002, + ODRIVE_ERROR_DC_BUS_OVER_VOLTAGE = 0x00000004, + ODRIVE_ERROR_DC_BUS_OVER_REGEN_CURRENT = 0x00000008, + ODRIVE_ERROR_DC_BUS_OVER_CURRENT = 0x00000010, + ODRIVE_ERROR_BRAKE_DEADTIME_VIOLATION = 0x00000020, + ODRIVE_ERROR_BRAKE_DUTY_CYCLE_NAN = 0x00000040, + ODRIVE_ERROR_INVALID_BRAKE_RESISTANCE = 0x00000080, +}; + +// ODrive.Can.Error +enum CanError { + CAN_ERROR_NONE = 0x00000000, + CAN_ERROR_DUPLICATE_CAN_IDS = 0x00000001, +}; + +// ODrive.Axis.Error +enum AxisError { + AXIS_ERROR_NONE = 0x00000000, + AXIS_ERROR_INVALID_STATE = 0x00000001, + AXIS_ERROR_WATCHDOG_TIMER_EXPIRED = 0x00000800, + AXIS_ERROR_MIN_ENDSTOP_PRESSED = 0x00001000, + AXIS_ERROR_MAX_ENDSTOP_PRESSED = 0x00002000, + AXIS_ERROR_ESTOP_REQUESTED = 0x00004000, + AXIS_ERROR_HOMING_WITHOUT_ENDSTOP = 0x00020000, + AXIS_ERROR_OVER_TEMP = 0x00040000, + AXIS_ERROR_UNKNOWN_POSITION = 0x00080000, +}; + +// ODrive.Motor.Error +enum MotorError { + MOTOR_ERROR_NONE = 0x00000000, + MOTOR_ERROR_PHASE_RESISTANCE_OUT_OF_RANGE = 0x00000001, + MOTOR_ERROR_PHASE_INDUCTANCE_OUT_OF_RANGE = 0x00000002, + MOTOR_ERROR_DRV_FAULT = 0x00000008, + MOTOR_ERROR_CONTROL_DEADLINE_MISSED = 0x00000010, + MOTOR_ERROR_MODULATION_MAGNITUDE = 0x00000080, + MOTOR_ERROR_CURRENT_SENSE_SATURATION = 0x00000400, + MOTOR_ERROR_CURRENT_LIMIT_VIOLATION = 0x00001000, + MOTOR_ERROR_MODULATION_IS_NAN = 0x00010000, + MOTOR_ERROR_MOTOR_THERMISTOR_OVER_TEMP = 0x00020000, + MOTOR_ERROR_FET_THERMISTOR_OVER_TEMP = 0x00040000, + MOTOR_ERROR_TIMER_UPDATE_MISSED = 0x00080000, + MOTOR_ERROR_CURRENT_MEASUREMENT_UNAVAILABLE = 0x00100000, + MOTOR_ERROR_CONTROLLER_FAILED = 0x00200000, + MOTOR_ERROR_I_BUS_OUT_OF_RANGE = 0x00400000, + MOTOR_ERROR_BRAKE_RESISTOR_DISARMED = 0x00800000, + MOTOR_ERROR_SYSTEM_LEVEL = 0x01000000, + MOTOR_ERROR_BAD_TIMING = 0x02000000, + MOTOR_ERROR_UNKNOWN_PHASE_ESTIMATE = 0x04000000, + MOTOR_ERROR_UNKNOWN_PHASE_VEL = 0x08000000, + MOTOR_ERROR_UNKNOWN_TORQUE = 0x10000000, + MOTOR_ERROR_UNKNOWN_CURRENT_COMMAND = 0x20000000, + MOTOR_ERROR_UNKNOWN_CURRENT_MEASUREMENT = 0x40000000, + MOTOR_ERROR_UNKNOWN_VBUS_VOLTAGE = 0x80000000, + MOTOR_ERROR_UNKNOWN_VOLTAGE_COMMAND = 0x100000000, + MOTOR_ERROR_UNKNOWN_GAINS = 0x200000000, + MOTOR_ERROR_CONTROLLER_INITIALIZING = 0x400000000, + MOTOR_ERROR_UNBALANCED_PHASES = 0x800000000, +}; + +// ODrive.Controller.Error +enum ControllerError { + CONTROLLER_ERROR_NONE = 0x00000000, + CONTROLLER_ERROR_OVERSPEED = 0x00000001, + CONTROLLER_ERROR_INVALID_INPUT_MODE = 0x00000002, + CONTROLLER_ERROR_UNSTABLE_GAIN = 0x00000004, + CONTROLLER_ERROR_INVALID_MIRROR_AXIS = 0x00000008, + CONTROLLER_ERROR_INVALID_LOAD_ENCODER = 0x00000010, + CONTROLLER_ERROR_INVALID_ESTIMATE = 0x00000020, + CONTROLLER_ERROR_INVALID_CIRCULAR_RANGE = 0x00000040, + CONTROLLER_ERROR_SPINOUT_DETECTED = 0x00000080, +}; + +// ODrive.Encoder.Error +enum EncoderError { + ENCODER_ERROR_NONE = 0x00000000, + ENCODER_ERROR_UNSTABLE_GAIN = 0x00000001, + ENCODER_ERROR_CPR_POLEPAIRS_MISMATCH = 0x00000002, + ENCODER_ERROR_NO_RESPONSE = 0x00000004, + ENCODER_ERROR_UNSUPPORTED_ENCODER_MODE = 0x00000008, + ENCODER_ERROR_ILLEGAL_HALL_STATE = 0x00000010, + ENCODER_ERROR_INDEX_NOT_FOUND_YET = 0x00000020, + ENCODER_ERROR_ABS_SPI_TIMEOUT = 0x00000040, + ENCODER_ERROR_ABS_SPI_COM_FAIL = 0x00000080, + ENCODER_ERROR_ABS_SPI_NOT_READY = 0x00000100, + ENCODER_ERROR_HALL_NOT_CALIBRATED_YET = 0x00000200, +}; + +// ODrive.SensorlessEstimator.Error +enum SensorlessEstimatorError { + SENSORLESS_ESTIMATOR_ERROR_NONE = 0x00000000, + SENSORLESS_ESTIMATOR_ERROR_UNSTABLE_GAIN = 0x00000001, + SENSORLESS_ESTIMATOR_ERROR_UNKNOWN_CURRENT_MEASUREMENT = 0x00000002, +}; + +#endif diff --git a/tools/arduino_enums_template.j2 b/tools/arduino_enums_template.j2 new file mode 100644 index 00000000..d7cb9cd7 --- /dev/null +++ b/tools/arduino_enums_template.j2 @@ -0,0 +1,22 @@ +#ifndef arduino_enums_template_h +#define arduino_enums_template_h + +/* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. +** To regenerate this file, nagivate to the top level of the ODrive repository and run: +** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/enums.h +*/ + +[%- for _, enum in value_types.items() %] +[%- if enum.is_enum %] + +// [[enum.fullname]] +enum [[(enum.parent.name if enum.name in ['Error', 'Mode'] else '') + enum.name ]] { + [%- for k, value in enum['values'].items() %] + [[((((enum.parent.name if enum.name in ['Error', 'Mode'] else '') + enum.name) | to_macro_case) + "_" + (k | to_macro_case)).ljust(40)]] = [% if enum.is_flags %]0x[['%08x' | format(value.value)]][% else %][[value.value]][% endif %], + [%- endfor %] +}; +[%- endif %] +[%- endfor %] + +#endif + From 2e36ac14c1fb219e8eb2e1f4efb79af70e7ab0e5 Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Fri, 11 Jun 2021 17:05:33 -0700 Subject: [PATCH 4/9] Update makefile to generate new arduino enums file Added command to makefile to generate enums.h for Arduino use. Did the same for the dockerfile. Added note on developer-guide markdown file to also update enums.h along with enums.py. --- Dockerfile | 4 ++++ Firmware/Makefile | 1 + docs/developer-guide.md | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8810dc23..5356399f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,10 @@ CMD \ --definitions odrive-interface.yaml \ --template ../tools/enums_template.j2 \ --output ../tools/odrive/enums.py && \ + python interface_generator_stub.py \ + --definitions odrive-interface.yaml \ + --template ../tools/arduino_enums_template.j2 \ + --output ../Arduino/ODriveArduino/enums.h && \ # Hack around Tup's dependency on FUSE tup init && \ tup generate build.sh && \ diff --git a/Firmware/Makefile b/Firmware/Makefile index 3191c4a2..bac32559 100644 --- a/Firmware/Makefile +++ b/Firmware/Makefile @@ -32,6 +32,7 @@ all: @$(PY_CMD) ../tools/odrive/version.py --output autogen/version.c @tup --quiet -no-environ-check @$(PY_CMD) interface_generator_stub.py --definitions odrive-interface.yaml --template ../tools/enums_template.j2 --output ../tools/odrive/enums.py + @$(PY_CMD) interface_generator_stub.py --definitions odrive-interface.yaml --template ../tools/arduino_enums_template.j2 --output ../Arduino/ODriveArduino/enums.h # Copy libfibre files to odrivetool if they were built @ ! test -f "fibre-cpp/build/libfibre-linux-amd64.so" || cp fibre-cpp/build/libfibre-linux-amd64.so ../tools/odrive/pyfibre/fibre/ diff --git a/docs/developer-guide.md b/docs/developer-guide.md index 360baaea..f3b70fb9 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -332,4 +332,4 @@ When filing a PR please go through this checklist: - Also, for each removed/moved/renamed API item use your IDE's search feature to search for occurrences of this name. Update the places you found (this will usually be documentation and test scripts). - If you added things to `odrive-interface.yaml` make sure the new things have decent documentation in the YAML file. We don't expect 100% coverage but use good sense of what to document. - Make sure your PR doesn't contain spurious changes that unnecessarily add or remove whitespace. These add noise and make the reviewer's lifes harder. - - If you changed any enums in `odrive-interface.yaml`, make sure you update [enums.py](../tools/odrive/enums.py). The file includes instructions on how to do this. Check the diff to verify that none of the existing enumerators changed their value. + - If you changed any enums in `odrive-interface.yaml`, make sure you update [enums.py](../tools/odrive/enums.py) and [enums.h](../Arduino/ODriveArduino/enums.h). The file includes instructions on how to do this. Check the diff to verify that none of the existing enumerators changed their value. From 319a9df4f6559d6ee61542d10ff7b1c7d2da0d13 Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Fri, 11 Jun 2021 17:32:43 -0700 Subject: [PATCH 5/9] Renamed enums.h to ODriveEnums.h --- Arduino/ODriveArduino/{enums.h => ODriveEnums.h} | 2 +- Dockerfile | 2 +- Firmware/Makefile | 2 +- docs/developer-guide.md | 2 +- tools/arduino_enums_template.j2 | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename Arduino/ODriveArduino/{enums.h => ODriveEnums.h} (99%) diff --git a/Arduino/ODriveArduino/enums.h b/Arduino/ODriveArduino/ODriveEnums.h similarity index 99% rename from Arduino/ODriveArduino/enums.h rename to Arduino/ODriveArduino/ODriveEnums.h index 3794d602..c4ffccf1 100644 --- a/Arduino/ODriveArduino/enums.h +++ b/Arduino/ODriveArduino/ODriveEnums.h @@ -3,7 +3,7 @@ /* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. ** To regenerate this file, nagivate to the top level of the ODrive repository and run: -** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/enums.h +** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/ODriveEnums.h */ // ODrive.GpioMode diff --git a/Dockerfile b/Dockerfile index 5356399f..06bdadf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ CMD \ python interface_generator_stub.py \ --definitions odrive-interface.yaml \ --template ../tools/arduino_enums_template.j2 \ - --output ../Arduino/ODriveArduino/enums.h && \ + --output ../Arduino/ODriveArduino/ODriveEnums.h && \ # Hack around Tup's dependency on FUSE tup init && \ tup generate build.sh && \ diff --git a/Firmware/Makefile b/Firmware/Makefile index bac32559..0f09b14c 100644 --- a/Firmware/Makefile +++ b/Firmware/Makefile @@ -32,7 +32,7 @@ all: @$(PY_CMD) ../tools/odrive/version.py --output autogen/version.c @tup --quiet -no-environ-check @$(PY_CMD) interface_generator_stub.py --definitions odrive-interface.yaml --template ../tools/enums_template.j2 --output ../tools/odrive/enums.py - @$(PY_CMD) interface_generator_stub.py --definitions odrive-interface.yaml --template ../tools/arduino_enums_template.j2 --output ../Arduino/ODriveArduino/enums.h + @$(PY_CMD) interface_generator_stub.py --definitions odrive-interface.yaml --template ../tools/arduino_enums_template.j2 --output ../Arduino/ODriveArduino/ODriveEnums.h # Copy libfibre files to odrivetool if they were built @ ! test -f "fibre-cpp/build/libfibre-linux-amd64.so" || cp fibre-cpp/build/libfibre-linux-amd64.so ../tools/odrive/pyfibre/fibre/ diff --git a/docs/developer-guide.md b/docs/developer-guide.md index f3b70fb9..0fd71c83 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -332,4 +332,4 @@ When filing a PR please go through this checklist: - Also, for each removed/moved/renamed API item use your IDE's search feature to search for occurrences of this name. Update the places you found (this will usually be documentation and test scripts). - If you added things to `odrive-interface.yaml` make sure the new things have decent documentation in the YAML file. We don't expect 100% coverage but use good sense of what to document. - Make sure your PR doesn't contain spurious changes that unnecessarily add or remove whitespace. These add noise and make the reviewer's lifes harder. - - If you changed any enums in `odrive-interface.yaml`, make sure you update [enums.py](../tools/odrive/enums.py) and [enums.h](../Arduino/ODriveArduino/enums.h). The file includes instructions on how to do this. Check the diff to verify that none of the existing enumerators changed their value. + - If you changed any enums in `odrive-interface.yaml`, make sure you update [enums.py](../tools/odrive/enums.py) and [ODriveEnums.h](../Arduino/ODriveArduino/ODriveEnums.h). The file includes instructions on how to do this. Check the diff to verify that none of the existing enumerators changed their value. diff --git a/tools/arduino_enums_template.j2 b/tools/arduino_enums_template.j2 index d7cb9cd7..9dadb270 100644 --- a/tools/arduino_enums_template.j2 +++ b/tools/arduino_enums_template.j2 @@ -3,7 +3,7 @@ /* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. ** To regenerate this file, nagivate to the top level of the ODrive repository and run: -** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/enums.h +** python Firmware/interface_generator_stub.py --definitions Firmware/odrive-interface.yaml --template tools/arduino_enums_template.j2 --output Arduino/ODriveArduino/ODriveEnums.h */ [%- for _, enum in value_types.items() %] From b1046716422fb20114aac3b9049bd6f2a604ec6f Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Sun, 13 Jun 2021 17:23:05 -0700 Subject: [PATCH 6/9] Follow naming/spacing convention --- Arduino/ODriveArduino/ODriveEnums.h | 5 +++-- tools/arduino_enums_template.j2 | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Arduino/ODriveArduino/ODriveEnums.h b/Arduino/ODriveArduino/ODriveEnums.h index c4ffccf1..f196ecbd 100644 --- a/Arduino/ODriveArduino/ODriveEnums.h +++ b/Arduino/ODriveArduino/ODriveEnums.h @@ -1,5 +1,6 @@ -#ifndef arduino_enums_template_h -#define arduino_enums_template_h + +#ifndef ODriveEnums_h +#define ODriveEnums_h /* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. ** To regenerate this file, nagivate to the top level of the ODrive repository and run: diff --git a/tools/arduino_enums_template.j2 b/tools/arduino_enums_template.j2 index 9dadb270..94418fa9 100644 --- a/tools/arduino_enums_template.j2 +++ b/tools/arduino_enums_template.j2 @@ -1,5 +1,6 @@ -#ifndef arduino_enums_template_h -#define arduino_enums_template_h + +#ifndef ODriveEnums_h +#define ODriveEnums_h /* TODO: This file is dangerous because the enums could potentially change between API versions. Should transmit as part of the JSON. ** To regenerate this file, nagivate to the top level of the ODrive repository and run: From e59ee5cda129397f95d4e1938ebc2fd83e5af9ee Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Sun, 13 Jun 2021 17:28:10 -0700 Subject: [PATCH 7/9] Replaced old inline enum with autogenerated enum header Deleted the manually added enum in the ODriveArduino class. Removed the scope resolution operator from the ODriveArduinoTest.ino file to access enums as it can be accessed from the global namespace. --- Arduino/ODriveArduino/ODriveArduino.h | 13 +------------ .../ODriveArduinoTest/ODriveArduinoTest.ino | 6 +++--- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Arduino/ODriveArduino/ODriveArduino.h b/Arduino/ODriveArduino/ODriveArduino.h index 0824110a..672e9db3 100644 --- a/Arduino/ODriveArduino/ODriveArduino.h +++ b/Arduino/ODriveArduino/ODriveArduino.h @@ -3,21 +3,10 @@ #define ODriveArduino_h #include "Arduino.h" +#include "ODriveEnums.h" class ODriveArduino { public: - enum AxisState_t { - AXIS_STATE_UNDEFINED = 0, // Date: Sun, 13 Jun 2021 20:43:08 -0700 Subject: [PATCH 8/9] Reflected Arduino changes in changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48f49a3e..43c357f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ Please add a note of your changes below this heading if you make a Pull Request. * Added torque mirroring to INPUT_MODE_MIRROR * `mechanical_power_bandwidth`, `electrical_power_bandwidth`, `spinout_electrical_power_threshold`, `spinout_mechanical_power_threshold` added to `controller.config` for spinout detection. * `mechanical_power` and `electrical_power` added to `controller`. +* Added autogenerated enums header file [ODriveEnums.h](../Arduino/ODriveArduino/ODriveEnums.h) for Arduino use. Created Jinja template and edited Makefile to autogenerate it. +* Added GetPosition member function in ODriveArduino class to complement existing GetVelocity, SetVelocity, and SetPosition functions. ### Changed * Step/dir performance improved! Dual axis step rates up to 250kHz have been tested @@ -55,6 +57,7 @@ Please add a note of your changes below this heading if you make a Pull Request. * Added `torque_mirror_ratio` and use it to feed-forward `controller_.torque_output` in `INPUT_MODE_MIRROR` * Accumulate integer steps in step/dir to avoid float precision errors * Circular setpoint mode must be enabled when the step/dir interface is used. +* Replaced inline enum in ODriveArduino class by including new autogenerated enum header file. ### API Migration Notes * `axis.config.turns_per_step` changed to `axis.controller.config.steps_per_circular_range` From 1bb5992ebae22f777eed5562a5d4bd55cf408607 Mon Sep 17 00:00:00 2001 From: Aaron de los Santos Date: Sun, 13 Jun 2021 21:46:21 -0700 Subject: [PATCH 9/9] Made changes clearer in changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43c357f5..4f895d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ Please add a note of your changes below this heading if you make a Pull Request. * Added torque mirroring to INPUT_MODE_MIRROR * `mechanical_power_bandwidth`, `electrical_power_bandwidth`, `spinout_electrical_power_threshold`, `spinout_mechanical_power_threshold` added to `controller.config` for spinout detection. * `mechanical_power` and `electrical_power` added to `controller`. -* Added autogenerated enums header file [ODriveEnums.h](../Arduino/ODriveArduino/ODriveEnums.h) for Arduino use. Created Jinja template and edited Makefile to autogenerate it. +* Added autogenerated enums header file [ODriveEnums.h](../Arduino/ODriveArduino/ODriveEnums.h) for Arduino use. Created Jinja template and edited Makefile to autogenerate it. Reflected change in Dockerfile and added note in developer-guide markdown file for updating ODriveEnums.h alongside enums.py. * Added GetPosition member function in ODriveArduino class to complement existing GetVelocity, SetVelocity, and SetPosition functions. ### Changed @@ -57,7 +57,8 @@ Please add a note of your changes below this heading if you make a Pull Request. * Added `torque_mirror_ratio` and use it to feed-forward `controller_.torque_output` in `INPUT_MODE_MIRROR` * Accumulate integer steps in step/dir to avoid float precision errors * Circular setpoint mode must be enabled when the step/dir interface is used. -* Replaced inline enum in ODriveArduino class by including new autogenerated enum header file. +* Replaced inline enum in ODriveArduino class by including new autogenerated ODriveEnums.h header file. +* Changed the example ODriveArduinoTest.ino file to reflect the new GetPosition member function. Also removed the scope resolution operator to access the enums as it can now be accessed from the global namespace. ### API Migration Notes * `axis.config.turns_per_step` changed to `axis.controller.config.steps_per_circular_range`