|
1 | 1 | #include "Commander.h"
|
2 |
| - |
| 2 | +#include <String.h> |
3 | 3 |
|
4 | 4 | Commander::Commander(Stream& serial, char eol, bool echo){
|
5 | 5 | com_port = &serial;
|
@@ -217,12 +217,18 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
|
217 | 217 | switch(motor->torque_controller){
|
218 | 218 | case TorqueControlType::voltage:
|
219 | 219 | println(F("volt"));
|
| 220 | + // change the velocity control limits if necessary |
| 221 | + if( !_isset(motor->phase_resistance) ) motor->PID_velocity.limit = motor->voltage_limit; |
220 | 222 | break;
|
221 | 223 | case TorqueControlType::dc_current:
|
222 | 224 | println(F("dc curr"));
|
| 225 | + // change the velocity control limits if necessary |
| 226 | + motor->PID_velocity.limit = motor->current_limit; |
223 | 227 | break;
|
224 | 228 | case TorqueControlType::foc_current:
|
225 | 229 | println(F("foc curr"));
|
| 230 | + // change the velocity control limits if necessary |
| 231 | + motor->PID_velocity.limit = motor->current_limit; |
226 | 232 | break;
|
227 | 233 | }
|
228 | 234 | break;
|
@@ -439,6 +445,61 @@ void Commander::scalar(float* value, char* user_cmd){
|
439 | 445 | println(*value);
|
440 | 446 | }
|
441 | 447 |
|
| 448 | + |
| 449 | +void Commander::target(FOCMotor* motor, char* user_cmd){ |
| 450 | + bool GET = isSentinel(user_cmd[0]); |
| 451 | + if(!GET){ |
| 452 | + float pos, vel, torque; |
| 453 | + switch(motor->controller){ |
| 454 | + case MotionControlType::torque: // setting torque target |
| 455 | + torque= atof(strtok (user_cmd," ")); |
| 456 | + motor->target = torque; |
| 457 | + break; |
| 458 | + case MotionControlType::velocity: // setting velocity target + torque limit |
| 459 | + vel= atof(strtok (user_cmd," ")); |
| 460 | + torque= atof(strtok (NULL," ")); |
| 461 | + motor->target = vel; |
| 462 | + motor->PID_velocity.limit = torque; |
| 463 | + // torque command can be voltage or current |
| 464 | + if(!_isset(motor->phase_resistance) && motor->torque_controller == TorqueControlType::voltage) motor->voltage_limit = torque; |
| 465 | + else motor->current_limit = torque; |
| 466 | + break; |
| 467 | + case MotionControlType::angle: // setting angle target + torque, velocity limit |
| 468 | + pos= atof(strtok (user_cmd," ")); |
| 469 | + vel= atof(strtok (NULL," ")); |
| 470 | + torque= atof(strtok (NULL," ")); |
| 471 | + motor->target = pos; |
| 472 | + motor->velocity_limit = vel; |
| 473 | + motor->P_angle.limit = vel; |
| 474 | + motor->PID_velocity.limit = torque; |
| 475 | + // torque command can be voltage or current |
| 476 | + if(!_isset(motor->phase_resistance) && motor->torque_controller == TorqueControlType::voltage) motor->voltage_limit = torque; |
| 477 | + else motor->current_limit = torque; |
| 478 | + break; |
| 479 | + case MotionControlType::velocity_openloop: // setting velocity target + torque limit |
| 480 | + vel= atof(strtok (user_cmd," ")); |
| 481 | + torque= atof(strtok (NULL," ")); |
| 482 | + motor->target = vel; |
| 483 | + // torque command can be voltage or current |
| 484 | + if(!_isset(motor->phase_resistance)) motor->voltage_limit = torque; |
| 485 | + else motor->current_limit = torque; |
| 486 | + break; |
| 487 | + case MotionControlType::angle_openloop: // setting angle target + torque, velocity limit |
| 488 | + pos= atof(strtok (user_cmd," ")); |
| 489 | + vel= atof(strtok (NULL," ")); |
| 490 | + torque= atof(strtok (NULL," ")); |
| 491 | + motor->target = pos; |
| 492 | + motor->velocity_limit = vel; |
| 493 | + // torque command can be voltage or current |
| 494 | + if(!_isset(motor->phase_resistance)) motor->voltage_limit = torque; |
| 495 | + else motor->current_limit = torque; |
| 496 | + break; |
| 497 | + } |
| 498 | + } |
| 499 | + //println(*value); |
| 500 | +} |
| 501 | + |
| 502 | + |
442 | 503 | bool Commander::isSentinel(char ch)
|
443 | 504 | {
|
444 | 505 | if(ch == eol)
|
|
0 commit comments