Skip to content

Commit 22d003c

Browse files
committed
performance optimisation - don't return angle on updateSensor()
1 parent c1201ed commit 22d003c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/BLDCMotor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
101101
if(sensor){
102102
exit_flag *= alignSensor();
103103
// added the shaft_angle update
104-
shaft_angle = sensor->updateSensor();
104+
sensor->updateSensor();
105+
shaft_angle = sensor->getAngle();
105106
}else if(monitor_port) monitor_port->println(F("MOT: No sensor."));
106107

107108
// aligning the current sensor - can be skipped
@@ -164,14 +165,16 @@ int BLDCMotor::alignSensor() {
164165
_delay(2);
165166
}
166167
// take and angle in the middle
167-
float mid_angle = sensor->updateSensor();
168+
sensor->updateSensor();
169+
float mid_angle = sensor->getAngle();
168170
// move one electrical revolution backwards
169171
for (int i = 500; i >=0; i-- ) {
170172
float angle = _3PI_2 + _2PI * i / 500.0f ;
171173
setPhaseVoltage(voltage_sensor_align, 0, angle);
172174
_delay(2);
173175
}
174-
float end_angle = sensor->updateSensor();
176+
sensor->updateSensor();
177+
float end_angle = sensor->getAngle();
175178
setPhaseVoltage(0, 0, 0);
176179
_delay(200);
177180
// determine the direction the sensor moved
@@ -201,7 +204,8 @@ int BLDCMotor::alignSensor() {
201204
// set angle -90(270 = 3PI/2) degrees
202205
setPhaseVoltage(voltage_sensor_align, 0, _3PI_2);
203206
_delay(700);
204-
zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->updateSensor(), pole_pairs));
207+
sensor->updateSensor();
208+
zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->getAngle(), pole_pairs));
205209
_delay(20);
206210
if(monitor_port){
207211
monitor_port->print(F("MOT: Zero elec. angle: "));

src/common/base_classes/Sensor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
// TODO add an init method to make the startup smoother by initializing internal variables to current values rather than 0
66

7-
float Sensor::updateSensor() {
7+
void Sensor::updateSensor() {
88
float val = getSensorAngle();
99
angle_prev_ts = _micros();
1010
float d_angle = val - angle_prev;
1111
// if overflow happened track it as full rotation
1212
if(abs(d_angle) > (0.8f*_2PI) ) full_rotations += ( d_angle > 0 ) ? -1 : 1;
1313
angle_prev = val;
14-
return getAngle();
1514
}
1615

1716

src/common/base_classes/Sensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Sensor{
9595
*
9696
* Returns the same value as getAngle() as its result
9797
*/
98-
virtual float updateSensor();
98+
virtual void updateSensor();
9999

100100
/**
101101
* returns 0 if it does need search for absolute zero

0 commit comments

Comments
 (0)