@@ -54,15 +54,12 @@ void Commander::run(Stream& serial, char eol){
54
54
}
55
55
56
56
com_port = tmp; // reset the instance to the internal value
57
- this ->eol = eol_tmp;
57
+ this ->eol = eol_tmp;
58
58
}
59
59
60
60
void Commander::run (char * user_input){
61
61
// execute the user command
62
62
char id = user_input[0 ];
63
-
64
-
65
-
66
63
switch (id){
67
64
case CMD_SCAN:
68
65
for (int i=0 ; i < call_count; i++){
@@ -102,14 +99,25 @@ void Commander::run(char* user_input){
102
99
}
103
100
104
101
void Commander::motor (FOCMotor* motor, char * user_command) {
102
+
103
+ // if target setting
104
+ if (isDigit (user_command[0 ]) || user_command[0 ] == ' -' || user_command[0 ] == ' +' ){
105
+ printVerbose (F (" Target: " ));
106
+ motor->target = atof (user_command);
107
+ println (motor->target );
108
+ return ;
109
+ }
110
+
105
111
// parse command letter
106
112
char cmd = user_command[0 ];
107
113
char sub_cmd = user_command[1 ];
114
+ // check if there is a subcommand or not
108
115
int value_index = (sub_cmd >= ' A' && sub_cmd <= ' Z' ) ? 2 : 1 ;
109
116
// check if get command
110
117
bool GET = isSentinel (user_command[value_index]);
111
118
// parse command values
112
- float value = atof (&user_command[value_index]);
119
+ float value = atof (&user_command[value_index]);
120
+
113
121
114
122
// a bit of optimisation of variable memory for Arduino UNO (atmega328)
115
123
switch (cmd){
@@ -181,7 +189,7 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
181
189
break ;
182
190
default :
183
191
// change control type
184
- if (!GET && value >= 0 && (int )value < 5 )// if set command
192
+ if (!GET && value >= 0 && (int )value < 5 ) // if set command
185
193
motor->controller = (MotionControlType)value;
186
194
switch (motor->controller ){
187
195
case MotionControlType::torque:
@@ -367,10 +375,9 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
367
375
break ;
368
376
}
369
377
break ;
370
- default : // target change
371
- printVerbose (F (" Target: " ));
372
- motor->target = atof (user_command);
373
- println (motor->target );
378
+ default : // unknown cmd
379
+ printVerbose (F (" unknown cmd " ));
380
+ printError ();
374
381
}
375
382
}
376
383
@@ -440,12 +447,7 @@ bool Commander::isSentinel(char ch)
440
447
return true ;
441
448
else if (ch == ' \r ' )
442
449
{
443
- if (verbose == VerboseMode::user_friendly)
444
- {
445
- print (F (" Warning! \\ r detected but is not configured as end of line sentinel, which is configured as ascii code '" ));
446
- print (int (eol));
447
- print (" '\n " );
448
- }
450
+ printVerbose (F (" Warn: \\ r detected! \n " ));
449
451
}
450
452
return false ;
451
453
}
0 commit comments