+
What is Swerve Drive?
+
Swerve drive (also called holonomic drive) is a drivetrain design where each wheel module can
+ independently rotate and drive in any direction. This allows the robot to move in any direction
+ while simultaneously rotating, providing exceptional maneuverability.
+
+
Kinematic Equations
+
The simulator calculates each module's state using inverse kinematics. Given a desired robot
+ velocity (vx, vy) and rotation rate (ω), we calculate each module's
+ required velocity.
+
+
Field-Relative vs Robot-Relative
+
This simulator uses field-relative control, meaning the velocity commands are
+ relative to the field, not the robot's current orientation. The inputs are transformed to
+ robot-relative coordinates using the current gyro heading:
+
+vrobot_x = vfield_x × cos(-θ) - vfield_y × sin(-θ)
+vrobot_y = vfield_x × sin(-θ) + vfield_y × cos(-θ)
+
+
Where θ is the robot's heading angle (gyro reading).
+
+
Module Velocity Calculation
+
For each module at position (xi, yi) relative to the robot's center of
+ rotation:
+
+ - Translation component: The robot's linear velocity (vrobot_x,
+ vrobot_y)
+ - Rotation component: Perpendicular to the position vector, with magnitude
+ proportional to distance from center:
+
+vrot_x = -yi × ω
+vrot_y = xi × ω
+
+
+ - Combined velocity: Vector sum of translation and rotation:
+
+vmodule_x = vrobot_x + vrot_x
+vmodule_y = vrobot_y + vrot_y
+
+
+
+
+
Module Angle and Speed
+
From the module's velocity vector, we calculate:
+
+ - Speed: The magnitude of the velocity vector: √(vx² +
+ vy²)
+ - Angle: The direction of the velocity vector: arctan2(vy,
+ vx)
+
+
+
Speed Normalization
+
If any module's calculated speed exceeds the maximum allowed speed, all module velocities are
+ scaled proportionally. This preserves the movement direction while respecting hardware limits:
+
+
+scale = max_speed / max(calculated_speeds)
+if scale < 1:
+ all_module_speeds × scale
+
+
+
Gyro Integration
+
The robot's heading (gyro angle) is continuously updated by integrating the rotation rate:
+
+θnew = θold + ω × Δt
+
+
Where Δt is the time step. The heading is normalized to stay within the range [-π, π].
+
+
Real-World Applications
+
Swerve drive systems are commonly used in:
+
+ - FRC (FIRST Robotics Competition): For competitive robots requiring precise
+ positioning
+ - Industrial AGVs: Automated guided vehicles in warehouses
+ - Research Platforms: Mobile robots requiring omnidirectional movement
+
+
+
Key Advantages
+
+ - True holonomic motion (can move in any direction without rotating)
+ - Can translate and rotate simultaneously
+ - Excellent maneuverability in constrained spaces
+ - No "drift" or unwanted rotation during translation
+
+
+
Implementation Considerations
+
+ - Mechanical Complexity: Each module requires two motors (drive and steering)
+
+ - Control Complexity: Requires coordinated control of all modules
+ - Sensor Requirements: Absolute encoders recommended for module angles
+ - Cost: More expensive than traditional drivetrains
+
+