Skip to content

Commit f54ef1e

Browse files
committed
Merge branch 'dev'
2 parents 5cc616f + 24bc493 commit f54ef1e

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

examples/motor_full_control_serial_examples/encoder/full_control_serial/full_control_serial.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,22 @@ void loop() {
112112
// if tatget not set in parameter uses motor.target variable
113113
motor.move();
114114

115-
// output motor state variabels to the monitoring port (Serial)
116-
// motor.monitor();
117-
118115
// user communication
119-
serialReceiveUserCommand();
116+
motor.command(serialReceiveUserCommand());
120117
}
121118

122119
// utility function enabling serial communication function with the user
123120
// user can set the target values and set/get the motor configuration useing motor commands
124121
// see documentation for full command list
125122
//
126123
// this function can be implemented in serialEvent function as well
127-
void serialReceiveUserCommand() {
124+
String serialReceiveUserCommand() {
128125

129126
// a string to hold incoming data
130127
static String received_chars;
131128

129+
String command = "";
130+
132131
while (Serial.available()) {
133132
// get the new byte:
134133
char inChar = (char)Serial.read();
@@ -139,11 +138,12 @@ void serialReceiveUserCommand() {
139138
if (inChar == '\n') {
140139

141140
// execute the user command
142-
motor.command(received_chars);
141+
command = received_chars;
143142

144143
// reset the command buffer
145144
received_chars = "";
146145
}
147146
}
147+
return command;
148148
}
149149

examples/motor_full_control_serial_examples/magnetic_sensor/full_control_serial/full_control_serial.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void setup() {
5959
// set control loop type to be used
6060
motor.controller = ControlType::voltage;
6161

62-
// contoller configuration based on the controll type
62+
// contoller configuration based on the control type
6363
motor.PI_velocity.P = 0.2;
6464
motor.PI_velocity.I = 20;
6565
// default voltage_power_supply
@@ -105,24 +105,23 @@ void loop() {
105105
// velocity, position or voltage
106106
// if tatget not set in parameter uses motor.target variable
107107
motor.move();
108-
109-
// output motor state variabels to the monitoring port (Serial)
110-
// motor.monitor();
111108

112109
// user communication
113-
serialReceiveUserCommand();
110+
motor.command(serialReceiveUserCommand());
114111
}
115112

116113
// utility function enabling serial communication function with the user
117114
// user can set the target values and set/get the motor configuration useing motor commands
118115
// see documentation for full command list
119116
//
120117
// this function can be implemented in serialEvent function as well
121-
void serialReceiveUserCommand() {
118+
String serialReceiveUserCommand() {
122119

123120
// a string to hold incoming data
124121
static String received_chars;
125122

123+
String command = "";
124+
126125
while (Serial.available()) {
127126
// get the new byte:
128127
char inChar = (char)Serial.read();
@@ -133,11 +132,12 @@ void serialReceiveUserCommand() {
133132
if (inChar == '\n') {
134133

135134
// execute the user command
136-
motor.command(received_chars);
135+
command = received_chars;
137136

138137
// reset the command buffer
139138
received_chars = "";
140139
}
141140
}
141+
return command;
142142
}
143143

src/BLDCMotor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ void BLDCMotor::monitor() {
468468
int BLDCMotor::command(String user_command) {
469469
// error flag
470470
int errorFlag = 1;
471+
// if empty string
472+
if(user_command.length() < 1) return errorFlag;
473+
471474
// parse command letter
472475
char cmd = user_command.charAt(0);
473476
// check if get command
@@ -512,6 +515,11 @@ int BLDCMotor::command(String user_command) {
512515
if(!GET) P_angle.velocity_limit = value;
513516
if(monitor_port) monitor_port->println(P_angle.velocity_limit);
514517
break;
518+
case 'T': // angle loop gain velocity_limit change
519+
if(monitor_port) monitor_port->print("P angle velocity limit: ");
520+
if(!GET) P_angle.velocity_limit = value;
521+
if(monitor_port) monitor_port->println(P_angle.velocity_limit);
522+
break;
515523
case 'C':
516524
// change control type
517525
if(monitor_port) monitor_port->print("Contoller type: ");

src/BLDCMotor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ class BLDCMotor
9595
void linkSensor(Sensor* sensor);
9696

9797
/**
98-
* Function intializing FOC algorithm
99-
* and aligning sensor's and motors's zero position
98+
* Function initializing FOC algorithm
99+
* and aligning sensor's and motors' zero position
100100
*/
101101
int initFOC();
102102
/**
103-
* Function runing FOC algorithm in real-time
103+
* Function running FOC algorithm in real-time
104104
* it calculates the gets motor angle and sets the appropriate voltages
105105
* to the phase pwm signals
106106
* - the faster you can run it the better Arduino UNO ~1ms, Bluepill ~ 100us
@@ -171,7 +171,7 @@ class BLDCMotor
171171
* Method using FOC to set Uq to the motor at the optimal angle
172172
* Heart of the FOC algorithm
173173
*
174-
* @param Uq Current volatge in q axis to set to the motor
174+
* @param Uq Current voltage in q axis to set to the motor
175175
* @param angle_el current electrical angle of the motor
176176
*/
177177
void setPhaseVoltage(float Uq, float angle_el);

0 commit comments

Comments
 (0)