The problem
Testing a smart-car algorithm needs somewhere realistic to run it. Our capstone team set out to build that place in the browser, so a developer could eventually drop in their own algorithm and watch it drive. The app calls itself the Distributed Smart Car Algorithm project, and the repository describes it as a tool to help researchers and professionals develop machine-learning path-finding for smart cars.
Before any smart algorithm, a test bed needs a baseline to compare against. That baseline is what we built: cars that follow their shortest routes and obey simple rules of the road.
How it works
- The map is the Sioux Falls network, a classic test network from transportation research: 24 intersections and 76 road links, each with a length, capacity and speed limit.
- 50 cars spawn with random origins and destinations, each given a shortest route by Dijkstra’s algorithm.
- A server loop moves every car every 50 milliseconds. Cars speed up and slow down in steps, brake using a stopping-distance estimate when the car ahead in their lane is too close, and stop at the edge of an intersection.
- Each intersection keeps a queue. The car at the front enters only if the next road has room; otherwise it goes to the back of the line.
- Roads have two lanes. A car moves into the lane that suits its next turn, changing lanes gradually before the intersection.
- Every tick, each car’s eight sensor slots (front, back, left, right and the four diagonals) are refreshed with the cars around it, and a second pass lets a car extend its lists with the lists of the cars it can see.
- The browser only draws. Positions stream from the server over socket.io to two stacked canvases, one for the map and one for the cars.
What I built
- The road model. I wrote the node, edge, edge-weight and graph objects: they load the network files, work out each road’s heading from its end points, keep a list of the cars in each lane, and expose the add, remove and lookup calls the rest of the team built on. I threaded the lane count through the node file, graph, map builder, edge and car objects.
- Routing. I integrated Dijkstra’s algorithm, adapted from an open-source implementation that is credited in the source, and reshaped the weighted graph into an object of objects so it could be searched.
- The car model. I abstracted the car object, added lane tracking and the eight sensors, and changed sensor updates to clear a whole list at once instead of removing one value at a time.
- Car spawning, with random positions along the roads (building on a teammate’s position logic) and each car registered on its road.
- Front-end plumbing: the socket updates, drawing the map in the browser, a double-buffered canvas, and trimming what the server sends to the few fields the browser needs.
- The first movement code, straight up, down, left and right. Teammates built most of the collision avoidance, intersection queues, lane-change logic and map drawing on top of it.
Two bugs worth naming
- Computing road headings failed because the map files were being read asynchronously. Reading both files synchronously fixed it.
- A car in the middle of a lane change has a fractional lane number, such as 1.5, which broke looking up the cars in a lane. I fixed the rounding at the lookup.
Where it stopped
The repository holds the baseline, not the smart algorithms. The sensors are refreshed every tick, but the baseline driving does not read them yet: collision avoidance works from the per-lane car lists. They are the hook for the smart-car algorithms the README lists as the next step. Tuning values such as the intersection offsets and distances are hard-coded, and the code has TODOs to move them into the map data.