From 0bc7417f35ded76f0f5ed1ef74b3bcdd20f79dea Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Wed, 29 Oct 2025 11:32:59 -0400 Subject: [PATCH] Minor control layout change + added documentation --- index.html | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index ed90a96..d4e9dc3 100644 --- a/index.html +++ b/index.html @@ -25,18 +25,18 @@
Translation & Rotation -
- - - 0 -
-
0
+
+ + + 0 +
+
@@ -51,7 +51,7 @@
- + 0
@@ -106,9 +106,173 @@

About This Project

How To Use +
+

Getting Started

+

This interactive visualizer demonstrates how a swerve drive robot moves based on commanded + velocities. Use the controls to experiment with different configurations and movement patterns. +

+ +

Drive Controls

+
    +
  • Strafe Left/Right: Controls the robot's velocity in the X direction + (field-relative). Positive values move right, negative values move left.
  • +
  • Move Forward/Backward: Controls the robot's velocity in the Y direction + (field-relative). Positive values move forward, negative values move backward.
  • +
  • Rotation: Controls the robot's angular velocity (turn rate) in radians per + second. Positive values rotate counter-clockwise.
  • +
  • Max Module Speed: Sets the maximum speed limit for any individual swerve + module. If calculated speeds exceed this, all modules are scaled proportionally.
  • +
  • Reset Controls: Returns all velocity sliders to zero.
  • +
+ +

Preset Configurations

+

Choose from 9 pre-built robot configurations ranging from 2 to 16 wheels. Each preset + demonstrates different module arrangements:

+
    +
  • 2-Wheel: Differential drive arrangement
  • +
  • 3-Wheel Triangle: Three modules in an equilateral triangle
  • +
  • 4-Wheel Square: Classic square configuration
  • +
  • 4-Wheel Rectangle: Rectangular configuration for longer robots
  • +
  • 6-Wheel Hexagon: Hexagonal arrangement
  • +
  • 8-Wheel Octagon: Octagonal arrangement
  • +
  • 8-Wheel Square: Double-layered square with inner and outer modules
  • +
  • 12-Wheel Hexagon: Double-layered hexagonal arrangement
  • +
  • 16-Wheel Octagon: Double-layered octagonal arrangement
  • +
+ +

Custom Configurations

+

Create your own robot configuration:

+
    +
  1. Enter the desired number of modules (Minimum of 2)
  2. +
  3. Click Generate Position Inputs to create input fields
  4. +
  5. For each module, specify: +
      +
    • Module Name: A label for the module
    • +
    • X Position: Distance from robot center (pixels, positive = right) +
    • +
    • Y Position: Distance from robot center (pixels, positive = up)
    • +
    +
  6. +
  7. Click Apply Custom Configuration to see your design
  8. +
  9. Use Remove Position Inputs to clear the custom fields. This does not reset + the robot, only clears the input box
  10. +
+ +

Understanding the Visualization

+
    +
  • Robot Frame: The filled polygon connecting the outer-most module positions +
  • +
  • Modules: Circular markers at each wheel position
  • +
  • Velocity Arrows: Red arrows showing the direction and magnitude of each + module's velocity
  • +
  • Grid: Moves relative to the robot to show field-relative motion
  • +
  • Gyro Heading: The current rotation angle of the robot in degrees
  • +
+ +

Module States Panel

+

Displays real-time information for each module:

+
    +
  • Angle: The direction the module is pointing (in degrees)
  • +
  • Speed: The velocity of the module (in pixels/second)
  • +
+
- Explaination of Swerve Kinematics + Explanation of Swerve Kinematics +
+

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:

+
    +
  1. Translation component: The robot's linear velocity (vrobot_x, + vrobot_y)
  2. +
  3. Rotation component: Perpendicular to the position vector, with magnitude + proportional to distance from center: +
    +vrot_x = -yi × ω
    +vrot_y = xi × ω
    +                            
    +
  4. +
  5. Combined velocity: Vector sum of translation and rotation: +
    +vmodule_x = vrobot_x + vrot_x
    +vmodule_y = vrobot_y + vrot_y
    +                            
    +
  6. +
+ +

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
  • +
+