Skip to content

Commit df5f6de

Browse files
committed
inital implementation of the velocity feed forward
1 parent 4c8ea20 commit df5f6de

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/BLDCMotor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ void BLDCMotor::move(float new_target) {
418418
// angle set point
419419
shaft_angle_sp = target;
420420
// calculate velocity set point
421-
shaft_velocity_sp = P_angle( shaft_angle_sp - shaft_angle );
421+
shaft_velocity_sp = feed_forward_velocity + P_angle( shaft_angle_sp - shaft_angle );
422+
shaft_angle_sp = _constrain(shaft_angle_sp,-velocity_limit, velocity_limit);
422423
// calculate the torque command - sensor precision: this calculation is ok, but based on bad value from previous calculation
423424
current_sp = PID_velocity(shaft_velocity_sp - shaft_velocity); // if voltage torque control
424425
// if torque controlled through voltage

src/StepperMotor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ void StepperMotor::move(float new_target) {
307307
// angle set point
308308
shaft_angle_sp = target;
309309
// calculate velocity set point
310-
shaft_velocity_sp = P_angle( shaft_angle_sp - shaft_angle );
310+
shaft_velocity_sp = feed_forward_velocity + P_angle( shaft_angle_sp - shaft_angle );
311+
shaft_angle_sp = _constrain(shaft_angle_sp, -velocity_limit, velocity_limit);
311312
// calculate the torque command
312313
current_sp = PID_velocity(shaft_velocity_sp - shaft_velocity); // if voltage torque control
313314
// if torque controlled through voltage

src/common/base_classes/FOCMotor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class FOCMotor
155155

156156
// state variables
157157
float target; //!< current target value - depends of the controller
158+
float feed_forward_velocity = 0.0f; //!< current feed forward velocity
158159
float shaft_angle;//!< current motor angle
159160
float electrical_angle;//!< current electrical angle
160161
float shaft_velocity;//!< current motor velocity

0 commit comments

Comments
 (0)