Robot Visualization
Drive Controls
Robot Configuration
Module States
Gyro Heading: 0.0°
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:
- Enter the desired number of modules (Minimum of 2)
- Click Generate Position Inputs to create input fields
- 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)
- Click Apply Custom Configuration to see your design
- Use Remove Position Inputs to clear the custom fields. This does not reset the robot, only clears the input box
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)
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:
- 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