Skip to content

Fix intialization of sensor direction #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ void BLDCMotor::init() {
}
P_angle.limit = velocity_limit;

// if using open loop control, set a CW as the default direction if not already set
if ((controller==MotionControlType::angle_openloop
||controller==MotionControlType::velocity_openloop)
&& (sensor_direction == Direction::UNKNOWN)) {
sensor_direction = Direction::CW;
}

_delay(500);
// enable motor
SIMPLEFOC_DEBUG("MOT: Enable driver.");
Expand Down
7 changes: 7 additions & 0 deletions src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ void StepperMotor::init() {
}
P_angle.limit = velocity_limit;

// if using open loop control, set a CW as the default direction if not already set
if ((controller==MotionControlType::angle_openloop
||controller==MotionControlType::velocity_openloop)
&& (sensor_direction == Direction::UNKNOWN)) {
sensor_direction = Direction::CW;
}

_delay(500);
// enable motor
SIMPLEFOC_DEBUG("MOT: Enable driver.");
Expand Down
2 changes: 1 addition & 1 deletion src/common/base_classes/FOCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class FOCMotor
// sensor related variabels
float sensor_offset; //!< user defined sensor zero offset
float zero_electric_angle = NOT_SET;//!< absolute zero electric angle - if available
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
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

/**
* Function providing BLDCMotor class with the
Expand Down