Skip to content

Commit 4dd59b6

Browse files
author
Richard Unger
committed
introduce minimum angle to detect motion
1 parent 44e4c4a commit 4dd59b6

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/BLDCMotor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
113113
// added the shaft_angle update
114114
sensor->update();
115115
shaft_angle = shaftAngle();
116-
}else
116+
}else {
117+
exit_flag = 0; // no FOC without sensor
117118
SIMPLEFOC_DEBUG("MOT: No sensor.");
119+
}
118120

119121
// aligning the current sensor - can be skipped
120122
// checks if driver phases are the same as current sense phases
@@ -201,7 +203,8 @@ int BLDCMotor::alignSensor() {
201203
setPhaseVoltage(0, 0, 0);
202204
_delay(200);
203205
// determine the direction the sensor moved
204-
if (mid_angle == end_angle) {
206+
float moved = fabs(mid_angle - end_angle);
207+
if (moved<MIN_ANGLE_DETECT_MOVEMENT) { // minimum angle to detect movement
205208
SIMPLEFOC_DEBUG("MOT: Failed to notice movement");
206209
return 0; // failed calibration
207210
} else if (mid_angle < end_angle) {
@@ -212,7 +215,6 @@ int BLDCMotor::alignSensor() {
212215
sensor_direction = Direction::CW;
213216
}
214217
// check pole pair number
215-
float moved = fabs(mid_angle - end_angle);
216218
if( fabs(moved*pole_pairs - _2PI) > 0.5f ) { // 0.5f is arbitrary number it can be lower or higher!
217219
SIMPLEFOC_DEBUG("MOT: PP check: fail - estimated pp: ", _2PI/moved);
218220
} else

src/common/base_classes/Sensor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void Sensor::update() {
1717
/** get current angular velocity (rad/s) */
1818
float Sensor::getVelocity() {
1919
// calculate sample time
20-
float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6;
20+
float Ts = (angle_prev_ts - vel_angle_prev_ts)*1e-6f;
21+
// TODO handle overflow - we do need to reset vel_angle_prev_ts
2122
if (Ts<minDeltaT) return velocity; // don't update velocity if deltaT is too small
2223

2324
velocity = ( (float)(full_rotations - vel_full_rotations)*_2PI + (angle_prev - vel_angle_prev) ) / Ts;

src/common/foc_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define _ACTIVE 1
3333
#define _NC (NOT_SET)
3434

35+
#define MIN_ANGLE_DETECT_MOVEMENT (_2PI/101.0f)
36+
3537
// dq current structure
3638
struct DQCurrent_s
3739
{

0 commit comments

Comments
 (0)