Skip to content

Commit edce7d4

Browse files
committed
some refactoring and bug fixng
1 parent 1533bf2 commit edce7d4

File tree

27 files changed

+169
-63
lines changed

27 files changed

+169
-63
lines changed

examples/utils/calibration/alignment_and_cogging_test/alignment_and_cogging_test.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void testAlignmentAndCogging(int direction) {
2121
motor.move(0);
2222
_delay(200);
2323

24+
sensor.update();
2425
float initialAngle = sensor.getAngle();
2526

2627
const int shaft_rotation = 720; // 720 deg test - useful to see repeating cog pattern
@@ -40,6 +41,7 @@ void testAlignmentAndCogging(int direction) {
4041
_delay(5);
4142

4243
// measure
44+
sensor.update();
4345
float sensorAngle = (sensor.getAngle() - initialAngle) * 180 / PI;
4446
float sensorElectricAngle = sensorAngle * motor.pole_pairs;
4547
float electricAngleError = electricAngle - sensorElectricAngle;

examples/utils/calibration/find_pole_pair_number/encoder/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void setup() {
6464
motor.move(0);
6565
_delay(1000);
6666
// read the encoder angle
67+
encoder.update();
6768
float angle_begin = encoder.getAngle();
6869
_delay(50);
6970

@@ -75,6 +76,7 @@ void setup() {
7576
}
7677
_delay(1000);
7778
// read the encoder value for 180
79+
encoder.update();
7880
float angle_end = encoder.getAngle();
7981
_delay(50);
8082
// turn off the motor

examples/utils/calibration/find_pole_pair_number/magnetic_sensor/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ void setup() {
6363
motor.move(0);
6464
_delay(1000);
6565
// read the sensor angle
66+
sensor.update();
6667
float angle_begin = sensor.getAngle();
6768
_delay(50);
6869

6970
// move the motor slowly to the electrical angle pp_search_angle
7071
float motor_angle = 0;
7172
while(motor_angle <= pp_search_angle){
7273
motor_angle += 0.01f;
73-
sensor.getAngle(); // keep track of the overflow
74+
sensor.update(); // keep track of the overflow
7475
motor.move(motor_angle);
7576
}
7677
_delay(1000);
7778
// read the sensor value for 180
79+
sensor.update();
7880
float angle_end = sensor.getAngle();
7981
_delay(50);
8082
// turn off the motor

examples/utils/sensor_test/encoder/encoder_example/encoder_example.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ void setup() {
3333
}
3434

3535
void loop() {
36+
// iterative function updating the sensor internal variables
37+
// it is usually called in motor.loopFOC()
38+
// not doing much for the encoder though
39+
encoder.update();
3640
// display the angle and the angular velocity to the terminal
3741
Serial.print(encoder.getAngle());
3842
Serial.print("\t");

examples/utils/sensor_test/encoder/encoder_software_interrupts_example/encoder_software_interrupts_example.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ void setup() {
4646
}
4747

4848
void loop() {
49+
// iterative function updating the sensor internal variables
50+
// it is usually called in motor.loopFOC()
51+
// not doing much for the encoder though
52+
encoder.update();
4953
// display the angle and the angular velocity to the terminal
5054
Serial.print(encoder.getAngle());
5155
Serial.print("\t");

examples/utils/sensor_test/hall_sensors/hall_sensor_example/hall_sensor_example.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void setup() {
3737
}
3838

3939
void loop() {
40+
// iterative function updating the sensor internal variables
41+
// it is usually called in motor.loopFOC()
42+
sensor.update();
4043
// display the angle and the angular velocity to the terminal
4144
Serial.print(sensor.getAngle());
4245
Serial.print("\t");

examples/utils/sensor_test/hall_sensors/hall_sensor_software_interrupts_example/hall_sensors_software_interrupt_example.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ void setup() {
4949
}
5050

5151
void loop() {
52+
// iterative function updating the sensor internal variables
53+
// it is usually called in motor.loopFOC()
54+
sensor.update();
5255
// display the angle and the angular velocity to the terminal
5356
Serial.print(sensor.getAngle());
5457
Serial.print("\t");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ int max_count = 0;
3333
int min_count = 100000;
3434

3535
void loop() {
36+
// iterative function updating the sensor internal variables
37+
// it is usually called in motor.loopFOC()
38+
// this function reads the sensor hardware and
39+
// has to be called before getAngle nad getVelocity
40+
sensor.update();
3641

3742
// keep track of min and max
3843
if(sensor.raw_count > max_count) max_count = sensor.raw_count;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ void setup() {
2525
}
2626

2727
void loop() {
28+
// iterative function updating the sensor internal variables
29+
// it is usually called in motor.loopFOC()
30+
// this function reads the sensor hardware and
31+
// has to be called before getAngle nad getVelocity
32+
sensor.update();
2833
// display the angle and the angular velocity to the terminal
2934
Serial.print(sensor.getAngle());
3035
Serial.print("\t");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ void setup() {
2525
}
2626

2727
void loop() {
28+
// iterative function updating the sensor internal variables
29+
// it is usually called in motor.loopFOC()
30+
// this function reads the sensor hardware and
31+
// has to be called before getAngle nad getVelocity
32+
sensor0.update();
33+
sensor1.update();
34+
2835
_delay(200);
2936
Serial.print(sensor0.getAngle());
3037
Serial.print(" - ");

0 commit comments

Comments
 (0)