From f08b80da6c53cb43ac5250b750a02e42c8e62450 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 13:14:03 -0400 Subject: [PATCH 01/10] documentation and readability I have added additional content to improve readability, debugging, commands for calibration, and using AS5087s. --- docs/encoders.md | 121 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 4 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index 04cf9663..47ff0584 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -1,12 +1,16 @@ # Encoders ## Known and Supported Encoders -Check out the [ODrive Encoder Guide](https://docs.google.com/spreadsheets/d/1OBDwYrBb5zUPZLrhL98ezZbg94tUsZcdTuwiVNgVqpU). +Be sure to read the [ODrive Encoder Guide](https://docs.google.com/spreadsheets/d/1OBDwYrBb5zUPZLrhL98ezZbg94tUsZcdTuwiVNgVqpU). ## Encoder Calibration - -All encoder types that are currently supported require the ODrive to do some sort of encoder calibration at every startup before you can run the motor control. Take this into account when designing your application. - +Please take into account that all encoder types supported by ODrive require that you do some sort of encoder calibration. This requires the following: +* selecting an encoder and mounting it to your motor +* choosing an interface (e.g., AB, ABI or SPI) +* connecting the pins to the odrive +* loading the correct odrive firmware (the default will work in many cases) +* motor calibration +* saving the settings in the odrive for correct bootup ### Encoder without index signal @@ -39,3 +43,112 @@ That's it, now on every reboot the motor will turn in one direction until it fin * If you wish to scan for the index pulse in the other direction (if for example your axis usually starts close to a hard-stop), you can set a negative value in `.encoder.config.idx_search_speed`. * If your motor has problems reaching the index location due to the mechanical load, you can increase `.motor.config.calibration_current`. + +### Startup sequence notes + +The following are variables that MUST be set up for your encoder configuration. Your values will vary depending on your encoder: + +* `.encoder.config.cpr = 4000` +* `.encoder.config.mode = ENCODER_MODE_INCREMENTAL` + +The following are examples of values that MAY impact the success of calibration. Your values will vary depending on your setup: +* `.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT` +* `.encoder.config.cpr = 4000` +* `.encoder.config.calib_range = 0.05` +* `.motor.config.calibration_current = 10.0` +* `.motor.config.resistance_calib_max_voltage = 12.0` +* `.controller.config.vel_limit = 50000` + +Lots of other values can get you. It's a process. Thankfully there is a lot of good people that will help you debug calibration problems. + +If calibration works, congratulations. + +Now try: +* `.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL` +* `.controller.set_vel_setpoint(3000,0) ` +let it loop a few times and then set: +* `.requested_state = AXIS_STATE_IDLE` + +Do you still have no errors? Awesome. Now set these variables: +* `.encoder.config.pre_calibrated = True` +* `.motor.config.pre_calibrated = True ` + +And see if ODrive agrees that calibration worked by just running +* `.encoder.config.pre_calibrated` + +(using no "= True" ). Make sure that 'pre_calibrated' is in fact True. + +Also, if you have calibrated and encoder.pre_calibrated is equal to true, and you had no errors so far. Run this: +* `.encoder.config.use_index = True` +* `odrv0.save_configuration()` +* `odrv0.reboot()` + +and now see if after a reboot you can run: +* `.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH` + +without getting errors. + +## Encoder Problems + +There are several issues that may prevent you from completing encoder calibration. + +ODrive may not complete the calibrate sequence when you go to: +* `.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE` + +It completes the calibrate sequence after: +* `.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE` + +but fails after you go to: +* `odrvN.axisN.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL` + +Or maybe it vibrates in an entertaining way. See: +https://www.youtube.com/watch?v=gaRUmwvSyAs + +## Encoder Signals + +If your encoder is properly connected, run the command: +* `.encoder.shadow_count ` + +and look at your value. Then turn your motor by hand and see if that value changes. Also, notice that the command: +* `.encoder.config.cpr = 4000` + +must reflect the number of counts odrive receives after one complete turn of the motor. So use shadow_count to test if that is working properly. + +You will probably never be able to properly debug if you have problems unless you use an oscilloscope. If you have one, try the following: +Connect to the AB pins, see if you get square waves as you turn the motor. +Connect to the I pin, see if you get a pulse on a complete rotation. Sometimes this is hard to see. +If you are using SPI, connect to CLK, and CS pins, look for a signal like this: +[INSERT PIC] + +## Encoder Noise +Noise is found in all circuits, life is just about figuring out if it is preventing your system from working. Lots of users have no problems with noise interferring with their odrive operation, others will tell you "_I've been using the same encoder as you with no problems_". Power to 'em, that may be true, but it doesn't mean it will work for you. If you are concerned about noise, there are several possible sources: + +* Encoder wires may be too close to motor wires +* Long wires between encoder and ODrive +* Use of ribbon cable + +The following _might_ mitigate noise problems. Use twisted pairs, where one side of each twisted pair is tied to ground, the other side is tied to your signal. If you are using SPI, use a 20-50 ohm resistor in series on CLK, which is more susceptable noise. + +## AS5047/AS5048 Encoders +The AS5047/AS5048 encoders are Hall Effect/Magenetic sensors that can serve as rotary encoders for the ODrive. + +The AS5047 has 3 independent output interfaces: SPI, ABI, and PWM. +The AS5048 has 4 independent output interfaces: SPI, ABI, I2C, and PWM. + +Both chips come with evaluation boards that can simplify mounted the chips to your motor. For our purposes if you are using an evaluation board you should select the settings for 3.2v, and tie MOSI high to 3.2v. + +If you are having calibration problems - make sure your magnet is centered on the axis of rotation on the motor, some users report this has a significant impact on calibration. Also make sure your magnet height is within range of the spec sheet. + +#### Using ABI. +You can use ABI with the AS5047/AS5048 with the default ODrive firmware. For your wiring, connect A, B, 3.2v, GND to the labeled pins on the odrive +The acronym I and Z mean the same thing, connect those as well if you are using an index signal. + +#### Using SPI. +TobinHall has written a [branch](https://github.com/TobinHall/ODrive/tree/Non-Blocking_Absolute_SPI) that supports the SPI option on the AS5047/AS5048. Use his build to flash firmware on your ODrive and connect MISO, SCK, and CS to the labeled pins on the odrive + +Tie MOSI to 3.2v, connect to the SCK, CLK, MISO, GND and 3.2v pins on the ODrive. (note for SPI users, the acronym SCK and CLK mean the same thing, the acronym CSn and CS mean the same thing.) + +Add these commands to your calibration / startup script: +* `.encoder.config.abs_spi_cs_gpio_pin = 4` or which ever GPIO pin you choose +* `.encoder.config.mode = 257` +* `.axis0.encoder.config.cpr = 2**14` From ca3e1a9e3a96bd7947c9c1677399f55ce65a5caf Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:03:20 -0400 Subject: [PATCH 02/10] Update encoders.md --- docs/encoders.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/encoders.md b/docs/encoders.md index 47ff0584..41287300 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -53,7 +53,6 @@ The following are variables that MUST be set up for your encoder configuration. The following are examples of values that MAY impact the success of calibration. Your values will vary depending on your setup: * `.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT` -* `.encoder.config.cpr = 4000` * `.encoder.config.calib_range = 0.05` * `.motor.config.calibration_current = 10.0` * `.motor.config.resistance_calib_max_voltage = 12.0` From eccd2e541aac9d4d8ace8bcfcc2d9fd5b7df8818 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:06:22 -0400 Subject: [PATCH 03/10] edit Changed comment encoder wires running along motor wires --- docs/encoders.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/encoders.md b/docs/encoders.md index 41287300..27326c5e 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -122,7 +122,7 @@ If you are using SPI, connect to CLK, and CS pins, look for a signal like this: ## Encoder Noise Noise is found in all circuits, life is just about figuring out if it is preventing your system from working. Lots of users have no problems with noise interferring with their odrive operation, others will tell you "_I've been using the same encoder as you with no problems_". Power to 'em, that may be true, but it doesn't mean it will work for you. If you are concerned about noise, there are several possible sources: -* Encoder wires may be too close to motor wires +* Importantly, encoder wires may be too close to motor wires, avoid overlap as much as possible * Long wires between encoder and ODrive * Use of ribbon cable From 6c5af86dda21c57d4d68ccb5bc3dc60b1e6496f3 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:10:37 -0400 Subject: [PATCH 04/10] edit voltage 3.2 --> 3.3 --- docs/encoders.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index 27326c5e..5b984fac 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -126,7 +126,7 @@ Noise is found in all circuits, life is just about figuring out if it is prevent * Long wires between encoder and ODrive * Use of ribbon cable -The following _might_ mitigate noise problems. Use twisted pairs, where one side of each twisted pair is tied to ground, the other side is tied to your signal. If you are using SPI, use a 20-50 ohm resistor in series on CLK, which is more susceptable noise. +The following _might_ mitigate noise problems. Use shielded cable, or use twisted pairs, where one side of each twisted pair is tied to ground, the other side is tied to your signal. If you are using SPI, use a 20-50 ohm resistor in series on CLK, which is more susceptable noise. ## AS5047/AS5048 Encoders The AS5047/AS5048 encoders are Hall Effect/Magenetic sensors that can serve as rotary encoders for the ODrive. @@ -134,18 +134,18 @@ The AS5047/AS5048 encoders are Hall Effect/Magenetic sensors that can serve as r The AS5047 has 3 independent output interfaces: SPI, ABI, and PWM. The AS5048 has 4 independent output interfaces: SPI, ABI, I2C, and PWM. -Both chips come with evaluation boards that can simplify mounted the chips to your motor. For our purposes if you are using an evaluation board you should select the settings for 3.2v, and tie MOSI high to 3.2v. +Both chips come with evaluation boards that can simplify mounted the chips to your motor. For our purposes if you are using an evaluation board you should select the settings for 3.3v, and tie MOSI high to 3.3v. If you are having calibration problems - make sure your magnet is centered on the axis of rotation on the motor, some users report this has a significant impact on calibration. Also make sure your magnet height is within range of the spec sheet. #### Using ABI. -You can use ABI with the AS5047/AS5048 with the default ODrive firmware. For your wiring, connect A, B, 3.2v, GND to the labeled pins on the odrive +You can use ABI with the AS5047/AS5048 with the default ODrive firmware. For your wiring, connect A, B, 3.3v, GND to the labeled pins on the odrive The acronym I and Z mean the same thing, connect those as well if you are using an index signal. #### Using SPI. TobinHall has written a [branch](https://github.com/TobinHall/ODrive/tree/Non-Blocking_Absolute_SPI) that supports the SPI option on the AS5047/AS5048. Use his build to flash firmware on your ODrive and connect MISO, SCK, and CS to the labeled pins on the odrive -Tie MOSI to 3.2v, connect to the SCK, CLK, MISO, GND and 3.2v pins on the ODrive. (note for SPI users, the acronym SCK and CLK mean the same thing, the acronym CSn and CS mean the same thing.) +Tie MOSI to 3.3v, connect to the SCK, CLK, MISO, GND and 3.2v pins on the ODrive. (note for SPI users, the acronym SCK and CLK mean the same thing, the acronym CSn and CS mean the same thing.) Add these commands to your calibration / startup script: * `.encoder.config.abs_spi_cs_gpio_pin = 4` or which ever GPIO pin you choose From 63cf573224ee1df2851d493f30cc4a203cd6e6bb Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:17:04 -0400 Subject: [PATCH 05/10] more minor changes. --- docs/encoders.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index 5b984fac..fc9fa9dc 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -51,11 +51,11 @@ The following are variables that MUST be set up for your encoder configuration. * `.encoder.config.cpr = 4000` * `.encoder.config.mode = ENCODER_MODE_INCREMENTAL` -The following are examples of values that MAY impact the success of calibration. Your values will vary depending on your setup: -* `.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT` -* `.encoder.config.calib_range = 0.05` -* `.motor.config.calibration_current = 10.0` -* `.motor.config.resistance_calib_max_voltage = 12.0` +The following are examples of values that MAY impact the success of calibration. Do not use these values unless you understand why they are needed; your values will vary depending on your setup: +* `.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT` select if you have a gimbal or high amp motor +* `.encoder.config.calib_range = 0.05` helps to relax the accuracy of encoder counts during calibration +* `.motor.config.calibration_current = 10.0` _sometimes_ needed if this is a large motor +* `.motor.config.resistance_calib_max_voltage = 12.0` _sometimes_ needed depending on motor * `.controller.config.vel_limit = 50000` Lots of other values can get you. It's a process. Thankfully there is a lot of good people that will help you debug calibration problems. From ac41d0fccb02c4a1e041527e8d9e13d8beb17168 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:39:30 -0400 Subject: [PATCH 06/10] another set of edits --- docs/encoders.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index fc9fa9dc..794d4735 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -87,25 +87,22 @@ and now see if after a reboot you can run: without getting errors. -## Encoder Problems - -There are several issues that may prevent you from completing encoder calibration. - -ODrive may not complete the calibrate sequence when you go to: +## What happens if calibration fails +There are subtle ways that encoder problems will impact your ODrive. For example, ODrive may not complete the calibrate sequence when you go to: * `.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE` -It completes the calibrate sequence after: +Or, ODrive may complete the calibrate sequence after: * `.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE` -but fails after you go to: -* `odrvN.axisN.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL` +but then it fails after you go to: +* `.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL` -Or maybe it vibrates in an entertaining way. See: +Or ODrive may just vibrate in an entertaining way. See: https://www.youtube.com/watch?v=gaRUmwvSyAs -## Encoder Signals - -If your encoder is properly connected, run the command: +## Encoder Testing +There are things you can test to make sure your encoder is properly connected. +This run the command: * `.encoder.shadow_count ` and look at your value. Then turn your motor by hand and see if that value changes. Also, notice that the command: From 31c36719f812b7b071fcd9580170adbd1f28bf8e Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:50:28 -0400 Subject: [PATCH 07/10] nother edit --- docs/encoders.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index 794d4735..e50a0ca3 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -113,8 +113,7 @@ must reflect the number of counts odrive receives after one complete turn of the You will probably never be able to properly debug if you have problems unless you use an oscilloscope. If you have one, try the following: Connect to the AB pins, see if you get square waves as you turn the motor. Connect to the I pin, see if you get a pulse on a complete rotation. Sometimes this is hard to see. -If you are using SPI, connect to CLK, and CS pins, look for a signal like this: -[INSERT PIC] +If you are using SPI, have a lot at the signal on the CLK, and CS pins. There are many examples on the net for how these should behave. ## Encoder Noise Noise is found in all circuits, life is just about figuring out if it is preventing your system from working. Lots of users have no problems with noise interferring with their odrive operation, others will tell you "_I've been using the same encoder as you with no problems_". Power to 'em, that may be true, but it doesn't mean it will work for you. If you are concerned about noise, there are several possible sources: From e1fb29490da45a80c3639580602debbbda65ccb2 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 17:55:34 -0400 Subject: [PATCH 08/10] edit edit edit --- docs/encoders.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/encoders.md b/docs/encoders.md index e50a0ca3..dd2e9f47 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -5,15 +5,14 @@ Be sure to read the [ODrive Encoder Guide](https://docs.google.com/spreadsheets/ ## Encoder Calibration Please take into account that all encoder types supported by ODrive require that you do some sort of encoder calibration. This requires the following: -* selecting an encoder and mounting it to your motor -* choosing an interface (e.g., AB, ABI or SPI) -* connecting the pins to the odrive -* loading the correct odrive firmware (the default will work in many cases) -* motor calibration -* saving the settings in the odrive for correct bootup +* Selecting an encoder and mounting it to your motor +* Choosing an interface (e.g., AB, ABI or SPI) +* Connecting the pins to the odrive +* Loading the correct odrive firmware (the default will work in many cases) +* Motor calibration +* Saving the settings in the odrive for correct bootup ### Encoder without index signal - During encoder offset calibration the rotor must be allowed to rotate without any biased load during startup. That means mass and weak friction loads are fine, but gravity or spring loads are not okay. In the `odrivetool`, type `.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION` Enter. @@ -45,18 +44,17 @@ That's it, now on every reboot the motor will turn in one direction until it fin * If your motor has problems reaching the index location due to the mechanical load, you can increase `.motor.config.calibration_current`. ### Startup sequence notes - The following are variables that MUST be set up for your encoder configuration. Your values will vary depending on your encoder: * `.encoder.config.cpr = 4000` * `.encoder.config.mode = ENCODER_MODE_INCREMENTAL` -The following are examples of values that MAY impact the success of calibration. Do not use these values unless you understand why they are needed; your values will vary depending on your setup: +The following are examples of values that MAY impact the success of calibration. These are not all the varibles you have to set for startup. Only change these when you understand why they are needed; your values will vary depending on your setup: * `.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT` select if you have a gimbal or high amp motor * `.encoder.config.calib_range = 0.05` helps to relax the accuracy of encoder counts during calibration * `.motor.config.calibration_current = 10.0` _sometimes_ needed if this is a large motor * `.motor.config.resistance_calib_max_voltage = 12.0` _sometimes_ needed depending on motor -* `.controller.config.vel_limit = 50000` +* `.controller.config.vel_limit = 50000` low values result in the spinning motor stopping abruptly during calibration Lots of other values can get you. It's a process. Thankfully there is a lot of good people that will help you debug calibration problems. From 8a854568516890e9f6b88cc407e43b788f477684 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 18:02:06 -0400 Subject: [PATCH 09/10] Update encoders.md --- docs/encoders.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/encoders.md b/docs/encoders.md index dd2e9f47..8701fdb1 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -46,7 +46,7 @@ That's it, now on every reboot the motor will turn in one direction until it fin ### Startup sequence notes The following are variables that MUST be set up for your encoder configuration. Your values will vary depending on your encoder: -* `.encoder.config.cpr = 4000` +* `.encoder.config.cpr = 8192` * `.encoder.config.mode = ENCODER_MODE_INCREMENTAL` The following are examples of values that MAY impact the success of calibration. These are not all the varibles you have to set for startup. Only change these when you understand why they are needed; your values will vary depending on your setup: From 25fd61d80cbcadcf8797b2652cbf9e44eddf55b7 Mon Sep 17 00:00:00 2001 From: Owen White Date: Fri, 17 May 2019 18:25:27 -0400 Subject: [PATCH 10/10] edit --- docs/encoders.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/encoders.md b/docs/encoders.md index 8701fdb1..e63a6d4b 100644 --- a/docs/encoders.md +++ b/docs/encoders.md @@ -40,7 +40,7 @@ Below are the steps to do the one-time calibration and configuration. Note that That's it, now on every reboot the motor will turn in one direction until it finds the encoder index. -* If you wish to scan for the index pulse in the other direction (if for example your axis usually starts close to a hard-stop), you can set a negative value in `.encoder.config.idx_search_speed`. +* If you wish to scan for the index pulse in the other direction, that feature is currently undocumented. * If your motor has problems reaching the index location due to the mechanical load, you can increase `.motor.config.calibration_current`. ### Startup sequence notes