Skip to content

Commit

Permalink
Fixed differential drive vector arrow rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Nov 26, 2023
1 parent 04d1109 commit 870a6e8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/widgets/nt4_widgets/multi-topic/differential_drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ class DifferentialDrivePainter extends CustomPainter {

final double base = scaleFactor * arrowSize / 2;

final double arrowRotation = atan2(vectorY, vectorX);
final double arrowRotation = atan2(vectorY, vectorX) +
forwardSpeedSign * arcSign * arcLength / radius;

drawArrowHead(
canvas, center, vectorX, vectorY, arrowRotation, arrowAngle, base);
} else {
// Turning from inside the robot
final double turnSign = (leftSpeed - rightSpeed).sign;

// Turning from the center of the robot
Expand All @@ -378,6 +378,7 @@ class DifferentialDrivePainter extends CustomPainter {
drawArrowHead(canvas, center, turnSign * radius / 2, 0, arrowRotation,
arrowAngle, base);
} else {
// Turning from inside the robot
double dominant = turnRadius < 0 ? leftSpeed : rightSpeed;
double secondary = turnRadius < 0 ? rightSpeed : leftSpeed;
double radius = dominant.abs() * maxRadius;
Expand All @@ -394,8 +395,8 @@ class DifferentialDrivePainter extends CustomPainter {

final double base = scaleFactor * arrowSize / 2;

double tipX = 0.5 * scaleFactor * radius * cos(angle + startAngle);
double tipY = 0.5 * scaleFactor * radius * sin(angle + startAngle);
double tipX = 0.5 * radius * cos(angle + startAngle);
double tipY = 0.5 * radius * sin(angle + startAngle);

double arrowRotation = angle + startAngle + (pi / 2) * turnSign;

Expand Down

0 comments on commit 870a6e8

Please sign in to comment.