From 870a6e84779d3137c770fa13b38919e220b303a5 Mon Sep 17 00:00:00 2001 From: Gold872 Date: Sat, 25 Nov 2023 21:40:47 -0500 Subject: [PATCH] Fixed differential drive vector arrow rotation --- .../nt4_widgets/multi-topic/differential_drive.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/widgets/nt4_widgets/multi-topic/differential_drive.dart b/lib/widgets/nt4_widgets/multi-topic/differential_drive.dart index bc3b71c1..6d35724e 100644 --- a/lib/widgets/nt4_widgets/multi-topic/differential_drive.dart +++ b/lib/widgets/nt4_widgets/multi-topic/differential_drive.dart @@ -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 @@ -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; @@ -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;