Getting robots through the same crossing.
Multi-Bot · ROS 2 and Gazebo
I built a simulation with three TurtleBot3 robots sharing a small city, where they had to deal with crossings, traffic signals, and pedestrians. I wanted them to avoid collisions without getting stuck repeatedly yielding to each other, so I worked on how they shared intent as well as how they moved.
Sharing where the robot was going
I started by sharing each robot’s position, but that still left its neighbors guessing what it would do next. I added its next waypoint, the crossing it was approaching, and its estimated arrival time so the other robots could reason about a possible conflict before they were face to face.
intent = {
"stamp": now(),
"robot_id": my_id,
"intersection_id": next_crossing,
"eta": estimate_eta_seconds(),
"priority": my_priority
}
publish("/fleet/intent", intent)How I estimated arrival time
I estimated arrival time from the remaining distance along the global plan and a smoothed speed estimate. That helped distinguish robots at similar distances that were approaching at different speeds.
I kept the crossing identifier in the message because an arrival estimate only helped when both robots meant the same place. The full message also included the robot’s pose, next waypoint, and state, such as approaching, yielding, or crossing; I’ve kept the snippet above to the fields used in the arrival-order example.
I also needed to compare estimates on the same clock. In this illustrative example, A publishes at 10.0 seconds and expects to arrive 1.2 seconds later, while B publishes at 10.6 seconds and expects to arrive 0.9 seconds later. Comparing 1.2 with 0.9 directly would put them in the wrong order.
a_arrival = 10.0 + 1.2 # 11.2 seconds
b_arrival = 10.6 + 0.9 # 11.5 secondsAt a decision time of 10.8 seconds, I’d have 0.4 seconds left for A and 0.7 for B. That puts A first, assuming the timestamps share a clock and each ETA was computed for its message timestamp. I’d still need to account for prediction error and changes after publication.
I published intent over best-effort ROS 2 communication, which meant I had to think about freshness as well as delivery. A recent timestamp and a sensible arrival estimate describe different things; a freshly received message can still contain a poor prediction.
Deciding who should yield
When both robots kept backing off and trying again, I used their expected arrival order to decide who should go first. I compared their estimated arrivals at the same crossing and used priority to resolve close cases, while keeping local obstacles and traffic signals ahead of the ordinary right-of-way decision.
How I kept the decision consistent
I needed each robot to apply the same ordering rule to the contenders it could see. In this simplified example, I group arrivals close to the earliest estimate, prefer the higher priority within that group, and use robot ID as a final deterministic tie-breaker. I assume the ETAs have been adjusted to the same decision time using the message timestamps. I’ve shown a conservative yield when an ETA is unavailable or invalid, rather than treating the protocol’s −1 sentinel as an early arrival.
if blocked_locally() or red_light():
return STOP
peers = intents_for(my_intersection)
contenders = peers + [my_intent]
if any_unknown_eta(contenders):
return YIELD
first_eta = min(p["eta"] for p in contenders)
tied = near_first_arrival(
contenders, first_eta, tie_window)
winner = min(tied, key=priority_then_id)
return GO if winner == my_intent else YIELDHere, priority_then_id sorts higher priorities first and then lower IDs. tie_window is an illustrative tolerance, not a measured setting. This explains a consistent ETA-first decision; it isn’t a reservation protocol or proof that independently received messages give every robot the same view.
How I organized the checks in a behavior tree
I used a behavior tree so I could keep traffic rules, coordination, and route following in separate parts of the decision process. In a sequence, each child needs to succeed before the next one can run; a failure stops that sequence, while RUNNING means an action still has work to do.
For the simplified tree below, I use a reactive sequence so the earlier conditions get checked again while route following is running. I let the arrival-order node select a GO or YIELD mode and finish successfully, then pass that mode to the controller.
tree = ReactiveSequence(
LocalPathIsClear,
TrafficRulesAllowMotion,
SelectRightOfWayMode,
FollowRouteWithinLimits
)
if tick(tree) == FAILURE:
cancel_route_action()
publish_stop()If a required condition failed, I’d halt the route action and send a stop command to the controller. Selecting YIELD was different: I could still permit a restricted, clearance-checked motion mode rather than treating every yield as a failed safety condition. This is a conceptual tree showing that separation, not a full export of the project’s behavior tree.
Turning the decision into movement
I used Hybrid A* to produce a global route as a sequence of poses, including the heading the robot should have along the way. I then used the Dynamic Window Approach, or DWA, to choose the next linear and angular velocity. I passed the behavior tree’s decision into that local search so yielding changed which motions were allowed, while I kept publishing the robot’s intent.
How the local controller chose a command
I treated DWA as a search over velocity commands the robot could reach from its current motion. I checked their short predicted trajectories for collision risk, then compared the remaining candidates using route alignment, clearance, and speed.
if decision == STOP:
return 0.0, 0.0
commands = reachable_velocities(state)
commands = apply_mode(commands, decision)
safe = collision_and_braking_checks(commands)
if not safe:
return 0.0, 0.0
chosen = max(safe, key=path_clearance_speed)
return chosen.linear, chosen.angularIn this pseudocode, I use apply_mode to restrict the commands when the decision is YIELD; STOP produces a zero-velocity command. I still check collision risk and braking clearance before scoring progress, so a command that follows the route well doesn’t get to skip those checks.
I also kept coordination separate from immediate obstacle handling: being first in the arrival order didn’t mean the crossing was physically clear.
Checking a detection across several frames
I fine-tuned YOLOv8n on Gazebo images to detect signs, traffic lights, and pedestrians, but I found that reacting to each frame independently made isolated false detections disruptive. I tracked detections across frames and used a short vote for each track before committing its label to the scene.
frames = recent_frames(track_id, count=5)
votes = sum(
f.seen and f.label == "pedestrian"
and f.confidence >= 0.45
for f in frames
)
confirmed = votes >= 3What the vote could and couldn’t establish
I used the last five frames for the same tracked object, including frames where it wasn’t detected, and counted pedestrian detections at confidence of at least 0.45. I required three supporting frames, so three old detections spread across a longer gap couldn’t confirm the track. That gave me a way to reject an isolated detection without asking for a very high confidence on every frame.
For example, I’d count three supporting frames in [0.82, missing, 0.30, 0.77, 0.70] for the same pedestrian track. The missing frame and the low-confidence frame don’t support the vote, but the three good detections don’t have to be consecutive.
I still had to account for the delay that voting introduced, which depends on the camera’s frame cadence, especially when a person appeared from behind an obstacle. Agreement across frames didn’t prove a track was correct, and it didn’t replace the local controller’s obstacle checks. Tracking errors could also mix observations from different objects.
Checking progress as well as collisions
I evaluated the system over 200 simulated runs and recorded safe arrival in 94% of them, with intersection deadlocks falling from 1.46 to 0.18 per run compared with the baseline. I counted a run as a safe arrival only when it finished without a collision or timeout, because waiting forever wasn’t a useful solution.
I found the arrival estimate especially useful when I removed message fields in separate tests. It helped me make the right-of-way decision explicit, but dense pedestrian crossings still exposed cases where the robots waited until the run timed out.
What I would test next
I’d test delayed and missing intent messages, different robot speeds, and disagreements between the estimates each robot receives. I’d add a stale-intent timeout with a conservative fallback and check whether the fleet could recover afterward.
I’d also rerun the perception and motion checks on physical robots, because the Gazebo results don’t establish how the same vote window or local clearance model would behave with real sensors. The result I wanted to understand was whether I could keep both safe motion and useful progress when the shared information became less reliable.