Swerve drive and module classes complete

This commit is contained in:
2025-10-21 14:50:14 -04:00
parent bcf1196c6f
commit c60c8019ff

View File

@ -27,7 +27,18 @@ class SwerveModule {
calculateState(velocityX, velocityY, turnSpeed) { calculateState(velocityX, velocityY, turnSpeed) {
// Take the requested speed and turn rate of the robot and calculate // Take the requested speed and turn rate of the robot and calculate
// speed and angle of this module to achieve it // 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();
} }
} }