Skip to content

Commit 05672d2

Browse files
committed
motor init returns success
1 parent 150a40b commit 05672d2

File tree

7 files changed

+19
-8
lines changed

7 files changed

+19
-8
lines changed

examples/motion_control/open_loop_motor_control/open_loop_position_example/open_loop_position_example.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ void setup() {
3636
// as a protection measure for the low-resistance motors
3737
// this value is fixed on startup
3838
driver.voltage_limit = 6;
39-
driver.init();
39+
if(!driver.init()){
40+
Serial.println("Driver init failed!");
41+
return;
42+
}
4043
// link the motor and the driver
4144
motor.linkDriver(&driver);
4245

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

5457
// init motor hardware
55-
motor.init();
58+
if(!motor.init()){
59+
Serial.println("Motor init failed!");
60+
return;
61+
}
5662

5763
// add target command T
5864
command.add('T', doTarget, "target angle");

examples/motion_control/open_loop_motor_control/open_loop_velocity_example/open_loop_velocity_example.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ void setup() {
5353
motor.controller = MotionControlType::velocity_openloop;
5454

5555
// init motor hardware
56-
motor.init();
56+
if(!motor.init()){
57+
Serial.println("Motor init failed!");
58+
return;
59+
}
5760

5861
// add target command T
5962
command.add('T', doTarget, "target velocity");

src/BLDCMotor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void BLDCMotor::init() {
6767
if (!driver || !driver->initialized) {
6868
motor_status = FOCMotorStatus::motor_init_failed;
6969
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
70-
return;
70+
return 0;
7171
}
7272
motor_status = FOCMotorStatus::motor_initializing;
7373
SIMPLEFOC_DEBUG("MOT: Init");
@@ -105,6 +105,7 @@ void BLDCMotor::init() {
105105
enable();
106106
_delay(500);
107107
motor_status = FOCMotorStatus::motor_uncalibrated;
108+
return 1;
108109
}
109110

110111

src/BLDCMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BLDCMotor: public FOCMotor
4040
BLDCDriver* driver;
4141

4242
/** Motor hardware init function */
43-
void init() override;
43+
int init() override;
4444
/** Motor disable function */
4545
void disable() override;
4646
/** Motor enable function */

src/StepperMotor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void StepperMotor::init() {
3737
if (!driver || !driver->initialized) {
3838
motor_status = FOCMotorStatus::motor_init_failed;
3939
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
40-
return;
40+
return 0;
4141
}
4242
motor_status = FOCMotorStatus::motor_initializing;
4343
SIMPLEFOC_DEBUG("MOT: Init");
@@ -70,6 +70,7 @@ void StepperMotor::init() {
7070
_delay(500);
7171

7272
motor_status = FOCMotorStatus::motor_uncalibrated;
73+
return 1;
7374
}
7475

7576

src/StepperMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class StepperMotor: public FOCMotor
4343
StepperDriver* driver;
4444

4545
/** Motor hardware init function */
46-
void init() override;
46+
int init() override;
4747
/** Motor disable function */
4848
void disable() override;
4949
/** Motor enable function */

src/common/base_classes/FOCMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FOCMotor
7878
FOCMotor();
7979

8080
/** Motor hardware init function */
81-
virtual void init()=0;
81+
virtual int init()=0;
8282
/** Motor disable function */
8383
virtual void disable()=0;
8484
/** Motor enable function */

0 commit comments

Comments
 (0)