-
Notifications
You must be signed in to change notification settings - Fork 2
Add encoder calibration documentation #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anirudhupadhyaya
wants to merge
62
commits into
add-control-content
Choose a base branch
from
add-enc-anirudh
base: add-control-content
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
084135b
initial commit
anirudhupadhyaya d2652bf
Add content
anirudhupadhyaya 1f1b8a0
Update docs
anirudhupadhyaya d81c691
Update doc
anirudhupadhyaya e0fbf68
Update docs
anirudhupadhyaya cbc72d1
Update docs
anirudhupadhyaya 655f2b1
Update doc
anirudhupadhyaya cbd2100
Update block diagram
anirudhupadhyaya d971d20
Apply suggestions from code review
anirudhupadhyaya 63600c6
Update doc to address review comments
anirudhupadhyaya 3a1ca7b
Add line on low pass filter
anirudhupadhyaya 04c3490
Update source/getting-started/control-with-amdc/encoder-fb/index.md
anirudhupadhyaya 7bdd0aa
Edit background
elsevers c249ab3
Fix file name type-o
elsevers 52556e6
Fix type-os
elsevers 5ac7ce6
Add config instructions
elsevers 1532f0a
Edit first 1/3 of document
elsevers 5b5a78b
add simulink model of pll
elsevers 1086a13
Add pll test files
noguchi-takahiro 93cf84e
Change indexme file
Daehoon-Sung eab8281
Update index.md
Daehoon-Sung 196297a
Edit finding offset and step 1
elsevers b27375c
Edit finding the offset section
elsevers 36971f0
Add encoder angle diagram, first edits of text to use it.
elsevers 8dc006b
Add latex source for motor cross section
elsevers cb1c257
add test code
elsevers d515467
Merge branch 'add-control-content' into add-enc-anirudh
elsevers 41096e6
- Edit everything before finding the offset
elsevers f2ed019
Merge branch 'add-enc-anirudh' into user/Daehoon-Sung/update-offset-r…
elsevers 9e7a82b
change image naming to dash-case
elsevers 600fc24
Improve typesetting around the image
elsevers cc7f038
Add torque characteristic and update step 1 instructions.
elsevers 5e845e7
Make motor cross-section plot 2 poles, add phave v and w axes
elsevers a86055f
Merge branch 'add-enc-anirudh' into user/Daehoon-Sung/update-offset-r…
elsevers d0d86d6
Add clarifying comment to torque characteristic
elsevers 9341c81
Update index.md
Daehoon-Sung fc88ad4
Update the encoder offset plot
Daehoon-Sung 2747e11
Update index.md
Daehoon-Sung 24ff6a8
Update index.md
Daehoon-Sung 4a8698a
Update source/getting-started/control-with-amdc/encoder-fb/index.md
Daehoon-Sung ae4a93f
Update index.md
Daehoon-Sung 99a620f
Update index.md
Daehoon-Sung 783a3a2
Update index.md
Daehoon-Sung 281f09d
Fix rendering of equation
noguchi-takahiro dc92a10
Fix rendering issue of image
noguchi-takahiro 655ec82
Update the encoder image
Daehoon-Sung 0775c96
Merge branch 'user/Daehoon-Sung/update-offset-report' of https://gith…
Daehoon-Sung b5fe0f8
Update index.md
Daehoon-Sung bc7db65
Update the figure
Daehoon-Sung 59b8863
Clarify terminology for mechanical angle in documentation
Daehoon-Sung e0e3223
Enhance encoder offset determination section
Daehoon-Sung 64578a3
Clarify voltage equation with angular velocity note
Daehoon-Sung 5ac71e2
Clarify voltage vector description in index.md
Daehoon-Sung 39163c8
Fix voltage vector equation formatting
Daehoon-Sung b56bbdf
Refine description of encoder offset estimation process
Daehoon-Sung 02d299b
Fix minor grammatical error in encoder offset section
Daehoon-Sung ed8f8ad
Fix formatting in encoder offset determination section
Daehoon-Sung 2d0d0b1
Revise current command notation in encoder equations
Daehoon-Sung 78f9611
Fix rendering issues for images
noguchi-takahiro a826e60
Clarify angle calculation and encoder offset procedure
Daehoon-Sung f28d03d
Revise encoder offset section contents (#146)
elsevers 92cb825
Merge pull request #139 from Severson-Group/user/Daehoon-Sung/update-…
elsevers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
127 changes: 121 additions & 6 deletions
127
source/getting-started/control-with-amdc/encoder-fb/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,128 @@ | ||
| # Encoder Feedback | ||
|
|
||
| ## Background | ||
|
|
||
| Encoders provide rotor position feedback to the control system in a motor drive. This document describes a method to convert the raw readings of an encoder into meaningful position information which can be used by the contrl algorithm. Next, useful methods to obtain rotor speed from the measured position is presented. For more information on how an encoder works and how they may be interfaced with the AMDC please refer to this [document](https://docs.amdc.dev/hardware/subsystems/encoder.html#). | ||
|
|
||
| ## Calibration | ||
|
|
||
| - Converting from raw counts to "theta" | ||
| - Direction: +/- depending on phase connections | ||
| - Sync machines: dq offset | ||
| Incremental encoders are typically used with the AMDC and have a fixed number of counts per revolution `CPR` (for example, `CPR = 1024`). The user needs to provide code that interfaces to the AMDC's drivers to read the encoder count and convert it into usable angular information that is suitable for use within the control code. | ||
|
|
||
| ### Obtaining encoder count and translating it into rotor position | ||
|
|
||
| The recommended approach to reading the shaft position from the encoder is illustrated in the figure below: | ||
|
|
||
| <img src="./resources/EncoderCodeBlockDiargam.svg" width="100%" align="center"/> | ||
|
|
||
| As a first step, the user may use the AMDC `drv/encoder` driver module `encoder_get_position()` to get the count of the encoder reading. The`drv/encoder` driver module also has a function called `encoder_get_steps()` which gives the incremental change in the encoder position. Whereas, `encoder_get_position()` gives the actual position of the shaft and this can be converted to rotor position in radians. | ||
|
|
||
| Next, the user needs to verify if the encoder count is increasing or decreasing with counter-clock wise rotation of shaft. This may be done manually by rotating the shaft and observing the trend of the reported position with respect to the direction of rotation. In the figure, the signal `CCW` indicates this directionality. It must be set to `1`, if the encoder count increases with the counter clockwise rotation of shaft and `0` otherwise. Additionally, the user needs to provide the encoder offset, `offset` and the encoder counts per revolution, `ENCODER_COUNT_PER_REV`. A method to get the value of offset is described in the next [subsection](#finding-the-offset). Using all of this quantities, the obtained count can be translated into angular position using a simple linear equation. Note that, this document follows the convention of a positive rotor angle in the counter clockwise direction of shaft rotation while caclulating rotor position from the count signal. | ||
|
|
||
| Finally, the user must ensure that angle is within the bounds of $0$ and $2\pi$ by appropriately wrapping the `rotor position` signal using the `mod` function. This is shown in the final block in the diagram. | ||
|
|
||
| Example code to convert encoder to angular position in radians: | ||
| ```C | ||
| double task_get_theta_m(void) | ||
| { | ||
| // Get raw encoder position | ||
| uint32_t position; | ||
| encoder_get_position(&position); | ||
|
|
||
| int ENCODER_COUNT_PER_REV, CCW; | ||
| double enc_theta_m_offset; | ||
|
|
||
| // User to set encoder count per revolution | ||
| ENCODER_COUNT_PER_REV = 1024; | ||
|
|
||
| // Set 1 if encoder count increases with CCW rotation of shaft, Set 0 if encoder count increases with CW rotation of shaft | ||
| CCW = 1; | ||
|
|
||
| // Angular position to be computed | ||
| double theta_m_enc; | ||
|
|
||
| // User to set encoder offset | ||
| enc_theta_m_offset = 100; | ||
|
|
||
|
|
||
| // Convert to radians | ||
| if (CCW){ | ||
| theta_m_enc = (double) PI2 * ( ( (double)position - enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV); | ||
| } | ||
| else{ | ||
| theta_m_enc = (double) PI2 * ( ( (double)ENCODER_COUNT_PER_REV - (double)1 -(double)position + enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV); | ||
| } | ||
|
|
||
| // Mod by 2 pi | ||
| theta_m_enc = fmod(theta_m_enc,PI2); | ||
| return theta_m_enc; | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ### Finding the offset | ||
|
|
||
| The example code shown above makes uses of an encoder offset value, `enc_theta_m_offset`. It is necessary for the user to find this offset experimentally for their machine. For synchronous machines, this offset is the count value measured by the encoder when the d-axis of the rotor is aligned with the phase U winding axis of the stator. | ||
|
|
||
| To determine the appropriate offset value, eliminate any source of load torque on the shaft and apply a large current vector at 0 degrees ($I_u = I_0$, $I_v = I_w = -\frac{1}{2} I_0$). This should cause the rotor to align with the phase U winding axis. The offset value can now be obtained as `enc_theta_m_offset = encoder_get_position()`. Alternately, the user may also inject a current along the d-axis using the AMDC [Signal Injection](https://docs.amdc.dev/getting-started/user-guide/injection/index.html) module. While injecting d-axis current, the user must ensure that the rotor position is set to zero in the control code. | ||
|
|
||
| After obtaining the offset, the user needs to set the variable `enc_theta_m_offset` to the appropriate value in the `task_get_theta_m()` function. | ||
|
|
||
| To ensure that the obtained encoder offset is correct, the user may perform additional validation. For a permanent magnet synchronous motor, this can be done as follows: | ||
|
|
||
| 1. Spin the motor up-to a steady speed under no load conditions | ||
| 1. Measure the d-axis voltage commanded by the current regulator | ||
| 1. Repeat the experiment for a few different rotor speeds | ||
| 1. Plot the d-axis voltage against the rotor speed | ||
| 1. The d-axis voltage should be close to zero for all speeds, if the offset is tuned correctly | ||
| 1. In-case there is an error in the offset value, a significant speed dependent voltage will appear on the d-axis voltage. In this case, the user may have to re-measure the encoder offset. | ||
|
|
||
|
|
||
|
|
||
| ## Computing Speed from Position | ||
|
|
||
| - LPF | ||
| - State Filter | ||
| - Observer | ||
| The user needs to compute a rotor speed signal from the obtained position signal to be used in the control algorithm. There are several ways to do this. | ||
|
|
||
| ### Difference Equation Approach | ||
|
|
||
| A simple, but naive, way to do this would be to compute the discrete time derivative of the position signal in the controller as shown below. This can be referred to as $\Omega_{raw}$. | ||
|
|
||
| $$ | ||
| \Omega_\text{raw}[k] = \frac{\theta_m[k] - \theta_m[k-1]}{T_s} | ||
| $$ | ||
|
|
||
|
|
||
| Unfortunately, using this approach results in noise in $\Omega_\text{raw}$ due to the derivative operation and the digital nature of the incremental encoder. | ||
|
|
||
| ### Low Pass Filter Approach | ||
|
|
||
| To solve this, _a low pass filter_ may be applied to this signal. This is shown below to obtain a filtered speed, $\Omega_\text{lpf}$. | ||
|
|
||
| $$ | ||
| \Omega_\text{lpf}[k] = \Omega_\text{raw}[k](1 - e^{\omega_b T_s}) + \Omega_\text{lpf}[k-1]e^{\omega_b T_s} | ||
| $$ | ||
|
|
||
| ### Observer Approach | ||
|
|
||
| To obtain a no-lag estimate of the rotor speed, users may create an observer [[1]](#1), which implements a mechanical model of the rotor as shown below. | ||
|
|
||
anirudhupadhyaya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <img src="./resources/ObserverFigure.svg" width="100%" align="center"/> | ||
|
|
||
|
|
||
| The estimate of rotor speed is denoted by $\Omega_\text{sf}$. To implement this observer, the user needs to know the system parameters: | ||
| - `J`: the inertia of the rotor | ||
| - `b` the damping coefficient of the rotor. | ||
|
|
||
| It is also necessary to provide the electromechanical torque, $T_{em}$ as input to the mechanical model. | ||
|
|
||
| The `PI` portion of the observer closes the loop on the speed, with $\Omega_\text{raw}$ being the reference input. The recommended tuning approach is as follows: | ||
| $$ | ||
| K_p = \omega_{sf}b, K_i = \omega_{sf}J | ||
| $$ | ||
anirudhupadhyaya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| This tuning ensures a pole zero cancellation in the closed transfer function, resulting in a unity transfer function for speed tracking under ideal parameter estimates of `J` and `b`. An observer bandwidth of 10 Hz is typical of most systems, but similar to the low pass filter approach, users may need to alter this based on the unique aspects of their system. | ||
|
|
||
|
|
||
| # References | ||
| <a id="1"></a> 1. R. D. Lorenz and K. W. Van Patten, "High-resolution velocity estimation for all-digital, AC servo drives," in IEEE Transactions on Industry Applications, vol. 27, no. 4, pp. 701-705, July-Aug. 1991, doi: 10.1109/28.85485. keywords: {Servomechanisms;Optical feedback;Optical signal processing;Transducers;Signal resolution;Velocity measurement;Position control;Feedback loop;Velocity control;Noise reduction} | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Daehoon-Sung I am sure you know about this section well and contribute to update some.