From c60c8019ffc86dd44a9188cd81bf2b4f9f1fcd46 Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Tue, 21 Oct 2025 14:50:14 -0400 Subject: [PATCH] Swerve drive and module classes complete --- script.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 574a548..f3d830e 100644 --- a/script.js +++ b/script.js @@ -27,7 +27,18 @@ class SwerveModule { calculateState(velocityX, velocityY, turnSpeed) { // Take the requested speed and turn rate of the robot and calculate // speed and angle of this module to achieve it - throw new Error("Not Yet Implemented"); + + // Calculate rotation contribution (perpendicular to position vector) + const rotX = -this.position.y * omega; + const rotY = this.position.x * omega; + + // Combine translation and rotation + this.velocity.x = velocityX + rotX; + this.velocity.y = velocityY + rotY; + + // Calculate speed and angle + this.speed = this.velocity.magnitude(); + this.angle = this.velocity.angle(); } }