13 call_list[call_count] = onCommand;
14 call_ids[call_count] = id;
15 call_label[call_count] = label;
25 received_chars[rec_cnt] = (char)
com_port->read();
27 if (received_chars[rec_cnt++] ==
'\n') {
32 received_chars[0] = 0;
44 while (serial.available()) {
46 received_chars[rec_cnt] = (char)serial.read();
48 if (received_chars[rec_cnt++] ==
'\n') {
53 received_chars[0] = 0;
63 char id = user_input[0];
66 for(
int i=0; i < call_count; i++){
69 if(call_label[i]) println(call_label[i]);
75 printVerbose(F(
"Verb:"));
88 printVerbose(F(
"Decimal:"));
92 for(
int i=0; i < call_count; i++){
93 if(
id == call_ids[i]){
94 call_list[i](&user_input[1]);
104 char cmd = user_command[0];
105 char sub_cmd = user_command[1];
106 int value_index = (sub_cmd >=
'A' && sub_cmd <=
'Z') ? 2 : 1;
108 bool GET = user_command[value_index] ==
'\n';
110 float value = atof(&user_command[value_index]);
115 printVerbose(F(
"PID curr q| "));
117 else pid(&
motor->PID_current_q,&user_command[1]);
120 printVerbose(F(
"PID curr d| "));
122 else pid(&
motor->PID_current_d, &user_command[1]);
125 printVerbose(F(
"PID vel| "));
127 else pid(&
motor->PID_velocity, &user_command[1]);
130 printVerbose(F(
"PID angle| "));
132 else pid(&
motor->P_angle, &user_command[1]);
135 printVerbose(F(
"Limits| "));
138 printVerbose(F(
"volt: "));
140 motor->voltage_limit = value;
141 motor->PID_current_d.limit = value;
142 motor->PID_current_q.limit = value;
146 println(
motor->voltage_limit);
149 printVerbose(F(
"curr: "));
151 motor->current_limit = value;
157 println(
motor->current_limit);
160 printVerbose(F(
"vel: "));
162 motor->velocity_limit = value;
163 motor->P_angle.limit = value;
165 println(
motor->velocity_limit);
173 printVerbose(F(
"Motion: "));
176 printVerbose(F(
"downsample: "));
177 if(!GET)
motor->motion_downsample = value;
178 println((
int)
motor->motion_downsample);
182 if(!GET && value >= 0 && (
int)value < 5)
184 switch(
motor->controller){
186 println(F(
"torque"));
195 println(F(
"vel open"));
198 println(F(
"angle open"));
206 printVerbose(F(
"Torque: "));
207 if(!GET && (int8_t)value >= 0 && (int8_t)value < 3)
209 switch(
motor->torque_controller){
214 println(F(
"dc curr"));
217 println(F(
"foc curr"));
223 printVerbose(F(
"Status: "));
224 if(!GET) (bool)value ?
motor->enable() :
motor->disable();
225 println(
motor->enabled);
229 printVerbose(F(
"R phase: "));
231 motor->phase_resistance = value;
233 motor->voltage_limit =
motor->current_limit*value;
234 motor->PID_velocity.limit=
motor->current_limit;
242 printVerbose(F(
"Sensor | "));
245 printVerbose(F(
"offset: "));
246 if(!GET)
motor->sensor_offset = value;
247 println(
motor->sensor_offset);
250 printVerbose(F(
"el. offset: "));
251 if(!GET)
motor->zero_electric_angle = value;
252 println(
motor->zero_electric_angle);
260 printVerbose(F(
"Monitor | "));
263 switch((uint8_t)value){
265 printVerbose(F(
"target: "));
266 println(
motor->target);
269 printVerbose(F(
"Vq: "));
270 println(
motor->voltage.q);
273 printVerbose(F(
"Vd: "));
274 println(
motor->voltage.q);
277 printVerbose(F(
"Cq: "));
278 println(
motor->voltage.q);
281 printVerbose(F(
"Cd: "));
282 println(
motor->voltage.q);
285 printVerbose(F(
"vel: "));
286 println(
motor->shaft_velocity);
289 printVerbose(F(
"angle: "));
290 println(
motor->shaft_angle);
298 printVerbose(F(
"downsample: "));
299 if(!GET)
motor->monitor_downsample = value;
300 println((
int)
motor->monitor_downsample);
303 motor->monitor_variables = (uint8_t) 0;
307 if(!GET)
motor->monitor_variables = (uint8_t) 0;
308 for(
int i = 0; i < 7; i++){
309 if(user_command[value_index+i] ==
'\n')
break;
310 if(!GET)
motor->monitor_variables |= (user_command[value_index+i] -
'0') << (6-i);
311 print( (user_command[value_index+i] -
'0') );
321 printVerbose(F(
"Target: "));
322 motor->target = atof(user_command);
323 println(
motor->target);
328 char cmd = user_cmd[0];
329 bool GET = user_cmd[1] ==
'\n';
330 float value = atof(&user_cmd[1]);
335 if(!GET)
pid->P = value;
340 if(!GET)
pid->I = value;
345 if(!GET)
pid->D = value;
349 printVerbose(
"ramp: ");
350 if(!GET)
pid->output_ramp = value;
351 println(
pid->output_ramp);
354 printVerbose(
"limit: ");
355 if(!GET)
pid->limit = value;
365 char cmd = user_cmd[0];
366 bool GET = user_cmd[1] ==
'\n';
367 float value = atof(&user_cmd[1]);
371 printVerbose(F(
"Tf: "));
372 if(!GET)
lpf->Tf = value;
382 bool GET = user_cmd[0] ==
'\n';
383 if(!GET) *value = atof(user_cmd);
388 void Commander::print(
const int number){
392 void Commander::print(
const float number){
396 void Commander::print(
const char* message){
400 void Commander::print(
const __FlashStringHelper *message){
404 void Commander::print(
const char message){
409 void Commander::println(
const int number){
413 void Commander::println(
const float number){
417 void Commander::println(
const char* message){
421 void Commander::println(
const __FlashStringHelper *message){
425 void Commander::println(
const char message){
431 void Commander::printVerbose(
const char* message){
434 void Commander::printVerbose(
const __FlashStringHelper *message){
437 void Commander::printError(){