Simulation for FIRST robotics on collision avoidant autonomous path generation around dynamic obstacles.
- A simulation: a virtual environment to experiment with collision avoidant path planning.
- Uses a field‑based approach: obstacles create repulsive fields that allow the path to be optimized by following the negative gradient away from obstacles.
- Built with
nannoufor rendering andnannou_eguifor interactive controls. - loads simple 3D shapes from
models/*.stlto draw obstacles and markers. - Intended for robotics path planning experiments, such as FIRST Robotics autonomous routines.
- Field and models: The app draws a rectangular field and renders STL models (robot base, cubes, etc.) as wireframes for visibility.
- Obstacles: Each obstacle contributes to a scalar “height” field in the plane. The total field is the sum of all obstacle fields.
- Path generation: A straight, segmented path is seeded between the robot’s start and the target. Each intermediate point gets a height based on nearby obstacles.
- Path optimization: Iteratively adjusts path points by moving them along the negative gradient of the obstacle field and enforcing a minimum obstacle clearance. The process stops when all points are “low enough” and safely distant, or when max iterations are reached.
- Visualization: You can toggle a gradient field overlay, see the generated path, place points along the path, and tune parameters (segments, speeds, resolutions).
This project uses transformed piecewise cosine field functions and gradient decent optimization to shape a collision avoidant path.
- Obstacle field (transformed piecewise cosine): for obstacle
$i$ with center$c_{i}$ and clearance radius$R_{\mathrm{calc}, i}$
where
- Gradient (repulsive direction): letting $\mathbf{e}{r} = (p - c{i})/r$ be the radial unit vector,
In code, this is scaled by an adjustment rate and applied so that points move away from obstacles when accumulating gradients across all obstacles.
- Total field and descent step:
and path points are updated by a repulsive step akin to
with additional clearance enforcement when
- Convergence criteria: the optimizer stops when point heights fall below a threshold and all points maintain a minimum safe distance from every obstacle, or after a maximum iteration cap.
The followed path is a uniform Catmull–Rom spline through the optimized path points.
- Spline point for four consecutive points
$p_0, p_1, p_2, p_3$ with local parameter$t \in [0,1]$ :
- Tangent (derivative) of the spline:
- Global progress to segment mapping. With
$N$ control points, there are$M = N - 3$ spline segments. For global progress$\tilde t \in [0,1]$ :
- Velocity (continuous formulation) with target speed
$v_{\text{target}}$ :
- Implementation detail (finite-difference arc-length step): choose a small
$\Delta \tilde t$ so the chord length matches$d = v_{\text{target}}* \Delta t$ :
- Next position update over time step
$\Delta t$ :
This effectively implements the process of advancing global progress by
In the right panel:
- Toggle
Show Gradient Functionand adjustX Resolution,Y Resolution, andLine Resolution. - Click
Update Gradient Fieldto refresh the overlay. - Under
Obstacles:Create New Obstacleinputs for name, scale, and position.Add Obstacleto place it on the field.- Manage existing obstacles: select, move, change radius,
Delete Obstacle.
- Under
Target Position:- Drag
XandYto move the goal, auto regenerating and re‑optimizing the path. Robot Movement: sliders forX Velocity,Y Velocity, andTarget Speed.
- Drag
- Under
Path Settings:- Toggle
Show Path. - Adjust
Path Segments. - Buttons:
Generate Path,Follow Path,Place Points Along Path,Clear All Path Points.
- Toggle
src/main.rs— app entry and UI, rendering and interaction.src/robot.rs— robot model, path generation, optimization, path following.src/obstacle.rs— obstacle model with cosine and gaussian field functions and gradients.src/gradient_field.rs— builds gradient wire overlays from the field function.src/model.rs,src/wire.rs,src/position.rs,src/field.rs,src/target_position.rs— supporting types for geometry, drawing, and state.models/— STL models used for wireframe visualization.
- The cosine field is the default for optimization, but gaussian field utilities exist and can be experimented with.
- Path optimization caps at a max iteration count to avoid infinite loops.
- thresholds and rates are configurable in code.




