Pathfinder.m
directs a swarm of robots to follow individual paths within the testbed from waypoint to waypoint, iteratively awaiting the swarm's convergence on each set of waypoints before advancing to the next set of waypoints. It demonstrates the key fundamentals underlying OpenSwarm, leveraging the Actor
classes Vision.m
, Navigator.m
, Messenger.m
, and Plotter.m
along with the Model
classes Environment.m
, Point.m
, Position.m
and Burst.m
to track and guide robots in the field.
As currently configured, Pathfinder.m
reads the sequence of waypoints which determine each robot's path from a CSV file, allowing one to conduct repeatable experiments on a predetermined path.
With slight modification, however, the code of Pathfinder.m
could easily be utilized to generate and/or update such waypoints during run-time, opening the door to adaptive control algorithms responsive to the real-time state of the swarm. As such, Pathfinder.m
provides a wonderful encapsulation of what's possible with OpenSwarm.
Note that the Vision.m
class is responsible for all webcam image processing and positional tracking of the robots, and that
- Robots are assigned IDs 1, 2, 3, ..., n based on their distance from the origin of the testbed in the first image frame processed by
Vision.m
, and - Robot IDs are reassigned from frame to frame by a between-frame nearest-neighbor search (such that
Vision.m
inductively "knows" which robot is which in any given frame by comparing it to the last frame, and makes the above assumption to assign IDs on the first frame).
Without diving too deeply into the implementation details of Vision.m
, this means that in order for Pathfinder.m
(and, by extension, any program leveraging Vision.m
) to properly function:
- Robot with
ID = 1
flashed to itsConfiguration.h
file should be nearest the testbed origin before running the script, - Robot with
ID = 2
flashed to itsConfiguration.h
file should be 2nd nearest the testbed origin before running the script, etc...
An easy way to achieve such a valid starting position is to simply order the robots by ID along the bottom x-axis of the testbed prior to running the script. See the video below for an example.
initialize dependencies
read targets from csv
for i in (1, number of targets in sequence) do:
while (swarm is not converged on this target set) do:
take webcam photo and update robot positions
compare positions to targets and generate directions
send directions to swarm
wait for swarm to execute directions
end while
update targets to next set in sequence
end for
Example run of Pathfinder.m
with circle.csv
as path input: