Skip to content

Commit c0a0bfe

Browse files
committed
Fix a numerical issue in the trajectory planner that could cause sudden jumps of the position setpoint.
If certain inputs were passed to trajectory planner, an expression inside the trajectory planner which is an argument to sqrtf() could become negative due to finite floating point accuracy. This led to Vr_ == NaN and then Tf_ == 0, causing the trajectory to jump to the final setpoint instantaneously. To the user, this manifested as a sudden increase in velocity (limited by controller.config.vel_limit) and/or an overcurrent fault. This bug was likely to show up when constantly sending trajectory setpoints while moving in the negative direction. See also: https://discourse.odriverobotics.com/t/move-to-pos-not-works-well/4626
1 parent 1c94763 commit c0a0bfe

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Please add a note of your changes below this heading if you make a Pull Request.
33

44
# Releases
5+
## [0.4.12] - 2020-05-06
6+
### Changed
7+
* Fixed a numerical issue in the trajectory planner that could cause sudden jumps of the position setpoint
8+
59
## [0.4.11] - 2019-07-25
610
### Added
711
* Separate lockin configs for sensorless, index search, and general.

Firmware/MotorControl/trapTraj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool TrapezoidalTrajectory::planTrapezoidal(float Xf, float Xi, float Vi,
4444
// Are we displacing enough to reach cruising speed?
4545
if (s*dX < s*dXmin) {
4646
// Short move (triangle profile)
47-
Vr_ = s * sqrtf((Dr_*SQ(Vi) + 2*Ar_*Dr_*dX) / (Dr_ - Ar_));
47+
Vr_ = s * sqrtf(std::fmax((Dr_*SQ(Vi) + 2*Ar_*Dr_*dX) / (Dr_ - Ar_), 0.0f));
4848
Ta_ = std::max(0.0f, (Vr_ - Vi) / Ar_);
4949
Td_ = std::max(0.0f, -Vr_ / Dr_);
5050
Tv_ = 0.0f;

0 commit comments

Comments
 (0)