Skip to content

Commit 5caa643

Browse files
authored
Merge pull request #384 from runger1101001/nocascade
Add a MotionControlMode::angle_nocascade which uses a single PID for angle control
2 parents b9aea23 + 7d8891a commit 5caa643

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/BLDCMotor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,15 @@ void BLDCMotor::move(float new_target) {
442442
case MotionControlType::torque:
443443
current_sp = target;
444444
break;
445+
case MotionControlType::angle_nocascade:
446+
// TODO sensor precision: this calculation is not numerically precise. The target value cannot express precise positions when
447+
// the angles are large. This results in not being able to command small changes at high position values.
448+
// to solve this, the delta-angle has to be calculated in a numerically precise way.
449+
// angle set point
450+
shaft_angle_sp = target;
451+
// calculate the torque command - no velocity loop
452+
current_sp = P_angle( shaft_angle_sp - shaft_angle );
453+
break;
445454
case MotionControlType::angle:
446455
// TODO sensor precision: this calculation is not numerically precise. The target value cannot express precise positions when
447456
// the angles are large. This results in not being able to command small changes at high position values.

src/StepperMotor.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ int StepperMotor::init() {
4646
if(voltage_limit > driver->voltage_limit) voltage_limit = driver->voltage_limit;
4747
// constrain voltage for sensor alignment
4848
if(voltage_sensor_align > voltage_limit) voltage_sensor_align = voltage_limit;
49-
5049

5150
// update limits in the motor controllers
5251
updateCurrentLimit(current_limit);
@@ -414,6 +413,15 @@ void StepperMotor::move(float new_target) {
414413
case MotionControlType::torque:
415414
current_sp = target;
416415
break;
416+
case MotionControlType::angle_nocascade:
417+
// TODO sensor precision: this calculation is not numerically precise. The target value cannot express precise positions when
418+
// the angles are large. This results in not being able to command small changes at high position values.
419+
// to solve this, the delta-angle has to be calculated in a numerically precise way.
420+
// angle set point
421+
shaft_angle_sp = target;
422+
// calculate the torque command - no velocity loop
423+
current_sp = P_angle( shaft_angle_sp - shaft_angle );
424+
break;
417425
case MotionControlType::angle:
418426
// TODO sensor precision: this calculation is not numerically precise. The target value cannot express precise positions when
419427
// the angles are large. This results in not being able to command small changes at high position values.

src/common/base_classes/FOCMotor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ enum MotionControlType : uint8_t {
2828
torque = 0x00, //!< Torque control
2929
velocity = 0x01, //!< Velocity motion control
3030
angle = 0x02, //!< Position/angle motion control
31-
velocity_openloop = 0x03, //!< Open loop velocity control
32-
angle_openloop = 0x04 //!< Open loop position/angle control
31+
velocity_openloop = 0x03,
32+
angle_openloop = 0x04,
33+
angle_nocascade = 0x05 //!< Position/angle motion control without velocity cascade
3334
};
3435

3536
/**

src/communication/Commander.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ void Commander::motion(FOCMotor* motor, char* user_cmd, char* separator){
404404
case MotionControlType::angle_openloop:
405405
println(F("angle open"));
406406
break;
407+
case MotionControlType::angle_nocascade:
408+
println(F("angle nocascade"));
409+
break;
407410
}
408411
break;
409412
}
@@ -513,6 +516,7 @@ void Commander::target(FOCMotor* motor, char* user_cmd, char* separator){
513516
float pos, vel, torque;
514517
char* next_value;
515518
switch(motor->controller){
519+
case MotionControlType::angle_nocascade:
516520
case MotionControlType::torque: // setting torque target
517521
torque = atof(strtok (user_cmd, separator));
518522
motor->target = torque;

0 commit comments

Comments
 (0)