Skip to content

Commit 451be63

Browse files
Merge pull request #297 from runger1101001/dev
Fix intialization of sensor direction
2 parents c4b911d + 012608c commit 451be63

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/BLDCMotor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ void BLDCMotor::init() {
9292
}
9393
P_angle.limit = velocity_limit;
9494

95+
// if using open loop control, set a CW as the default direction if not already set
96+
if ((controller==MotionControlType::angle_openloop
97+
||controller==MotionControlType::velocity_openloop)
98+
&& (sensor_direction == Direction::UNKNOWN)) {
99+
sensor_direction = Direction::CW;
100+
}
101+
95102
_delay(500);
96103
// enable motor
97104
SIMPLEFOC_DEBUG("MOT: Enable driver.");

src/StepperMotor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ void StepperMotor::init() {
5656
}
5757
P_angle.limit = velocity_limit;
5858

59+
// if using open loop control, set a CW as the default direction if not already set
60+
if ((controller==MotionControlType::angle_openloop
61+
||controller==MotionControlType::velocity_openloop)
62+
&& (sensor_direction == Direction::UNKNOWN)) {
63+
sensor_direction = Direction::CW;
64+
}
65+
5966
_delay(500);
6067
// enable motor
6168
SIMPLEFOC_DEBUG("MOT: Enable driver.");

src/common/base_classes/FOCMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class FOCMotor
205205
// sensor related variabels
206206
float sensor_offset; //!< user defined sensor zero offset
207207
float zero_electric_angle = NOT_SET;//!< absolute zero electric angle - if available
208-
Direction sensor_direction = Direction::CW; //!< default is CW. if sensor_direction == Direction::CCW then direction will be flipped compared to CW. Set to UNKNOWN to set by calibration
208+
Direction sensor_direction = Direction::UNKNOWN; //!< default is CW. if sensor_direction == Direction::CCW then direction will be flipped compared to CW. Set to UNKNOWN to set by calibration
209209

210210
/**
211211
* Function providing BLDCMotor class with the

0 commit comments

Comments
 (0)