Writing the doc

This commit is contained in:
Lucien Renaud 2022-05-19 23:29:07 +02:00
parent 5e5d491869
commit 095bf9e1b3
3 changed files with 31 additions and 4 deletions

View File

@ -39,9 +39,36 @@ Ratiometric means that the output signal is proportional to the voltage supply t
These oscilloscope traces are the sensor output when rotating the rotor forth and back. (a bit less than 180º on the 3rd motor)
The channel 0 (Yellow) is the Hall 1 and the Channel 1 (Green) is the Hall 2
![hall sensors traces](LinearHallTrace_3rd_motor_120deg.png)
![hall sensors traces](courbes.png)
### 3. Analysis
We can see that in the first movement (positive rotation), the green is out of phase of π/2.`
![Sinwave figure](cosSinEncoderDiagram.png)
### 3. Encoding the position
1. Get the angle of one periodic signal
Since the 2 signals correspond to a cos and sin signals, it is possible to compute the angle inside the period using arctan2 function.
2. Incremental position
- increment periods
- start from known position (one end)
## Coding the solution
1. Get the angle in the perdiod
In order to compute the angle from the cos and sin with atan, it is necessary to remap the values of the analog readings from -1 to 1.
Beforehand, the maximum and minimum peak of the signals need to be found. It can be done by swiping the motor on startup in open-loop mode.
Then the arctan function can be applied. It is preferable to use arctan2 as it will give an angle within the 4 quadrants (-π,π). Whereas arctan give an angle between (-π/2,π/2). [Wikipedia](https://en.wikipedia.org/wiki/Atan2)
```C++
float norm(float x, float in_min, float in_max)
{
return (float)(x + 1.0) * (2.0) / (float)(in_max - in_min) -1.0;
}
A = norm(analogRead(CH1),minCh1, maxCh1);
B = norm(analogRead(CH2),minCh2, maxCh2);
angle = atan2(A,B);
```
We can see that in the first movement (positive rotation), the green is out of phase and opposite
### 4. Encoder strategy

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
docs/courbes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB