Skip to content

Commit 4c6061c

Browse files
committed
FEAT minimal modifiaction of examples to pass the compile
1 parent a917406 commit 4c6061c

File tree

7 files changed

+50
-148
lines changed

7 files changed

+50
-148
lines changed

examples/hardware_specific_examples/DRV8302_driver/3pwm_example/encoder/full_control_serial/full_control_serial.ino

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ Encoder encoder = Encoder(2, 3, 8192);
3636
void doA(){encoder.handleA();}
3737
void doB(){encoder.handleB();}
3838

39+
40+
// commander interface
41+
Commander command = Commander(Serial);
42+
void onA(String cmd){ command.motor(&motor, cmd); }
43+
3944
void setup() {
4045

4146
// initialize encoder sensor hardware
@@ -99,6 +104,8 @@ void setup() {
99104
// set the inital target value
100105
motor.target = 2;
101106

107+
// define the motor id
108+
command.add('A', onA);
102109

103110
Serial.println(F("Full control example: "));
104111
Serial.println(F("Run user commands to configure and the motor (find the full command list in docs.simplefoc.com) \n "));
@@ -119,33 +126,5 @@ void loop() {
119126
motor.move();
120127

121128
// user communication
122-
motor.command(serialReceiveUserCommand());
123-
}
124-
125-
// utility function enabling serial communication the user
126-
String serialReceiveUserCommand() {
127-
128-
// a string to hold incoming data
129-
static String received_chars;
130-
131-
String command = "";
132-
133-
while (Serial.available()) {
134-
// get the new byte:
135-
char inChar = (char)Serial.read();
136-
// add it to the string buffer:
137-
received_chars += inChar;
138-
139-
// end of user input
140-
if (inChar == '\n') {
141-
142-
// execute the user command
143-
command = received_chars;
144-
145-
// reset the command buffer
146-
received_chars = "";
147-
}
148-
}
149-
return command;
150-
}
151-
129+
command.run();
130+
}

examples/hardware_specific_examples/DRV8302_driver/6pwm_example/encoder/full_control_serial/full_control_serial.ino

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ Encoder encoder = Encoder(2, 3, 8192);
3939
void doA(){encoder.handleA();}
4040
void doB(){encoder.handleB();}
4141

42+
43+
// commander interface
44+
Commander command = Commander(Serial);
45+
void onA(String cmd){ command.motor(&motor, cmd); }
46+
4247
void setup() {
4348

4449
// initialize encoder sensor hardware
@@ -100,6 +105,8 @@ void setup() {
100105
// set the inital target value
101106
motor.target = 2;
102107

108+
// define the motor id
109+
command.add('A', onA);
103110

104111
Serial.println(F("Full control example: "));
105112
Serial.println(F("Run user commands to configure and the motor (find the full command list in docs.simplefoc.com) \n "));
@@ -120,33 +127,5 @@ void loop() {
120127
motor.move();
121128

122129
// user communication
123-
motor.command(serialReceiveUserCommand());
130+
command.run();
124131
}
125-
126-
// utility function enabling serial communication the user
127-
String serialReceiveUserCommand() {
128-
129-
// a string to hold incoming data
130-
static String received_chars;
131-
132-
String command = "";
133-
134-
while (Serial.available()) {
135-
// get the new byte:
136-
char inChar = (char)Serial.read();
137-
// add it to the string buffer:
138-
received_chars += inChar;
139-
140-
// end of user input
141-
if (inChar == '\n') {
142-
143-
// execute the user command
144-
command = received_chars;
145-
146-
// reset the command buffer
147-
received_chars = "";
148-
}
149-
}
150-
return command;
151-
}
152-

examples/motor_commands_serial_examples/encoder/full_control_serial/full_control_serial.ino

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Encoder encoder = Encoder(2, 3, 8192);
5353
void doA(){encoder.handleA();}
5454
void doB(){encoder.handleB();}
5555

56+
57+
// commander interface
58+
Commander command = Commander(Serial);
59+
void onA(String cmd){ command.motor(&motor, cmd); }
60+
5661
void setup() {
5762

5863
// initialize encoder sensor hardware
@@ -103,6 +108,8 @@ void setup() {
103108
// set the inital target value
104109
motor.target = 2;
105110

111+
// define the motor id
112+
command.add('A', onA);
106113

107114
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
108115
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
@@ -121,33 +128,5 @@ void loop() {
121128
motor.move();
122129

123130
// user communication
124-
motor.command(serialReceiveUserCommand());
125-
}
126-
127-
// utility function enabling serial communication the user
128-
String serialReceiveUserCommand() {
129-
130-
// a string to hold incoming data
131-
static String received_chars;
132-
133-
String command = "";
134-
135-
while (Serial.available()) {
136-
// get the new byte:
137-
char inChar = (char)Serial.read();
138-
// add it to the string buffer:
139-
received_chars += inChar;
140-
141-
// end of user input
142-
if (inChar == '\n') {
143-
144-
// execute the user command
145-
command = received_chars;
146-
147-
// reset the command buffer
148-
received_chars = "";
149-
}
150-
}
151-
return command;
152-
}
153-
131+
command.run();
132+
}s

examples/motor_commands_serial_examples/hall_sensor/full_control_serial/full_control_serial.ino

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ void doC(){sensor.handleC();}
5959
// If no available hadware interrupt pins use the software interrupt
6060
PciListenerImp listenC(sensor.pinC, doC);
6161

62+
63+
// commander interface
64+
Commander command = Commander(Serial);
65+
void onA(String cmd){ command.motor(&motor, cmd); }
66+
67+
6268
void setup() {
6369

6470
// initialize encoder sensor hardware
@@ -110,6 +116,8 @@ void setup() {
110116
// set the inital target value
111117
motor.target = 2;
112118

119+
// define the motor id
120+
command.add('A', onA);
113121

114122
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
115123
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
@@ -128,33 +136,7 @@ void loop() {
128136
motor.move();
129137

130138
// user communication
131-
motor.command(serialReceiveUserCommand());
139+
command.run();
132140
}
133141

134-
// utility function enabling serial communication the user
135-
String serialReceiveUserCommand() {
136-
137-
// a string to hold incoming data
138-
static String received_chars;
139-
140-
String command = "";
141-
142-
while (Serial.available()) {
143-
// get the new byte:
144-
char inChar = (char)Serial.read();
145-
// add it to the string buffer:
146-
received_chars += inChar;
147-
148-
// end of user input
149-
if (inChar == '\n') {
150-
151-
// execute the user command
152-
command = received_chars;
153-
154-
// reset the command buffer
155-
received_chars = "";
156-
}
157-
}
158-
return command;
159-
}
160142

examples/motor_commands_serial_examples/magnetic_sensor/full_control_serial/full_control_serial.ino

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
5353
//StepperMotor motor = StepperMotor(50);
5454
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6, 8);
5555

56+
// commander interface
57+
Commander command = Commander(Serial);
58+
void onA(String cmd){ command.motor(&motor, cmd); }
59+
5660
void setup() {
5761

5862
// initialise magnetic sensor hardware
@@ -102,6 +106,8 @@ void setup() {
102106
// set the inital target value
103107
motor.target = 2;
104108

109+
// define the motor id
110+
command.add('A', onA);
105111

106112
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
107113
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
@@ -120,33 +126,6 @@ void loop() {
120126
motor.move();
121127

122128
// user communication
123-
motor.command(serialReceiveUserCommand());
124-
}
125-
126-
// utility function enabling serial communication the user
127-
String serialReceiveUserCommand() {
128-
129-
// a string to hold incoming data
130-
static String received_chars;
131-
132-
String command = "";
133-
134-
while (Serial.available()) {
135-
// get the new byte:
136-
char inChar = (char)Serial.read();
137-
// add it to the string buffer:
138-
received_chars += inChar;
139-
140-
// end of user input
141-
if (inChar == '\n') {
142-
143-
// execute the user command
144-
command = received_chars;
145-
146-
// reset the command buffer
147-
received_chars = "";
148-
}
149-
}
150-
return command;
129+
command.run();
151130
}
152131

examples/osc_control_examples/osc_esp32_3pwm/osc_esp32_3pwm.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ MagneticSensorI2C sensor = MagneticSensorI2C(0x40, 14, 0xFE, 8);
6363
BLDCMotor motor = BLDCMotor(11);
6464
BLDCDriver3PWM driver = BLDCDriver3PWM(25, 26, 27);
6565

66+
// commander interface
67+
Commander command = Commander(Serial);
6668

6769
void setup() {
6870
Serial.begin(115200);
@@ -126,7 +128,7 @@ void cmdControl(OSCMessage &msg){
126128
if (msg.isString(0)) {
127129
msg.getString(0,cmdStr,16);
128130
String it(cmdStr);
129-
motor.command(it);
131+
command.motor(&motor,it);
130132
}
131133
}
132134

src/BLDCMotor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
103103
// checks if driver phases are the same as current sense phases
104104
// and checks the direction of measuremnt.
105105
_delay(500);
106-
if(current_sense) exit_flag *= alignCurrentSense();
107-
else if(monitor_port) monitor_port->println(F("MOT: No current sense."));
108-
106+
if(exit_flag){
107+
if(current_sense) exit_flag *= alignCurrentSense();
108+
else if(monitor_port) monitor_port->println(F("MOT: No current sense."));
109+
}
110+
109111
if(exit_flag){
110112
if(monitor_port) monitor_port->println(F("MOT: Ready."));
111113
}else{

0 commit comments

Comments
 (0)