← Projects/P-01
Simulated autonomous surface vessel
For ME 503 at Embry-Riddle, a course on autonomous vehicles, I wrote the autonomy function for a simulated twin-thruster boat carrying GPS, a camera and a Livox LiDAR. Each weekly assignment got a new version. The work started with a kinematic model and dead reckoning, moved through color segmentation, a YOLOv2 detector, LiDAR mapping and obstacle avoidance, and ended in a final project: a four-phase mission that follows buoy gates, reads a lighthouse's color sequence and returns to its start gate. Everything ran in the instructor's simulator, and his starter code is credited at the end.
- 210
- simulator frames hand-labeled for the YOLOv2 detector
- 0.363 m
- GPS CEP95, boat at rest for 30 s
- 16 min 33 s
- YOLOv2 training run on a single CPU
- 4
- phases in the final mission: home scan, gates, lighthouse, return
01Boat model, dead reckoning and waypoints
The simulated boat steers by differential thrust, with one command per thruster (port and starboard), each between −1 and 1. I first implemented a kinematic model of the boat. Then I ran the same 36-second command sequence (forward, stop, reverse, stop, turn in place, stop) through my model and through the simulator's dynamic model. The kinematic model responds in rectangular steps. The dynamic model rises and decays smoothly because it includes inertia, thruster dynamics and damping.
Dead reckoning came next. A constant thrust difference between the two motors traces a circle; the assignment asked for a 6 m radius. A 6 × 6 m square, run as a forward–stop–turn–stop state machine, never closed. Because of rotational momentum, a commanded 90° turn never ends at exactly 90°, so every corner adds heading error and the track came out almond-shaped. Left running, the boat's final position became very hard to predict: with nothing to correct them, small biases build up as drift.
With GPS available, I measured its noise with the boat at rest for 30 s: mean radial error 0.143 m, CEP95 0.363 m and a heading standard deviation of 0.85°. I first drew the waypoints clicked onto the map with acceptance circles of that radius; the final waypoint follower used a looser 1 m. A PID loop with anti-windup turns the bow toward the active waypoint. A proportional term adds forward thrust once the heading error drops below 25°, at full weight within 12°. The boat has to stay inside the circle for 0.5 s before the next waypoint becomes active.
02Vision: color masks, then YOLO
The lighthouse task starts with the camera. I built a test course with the lighthouse about 5 m behind the boat. My first pipeline was classical: convert each frame to HSV, build red, green, blue and black masks, clean them with morphology and run connected components. Only regions in a central vertical band, straight ahead, are kept. Each region is scored as 0.6 × its dominant-color fraction plus 0.4 × a shape score (the mean of solidity and extent). The best one becomes the panel, labeled R, G, B or K. A debounce based on IoU and hold time keeps the box steady, and a small sequence builder turns successive colors into a code such as "RGB".
For the symbol-finding task I switched to deep learning. I hand-labeled 210 simulator frames in MATLAB's Ground Truth Labeler, which took about an hour. I then trained a YOLOv2 detector with the instructor's training script: a ResNet-50 backbone, the four symbol types merged into one "Symbols" class, 224 × 224 input, four anchor boxes, Adam at a learning rate of 10−4, 100 epochs and mini-batch 16. MATLAB's export of the labels kept every fifth frame, so the network actually trained on 42 images. Training took 16 min 33 s on a single CPU, and the mini-batch loss fell from 15.0 to 0.1.
A detection becomes a target only after it scores at least 0.9 in three consecutive frames. Range comes from the pinhole model: focal length times the 0.613 m symbol height, divided by the box height on the sensor. Bearing comes from the pixel offset of the box center. The camera offset and the boat's yaw turn range and bearing into a waypoint in the global north-east-down (NED) frame. A search → track → align state machine drives the boat. In search it moves forward and reverses its turn direction every 5 s. In track it steers to the waypoint. If the target is lost for more than 3 s, it goes back to searching. The detector still produced occasional false positives.
03LiDAR: mapping, segmentation, avoidance
The Livox LiDAR reports points in its own frame, with +Y to port and +Z up. I derived the transforms to the boat's forward-right-down (FRD) frame: a fixed offset 0.27 m forward and a flip of the Y and Z axes. A yaw rotation then takes the points to the global NED frame. The running map drops near-zero returns and reflections from the water and timestamps every point. It keeps only a rolling time window, so old returns fade out.
The segmentation assignment started from the instructor's mapping solution. I clustered the last second of returns inside the 60 × 60 m course with DBSCAN and gave each cluster a convex hull and a centroid. The midpoint between the two nearest centroids defines a gate, and a heading controller steers the boat through it.
To test obstacle avoidance I designed a cluttered course with five hard-coded waypoints laid out as a star, each leg crossing five or more obstacles. This assignment built on the instructor's posted segmentation solution. A rectangular danger box in the FRD frame watches the path ahead. The first version, 0.5–3 m ahead and ±1 m to each side, reacted too early. I tightened it to 0.8–2.2 m ahead and ±0.7 m and required at least five returns inside before it triggers, so stray points are ignored. When it triggers, the boat turns in place toward the more open side, away from the mean lateral position of the points in the box. This tangent-bug-style rule avoids always turning the same way.
04The final mission
The final project combined these pieces into one Autonomy.m for a live demonstration in class on 6 December, on a course handed out on the day. A four-phase state machine runs the mission:
- Home scan. Turn 90° toward the start buoys and hold for 2 s. Cluster the LiDAR returns, store the midpoint of the two nearest clusters as the home gate, then turn back to the course.
- Gates. Until 60 s into the run, follow red–green and black–black buoy pairs that are 1–6 m apart and ahead of the boat, nearest first. To color each LiDAR cluster, the code projects its centroid into the camera image and classifies the mean HSV of an 11 × 11-pixel patch around it. Docks and shore are rejected by size and position. A tapered danger zone, reaching 2 m ahead and 0.5 m to each side, overrides the steering whenever a return enters it.
- Lighthouse. Drive to the center of the course and run a five-waypoint search pattern until a LiDAR return higher than 1.5 m marks the tower. Approach to 4 m, with a pull toward the tower and a push away from every return within 3 m that grows as 1/d. Brake with 0.5 s of reverse thrust, then lock onto the panel and read it: wait for black, then record the next three colors as they change.
- Return. Drive back to the stored home gate and stop within 0.4 m of it.
A practice run on 5 December used an earlier version of the code that did not yet have the home scan. Its log shows the tower found at (38.8, 12.0) m, the panel read as B-G-R and the switch to the return leg at 114 s.
In the live demonstration the boat completed every mission: it went through the buoy gates, read the lighthouse's color sequence and returned to its start gate. The run scored 1,000 points, and the final project was graded 10/10.
05What was supplied
The instructor, Dr. Eric Coyle, supplied the simulator (BoatSim) with the boat's dynamic model, the CourseBuilder tool and its object models, and the Autonomy.m template that every assignment fills in. Several assignments also started from his code:
- the YOLOv2 training script began as his template;
- the segmentation assignment began from his mapping solution, and its PD heading controller came from his camera-geometry solution;
- the obstacle-avoidance assignment and the final built on his posted segmentation solution. The LiDAR mapping, DBSCAN clustering, LiDAR object classifier and PD waypoint follower in the final come from it.
My own work in the weekly assignments: the logic added on top each week, the labels on the 210 training frames and the trained network, the lighthouse and obstacle test courses, and the reports.