Skip to content

Commit

Permalink
motor init returns success
Browse files Browse the repository at this point in the history
  • Loading branch information
askuric committed Jul 21, 2024
1 parent 150a40b commit 05672d2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void setup() {
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 6;
driver.init();
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);

Expand All @@ -52,7 +55,10 @@ void setup() {
motor.controller = MotionControlType::angle_openloop;

// init motor hardware
motor.init();
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}

// add target command T
command.add('T', doTarget, "target angle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ void setup() {
motor.controller = MotionControlType::velocity_openloop;

// init motor hardware
motor.init();
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}

// add target command T
command.add('T', doTarget, "target velocity");
Expand Down
3 changes: 2 additions & 1 deletion src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void BLDCMotor::init() {
if (!driver || !driver->initialized) {
motor_status = FOCMotorStatus::motor_init_failed;
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
return;
return 0;
}
motor_status = FOCMotorStatus::motor_initializing;
SIMPLEFOC_DEBUG("MOT: Init");
Expand Down Expand Up @@ -105,6 +105,7 @@ void BLDCMotor::init() {
enable();
_delay(500);
motor_status = FOCMotorStatus::motor_uncalibrated;
return 1;
}


Expand Down
2 changes: 1 addition & 1 deletion src/BLDCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BLDCMotor: public FOCMotor
BLDCDriver* driver;

/** Motor hardware init function */
void init() override;
int init() override;
/** Motor disable function */
void disable() override;
/** Motor enable function */
Expand Down
3 changes: 2 additions & 1 deletion src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void StepperMotor::init() {
if (!driver || !driver->initialized) {
motor_status = FOCMotorStatus::motor_init_failed;
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
return;
return 0;
}
motor_status = FOCMotorStatus::motor_initializing;
SIMPLEFOC_DEBUG("MOT: Init");
Expand Down Expand Up @@ -70,6 +70,7 @@ void StepperMotor::init() {
_delay(500);

motor_status = FOCMotorStatus::motor_uncalibrated;
return 1;
}


Expand Down
2 changes: 1 addition & 1 deletion src/StepperMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class StepperMotor: public FOCMotor
StepperDriver* driver;

/** Motor hardware init function */
void init() override;
int init() override;
/** Motor disable function */
void disable() override;
/** Motor enable function */
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 @@ -78,7 +78,7 @@ class FOCMotor
FOCMotor();

/** Motor hardware init function */
virtual void init()=0;
virtual int init()=0;
/** Motor disable function */
virtual void disable()=0;
/** Motor enable function */
Expand Down

0 comments on commit 05672d2

Please sign in to comment.