Skip to content

Commit 01cde01

Browse files
committed
added info to README + removed prints
1 parent 98edcc5 commit 01cde01

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/encoders/calibrated/CalibratedSensor.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ void CalibratedSensor::calibrate(FOCMotor &motor, float* lut, float zero_electri
188188
zero_angle_prev = zero_angle;
189189
avg_elec_angle += zero_angle/n_ticks;
190190

191-
motor.monitor_port->print(">error:");
192-
motor.monitor_port->println(zero_angle);
193-
motor.monitor_port->print(">zero_angle:");
194-
motor.monitor_port->println(avg_elec_angle);
191+
// motor.monitor_port->print(">zero:");
192+
// motor.monitor_port->println(zero_angle);
193+
// motor.monitor_port->print(">zero_average:");
194+
// motor.monitor_port->println(avg_elec_angle/2.0);
195195
}
196196
_delay(2000);
197197

@@ -227,10 +227,10 @@ void CalibratedSensor::calibrate(FOCMotor &motor, float* lut, float zero_electri
227227
zero_angle_prev = zero_angle;
228228
avg_elec_angle += zero_angle/n_ticks;
229229

230-
motor.monitor_port->print(">error:");
231-
motor.monitor_port->println(zero_angle);
232-
motor.monitor_port->print(">zero_angle:");
233-
motor.monitor_port->println(avg_elec_angle);
230+
// motor.monitor_port->print(">zero:");
231+
// motor.monitor_port->println(zero_angle);
232+
// motor.monitor_port->print(">zero_average:");
233+
// motor.monitor_port->println(avg_elec_angle/2.0);
234234
}
235235

236236
// get post calibration mechanical angle.
@@ -261,7 +261,7 @@ void CalibratedSensor::calibrate(FOCMotor &motor, float* lut, float zero_electri
261261
int index_offset = floor((float)n_lut * raw_offset / _2PI);
262262
float dn = n_ticks / (float)n_lut;
263263

264-
motor.monitor_port->println("Constructing LUT: ");
264+
motor.monitor_port->println("Constructing LUT.");
265265
_delay(1000);
266266
// Build Look Up Table
267267
for (int i = 0; i < n_lut; i++)
@@ -273,7 +273,7 @@ void CalibratedSensor::calibrate(FOCMotor &motor, float* lut, float zero_electri
273273
// negate the error if the sensor is in the opposite direction
274274
calibrationLut[ind] = motor.sensor_direction * calibrationLut[ind];
275275
}
276-
motor.monitor_port->println("Calibration LUT: ");
276+
motor.monitor_port->println("");
277277
_delay(1000);
278278

279279
// Display the LUT

src/encoders/calibrated/README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ Please see the more complete [example](https://github.com/simplefoc/Arduino-FOC-
8686
The code has been rewritten to reduce its memory footprint and allow more flexible Lookup table (LUT) sizing.
8787
Additionally, the calibrated sensor class now supports providing the saved LUT as a paramer for calibration. This allows you to save the LUT and load it on startup to avoid recalibration on each startup.
8888

89+
Once you do the calibration once, it will output something like this:
90+
91+
```
92+
...
93+
94+
Starting Sensor Calibration.
95+
MOT: Align sensor.
96+
MOT: sensor_direction==CCW
97+
MOT: PP check: OK!
98+
MOT: Zero elec. angle: 3.17
99+
MOT: No current sense.
100+
MOT: Ready.Rotating: CCW
101+
Rotating: CW
102+
Average Zero Electrical Angle: 4.01
103+
Constructing LUT.
104+
105+
float calibrationLut[50] = {0.003486, 0.005795, 0.007298, 0.008303, 0.008771, 0.007551, 0.005986, 0.004115, 0.001361, -0.001392, -0.004069, -0.007474, -0.010420, -0.013135, -0.014891, -0.017415, -0.018328, -0.019125, -0.018849, -0.017193, -0.015152, -0.012422, -0.008579, -0.003970, 0.000678, 0.005211, 0.009821, 0.013280, 0.016470, 0.018127, 0.018376, 0.016969, 0.016716, 0.015466, 0.013602, 0.011431, 0.008646, 0.006092, 0.003116, 0.000409, -0.002342, -0.004367, -0.005932, -0.006998, -0.007182, -0.007175, -0.006017, -0.003746, -0.001783, 0.000948};
106+
float zero_electric_angle = 4.007072;
107+
Direction sensor_direction = Direction::CCW;
108+
Sensor Calibration Done
109+
...
110+
```
111+
89112
The LUT and sensor's zero angle and direction are outputed by the calibration process to the Serial terminal. So you can copy and paste them into your code.
90113

91114
Your code will look something like this:
@@ -95,9 +118,9 @@ Your code will look something like this:
95118
// number of LUT entries
96119
const N_LUT = 100;
97120
// Lookup table that has been ouptut from the calibration process
98-
float calibrationLut[N_LUT] = {...};
99-
float zero_eletrical_angle = 0.0;
100-
Direction sensor_direction = Direction::CW;
121+
float calibrationLut[50] = {0.003486, 0.005795, 0.007298, 0.008303, 0.008771, 0.007551, 0.005986, 0.004115, 0.001361, -0.001392, -0.004069, -0.007474, -0.010420, -0.013135, -0.014891, -0.017415, -0.018328, -0.019125, -0.018849, -0.017193, -0.015152, -0.012422, -0.008579, -0.003970, 0.000678, 0.005211, 0.009821, 0.013280, 0.016470, 0.018127, 0.018376, 0.016969, 0.016716, 0.015466, 0.013602, 0.011431, 0.008646, 0.006092, 0.003116, 0.000409, -0.002342, -0.004367, -0.005932, -0.006998, -0.007182, -0.007175, -0.006017, -0.003746, -0.001783, 0.000948};
122+
float zero_electric_angle = 4.007072;
123+
Direction sensor_direction = Direction::CCW;
101124

102125
// provide the sensor class and the number of points in the LUT
103126
CalibratedSensor sensor_calibrated = CalibratedSensor(sensor, N_LUT);

0 commit comments

Comments
 (0)