diff --git a/docs/LinearHallEncoder.md b/docs/LinearHallEncoder.md index 7df4496..a0fbbe1 100644 --- a/docs/LinearHallEncoder.md +++ b/docs/LinearHallEncoder.md @@ -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 \ No newline at end of file diff --git a/docs/cosSinEncoderDiagram.png b/docs/cosSinEncoderDiagram.png new file mode 100644 index 0000000..3f2109b Binary files /dev/null and b/docs/cosSinEncoderDiagram.png differ diff --git a/docs/courbes.png b/docs/courbes.png new file mode 100644 index 0000000..b1bf8fa Binary files /dev/null and b/docs/courbes.png differ