Skip to content

Commit 92203b6

Browse files
committed
initial support for common position+velocity+torque setting with commander #81
1 parent 4acf3d6 commit 92203b6

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/communication/Commander.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "Commander.h"
2-
2+
#include <String.h>
33

44
Commander::Commander(Stream& serial, char eol, bool echo){
55
com_port = &serial;
@@ -217,12 +217,18 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
217217
switch(motor->torque_controller){
218218
case TorqueControlType::voltage:
219219
println(F("volt"));
220+
// change the velocity control limits if necessary
221+
if( !_isset(motor->phase_resistance) ) motor->PID_velocity.limit = motor->voltage_limit;
220222
break;
221223
case TorqueControlType::dc_current:
222224
println(F("dc curr"));
225+
// change the velocity control limits if necessary
226+
motor->PID_velocity.limit = motor->current_limit;
223227
break;
224228
case TorqueControlType::foc_current:
225229
println(F("foc curr"));
230+
// change the velocity control limits if necessary
231+
motor->PID_velocity.limit = motor->current_limit;
226232
break;
227233
}
228234
break;
@@ -439,6 +445,61 @@ void Commander::scalar(float* value, char* user_cmd){
439445
println(*value);
440446
}
441447

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+
442503
bool Commander::isSentinel(char ch)
443504
{
444505
if(ch == eol)

src/communication/Commander.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ class Commander
173173
* - It can be set by sending 'value' - (ex. 0.01f for settin *value=0.01)
174174
*/
175175
void scalar(float* value, char* user_cmd);
176-
176+
/**
177+
* Target setting interface, enables setting the target and limiting variables at once.
178+
* The valeus are sent separated by a space. ex. P2.34 70 2
179+
* `P` is the user defined command, `2.34` is the target angle `70` is the target
180+
* velocity and `2` is the desired max current.
181+
* It depends of the motion control mode:
182+
* - torque : torque (ex. P2.5)
183+
* - velocity : velocity torque (ex.P10 2.5)
184+
* - angle : angle velocity torque (ex.P3.5 10 2.5)
185+
*/
186+
void target(FOCMotor* motor, char* user_cmd);
177187
private:
178188
// Subscribed command callback variables
179189
CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number

0 commit comments

Comments
 (0)