Difference between revisions of "Swarm Robot Project Simulator"

From Mech
Jump to navigationJump to search
Line 57: Line 57:


=Recording a movie=
=Recording a movie=
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length, in frames. The movie will be saved as "movie.avi" in the same directory as the simulator M-file.
To record a run of the simulation, simply set MOVIE_FRAME_COUNT to the desired movie length, in frames. The movie will be saved as "movie.avi" in the same directory as the simulator M-file.


Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression. See [[Swarm Robot Project Documentation#Making Videos with Overlays]].
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression. See [[Swarm Robot Project Documentation#Making Videos with Overlays]].

Revision as of 22:04, 24 May 2009

The simulator is a part of the Swarm Robot Project that attempts to model the robots using MATLAB. It is built around a generic control structure so that it can be easily adapted to run other algorithms. Features include: asynchronous update cycles, a packet model, lossy communication, and flexible rendering options.

Getting started

To run the simulator:

  1. Download the m-file
  2. Open it and press Run.
  3. If prompted, select "Change Directory".

This version implements the formation control algorithm. When run, the swarm will start centered around a random location and then converge in on the goal moments (the stationary green ellipse). The user may click a location on the grid to restart the simulation with the robots centered around that point.

Constants

The constants at the top of the M-file (denoted by all-caps) give the user a great deal of control over the performance and rendering of the simulation without having to understand the code.

See the inline comments for details.

Control structure

Control structure flow chart. Blue boxes represent functions that can be found in the code.

The control structure is the logic portion of the code, representing code that might actually be run on the e-pucks. It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.

The whole control structure is called from updateBotComputations. Information about neighbors flows to and from the consensus estimator via the packet model.

Environment

The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.

Time model

The simulation advances in timesteps; equally spaced spans of time. Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).

The main loop runs once per timestep. It moves the robots along their chosen velocity vectors every timestep and makes calls to time-dependent update functions as needed.

Data model

Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called bots. Each bot is individually represented as a structure, with the following fields:

  • bots vector of N robots
    • state information the robot knows about itself
      • p position (arranged randomly inside a square of side length SIDE, centered about a specified point)
      • angle rotational orientation
    • packets vector of N received packets (packet i of bot i is that robot's own estimate and does not age like the rest)
      • age timesteps since received
      • v PI decision variable
      • w PI estimator state
    • u velocity
    • lastUpdate timestep of last update
    • waitTime timesteps between previous update and next update

Packet model

Consensus information is transferred between the e-pucks using wireless communications. The simulator transfers packets between robots on an asynchronous basis and includes the possibility of packet loss as a function of distance. Each robot's packets vector contains the most recently received packet from each of its neighbors. A robot will transmit its own consensus information just before its control structure is executed.

Packet loss is modeled by a cumulative Rice function, as advised by problem of Wi-Fi radio-fading simulation: Solution and applications. As distance between agents increases, the probability of receiving a packet decreases.

Visualizing packet loss

Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.

Between two agents...

  • a black line means at least one agent has a fresh packet from the other.
  • a red line means neither has fresh data, but at least one is using stale data.
  • no line means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.

Recording a movie

To record a run of the simulation, simply set MOVIE_FRAME_COUNT to the desired movie length, in frames. The movie will be saved as "movie.avi" in the same directory as the simulator M-file.

Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression. See Swarm Robot Project Documentation#Making Videos with Overlays.