<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NealEhardt</id>
	<title>Mech - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NealEhardt"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/NealEhardt"/>
	<updated>2026-04-14T09:08:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Setup,_Use,_and_Modeling_of_Harmonic_Drive_Motors_with_Junus_Amps&amp;diff=22150</id>
		<title>Setup, Use, and Modeling of Harmonic Drive Motors with Junus Amps</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Setup,_Use,_and_Modeling_of_Harmonic_Drive_Motors_with_Junus_Amps&amp;diff=22150"/>
		<updated>2013-05-16T16:29:09Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Motor Modeling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting up the Junus Amplifier =&lt;br /&gt;
&lt;br /&gt;
[[Image:power_supply_diagram.png|thumb|Power Supply Diagram|right]]&lt;br /&gt;
The first thing you need to run the amplifier is to find a DC power source that outputs 20-90V with a maximum current greater than what you expect your motor(s) to draw.  This should be connected to the amplifier according to the following diagram, where the capacitors and diodes are rated for the voltages/currents you are expecting to see.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, use the USB to RS-232 cable to connect the amp to your PC.  If this doesn&amp;#039;t work you will need to find and install the driver for the HL-340 USB to serial converter (there is a copy of the driver in the folder Philip&amp;#039;s Files\usb-serial-driver.zip on the desktop of the PC used for the QNX manipulation project).  You will also need to download and install [http://www.copleycontrols.com/Motion/Downloads/index.html CME2] (Copley Motion Explorer); note that Copley&amp;#039;s documentation for the amplifier and software can also be downloaded from the same page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
[[Image:copley_basic_setup.png|thumb|Basic Setup Menu|right]]&lt;br /&gt;
Open the program and add the COM port used by the USB to serial cable to the list (the list can be changed later in the Tools -&amp;gt; Communication Wizard menu).  Next go to Amplifier -&amp;gt; Basic Setup.  Here you select from the different operational modes and input types.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Operating Modes ==&lt;br /&gt;
* Current - This is the most commonly used mode.  Here, the amplifier will create an output current proportional to some input signal to drive the attached actuator.  In this mode there is only one control loop running within the amplifier making it the preferred choice (the more control that can be done outside the amp, the less of a black box it is).&lt;br /&gt;
* Velocity - This mode takes the current control mode and adds another feedback loop around the current control loop so that the velocity of the motor is proportional to the input signal.  For the Junus amps, the motor speed is estimated from the back emf of the motor during use, making it less reliable than the current control mode.&lt;br /&gt;
&lt;br /&gt;
== Command Sources ==&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
[[Image:junus_amp_pin_diagram.png|thumb|Junus Amp Input Pin Diagram|right]]&lt;br /&gt;
The pin diagram for the Junus amp is found to the right.&lt;br /&gt;
* Analog Command - In this mode, an analog input is connected to pins 2 and 9, with the analog reference voltage going to pin 9 and the signal going to pin 2.  The voltage range for the input is +/- 10V with the output being proportional to the voltage, i.e. 0V is 0A (or 0rpm) output, +10V is maximum positive current output, and -10V is maximum negative current output.&lt;br /&gt;
* PWM Command - In this mode the output is related to the duty cycle of the PWM signal in one of two ways.  To switch between these modes, click on the PWM command button in the block diagram.&lt;br /&gt;
** 50% mode - This mode uses a single input pin (pin 3).  Here a 50% duty cycle is the zero point (0A or 0rpm) with 0% being fully negative and 100% being fully positive.&lt;br /&gt;
** 100% mode - In addition to the PWM input pin there is an extra input pin (pin 4) to control the sign (or direction) of the output.  Here, a 0% duty cycle is the zero point, 100% duty cycle with the direction pin LO is fully negative and 100% duty cycle with the direction pin HI is fully positive.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now click on the Motor button in the block diagram.  Here you can input all the necessary parameters about your motor from the data sheet, or that you experimentally found.  Now you are ready to look at the control loop.  There is a PI controller with tunable parameters used to control the output current.  While you are welcome to play around with the parameters on your own, I would suggest that you click on the I Loop button and select Auto Tune, at least to get a starting point for the parameters.  It will give you several options based on different levels of aggressiveness of the controller.&lt;br /&gt;
&lt;br /&gt;
Click on Input/Output.  Here you can set up the different input and output pins.  I recommend using IN1 as Amp Enable-HI (or LO) Enables With Clear Faults (pin 13).  This ensures that the motor can only spin when you give it a command to turn on.  Choose HI if your digital outputs default to LO, or vice versa, as it can vary depending on the presence of pull-up resistors, etc.  You now have your amp configured and you are ready to start controlling your motor.&lt;br /&gt;
&lt;br /&gt;
There are also a couple of other utilities built into the CME2 software.  The first is the Control Panel (second button from the left in the top menu).  This allows you to software enable/disable the amplifier as well as monitor various inputs/outputs of the motor during use.  The other is the Scope (third button from the left in the top menu).  This lets you apply various functions to drive the motor and monitor inputs/outputs over time.  This is useful for making sure your control parameters are tuned the way you like them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Using the Motor =&lt;br /&gt;
&lt;br /&gt;
If you are using analog command mode, a simple test to make sure your setup is working correctly is to connect the enable pin to +5V (or GND, depending on how it was configured) and use a potentiometer to control the input voltage and make sure the motor spins as you would expect it to.  As a reminder, 0V is 0 output, negative voltage will move it in one direction and positive voltage in the other.&lt;br /&gt;
&lt;br /&gt;
If you are using PWM command mode, a more involved test would be to do the activity found [[ME 333 Lab 4 | here]].  For our system, the plant would be the entire amp/motor package and feedback loop in the diagram at the top is designed to control the position of the motor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Motor Modeling =&lt;br /&gt;
&lt;br /&gt;
For our purposes, we have chosen to model the motor using the following equation, where &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; is the output torque, &amp;lt;math&amp;gt;k_m&amp;lt;/math&amp;gt; is the motor constant, &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the command current, &amp;lt;math&amp;gt;\mu_d&amp;lt;/math&amp;gt; is the dynamic friction coefficient, &amp;lt;math&amp;gt;\mu_s&amp;lt;/math&amp;gt; is the static friction, &amp;lt;math&amp;gt;\omega&amp;lt;/math&amp;gt; is the speed of the motor, and the &amp;lt;math&amp;gt;sgn&amp;lt;/math&amp;gt; function returns the sign of its argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \tau = k_m i - \mu_d \omega - \mu_s sgn(\omega) \,&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This can be easily solved to find the necessary command current (and thus the analog or PWM input) needed to follow a reference trajectory, which would be the feedforward model of our system.&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
To determine the values of the parameters in the above equation, you should run a series of tests at various input levels to make sure the parameters are constant at various speeds and accelerations of the motor.  To set up the experiment you will need a mount for the motor (a table-mount vice works well), an object of known inertia (ex. momentum wheel), and you will need to hook up the encoder on the motor to a device that can read it in (ex. decoding chip connected to a PIC).&lt;br /&gt;
&lt;br /&gt;
== Experiment ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
[[Image:motor_model_wiring.png|200px|Wiring diagram for the motor modeling setup|right]]&lt;br /&gt;
For each run of the experiment, the motor is driven by three periods of a square wave current at a specified amplitude.  Multiple periods are used to allow transient behavior to die down and for filtering purposes, described in the following section.  During each run the position from the encoder is recorded and post-processing is used to find the velocity and acceleration associated with the trajectory.&lt;br /&gt;
&lt;br /&gt;
Code used to drive the motor during the experiment can be downloaded [[Media:motor_model_PIC_code.zip|here]].  This code is meant to be run on the [Introduction to the PIC32|PIC32 board].  The basic wiring diagram is to the right and the datasheet for the LS7083 decoder can be found here [http://pdf1.alldatasheet.com/datasheet-pdf/view/71312/LSI/LS7083.html] and includes all the wiring diagrams necessary.&lt;br /&gt;
&lt;br /&gt;
To actually run the experiment, use the MATLAB code [[Media:motor_model_analysis_code.zip|here]].  The function dataCollection takes in the amplitude of your square wave current and outputs this to the amp.  It then collects the trajectory data and saves it to a .mat file (see file for details on directory and file name format).  Note that the COM port, Imax (maximum current set on the amp), and other variables must be changed in both the MATLAB code and the amp or PIC.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Filtering ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
[[Image:filtering_example.png|200px|An example of filtering data|right]]&lt;br /&gt;
To find the velocity and acceleration of the motor during the experiment, the raw data from the encoder must be smoothed otherwise there are large spikes in the calculated derivatives due to signal noise, etc.  To smooth the data, a moving average is used (this is why we collected extra periods of data, so we can still apply the moving average to the end points).  The idea of a moving average is the filtered value at a specific time is the average of the unfiltered value and the nearest N values in each direction.  Choosing a low N leads to less smoothing but retains more of the original data.  I found that an N of 5 was good for my data set, but this will be different for each application depending on the amount of noise, etc.  The number of points to use in the filter is the second (and optional) argument to the MATLAB file fitParameters.  In this function, the raw data is first smoothed using the moving average, then finite differences are used to calculate the velocity.  This is then smoothed using the same moving average and finite differences are used again to find the acceleration.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Fitting Parameters ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
[[Image:model_example.png|200px|An example of motor model data|right]]&lt;br /&gt;
Now that you have the acceleration, you can easily find the torque because you know the inertia of the object being rotated.  Going back to the model, you now have the torque and velocity so you can solve for the three unknowns.  You can also choose to model the motor as having a different set of parameters for positive and negative torques, something I found to work better than a single set of parameters.&lt;br /&gt;
&lt;br /&gt;
In the figure to the right, an example of a motor model is shown, with trials run at 50 mA intervals from 150 to 400 mA.  The filtered data is plotted as the dots and the ideal model based on the calculated parameters are the solid lines, this type of plot can be generated from the function batchProcess.  In this plot, the effect of filtering is evident in the rounded edges near the transition points (crossing zero velocity and zero acceleration lines).  You can also see the motor is reaching its maximum speed at 200 mA.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14574</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14574"/>
		<updated>2009-12-01T04:22:17Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Versions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Versions=&lt;br /&gt;
There are now two versions of the simulator that implement different algorithms.  They both use the same control structure, which this article outlines in context of the formation control algorithm.&lt;br /&gt;
&lt;br /&gt;
==Formation control==&lt;br /&gt;
File: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
&lt;br /&gt;
Here the robots orient themselves so that their moments (quantifiers of the group&amp;#039;s shape and position) match a predefined set of goal moments.&lt;br /&gt;
&lt;br /&gt;
The swarm will start centered around a random point and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Environment sensing==&lt;br /&gt;
File: [[Image:Swarm_Robot_Project_Simulator_environment.zip]]&lt;br /&gt;
&lt;br /&gt;
Here the robots are placed in an environment with up to 3 variables that are functions of location.  The robots collaboratively model these variables and relocate themselves to get optimal sensor readings.&lt;br /&gt;
&lt;br /&gt;
The swarm starts clustered at a random location in an environment with randomly chosen parameters.  The three environment variables are displayed on top of each other as red, green, and blue.  Click on an agent to open a plot of its error (a black field indicates perfect estimate of all colors).  The environment function is defined in &amp;#039;&amp;#039;basefunction.m&amp;#039;&amp;#039; and it can be changed to anything.&lt;br /&gt;
&lt;br /&gt;
For this application, the agents&amp;#039; states have three extra data fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;Y&amp;#039;&amp;#039;&amp;#039; information matrix&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;Tau&amp;#039;&amp;#039;&amp;#039; information vector&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;sensorR&amp;#039;&amp;#039;&amp;#039; sensor covariance&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download one of the zip files above.&lt;br /&gt;
# Extract the &amp;#039;&amp;#039;Simulator&amp;#039;&amp;#039; folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Code organization==&lt;br /&gt;
Each M-file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  At the top of &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;, you will find some constants (denoted by all-caps) that make it easy to change the performance and rendering of the simulation without having to read into the code.  See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes from the flowchart to the right represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
Note: the present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment is a set of abstractions that encapsulate the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a struct, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the agent knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of bot &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is that agent&amp;#039;s own estimate and always has an age of 0.)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity chosen by Controller&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between last update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/ The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;br /&gt;
&lt;br /&gt;
[[Category:SwarmRobotProject]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=14560</id>
		<title>Swarm Robot Project Documentation</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=14560"/>
		<updated>2009-11-18T20:53:15Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Simulator */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
==Overview==&lt;br /&gt;
Nullam tincidunt, tellus sit amet elementum imperdiet, nunc arcu imperdiet nisl, vitae hendrerit erat nulla eu erat. Vivamus suscipit ante quis leo volutpat mollis. Proin placerat dui id arcu fringilla aliquam. In nec felis a ligula molestie ultrices. Curabitur dapibus vulputate nulla fermentum sollicitudin. Mauris id dui neque, et ultricies ante. Maecenas ac arcu at mauris posuere ultricies at sit amet magna. Etiam eu eros nunc, non hendrerit dui. Morbi blandit dui sed orci euismod eget dignissim purus fermentum. Curabitur nunc arcu, auctor et semper eu, aliquet a odio. Nam ut leo at sapien dictum luctus eu non nibh. &lt;br /&gt;
&lt;br /&gt;
To quickly get a grasp of how to run the &amp;#039;&amp;#039;&amp;#039;Swarm Consensus Estimation Project&amp;#039;&amp;#039;&amp;#039;, refer to the &amp;#039;&amp;#039;&amp;#039;[[Swarm_E-puck_Quickstart_Guide|Swarm e-puck Quickstart Guide]]&amp;#039;&amp;#039;&amp;#039;. This guide provides instruction on setting up the computer systems, what programs to run, and how to configure the e-pucks. For more detailed information about each step, such as program configuration, etc, please read through this article.&lt;br /&gt;
&lt;br /&gt;
==The e-puck==&lt;br /&gt;
The e-puck is a cylindrical robot from EPFL with a diameter of 70 mm and a height of 53 mm, with a stepper motor driven wheel mounted on each side of the body.  The small size of the e-puck made it ideal for the project, and the stepper motor driven wheels offered consistency and accuracy, both of which are highly desirable features for experiments requiring motion planning and dead reckoning. In order to address the requirement for wireless communication, the original extension module on the e-puck which contained peripherals including a speaker, infrared receiver, and mode selection switch, was replaced by a custom-made extension module that held an XBee radio module which connected to the serial port of the microcontroller.  &lt;br /&gt;
&lt;br /&gt;
Information about the e-puck can be found at [http://www.e-puck.org/ http://www.e-puck.org/], and additional documentation by going to &amp;#039;&amp;#039;&amp;#039;Download&amp;gt;Documentation&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
===[[Swarm_Project_E-puck_Code|e-puck code]]===&lt;br /&gt;
The Swarm Consensus Estimation Project E-puck code can be downloaded here: &amp;#039;&amp;#039;&amp;#039;[[Media: Swarm_epucks_code.zip|Swarm Consensus Project e-puck Code]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Documentation of the code can be found at &amp;#039;&amp;#039;&amp;#039;[[Swarm_Project_E-puck_Code|Swarm Consensus Project e-puck Code Documentation]]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The e-puck code was written in C and compiled using Microchip&amp;#039;s &amp;#039;&amp;#039;MPLAB C Compiler for dsPIC DSCs&amp;#039;&amp;#039; (student version).  The student version can be downloaded from [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en535363 Microchip&amp;#039;s website].  When you set up the project, be sure to add the linker library file (libp30F6014A-coff.a) and linker script (p30f6014A.gld) in the project.&lt;br /&gt;
&lt;br /&gt;
*Note that the e-pucks will start out in &amp;#039;sleep&amp;#039; mode, meaning they do not send out packets, nor do they move.  Use the [[Machine_Vision_Localization_System#Commands|&amp;#039;wake&amp;#039; command]] in the vision system command window to wake the e-pucks.&lt;br /&gt;
&lt;br /&gt;
==Packet Structure==&lt;br /&gt;
The send and receive packets (for the XBee radios using their proprietary API mode) are different, e.g. the packet received by one PIC is not the exact copy of the packet what was sent out of the other PIC&amp;#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters. Using API 2 packets is important in order to ensure that corrupted or incomplete packets are dropped. For more information about the API modes (1 and 2), and their uses, refer to [http://www.digi.com/support/kbase/kbaseresultdetl.jsp?kb=184 this] and [http://www.digi.com/support/kbase/kbaseresultdetl.jsp?id=2199 this] as well as the XBee [http://www.digi.com/products/wireless/point-multipoint/xbee-series1-moduledocs.jsp manual and datasheets].&lt;br /&gt;
&lt;br /&gt;
===Data Frame===&lt;br /&gt;
The data frame of the packet contains the data needed for the swarm consensus estimator, as well as any additional statistics that we may wish to piggyback with the packet (for example, position and orientation data for data logging).&lt;br /&gt;
&lt;br /&gt;
The data frame (in its current state) contains 15 floating point numbers.  The contents are as follows:&lt;br /&gt;
#x_1&lt;br /&gt;
#w_1&lt;br /&gt;
#x_2&lt;br /&gt;
#w_2&lt;br /&gt;
#x_3&lt;br /&gt;
#w_3&lt;br /&gt;
#x_4&lt;br /&gt;
#w_4&lt;br /&gt;
#x_5&lt;br /&gt;
#w_5&lt;br /&gt;
#Robot X coordinate&lt;br /&gt;
#Robot Y coordinate&lt;br /&gt;
#Robot Theta orientation&lt;br /&gt;
#Robot left wheel speed&lt;br /&gt;
#Robot right wheel speed&lt;br /&gt;
&lt;br /&gt;
Each individual number is a 32-bit floating point value, or 4 bytes each, which means that the data frame is 60 bytes long (15 x 4 = 60), although it could be longer if escape characters are needed (see &amp;#039;&amp;#039;API Operation&amp;#039;&amp;#039; in the XBee Manual).&lt;br /&gt;
&lt;br /&gt;
Additional values may be added to the packet data frame. For example, the e-pucks currently are fitted with a color sensor board, allowing the e-puck to detect the color  of the environment it is in. Tracking and logging these values (red, green, blue) is important, and thus three additional values are added to the data frame. Consequently in the packet handling (XBeePacket) code, the &amp;quot;additional_num&amp;quot; value must be changed from 5 to 8 to accommodate three additional values. This change must be made across all the packet handling code, on both the computers and e-pucks, as an e-puck will not be able to read code with 15 values if its own code is changed to send/receive 18 value packets. The resulting packet data frame would contain the same values 1 - 15 as above, but also 16, 17 and 18, which would represent the R, G, and B values from the color sensor.&lt;br /&gt;
&lt;br /&gt;
==XBee Radios==&lt;br /&gt;
The XBee radio module is a low-cost, low-power (1mW) radio that uses the IEEE 802.15.4 standard (which specifies the physical layer and medium access control layer of the network) and operates on the 2.4GHz ISM frequency band.  Each module contains both a RF transceiver and a microcontroller whose firmware provides a basic implementation of networking capabilities such as addressing, packet, and checksums.  The radios together form a peer-to-peer network where each member of the network can broadcast messages to any other member of the network.  The XBee module communicates with the PIC microcontroller on the e-puck via the serial port using the RS-232 serial data transfer protocol at 115200 bauds per second.&lt;br /&gt;
&lt;br /&gt;
Due to the robust nature of the swarming algorithm, some packet loss was acceptable; packet recovery schemes were foregone in favor of simplicity and lower power consumption.  &lt;br /&gt;
&lt;br /&gt;
===XBee Radio Configuration===&lt;br /&gt;
The XBee radio has 20 input/output pins whose signals and functions can be found in section 1.5 in the user’s manual.  The only pins that are of particular interest us are:&lt;br /&gt;
*Pin 1: 3.3V Power&lt;br /&gt;
*Pin 2 (output): UART Data Out&lt;br /&gt;
*Pin 3 (input): UART Data In&lt;br /&gt;
*Pin 10: Power Ground&lt;br /&gt;
*Pin 12 (output): CTS flow control&lt;br /&gt;
*Pin 16 (input): RTS flow control&lt;br /&gt;
&lt;br /&gt;
The RTS and CTS signals are for flow control.  When the RTS line is pulled low, the XBee module will hold any data waiting to be sent to the microcontroller in a buffer until the line is pulled high again.  When the buffer is almost full, the XBee module will pull the CTS signal high.&lt;br /&gt;
&lt;br /&gt;
Details about the XBee radio and its operation can be found in the user’s manual.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Two firmware options for the microcontroller are available from Digi.  The first option implements a suite of networking capabilities including packets, checksums, addressing, and diagnostics; this implementation is specific to the XBee radios and not compatible with other wireless devices.  The second option is a ZigBee protocol stack, which is a mesh networking standard for low data rate networks.  Because routing and mesh networking capabilities were not needed for this project, the first option was used for simplicity.&lt;br /&gt;
&lt;br /&gt;
The XBee module can be configured using the X-CTU terminal program from Digi, either by sending commands from the terminal or by using the configuration utility found under the “Modem Configuration” tab.  Entering the &amp;#039;&amp;#039;&amp;#039;+++&amp;#039;&amp;#039;&amp;#039; string into the terminal will make the radio enter command mode.  Wait until the XBee return The functions of the commands are described below:&lt;br /&gt;
&lt;br /&gt;
====Configuration for e-puck XBee radios====&lt;br /&gt;
For this project, each of the radios on the e-pucks were configured by typing the following commands into the terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
+++&lt;br /&gt;
atre&lt;br /&gt;
atmy &amp;lt;ID&amp;gt;&lt;br /&gt;
atap 2&lt;br /&gt;
atd6 1&lt;br /&gt;
atbd 7&lt;br /&gt;
atwr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;ID&amp;gt; is an ID number used to differentiate the radios.  The firmware on the e-puck requires that the IDs range from 0 to 31.  In our case, the XBee radios on the robots were given ID numbers 1 through 8, and the base station radio was given an ID of 0.  &lt;br /&gt;
&lt;br /&gt;
====Configuration for base station/data logger XBee radios====&lt;br /&gt;
In order to distinguish the radios used by the vision system, real-time display, and data logger, we give them the ID 0 (which means that no robot should have an XBee with ID 0.  When a robot received a packet from radio ID 0, then it knows that it is from the vision system computer.).  The configuration is the same, except that we do not need flow control, and the ID is always 0.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
+++&lt;br /&gt;
atre&lt;br /&gt;
atmy 0&lt;br /&gt;
atap 2&lt;br /&gt;
atbd 7&lt;br /&gt;
atwr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;3&amp;quot;&lt;br /&gt;
|+&amp;#039;&amp;#039;&amp;#039;XBee AT Commands&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Description &lt;br /&gt;
|-&lt;br /&gt;
|  ATRE || Resets the radio parameters to their factory default.&lt;br /&gt;
|-&lt;br /&gt;
|  ATMY &amp;lt;ID&amp;gt;|| Sets the ID of the radio.&lt;br /&gt;
|-&lt;br /&gt;
|  ATAP 2 || Enables mode 2 of the radio’s API to enable &amp;lt;br&amp;gt;&lt;br /&gt;
advanced features such as packets and addressing&lt;br /&gt;
|-&lt;br /&gt;
| ATD6 1|| Enables the RTS flow control pin.  If this pin is pulled low, &amp;lt;br&amp;gt;&lt;br /&gt;
the XBee will hold bytes to be transmitted to the microcontroller in its buffer.&lt;br /&gt;
|-&lt;br /&gt;
| ATBD 7 || Sets to baud rate to 115200 bps.&lt;br /&gt;
|-&lt;br /&gt;
| ATWR|| Writes the new setting to non-volatile memory.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In order for the radios to be able to communicate, they must all be on the same channel and have the same network ID.  If the radios experience interference from other XBee radios, the channel or network ID can be changed.&lt;br /&gt;
&lt;br /&gt;
===XBee Interface Extension Board===&lt;br /&gt;
The XBee Interface Extension Board was created with Traxmaker.  The extension modules plug into the e-puck via [[Media:Samtec BTE-020-02-L-D-A.zip |Samtec BTE-020-02-L-D-A]] connectors, which can be obtained directly from Samtec or one of their distributors.  The Traxmaker parts library, which contains the connector and can be downloaded here: [[Media:Traxmaker_XBee_Lbrary.zip]].&lt;br /&gt;
====Current Version====&lt;br /&gt;
[[Image:e-puck_XBee_board_v1.gif|left|thumb]]&lt;br /&gt;
The Traxmaker file for the current version of the XBee extension board can be downloaded here :[[Media:e-puck_xbee_board_v1.PCB]].  Note that the CTS and RTS pins were connected to the sel2 and sel3 pins (instead of y0 and y1) by soldering on jumper wires.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Board In Development====&lt;br /&gt;
[[Image:epuck_xbee_board_v2.gif|thumb|left]]A version of the e-puck with a color sensor circuit built in can be downloaded here: [[Media:epuck_xbee_board_v2.zip|Xbee Interface Extension Board Version 2]].  This version uses a high-impedance op-amp to amplify signals from three photodiodes (for red, green, and blue), and feeds the outputs into the ADC channels formerly used by the X,Y, and Z axis accelerometers.  A 10k potentiometer adjusts the sensitivity for each channel of the amplifier.  The RTS flow control line on the XBee is connected to the sel3 line of the e-puck.  The CTS line is not hardwired to the sel2 pin, but can easily be connected with a jumper.&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Assembling the Boards====&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Parts:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#2x 10 pos. 2 mm pitch socket (Digikey S5751-10-ND)&lt;br /&gt;
#LE-33 low dropout voltage regulator (Digikey 497-4258-1-ND)&lt;br /&gt;
#2.2uF tantalum capacitor (Digikey 399-3536-ND)&lt;br /&gt;
#2x Samtec BTE-020-02-L-D-A (Order directly from Samtec)&lt;br /&gt;
#0.1&amp;quot;header pins for RTS and CTS pins (you can also use wire for a permanent connection.&lt;br /&gt;
#2x 0.1&amp;quot; jumpers for connecting RTS and CTS pins if you used header pins(Digikey S9000-ND)&lt;br /&gt;
&lt;br /&gt;
==Machine Vision Localization System==&lt;br /&gt;
A vision system was developed for robot localization, similar to GPS for each individual robot.  The system uses cameras mounted overhead and pattern recognition algorithms to track the position and orientation of various targets (robots) in a workspace, and radios the data to the respective robots.  The description of the system can be found at [[Machine_Vision_Localization_System]].&lt;br /&gt;
&lt;br /&gt;
==Simulator==&lt;br /&gt;
A MATLAB simulation of the swarm can be found here: [[Swarm Robot Project Simulator]].&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s early version implementing the formation control algorithm: [[Image:swarm_robot_simulation.zip]].&lt;br /&gt;
&lt;br /&gt;
==Analysis Tools==&lt;br /&gt;
There are some useful tools that can help you visualize the system, log data, and debug software.  They interface with an XBee radio through the serial port, and should be configured like the rest of the radios.  &lt;br /&gt;
==Real-time Display==&lt;br /&gt;
This is a real-time visualization system that displays the state of the system while it is running.  It will draw the ellipse representing the target (the black ellipse)It is written in MATLAB.  You can get the files here:[[Image:swarm_RT_display.zip]].&lt;br /&gt;
# Connect a configured XBee radio to the computer.  Be sure to give the radio ID 0.    If you are running another program that uses a serial port, such as the vision system, you will have to use another port and XBee radio.  Each serial port can only be accessed by one serial port at a time (therefore, you could have multiple radios connected to the same computer).&lt;br /&gt;
# Run the &amp;lt;tt&amp;gt;open_serial.m&amp;lt;/tt&amp;gt; script after replacing the &amp;#039;COM1&amp;#039; parameter in the &amp;#039;&amp;#039;&amp;#039;initXBeeSerial&amp;#039;&amp;#039;&amp;#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &amp;#039;q&amp;#039; to stop the logger.  Run the script again if you want to resume.  &lt;br /&gt;
#run the close_serial.m script to close the serial port when you are done.&lt;br /&gt;
&lt;br /&gt;
==Using the Data Logger with Timestamp==&lt;br /&gt;
Download the project here: [[Image:swarm_data_logger.zip]]&lt;br /&gt;
&lt;br /&gt;
This program connects to a configured XBee radio (make sure the ID is 0) at the serial port, and reads and parses any XBee packets it receives.  It will output two MATLAB files, &amp;lt;tt&amp;gt;main_log.m&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;run_me.m&amp;lt;/tt&amp;gt;.  The file &amp;lt;tt&amp;gt;main_log.m&amp;lt;/tt&amp;gt; contains all of the information in the received packets with a real-time timestamp (in seconds since the start of the program) added, and the file &amp;lt;tt&amp;gt;run_me.m&amp;lt;/tt&amp;gt; contains a short example on how to plot the data.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;It is important that you don&amp;#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&amp;#039;t be able to read it.  To stop logger, press &amp;#039;a&amp;#039;.  This will make it close the files correctly.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;main_log.m&amp;lt;/tt&amp;gt; output file, when run, will create several arrays in the work space.  It will also have a struct called &amp;#039;&amp;#039;&amp;#039;agents&amp;#039;&amp;#039;&amp;#039; which contains copies of these arrays--putting them in a struct makes it possible to access the data by manipulating indexes instead of variable names.  The vector &amp;#039;&amp;#039;&amp;#039;agent_list&amp;#039;&amp;#039;&amp;#039; contains the IDs of the agents whose data corresponds to the data in the &amp;#039;&amp;#039;&amp;#039;agents&amp;#039;&amp;#039;&amp;#039; struct.&lt;br /&gt;
&lt;br /&gt;
==Packet Data Viewer==&lt;br /&gt;
Download the project here: [[Image:swarm_packet_data_viewer.zip]]&lt;br /&gt;
&lt;br /&gt;
This program will display the raw data in the packets; it is useful for debugging.  Written with VC++.&lt;br /&gt;
&lt;br /&gt;
==Packet Sender==&lt;br /&gt;
Download the project here: [[Image:swarm_XBee_packet_sender.zip]]&lt;br /&gt;
&lt;br /&gt;
This program sends out XBee formatted packets in an infinite loop.  It is useful for debugging.&lt;br /&gt;
&lt;br /&gt;
==Making Videos with Overlays==&lt;br /&gt;
This section explains how to make a video with overlaid figures in MATLAB.  To make the video, you&amp;#039;ll need the footage, and the output file from the data logger.  To align the plotting coordinates with the real-world coordinates, we will use nine equally spaced points arranged in a rectangle centered at the origin for reference points (for example, we can use the center 9 of the 25 dots used to calibrate the camera.  Therefore, we need at least a frame where the dots can be seen.&lt;br /&gt;
&lt;br /&gt;
This script assumes that your camera is mounted above the workspace, pointed directly down.  It also assumes that your camera has no distortions, and that the x and y axes are perfectly horizontal and vertical, respectively.&lt;br /&gt;
&lt;br /&gt;
You can download the MATLAB files you need here: [[Image:swarm_plotting_files.zip]]&lt;br /&gt;
&lt;br /&gt;
Procedure for Taking the Video:&lt;br /&gt;
#Turn on all the robots.&lt;br /&gt;
#Start the video camera.&lt;br /&gt;
#Turn on and start the data logger.&lt;br /&gt;
#Turn on the vision system.&lt;br /&gt;
#Send commands to the swarm to change the settings if needed, and send the wake command to start the swarm.&lt;br /&gt;
#Send the sleep command the stop the swarm when done.&lt;br /&gt;
#Press &amp;#039;a&amp;#039; at the data logger window to close the file, and &amp;#039;q&amp;#039; to close the program.&lt;br /&gt;
#Turn off the video camera and robots.&lt;br /&gt;
&lt;br /&gt;
Procedure for generating the video:&lt;br /&gt;
#Extract the frames of the video with VirtualDub, starting at the moment the robots start moving from the wake command.&lt;br /&gt;
#Align the plotting axis and the real-world axis of video in Matlab.&lt;br /&gt;
#Run the script to generate the uncompressed video file.&lt;br /&gt;
#Compress the video.&lt;br /&gt;
&lt;br /&gt;
==Recording the Data==&lt;br /&gt;
To make a video with Matlab plots overlaid on top of the original footage, you need to log the messages from the base station as well as the robots while the video is running.  You should start the logger before sending out commands with the vision system, so that the logger can record the commands as well.&lt;br /&gt;
&lt;br /&gt;
==Extracting Frames with VirtualDub==&lt;br /&gt;
You can extract the frames from a video with a program called VirtualDub ([http://www.virtualdub.org http://www.virtualdub.org]).  VirtualDub is a free video processing program for splitting, compressing, and processing videos.&lt;br /&gt;
&lt;br /&gt;
Install VirtualDub, and open the video recording (VirtualDub can&amp;#039;t open all file types, but most .avi or .mpeg files should be fine).  &lt;br /&gt;
&lt;br /&gt;
#Move the slider to the frame where the final &amp;quot;wake&amp;quot; command is given (this should be when the robots start moving).  &lt;br /&gt;
#Click the &amp;#039;&amp;#039;Mark In&amp;#039;&amp;#039; button [[Image:virtualdub_markin.gif]] to indicate the start of the clip.  &lt;br /&gt;
#Move the slider to where you wish to end the video and click the &amp;#039;&amp;#039;Mark Out&amp;#039;&amp;#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &amp;#039;&amp;#039;&amp;#039;File&amp;gt;Export&amp;gt;Image Sequence...&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#Enter &amp;#039;&amp;#039;frame&amp;#039;&amp;#039; for filename, &amp;#039;&amp;#039;.jpeg&amp;#039;&amp;#039; for the filename suffix, and &amp;#039;&amp;#039;1&amp;#039;&amp;#039; for the minimum number of digits.  &lt;br /&gt;
#Make a folder named &amp;quot;Frames&amp;quot; and set it to be the output directory.&lt;br /&gt;
#Select JPEG as the file type, set quality to 100.&lt;br /&gt;
#Click OK to start extracting frames.&lt;br /&gt;
&lt;br /&gt;
[[Image:virtualdub_extract_frames.gif]]&lt;br /&gt;
&lt;br /&gt;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Aligning the Axes===&lt;br /&gt;
To generate the video, you first need to download the Matlab .m files: [[Image:swarm_plotting_files.zip]].&lt;br /&gt;
&lt;br /&gt;
Extract the files, and take the &amp;#039;&amp;#039;&amp;#039;Frames&amp;#039;&amp;#039;&amp;#039; folder holding the movie frames and &amp;#039;&amp;#039;&amp;#039;main_log.m&amp;#039;&amp;#039;&amp;#039; generated by the data logger, and put them in the extracted folder which also holds VIDEO_OVERLAY.m&lt;br /&gt;
&lt;br /&gt;
We must now align the plotting axes with the real world axes in the video, so that the position and SCALE will be correct when we overly the figures.  To do this, we will use nine equally spaced points arranged in a rectangle centered at the origin.  The alignment parameters are saved, so you only need to do this once if you don&amp;#039;t move the camera.  If need be, you can make a short video clip with marked points on the testbed just for alignment.&lt;br /&gt;
&lt;br /&gt;
To perform the alignment, &lt;br /&gt;
#Make sure RES is set to the width and height of the resolution of the frames, in pixels (e.g. [width height]).&lt;br /&gt;
#Go to DOT_X and DOT_Y and set these to the x-axis and y-axis spacing between each of the nine dots in the real world.&lt;br /&gt;
#Set TEST_OVERLAY_FITTING = 1 and GEN_MOV = 0 and run the script.  This will plot a square and nine &amp;#039;+&amp;#039; points in on top of the first frame of the video.  Make sure the square is a true square, and not distorted.&lt;br /&gt;
#Adjust X_OFFSET and Y_OFFSET until the center &amp;#039;+&amp;#039; is lined up with the center dot (the origin of the real world coordinate system).&lt;br /&gt;
#Adjust SCALE until the other 8 dots are well matched up.  SCALE will scale the axis, so increasing SCALE will increase the range of the axis, thus decreasing the unit distance.&lt;br /&gt;
#The overlay axes should how match the real world axes in the video.&lt;br /&gt;
#Reset TEST_OVERLAY_FITTING = 0.&lt;br /&gt;
&lt;br /&gt;
===Setting Configurations===&lt;br /&gt;
If you run the &amp;#039;&amp;#039;&amp;#039;VIDEO_OVERLAY.m&amp;#039;&amp;#039;&amp;#039; script with &amp;#039;GEN_MOV=0&amp;#039;, you can preview what the video will look like, but the video will not be saved.&lt;br /&gt;
&lt;br /&gt;
To generate the video, you need to enter the settings that you want.&lt;br /&gt;
*VIDEO_TIME=&amp;#039;&amp;#039;TIME_IN_SECONDS&amp;#039;&amp;#039;: (default = 75) This is the desired video duration in seconds.  You must have enough data and video frames to generate the video of this duration.&lt;br /&gt;
*FPS=&amp;#039;&amp;#039;FRAMES_PER_SECOND&amp;#039;&amp;#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&amp;#039;&amp;#039;GOAL STATISTICS&amp;#039;&amp;#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&amp;#039;s initial first moments and second central moments ([x y xx xy yy]).  If you change the goal from the command console and the data logger recorded it, these values will be overwritten.&lt;br /&gt;
*COMMR =&amp;#039;&amp;#039;COMMUNICATION_RADIUS&amp;#039;&amp;#039;  (default =  Inf) This is the default communication radius in millimeters.  If you change the radius from the command console and the data logger recorded it, this value will be overwritten.&lt;br /&gt;
&lt;br /&gt;
===Draw Options===&lt;br /&gt;
*DRAW_COMM_LINKS: =1 to draw communication links, =0 otherwise.&lt;br /&gt;
*DRAW_SWARM_ELLIPSE: =1 to draw actual ellipse representing swarm, =0 otherwise.&lt;br /&gt;
*DRAW_GOAL_ELLIPSE: =1 to draw the goal ellipse, =0 otherwise.&lt;br /&gt;
*DRAW_INDIVIDUAL_ESTIMATES: =1 to draw the individual estimates of the swarm of each robot, =0 otherwise.&lt;br /&gt;
*DRAW_ROBOT_MARKER_DOT: =1 to draw colored dots on top of the robots, = 0 otherwise.&lt;br /&gt;
*COMM_LINE_THICKNESS: the thickness of the lines if communication links are drawn.&lt;br /&gt;
*DOT_MARKER_SIZE: the size of dot marker if the dots are drawn.&lt;br /&gt;
&lt;br /&gt;
===Generate Movie File===&lt;br /&gt;
GEN_MOV: =1 to generate and save the movie (could take a long time), =0 for preview only (much faster, but video won&amp;#039;t be saved).&lt;br /&gt;
&lt;br /&gt;
===Repairing Damaged Videos===&lt;br /&gt;
Sometimes, the video generated by MATLAB will be damaged.  You can try to repair the file by opening it with VirtualDub, selecting &amp;#039;&amp;#039;&amp;#039;Video&amp;gt;Direct Steam Copy&amp;#039;&amp;#039;&amp;#039;, and then &amp;#039;&amp;#039;&amp;#039;File&amp;gt;Save as AVI&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
===Compressing the Video===&lt;br /&gt;
There are many ways to compress the video, including using VirtualDub or Quicktime.  To compress the video with Quicktime, open the video and select &amp;#039;&amp;#039;&amp;#039;File&amp;gt;Export&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
To use VirtualDub, select &amp;#039;&amp;#039;&amp;#039;Video&amp;gt;Full Processing Mode&amp;#039;&amp;#039;&amp;#039;, go to &amp;#039;&amp;#039;&amp;#039;Video&amp;gt;Compression&amp;#039;&amp;#039;&amp;#039; and select the compression you want to use (you must have the codecs installed on your system), and the go to &amp;#039;&amp;#039;&amp;#039;File&amp;gt;Save as AVI&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
[[Category:SwarmRobotProject]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_Robot_Project_Simulator_environment.zip&amp;diff=14553</id>
		<title>File:Swarm Robot Project Simulator environment.zip</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_Robot_Project_Simulator_environment.zip&amp;diff=14553"/>
		<updated>2009-11-17T19:55:08Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14552</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14552"/>
		<updated>2009-11-17T19:52:22Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Versions=&lt;br /&gt;
There are now two versions of the simulator that implement different algorithms: formation control and environment sensing.  They both use the same control structure, which this article describes from the perspective of the formation control algorithm.&lt;br /&gt;
&lt;br /&gt;
==Formation control==&lt;br /&gt;
File: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
&lt;br /&gt;
The swarm will start centered around a random point and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Environment sensing==&lt;br /&gt;
File: [[Image:Swarm_Robot_Project_Simulator_environment.zip]]&lt;br /&gt;
&lt;br /&gt;
The swarm starts clustered at a random location in an environment with randomly chosen parameters.  The agents monitor three variables, displayed as red, green, and blue.  Click on an agent to open a plot of its error (a black field indicates perfect estimate of all colors).  The environment function is defined in &amp;#039;&amp;#039;basefunction.m&amp;#039;&amp;#039; and it can be changed to anything.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download one of the zip files above.&lt;br /&gt;
# Extract the &amp;#039;&amp;#039;Simulator&amp;#039;&amp;#039; folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Code organization==&lt;br /&gt;
Each M-file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  At the top of &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;, you will find some constants (denoted by all-caps) that make it easy to change the performance and rendering of the simulation without having to read into the code.  See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes from the flowchart to the right represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
Note: the present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment is a set of abstractions that encapsulate the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a struct, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the agent knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of bot &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is that agent&amp;#039;s own estimate and always has an age of 0.)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity chosen by Controller&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between last update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/ The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;br /&gt;
&lt;br /&gt;
[[Category:SwarmRobotProject]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14207</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=14207"/>
		<updated>2009-08-27T20:12:59Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Packet model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the &amp;#039;&amp;#039;Simulator&amp;#039;&amp;#039; folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Organization==&lt;br /&gt;
Each M-file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  At the top of &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;, you will find some constants (denoted by all-caps) that 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.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes from the flowchart to the right represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
Note: the present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment is a set of abstractions that encapsulate the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a struct, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the agent knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of bot &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is that agent&amp;#039;s own estimate and always has an age of 0.)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity chosen by Controller&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between last update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/ The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;br /&gt;
&lt;br /&gt;
[[Category:SwarmRobotProject]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13301</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13301"/>
		<updated>2009-05-28T19:30:12Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the &amp;#039;&amp;#039;Simulator&amp;#039;&amp;#039; folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Organization==&lt;br /&gt;
Each M-file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  At the top of &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;, you will find some constants (denoted by all-caps) that 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.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes from the flowchart to the right represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
Note: the present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment is a set of abstractions that encapsulate the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a struct, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the agent knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of bot &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is that agent&amp;#039;s own estimate and always has an age of 0.)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity chosen by Controller&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between last update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13300</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13300"/>
		<updated>2009-05-28T04:37:48Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Data model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a struct, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the agent knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet &amp;#039;&amp;#039;i&amp;#039;&amp;#039; of bot &amp;#039;&amp;#039;i&amp;#039;&amp;#039; is that agent&amp;#039;s own estimate and always has an age of 0.)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity chosen by Controller&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between last update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13297</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13297"/>
		<updated>2009-05-27T15:42:28Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Time model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events, such as updating robot calculations or rendering.  Their size (relative to other time-based units) is defined by the constant &amp;#039;&amp;#039;dT&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13296</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13296"/>
		<updated>2009-05-25T19:14:38Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Consensus Input */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.  In the formation control implementation, this step causes the estimates to follow the agents instead of converging to the starting location.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13295</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13295"/>
		<updated>2009-05-25T19:02:28Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file: [[Image:Swarm_Robot_Project_Simulator.zip]]&lt;br /&gt;
# Extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_Robot_Project_Simulator.zip&amp;diff=13294</id>
		<title>File:Swarm Robot Project Simulator.zip</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_Robot_Project_Simulator.zip&amp;diff=13294"/>
		<updated>2009-05-25T19:00:25Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_simulator_control_structure.png&amp;diff=13293</id>
		<title>File:Swarm simulator control structure.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_simulator_control_structure.png&amp;diff=13293"/>
		<updated>2009-05-25T18:58:02Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13292</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13292"/>
		<updated>2009-05-25T18:47:38Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Control structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# [[Image:Swarm_Robot_Project_Simulator.zip|Download the zip file]] and extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simulator_control_structure.png|300px|right|thumb|Control structure flowchart]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&lt;br /&gt;
==Blue boxes==&lt;br /&gt;
The blue boxes represent functions that are defined in their own files.  They are the building blocks of the consensus-based swarm model.&lt;br /&gt;
&lt;br /&gt;
===Plant===&lt;br /&gt;
The interface between the agent and the environment.  For the formation control implementation, this models an e-puck following a velocity vector.&lt;br /&gt;
&lt;br /&gt;
===Sensors===&lt;br /&gt;
Consolidates information from the environment into a form readable by Consensus Input and the Controller.&lt;br /&gt;
&lt;br /&gt;
===Consensus Estimator===&lt;br /&gt;
A discrete-time PI estimator that uses packet structs for its input and output.&lt;br /&gt;
&lt;br /&gt;
===Consensus Input===&lt;br /&gt;
Injects the agent&amp;#039;s own information into the estimator-communication cycle.&lt;br /&gt;
&lt;br /&gt;
===Controller===&lt;br /&gt;
Uses the agent&amp;#039;s sensory and consensus information to select a set of controls, sent to the plant.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13291</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13291"/>
		<updated>2009-05-25T06:51:40Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# [[Image:Swarm_Robot_Project_Simulator.zip|Download the zip file]] and extract the Simulator folder.&lt;br /&gt;
# Open &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039; and press Run.&lt;br /&gt;
# When prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Files==&lt;br /&gt;
Each file is a MATLAB function.  The central one is &amp;#039;&amp;#039;simulator.m&amp;#039;&amp;#039;.  See Control Structure for details about the other ones.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flowchart.  Blue boxes represent functions that are defined in their own files.]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13290</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13290"/>
		<updated>2009-05-25T06:37:31Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file and extract the folder.&lt;br /&gt;
# Open simulator.m and press Run.&lt;br /&gt;
# If prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flowchart.  Blue boxes represent functions that are defined in their own files.]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating passage of time, motion of the agents, and lossy wireless communication.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
The main loop runs once per timestep.  It updates the plant every timestep and makes calls to time-dependent update functions as needed.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13289</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13289"/>
		<updated>2009-05-25T03:06:34Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The simulator is a part of the [[Swarm Robot Project]] that attempts to model the robots using MATLAB.  It is built around a modular 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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the zip file and extract the folder.&lt;br /&gt;
# Open simulator.m and press Run.&lt;br /&gt;
# If prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==What you&amp;#039;re seeing==&lt;br /&gt;
This version implements the formation control algorithm.  The swarm will start centered around a random location and then converge on the goal moments (shown as the stationary green ellipse).  The user may click a location on the grid to restart the simulation with the robots centered around that point.&lt;br /&gt;
&lt;br /&gt;
=Constants=&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flowchart.  Blue boxes represent functions that are defined in their own files.]]&lt;br /&gt;
The control structure represents the decentralized code that runs on the individual e-pucks.  It is written modularly and without extraneous dependencies so it can be readily adapted to other algorithms.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Collision avoidance==&lt;br /&gt;
The velocity output from the Controller is put through a collision avoidance algorithm.  It is not shown in the flowchart because the algorithm has access to the positions of all the agents (information not known to any single agent).&lt;br /&gt;
&lt;br /&gt;
The present algorithm does not work very well.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by setting the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because the last communicated packet is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, set MOVIE_FRAME_COUNT to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13288</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13288"/>
		<updated>2009-05-25T03:04:26Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Recording a movie */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the m-file&lt;br /&gt;
# Open it and press Run.&lt;br /&gt;
# If prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=Constants=&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
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 &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13283</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13283"/>
		<updated>2009-05-07T21:23:02Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
To run the simulator:&lt;br /&gt;
# Download the m-file&lt;br /&gt;
# Open it and press Run.&lt;br /&gt;
# If prompted, select &amp;quot;Change Directory&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=Constants=&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle&amp;#039;&amp;#039;&amp;#039; rotational orientation&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;#039; PI decision variable&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w&amp;#039;&amp;#039;&amp;#039; PI estimator state&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length, in frames.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13282</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13282"/>
		<updated>2009-05-07T18:58:25Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Control structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
=Constants=&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13281</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13281"/>
		<updated>2009-05-07T16:44:49Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
=Getting started=&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
=Constants=&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
=Control structure=&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
=Environment=&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Packet model==&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
=Recording a movie=&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13280</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13280"/>
		<updated>2009-05-07T16:44:13Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Packet model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
===Time model===&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Data model===&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
===Packet model===&lt;br /&gt;
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&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
===Visualizing packet loss===&lt;br /&gt;
Packet loss can be easily visualized by turning the constant DRAW_CONNECTIONS to true.&lt;br /&gt;
&lt;br /&gt;
Between two agents...&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a black line&amp;#039;&amp;#039;&amp;#039; means at least one agent has a fresh packet from the other.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;a red line&amp;#039;&amp;#039;&amp;#039; means neither has fresh data, but at least one is using stale data.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;no line&amp;#039;&amp;#039;&amp;#039; means neither agent is using data from the other because it is older than PACKET_AGE_LIMIT.&lt;br /&gt;
&lt;br /&gt;
==Recording a movie==&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13279</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13279"/>
		<updated>2009-05-07T16:30:13Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
The environment encapsulates the control structure, simulating wireless communications, passage of time, and the motion of the robots.&lt;br /&gt;
&lt;br /&gt;
===Time model===&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Data model===&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
===Packet model===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Each robot&amp;#039;s &amp;#039;&amp;#039;packets&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Packet loss is modeled by a cumulative Rice function, as advised by [http://www.springerlink.com/content/u34264k58822l872/|The problem of Wi-Fi radio-fading simulation: Solution and applications].  As distance between agents increases, the probability of receiving a packet decreases.&lt;br /&gt;
&lt;br /&gt;
==Recording a movie==&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13278</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13278"/>
		<updated>2009-05-07T15:58:15Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Control structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for more details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Recording a movie==&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs at full quality because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13277</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13277"/>
		<updated>2009-05-07T15:55:45Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for more details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from the &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;br /&gt;
&lt;br /&gt;
==Recording a movie==&lt;br /&gt;
To record a run of the simulation, simply set MOVIE_FRAMES to the desired movie length.  The movie will be saved as &amp;quot;movie.avi&amp;quot; in the same directory as the simulator M-file.&lt;br /&gt;
&lt;br /&gt;
Movies are recorded as uncompressed AVIs at full quality because MATLAB does a poor job of compression.  See [[Swarm Robot Project Documentation#Making Videos with Overlays]].&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13276</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13276"/>
		<updated>2009-05-07T15:38:14Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Control structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for more details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb|Control structure flow chart.  Blue boxes represent functions that can be found in the code.]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The whole control structure is called from the &amp;#039;&amp;#039;updateBotComputations&amp;#039;&amp;#039;.  Information about neighbors flows to and from the consensus estimator via the packet model.  Currently, no information from the environment is used by &amp;#039;&amp;#039;sensors&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_simlulator_control_structure.png&amp;diff=13275</id>
		<title>File:Swarm simlulator control structure.png</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_simlulator_control_structure.png&amp;diff=13275"/>
		<updated>2009-05-07T15:26:43Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13274</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13274"/>
		<updated>2009-05-07T15:26:20Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Control structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for more details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
[[Image:swarm_simlulator_control_structure.png|300px|right|thumb]]&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13273</id>
		<title>Swarm Robot Project Simulator</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Simulator&amp;diff=13273"/>
		<updated>2009-05-07T15:24:38Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
The simulator is contained in a single executable M-file.  This version implements the formation control algorithm.  When it is run, the swarm will start centered around a random location and then move 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.&lt;br /&gt;
&lt;br /&gt;
==Constants==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
See the inline comments for more details.&lt;br /&gt;
&lt;br /&gt;
==Control structure==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Time model==&lt;br /&gt;
The simulation advances in &amp;#039;&amp;#039;timesteps&amp;#039;&amp;#039;; equally spaced spans of time.  Timesteps are the unit used in specifying the distance between discrete events (ie. updating robot calculations or rendering).&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Data model==&lt;br /&gt;
Since all state data in the simulation can be associated with a robot, the only stored variable is a vector of N robots called &amp;#039;&amp;#039;bots&amp;#039;&amp;#039;.  Each bot is individually represented as a structure, with the following fields (&amp;#039;&amp;#039;and initial value&amp;#039;&amp;#039;):&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;bots&amp;#039;&amp;#039;&amp;#039; vector of N robots&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;state&amp;#039;&amp;#039;&amp;#039; information the robot knows about itself&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;p ([&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;; &amp;#039;&amp;#039;rand&amp;#039;&amp;#039;])&amp;#039;&amp;#039;&amp;#039; position (arranged randomly inside a square of side length SIDE, centered about a specified point)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;angle (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; direction facing&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;packets&amp;#039;&amp;#039;&amp;#039; vector of N received packets (packet i of bot i is that robot&amp;#039;s own estimate and does not age like the rest)&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;age (PACKET_AGE_LIMIT+1)&amp;#039;&amp;#039;&amp;#039; timesteps since received&lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;v ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; moments (packet i of bot i has v initialized to [p(1), p(2), 0, 0, 0]) &lt;br /&gt;
*** &amp;#039;&amp;#039;&amp;#039;w ([0; 0; 0; 0; 0])&amp;#039;&amp;#039;&amp;#039; I have no idea&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;u ([0; 0])&amp;#039;&amp;#039;&amp;#039; velocity&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;lastUpdate (0)&amp;#039;&amp;#039;&amp;#039; timestep of last update&lt;br /&gt;
** &amp;#039;&amp;#039;&amp;#039;waitTime (&amp;#039;&amp;#039;rand&amp;#039;&amp;#039;)&amp;#039;&amp;#039;&amp;#039; timesteps between previous update and next update&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Template:PIC&amp;diff=13151</id>
		<title>Template:PIC</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Template:PIC&amp;diff=13151"/>
		<updated>2009-04-23T20:12:30Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;3&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#efefFf;&amp;quot; | [[PIC Microcontroller]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;[[PIC MCUs: Capabilities of PIC18F4520|PIC18F4520]]&amp;#039;&amp;#039;&amp;#039; || width=&amp;quot;100%&amp;quot; | [[Digital inputs &amp;amp; outputs|Digital I/O]] • [[PIC18F4520: Analog Inputs|Analog Input]] • [[PIC18F4520: PWM Motor Control|PWM Motor Control]] • [[PIC MCUs: 4520 Board|4250 Board]] • [[Sample code for most PIC18F4520 operations|Sample code]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;General Communication&amp;#039;&amp;#039;&amp;#039; || [[PIC RS232|RS232 (Serial)]] • [[SPI - Serial Peripheral Interface - on the PIC|SPI]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Inter-PIC Communication&amp;#039;&amp;#039;&amp;#039; || [[I2C communication between PICs|I&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;C]] • [[IR communication between PICs|IR]] • [[SPI communication between PICs|SPI]] • [[XBee radio communication between PICs|XBee]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Coding&amp;#039;&amp;#039;&amp;#039; || [[PIC Microcontrollers with CCS Compiler|CCS Compiler]] • [[CCS IDE]] • [[PIC Microcontrollers with C18 Compiler|C18 Compiler]] • [[Debugging C on a PIC|Debugging]] • [[PIC computation time benchmarks|Benchmarks]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Other&amp;#039;&amp;#039;&amp;#039; || [[Stepper motor control with the PIC | Stepper motor control]] • [[PIC MCUs: Hardware and Connections | Hardware and Connections]] • [[Analog Output]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Digital_inputs_%26_outputs&amp;diff=10843</id>
		<title>Digital inputs &amp; outputs</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Digital_inputs_%26_outputs&amp;diff=10843"/>
		<updated>2009-03-13T03:40:28Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Which pins are accessible on the 4520 prototyping board?==&lt;br /&gt;
&lt;br /&gt;
[[Image:pinsbroughtout2.jpg|right]]&lt;br /&gt;
&lt;br /&gt;
Most pins on the PIC are  brought out to easily accessible lines on the 4520 board.  Feel free to connect to the few others as well.&lt;br /&gt;
&lt;br /&gt;
Do not drive any pin outside the range 0 to 5 volts, which can damage the PIC.&lt;br /&gt;
&lt;br /&gt;
Most pins have several possible different input or output purposes, as evidenced by several names.  Your software determines which purpose is in effect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Digital I/O pins (five &amp;quot;ports&amp;quot;)===&lt;br /&gt;
&lt;br /&gt;
[[Image:4520pindiagramdigitalports.jpg|right]]&lt;br /&gt;
&lt;br /&gt;
With the exception of the positive voltage supply and ground pins, all pins on the PIC18F4520 can be used as digital I/O, however a few other pins (shown in gray below) are commonly utilized for communication instead of for digital I/O.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Demo circuit for digital inputs and outputs==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Digitalio.gif|right]]&lt;br /&gt;
The 4520 board has 32 1K resistors-to-ground built in, and spaces for 32 LEDs to be inserted, as shown in the circuit below  You can see that the resistors are isolated from and have no effect on the PIC unless the LED is inserted.&lt;br /&gt;
 &lt;br /&gt;
At right is a demo circuit for digital input and digital output.  Two LEDs have been inserted, and a pull-up switch and 4.7K pull-down resistor added.&lt;br /&gt;
&lt;br /&gt;
Pin C1 is intended as a digital input, and will be designated so in software.  When pushbutton switch S1 is depressed, it brings input C1 high, and the left LED illuminates. Otherwise input C1 is held low by the 4.7K resistor to ground. (The LED and its resistor cannot be counted upon to hold input C1 low.)&lt;br /&gt;
&lt;br /&gt;
Pin D7 is intended as a digital output.   When the PIC drives it high, the right LED illuminates, and otherwise not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Sample code==&lt;br /&gt;
&lt;br /&gt;
[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&lt;br /&gt;
&lt;br /&gt;
The code digitalio.c is a complete C program that will compile and run.&lt;br /&gt;
&lt;br /&gt;
You can read or write one bit at a time, or a whole 8-bit port as a byte.   The demo code illustrates the functions input_c() which reads the whole C port as a byte (and returns an int8 value) and output_d(value) which writes to the whole D port as a byte (and takes an int8 argument).  &lt;br /&gt;
&lt;br /&gt;
You can also read a single pin using input(PIN_C4)  which returns 1 or 0.   PIN_C4 and its siblings are defined in the 18f4520.h &amp;quot;include&amp;quot; file.  &lt;br /&gt;
&lt;br /&gt;
For output to a single pin, you can use output_high(PIN_D7) and output_low(PIN_D7) which drive pin D7 high or low, or you can set it to a value in a variable with output_bit(PIN_D7, value) where value is 1 or 0.&lt;br /&gt;
&lt;br /&gt;
All of the above built-in functions include instructions to set the targeted port or pin to digital input mode or digital output mode.   That takes a few extra microseconds every time the function is called.  It is possible to turn this part of the function code off, if you take responsibility to set the direction of the port or pin yourself.&lt;br /&gt;
&lt;br /&gt;
switch bounce - most mechanical switches &amp;quot;bounce&amp;quot; which means they open and close several times when activated, over a period of a few mS.  If this is a problem for your software, there are a lot of ways to debounce switches electronically.   Better, write your software so it doesn&amp;#039;t get confused by multiple open-close cycles.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[PIC18F4520: Digital Inputs]]&lt;br /&gt;
*[[PIC18F4520: Digital Outputs]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Digital_inputs_%26_outputs&amp;diff=10842</id>
		<title>Digital inputs &amp; outputs</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Digital_inputs_%26_outputs&amp;diff=10842"/>
		<updated>2009-03-13T03:39:32Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:pinsbroughtout2.jpg|right]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which pins are accessible on the 4520 prototyping board?==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Most pins on the PIC are  brought out to easily accessible lines on the 4520 board.  Feel free to connect to the few others as well.&lt;br /&gt;
&lt;br /&gt;
Do not drive any pin outside the range 0 to 5 volts, which can damage the PIC.&lt;br /&gt;
&lt;br /&gt;
Most pins have several possible different input or output purposes, as evidenced by several names.  Your software determines which purpose is in effect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:4520pindiagramdigitalports.jpg|right]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Digital I/O pins (five &amp;quot;ports&amp;quot;)===&lt;br /&gt;
&lt;br /&gt;
With the exception of the positive voltage supply and ground pins, all pins on the PIC18F4520 can be used as digital I/O, however a few other pins (shown in gray below) are commonly utilized for communication instead of for digital I/O.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Demo circuit for digital inputs and outputs==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:Digitalio.gif|right]]&lt;br /&gt;
The 4520 board has 32 1K resistors-to-ground built in, and spaces for 32 LEDs to be inserted, as shown in the circuit below  You can see that the resistors are isolated from and have no effect on the PIC unless the LED is inserted.&lt;br /&gt;
 &lt;br /&gt;
At right is a demo circuit for digital input and digital output.  Two LEDs have been inserted, and a pull-up switch and 4.7K pull-down resistor added.&lt;br /&gt;
&lt;br /&gt;
Pin C1 is intended as a digital input, and will be designated so in software.  When pushbutton switch S1 is depressed, it brings input C1 high, and the left LED illuminates. Otherwise input C1 is held low by the 4.7K resistor to ground. (The LED and its resistor cannot be counted upon to hold input C1 low.)&lt;br /&gt;
&lt;br /&gt;
Pin D7 is intended as a digital output.   When the PIC drives it high, the right LED illuminates, and otherwise not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Sample code==&lt;br /&gt;
&lt;br /&gt;
[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&lt;br /&gt;
&lt;br /&gt;
The code digitalio.c is a complete C program that will compile and run.&lt;br /&gt;
&lt;br /&gt;
You can read or write one bit at a time, or a whole 8-bit port as a byte.   The demo code illustrates the functions input_c() which reads the whole C port as a byte (and returns an int8 value) and output_d(value) which writes to the whole D port as a byte (and takes an int8 argument).  &lt;br /&gt;
&lt;br /&gt;
You can also read a single pin using input(PIN_C4)  which returns 1 or 0.   PIN_C4 and its siblings are defined in the 18f4520.h &amp;quot;include&amp;quot; file.  &lt;br /&gt;
&lt;br /&gt;
For output to a single pin, you can use output_high(PIN_D7) and output_low(PIN_D7) which drive pin D7 high or low, or you can set it to a value in a variable with output_bit(PIN_D7, value) where value is 1 or 0.&lt;br /&gt;
&lt;br /&gt;
All of the above built-in functions include instructions to set the targeted port or pin to digital input mode or digital output mode.   That takes a few extra microseconds every time the function is called.  It is possible to turn this part of the function code off, if you take responsibility to set the direction of the port or pin yourself.&lt;br /&gt;
&lt;br /&gt;
switch bounce - most mechanical switches &amp;quot;bounce&amp;quot; which means they open and close several times when activated, over a period of a few mS.  If this is a problem for your software, there are a lot of ways to debounce switches electronically.   Better, write your software so it doesn&amp;#039;t get confused by multiple open-close cycles.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[PIC18F4520: Digital Inputs]]&lt;br /&gt;
*[[PIC18F4520: Digital Outputs]]&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC_computation_time_benchmarks&amp;diff=10811</id>
		<title>PIC computation time benchmarks</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC_computation_time_benchmarks&amp;diff=10811"/>
		<updated>2009-03-10T22:51:48Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Circuit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The goal of this task is to determine the speed at which the [http://hades.mech.northwestern.edu/wiki/index.php/4520_Board_intro PIC 18F4520] (with 20MHz clock) makes certain calculations. There are many different  ways to calculate common functions, such as Taylor expansion versus using the sine command. Some of these methods are faster than others, which could effect your program. When a program is dependent on time, such as while using an interrupt service routine for dead reckoning, a slower calculation might not complete within the ISR. Therefore, it is important to use the most efficient method for simple math and trigonometric functions. The following is empirical data of the speed to which certain data types conduct functions.&lt;br /&gt;
&lt;br /&gt;
The process involved programming the function onto a PIC from a PC and using an oscilloscope to measure the time it took to complete. First, we checked to see if our procedure was free of errors. This was done by programming in a simple delay (e.g., 10&amp;amp;mu;s to 50ms) and measuring its accuracy using the cursor feature on the oscilloscope. A digital output was used. The program would output high, run the delay, output low and run another delay. This would effectively display a square wave, where each delay should represent either the logic low or high on the scope. We found no error in our procedure. We then replaced a delay with a function (e.g., 2 + 5). Eventually we changed the code to conduct the function ten times consecutively. This was done to make oscilloscope measurement easier. The number of iterations of the function corresponded linearly with the time, so the time it took to do one function equated to ten times longer for ten functions, or one hundred times longer for one hundred functions. Our findings are summarized below.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Circuit ==&lt;br /&gt;
[[Image:circuit_diagram.bmp|thumb|400px|Circuit Diagram]]&lt;br /&gt;
The circuit to conduct this test required the PIC 18F4520, power source and an oscilloscope hooked up to a digital output &amp;amp; ground. In the example below the wall power source was used, but a battery could be interchanged. The serial connection was used to update the PIC with each new test written with PIC-C on a nearby PC.&lt;br /&gt;
&lt;br /&gt;
An example of an oscilloscope reading can be seen below right. Test readings were accurate with 1, 10 and 100 iteration tests. The cursor function was used to measure the duration of the high output.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:pic_configuration.jpg|thumb|500px|left|Circuit Configuration]]&lt;br /&gt;
[[Image:example_oscilloscope_reading.jpg|thumb|400px|right|Example of Oscilloscope Reading]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#include &amp;lt;math.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT&lt;br /&gt;
#use delay (clock=20000000)&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
void main(void) {&lt;br /&gt;
 &lt;br /&gt;
   float z;&lt;br /&gt;
   float x=0;&lt;br /&gt;
   float y;&lt;br /&gt;
   float xsquared, xcubed, xfifth, xseventh, xninth;&lt;br /&gt;
   &lt;br /&gt;
   while(TRUE){&lt;br /&gt;
&lt;br /&gt;
        &lt;br /&gt;
      output_high(LED_0);  // Do not use loop for the calculations because it will take time to iterate&lt;br /&gt;
         &lt;br /&gt;
         //ninth order Taylor series (sine). Multiply by 1/n! instead of dividing by n! (multiplication is faster)&lt;br /&gt;
         &lt;br /&gt;
         xsquared = x*x;      //use these variables to keep calculation time down (instead of x*x*x*x*x....)&lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573); &lt;br /&gt;
         xsquared = x*x;      &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;      &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;      &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;    &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333) - (xseventh*.0001984127) + (xninth*.00000275573);&lt;br /&gt;
         &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
         z = x + y;  // code for simple math, change operations and variable types&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
         z = x + y;&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
                &lt;br /&gt;
      output_low(LED_0);&lt;br /&gt;
         &lt;br /&gt;
         //seventh order Taylors series (sine)&lt;br /&gt;
         &lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
         xsquared = x*x;     &lt;br /&gt;
         xcubed=xsquared*x;&lt;br /&gt;
         xfifth=xcubed*xsquared;&lt;br /&gt;
         xseventh=xfifth*xsquared;&lt;br /&gt;
         xninth=xseventh*xsquared;&lt;br /&gt;
         z = x - (xcubed*0.1666666) + (xfifth*.008333333);&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
&lt;br /&gt;
         z = sqrt(x);  //square root test&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
         z = sqrt(x);&lt;br /&gt;
&lt;br /&gt;
*/                  &lt;br /&gt;
              &lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
=== Simple Math Functions ===&lt;br /&gt;
&lt;br /&gt;
The below table contains the results from our operation testing. All the values are given in &amp;amp;mu;s and the value in parentheses is the time normalized to the quickest operation in the entire table.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;100%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Function&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Int8&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Int16&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Int32&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Signed Int8&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Signed Int16&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Signed Int32&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Float&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Addition (+)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.64&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.24&amp;amp;mu;s (1.94)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.44&amp;amp;mu;s (3.81)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.64&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.24&amp;amp;mu;s (1.94)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.44&amp;amp;mu;s (3.81)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;25.6&amp;amp;mu;s (40.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Subtraction (-)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.68&amp;amp;mu;s (1.06)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.28&amp;amp;mu;s (2.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.48&amp;amp;mu;s (3.88)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.68&amp;amp;mu;s (1.06)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.28&amp;amp;mu;s (2.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.48&amp;amp;mu;s (3.88)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;29.8&amp;amp;mu;s (46.56)*&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Multiplication (*)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.8&amp;amp;mu;s (1.25)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;6.0&amp;amp;mu;s (9.38)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;45.0&amp;amp;mu;s (70.31)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.92&amp;amp;mu;s (1.44)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;6.0&amp;amp;mu;s (9.38)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;46.0&amp;amp;mu;s (71.88)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;26.0&amp;amp;mu;s-28.0&amp;amp;mu;s (40.63-43.75)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Division (/)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;19.4&amp;amp;mu;s (30.31)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;60.8&amp;amp;mu;s (95.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;195.0&amp;amp;mu;s (304.69)*&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;22.4&amp;amp;mu;s (35.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;64.4&amp;amp;mu;s (100.63)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;201.0&amp;amp;mu;s (314.06)*&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;176.0&amp;amp;mu;s-226.0&amp;amp;mu;s (275.00-353.13)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;And (&amp;amp;)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.64&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.24&amp;amp;mu;s (1.94)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.44&amp;amp;mu;s (3.81)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Or ( | )&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.68&amp;amp;mu;s (1.06)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.28&amp;amp;mu;s (2.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.48&amp;amp;mu;s (3.88)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;gt;&amp;gt;1)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.64&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.04&amp;amp;mu;s (1.63)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.84&amp;amp;mu;s (2.88)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;gt;&amp;gt;2)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.04&amp;amp;mu;s (1.63)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.64&amp;amp;mu;s (2.56)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.84&amp;amp;mu;s (4.44)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;gt;&amp;gt;3)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.24&amp;amp;mu;s (1.94)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.04&amp;amp;mu;s (3.19)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;3.64&amp;amp;mu;s (5.69)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;lt;&amp;lt;1)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.68&amp;amp;mu;s (1.06)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.08&amp;amp;mu;s (1.69)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.88&amp;amp;mu;s (2.94)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;lt;&amp;lt;2)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.08&amp;amp;mu;s (1.69)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.68&amp;amp;mu;s (2.63)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.88&amp;amp;mu;s (4.50)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Shift (&amp;lt;&amp;lt;3)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.28&amp;amp;mu;s (2.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2.08&amp;amp;mu;s (3.25)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;3.68&amp;amp;mu;s (5.75)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Table 1.1 Simple Math Functions&lt;br /&gt;
( * Indicates an averaged field)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As you can see, there are clear advantages to using smaller data types. There are even some operations that take slower with signed data types versus unsigned. Most all of the data was constant for small and large values for these simple math operations. For float data types, differing values tended to vary in time. Variability was also seen in some int32 calculations. These results are either given as an experimental range (if significant variability) or averaged (less than 4% variability).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Chapter 8 of the [http://129.105.69.13/datasheets/Microcontrollers/PIC18F4520.pdf PIC manual] lists the computation time for several multiply operations. Table 1.2 shows the values from the PIC manual compared to our measurements. As you can see, the calculation times are within an order of magnitude from each other. One difference is that in our measurements signed and unsigned multiplication took nearly the same amount of time. This was unexpected as the algorithm for signed multiplication (as outlined in the PIC manual) should take longer than unsigned multiplication.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;52.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Routine&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Time at 20 MHz clock speed*&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Measured Values&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;int8 x int8 (unsigned)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.2 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.8 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;int8 x int8 (signed)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.2 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.92 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;int16 x int16 (unsigned)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;5.6 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;6.0 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;int16 x int16 (signed)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;8.0 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;6.0 us&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Table 1.2 Multiplication times compared to PIC manual values (* Times derived from Table 8-1 of PIC manual)&lt;br /&gt;
&lt;br /&gt;
=== Multiplication, Division &amp;amp; Shifts ===&lt;br /&gt;
&lt;br /&gt;
For most integer types shifting is much quicker than multiplication and division. The exception is shifting more than one place for Int8 will take slightly longer. Therefore, if you are multiplying by 2&amp;lt;sup&amp;gt;#&amp;lt;/sup&amp;gt; (where # is any positive integer value) it is faster to use a shift. The same is true if you are dividing by any factor of 2&amp;lt;sup&amp;gt;#&amp;lt;/sup&amp;gt;. In this case shifting to the right divides and vice versa for multiplication.&lt;br /&gt;
&lt;br /&gt;
Division is much slower than multiplication across all data types. If you are computing a float it is much faster to multiply by a reciprocal. Below is a table of two functions that compute the same value but at very different speeds. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;35%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Function&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Time&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2 * 0.1&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;28&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2 / 10&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;200&amp;amp;mu;s (7.14)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2* 0.001&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;28&amp;amp;mu;s (1.00)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;2 / 1000&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;220&amp;amp;mu;s (7.86)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Trigonometric Functions &amp;amp; Square Root ===&lt;br /&gt;
&lt;br /&gt;
Table 1.3 shows the results from the trigonometric, square root, and [http://en.wikipedia.org/wiki/Taylor_expansion Taylor Expansion] tests. The Taylor expansion example below is a ninth order. To conduct seventh or fifth order expansions one just drops out the higher terms. Sine and cosine functions take about the same time with tangent being slightly slower. Also, the square root function was slightly slower than the sine function. Note that the fast cosine value (0.24 ms) was for cos(0). Other than this value the time range closely matches that for sine.  As shown the Taylor series approximation for sine is faster than using the sine command. It is important to note from our code that we multiplied by a reciprocal. Computing a Taylor series with division takes just a long as using the sine function. As expected, a higher order approximation will take more time. Depending on the amount of accuracy you need, using the Taylor approximation will save a significant amount of time.&lt;br /&gt;
&lt;br /&gt;
[[Image:Taylor_Expansion_9th_Order.bmp|thumb|300px|left|[[Taylor Expansion 9th Order]]]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;52.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Function&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Time Range (normalized)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Error&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Sin&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.27-1.20 ms (3.80-16.9)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Sin (Taylor-9th order)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.106-0.380 ms (1.49-5.35)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.006925&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Sin (Taylor-7th order)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.089-0.312 ms (1.25-4.39)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.07522&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Sin (Taylor-5th order)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.071-0.252 ms (1.00-3.55)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.5240&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Cos&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.24-1.14 ms (3.38-16.1)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;n/a&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Tan&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;1.37-2.52 ms (19.3-35.5)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;n/a&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Sqrt&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;12.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;0.98-1.26 ms (13.8-17.7)&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td width=&amp;quot;17.5%&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;font size=&amp;quot;-1&amp;quot;&amp;gt;n/a&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Table 1.3 Trigonometric Functions and Square Root (all measurements are for float variables)&lt;br /&gt;
&lt;br /&gt;
=== Algorithms for Square Root and Trigonometric Functions ===&lt;br /&gt;
There are several algorithms that can be used to compute the square root. The basic steps are:&lt;br /&gt;
&lt;br /&gt;
:   1. Start with an initial guess, &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;.&lt;br /&gt;
:   2. Multiply &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; by itself (or perform a different calculation).&lt;br /&gt;
:   3. See how close this solution is to the argument.&lt;br /&gt;
:   4. Change &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; and iterate until you are close enough to the argument.&lt;br /&gt;
&lt;br /&gt;
One such algorithm is the [http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method Babylonian method]. The way the PIC chooses the initial value, &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;, can affect the speed of the calculation. One way of choosing &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; is to set it equal to &amp;lt;math&amp;gt;2^{\left\lfloor D/2\right\rfloor}&amp;lt;/math&amp;gt; with D equal to the number of binary digits in the argument. The closer &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt; is to the actual answer the faster the computation will be. This is why there is a range for computation times because the initial value the PIC chooses will affect the algorithm speed. The algorithm also conducted an initial test of validity. Values less than zero were immediately rejected, because this algorithm does not compute imaginary numbers. We also noticed that very large numbers (we tried 10&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt;) were also rejected. This initial validity test also contributes to slower calculation speeds. &lt;br /&gt;
&lt;br /&gt;
One method that the PIC can use to calculate trigonometric functions is the [http://en.wikipedia.org/wiki/CORDIC CORDIC algorithm].&lt;br /&gt;
CORDIC is a type of shift-and-add algorithm that rotates a vector. An initial vector, &amp;#039;&amp;#039;v&amp;#039;&amp;#039;&amp;lt;sub&amp;gt;&amp;#039;&amp;#039;0&amp;#039;&amp;#039;&amp;lt;/sub&amp;gt;, is set and then multiplied by a rotation matrix. The rotation of the vector is repeated until its angle is close to the desired angle, &amp;lt;math&amp;gt; \theta &amp;lt;/math&amp;gt;. The sine of &amp;lt;math&amp;gt; \theta &amp;lt;/math&amp;gt; is the vector&amp;#039;s projection onto the y-axis, while the cosine is the projection onto the x-axis. The number of iterations that the algorithm has to make depends on the angle, &amp;lt;math&amp;gt; \theta &amp;lt;/math&amp;gt;. Thus, the PIC&amp;#039;s computation time for trigonometric functions will vary depending on the angle.&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Template:PIC&amp;diff=10810</id>
		<title>Template:PIC</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Template:PIC&amp;diff=10810"/>
		<updated>2009-03-10T21:08:37Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;6&amp;quot; width=&amp;quot;100%&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | [[PIC Microcontroller]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;[[PIC MCUs: Capabilities of PIC18F4520|PIC18F4520]]&amp;#039;&amp;#039;&amp;#039; || width=&amp;quot;100%&amp;quot; | [[Digital inputs &amp;amp; outputs|Digital I/O]] • [[PIC18F4520: Analog Inputs|Analog Input]] • [[PIC18F4520: PWM Motor Control|PWM Motor Control]] • [[PIC MCUs: 4520 Board|4250 Board]] • [[Sample code for most PIC18F4520 operations|Sample code]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;General Communication&amp;#039;&amp;#039;&amp;#039; || [[PIC RS232|RS232 (Serial)]] • [[SPI - Serial Peripheral Interface - on the PIC|SPI]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Inter-Pic Communication&amp;#039;&amp;#039;&amp;#039; || [[I2C communication between PICs|I&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;C]] • [[IR communication between PICs|IR]] • [[SPI communication between PICs|SPI]] • [[XBee radio communication between PICs|XBee]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Coding&amp;#039;&amp;#039;&amp;#039; || [[PIC Microcontrollers with CCS Compiler|CCS Compiler]] • [[CCS IDE]] • [[PIC Microcontrollers with C18 Compiler|C18 Compiler]] • [[Debugging C on a PIC|Debugging]] • [[PIC computation time benchmarks|Benchmarks]]&lt;br /&gt;
|-&lt;br /&gt;
|&amp;#039;&amp;#039;&amp;#039;Other&amp;#039;&amp;#039;&amp;#039; || [[Stepper motor control with the PIC | Stepper motor control]] • [[PIC MCUs: Hardware and Connections | Hardware and Connections]] • [[Analog Output]]&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Machine_Vision_Localization_System&amp;diff=10797</id>
		<title>Machine Vision Localization System</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Machine_Vision_Localization_System&amp;diff=10797"/>
		<updated>2009-03-07T23:12:08Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Computer Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Project Files=&lt;br /&gt;
*[[Image:vision_system_localization_project.zip]] (Project files with source code)&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
This is a machine vision system that tracks multiple targets and can send out the positions via the serial port.  It was developed specifically for the [[Swarm_Robot_Project_Documentation|Swarm Robotics project]], but can be adapted for other uses.  It is based upon the [[Indoor_Localization_System]], but has several enhancements and bug fixes.  Refer to [[Indoor_Localization_System]] for a basic overview of the setup of the system and the workings of the patter identification algorithm.&lt;br /&gt;
==Major Enhancements/Changes==&lt;br /&gt;
* The system will now mark the targets with an overlay and display coordinate data onscreen.&lt;br /&gt;
* The serial output is now formatted for the XBee radio using the XBee&amp;#039;s API mode with escape characters.&lt;br /&gt;
* The calibration routine has been improved, and only needs to be performed once.&lt;br /&gt;
* A command interface for sending out commands via the serial port has been added.&lt;br /&gt;
* The system will discard targets too close to the edge of the camera frame to prevent misidentification due to clipping.&lt;br /&gt;
* The origin of the world coordinate is now in the middle, not the lower left corner.&lt;br /&gt;
* The GUI displaying the camera frames is now full sized instead of a thumbnail.  However, if your monitor isn&amp;#039;t big enough, you can resize them.&lt;br /&gt;
&lt;br /&gt;
==Major Bug Fixes==&lt;br /&gt;
* Two major memory leaks fixed.&lt;br /&gt;
* Calibration matricies are now calculated correctly.&lt;br /&gt;
* File handling bug that causes an off-by-one error in &amp;#039;&amp;#039;&amp;#039;LoadTargetData()&amp;#039;&amp;#039;&amp;#039; fixed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Target Patterns==&lt;br /&gt;
The target patterns and preprocessor can be downloaded at [[Indoor_Localization_System#Pre-processing_program_source_with_final_patterns:]].&lt;br /&gt;
&lt;br /&gt;
=OpenCV Documentation=&lt;br /&gt;
[http://opencv.willowgarage.com/wiki/ OpenCV Wiki]&lt;br /&gt;
&lt;br /&gt;
=Operation=&lt;br /&gt;
==Setting up the Cameras==&lt;br /&gt;
[[Image:camera_setup.png|300px|thumb|left]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cameras should be set up according to [[Indoor_Localization_System]] with one caveat: targets at the edge of the camera frame will now be discarded.  This prevents misidentification of patterns if one or more dots in the pattern fall off the screen, but it also means that there must be enough overlap that when the target is in the dead-zone of one camera, it is picked up by another camera.&lt;br /&gt;
&lt;br /&gt;
The height of the cameras will determine how small your patterns can be before becoming indistinguishable.  Changing the height also changes the focus, so be sure to adjust the focus when the height is changed.&lt;br /&gt;
&lt;br /&gt;
[[Image:machine_vision_single_frame.png|300px|thumb|left|Targets found in the margin are discarded.]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
[[Image:machine_vision_four_frames.png|300px|thumb|left|The frames must overlap; overlap by the width of one target to ensure that it will never be discarded by both cameras.]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
== How to Use The System ==&lt;br /&gt;
=== Camera Setup ===&lt;br /&gt;
The four cameras used were standard Logitech QuickCam Communicate Deluxes.  For future use, the videoInput library used is very compatible and works with most capture devices.  As measured, the viewing angle (from center) of the Logitech cameras was around 30 degrees (horizontal plane) and 25 degrees (vertical plane).&lt;br /&gt;
&lt;br /&gt;
[[Image:visual_localization_viewing_angle.jpg|right|thumb|300px|Approximate Viewing Angle of Logitech Cameras]]&lt;br /&gt;
&lt;br /&gt;
Before attaching the cameras, several considerations must be made.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;1.  Choose a desired ALL WHITE area to cover.&amp;#039;&amp;#039;&amp;#039;  &amp;#039;&amp;#039;&amp;#039;***IMPORTANT: If you want to be able to cover an continuous region, the images as seen by the cameras must overlap to ensure a target is at least fully visible in one frame of a camera***&amp;#039;&amp;#039;&amp;#039; Keep in mind that there is a trade-off between area, and resolution.  In addition, the size of the patterns will have to be increased above the threshold of noise.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;2.  Ensure that the cameras are all facing the same direction. &amp;#039;&amp;#039;&amp;#039; As viewed from above, the &amp;quot;top&amp;quot; of the cameras should all be facing the same direction (N/S/E/W).  For future use, if these directions must be variable, the image reflection and rotation parameters can be adjusted in software (though this has not been implemented).&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;3.  Try to mount the cameras as &amp;quot;normal&amp;quot; as possible.&amp;#039;&amp;#039;&amp;#039;  Although the camera calibration should determine the correct pose information, keeping the lenses of the cameras as normal as possible will reduce the amount of noise at the edges of the images.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Computer Setup ==&lt;br /&gt;
In the current implementation, this system has been developed for a Windows based computer (as restricted by the videoInput library).  The system should run in Windows XP or Vista.  To setup the computer to develop and run the software, the three required libraries must be installed.&lt;br /&gt;
&lt;br /&gt;
1.  Download and install the Logitech QuickCam Deluxe Webcam Drivers - http://www.logitech.com/index.cfm/435/3057&amp;amp;cl=us,en&lt;br /&gt;
&lt;br /&gt;
2.  Install Microsoft Visual Studio Professional (Express Edition is incompatible with some of the code)&lt;br /&gt;
&lt;br /&gt;
3.  Download and install Microsoft Windows Platform SDK - http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&amp;amp;displaylang=en&lt;br /&gt;
&lt;br /&gt;
4.  Download and install Microsoft DirectX 9+ SDK - http://www.microsoft.com/downloads/details.aspx?FamilyId=572BE8A6-263A-4424-A7FE-69CFF1A5B180&amp;amp;displaylang=en&lt;br /&gt;
&lt;br /&gt;
5.  Download and install Intel OpenCV Library - http://sourceforge.net/projects/opencvlibrary/&lt;br /&gt;
&lt;br /&gt;
6.  Download and install the videoInput Library - http://muonics.net/school/spring05/videoInput/&lt;br /&gt;
&lt;br /&gt;
7.  Download the source code for the vision system here: [[Media: Vision_localization_system_project.zip]]&lt;br /&gt;
&lt;br /&gt;
The project will probably not compile right after you open it.  You will have to put the correct directories into the environment.  In Visual C++, go to &lt;br /&gt;
&lt;br /&gt;
Tools&amp;gt;Options&amp;gt;Project and Solutions&amp;gt;VC++ directories&lt;br /&gt;
&lt;br /&gt;
and select &amp;#039;&amp;#039;&amp;#039;Include files&amp;#039;&amp;#039;&amp;#039; in the drop-down menu.  Add &amp;#039;&amp;#039;&amp;#039;(the directory paths on your computer may be different depending on your system, and the versions you installed.)&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
* C:\Program Files\OpenCV\otherlibs\highgui&lt;br /&gt;
* C:\Program Files\OpenCV\otherlibs\cvcam\include&lt;br /&gt;
* C:\Program Files\OpenCV\cvaux\include&lt;br /&gt;
* C:\Program Files\OpenCV\cxcore\include&lt;br /&gt;
* C:\Program Files\OpenCV\cv\include&lt;br /&gt;
* C:\Program Files\Microsoft SDKs\Windows\v6.1\Include&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;&amp;#039;&amp;#039;Library files&amp;#039;&amp;#039;&amp;#039; from the drop-down menu and add:&lt;br /&gt;
* C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\videoInputSrcAndDemos\libs\DShow\lib&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\compiledLib\compiledByVS2005&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\videoInputSrcAndDemos\libs\videoInput&lt;br /&gt;
&lt;br /&gt;
==Starting the Program==&lt;br /&gt;
# Compile and run the program.&lt;br /&gt;
# When you first run the program, it will open up a console window and ask you to enter a COM port number.  This is the number of the serial port that will be used to send out data.  Enter the number, and press Enter.  (e.g. &amp;lt;tt&amp;gt;Enter COM number: 4&amp;lt;enter&amp;gt;&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The program should now connect to the cameras, and will open two new windows: one with numbered quadrants (the GUI window), and one displaying the view of one of the cameras.  Use you mouse to click on the quadrant that corresponds to the camera view.  Repeat until all four cameras have been matched to the quadrants.&lt;br /&gt;
# Make sure the GUI window is selected, and press Enter.&lt;br /&gt;
# Go back to the console window, and you should now see a message asking you if you want to recalibrate your cameras.  Press &amp;#039;&amp;#039;&amp;#039;&amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt;&amp;#039;&amp;#039;&amp;#039; for yes and &amp;#039;&amp;#039;&amp;#039;&amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;&amp;#039;&amp;#039;&amp;#039; for no, then press Enter.  To recalibrate your cameras, see the calibration section.&lt;br /&gt;
# The GUI window should now show a thresholded image, and the console will display how many dots the camera sees.  [[Indoor_Localization_System#Real_time_Adjustable_Parameters| Adjust the thresholding parameters]] (+ and - for black/white, z and x for area) until you are satisfied with the thresholded image.&lt;br /&gt;
# Make sure the GUI window is selected, then hit Enter.&lt;br /&gt;
# Remove any calibration patterns, and hit Enter.  The program should now be running.&lt;br /&gt;
# When you turn on the robots, they will be in &amp;#039;&amp;#039;&amp;#039;sleep&amp;#039;&amp;#039;&amp;#039; mode.  Use the &amp;#039;&amp;#039;&amp;#039;wake&amp;#039;&amp;#039;&amp;#039; command to start them.&lt;br /&gt;
&lt;br /&gt;
==Camera Calibration==&lt;br /&gt;
The camera calibration routine used is explained in the document [[Media:Image_Formation_and Camera_Calibration.pdf | Image_Formation_and Camera_Calibration.pdf]] by Professor Ying Wu.&lt;br /&gt;
&lt;br /&gt;
The calibration routine uses 9 equally-spaced points per camera to find a mapping from the image coordinates to the real-world coordinates.  The field of view of the four cameras must overlap the center horizontal and vertical dots that form a &amp;#039;+&amp;#039; shape.&lt;br /&gt;
&lt;br /&gt;
The center dot should be seen by all four cameras.&lt;br /&gt;
&lt;br /&gt;
The size of the dots is not very important; the center of mass of each of the dots will be used.&lt;br /&gt;
&lt;br /&gt;
[[Image:machine_vision_calibration.png|300px|thumb|left|Twenty-five points are used to calibrate the cameras.  The field of view must overlap the dots that form a &amp;#039;+&amp;#039;.]]&lt;br /&gt;
&amp;lt;br clear = &amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calibrate:&lt;br /&gt;
# Place the 25 equally spaced dots on the testbed.  The dots should be well distributed throughout the testbed (don&amp;#039;t bunch the dots all up in a small area).&lt;br /&gt;
# Start the program, and type in &amp;#039;y&amp;#039; at the prompt that asks whether or not you wish to calibrate.  &lt;br /&gt;
# Enter the horizontal spacing (parameter A in the diagram) and vertical spacing (parameter B in the diagram) when prompted.  These numbers are recorded in the file &amp;lt;tt&amp;gt;calibration_dot_spacing.txt&amp;lt;/tt&amp;gt;.  &lt;br /&gt;
# The GUI window will then display a thresholded image and the console will display the number of dots seen by each camera.  Adjust the thresholding values until each camera sees only the nine dots being used to calibrate the camera. &lt;br /&gt;
# Select the GUI window and hit Enter. &lt;br /&gt;
# Remove the dots.&lt;br /&gt;
# Select the GUI window and hit Enter.&lt;br /&gt;
&lt;br /&gt;
The program should now be running.  Your calibration information will be recorded in &amp;lt;tt&amp;gt;Quadrant0.txt, Quadrant1.txt, Quadrant2.txt, Quadrant3.txt,&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;calibration_dot_spacing.txt&amp;lt;/tt&amp;gt;.  If you choose not to recalibrate your cameras next time, the data in these files will be used to generate the calibration matrices.&lt;br /&gt;
&lt;br /&gt;
When calibrating, the dots should be raised to the same height as the patterns on the robots.  It is possible to calibrate one camera at a time using only 9 dots by placing the dots under one camera at a time and running the calibration routine four times, making a copy of the &amp;lt;tt&amp;gt;Quadrant_.txt&amp;lt;/tt&amp;gt; file generated by the calibration routine for that camera (the other three files will be garbage) each time so that it will not be overwritten.  You can then copy the four good files back into the directory.&lt;br /&gt;
&lt;br /&gt;
==Pausing==&lt;br /&gt;
Hit &amp;#039;p&amp;#039; to pause the program, and hit &amp;#039;p&amp;#039; again to resume.&lt;br /&gt;
&lt;br /&gt;
==Using the Command Console==&lt;br /&gt;
To enter the command mode, hit &amp;#039;c&amp;#039;.  When in the command mode, the main loop is not running; the command mode must be exited to resume.  Type &amp;#039;exit&amp;#039; to exit the command mode and resume the main loop.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:  There is no guarantee that all of the robots will receive the command, due to packet loss.  It is advisable to send the command out multiple times to make sure the robots all receive it.  You can use the arrow keys to find previously sent messages.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enter commands in the following syntax: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;command name&amp;gt; &amp;lt;target ID&amp;gt; &amp;lt;parameter 1&amp;gt; &amp;lt;parameter 2&amp;gt; ... &amp;lt;parameter N&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;To broadcast the message, use ID 0.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
You can also enter multiple commands at a time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;sleep 1 sleep 2 wake 4 goto 0 100 -100 deadb 0 150&amp;lt;/tt&amp;gt;&lt;br /&gt;
===Commands===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;3&amp;quot;&lt;br /&gt;
|+&amp;#039;&amp;#039;&amp;#039;Commands Table&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Description !! Parameters !! Example&lt;br /&gt;
|-&lt;br /&gt;
| sleep || The robot will stop moving and stop sending data. || &amp;lt;tt&amp;gt;sleep &amp;lt;ID&amp;gt;&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; sleep 0 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| wake || The robot will wake from sleep and resume moving and sending data || &amp;lt;tt&amp;gt;wake &amp;lt;ID&amp;gt;&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; wake 0 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| goal || Change the swarm&amp;#039;s goal state. || &amp;lt;tt&amp;gt;goal &amp;lt;ID&amp;gt; &amp;lt;Ix&amp;gt; &amp;lt;Iy&amp;gt; &amp;lt;Ixx&amp;gt; &amp;lt;Ixy&amp;gt; &amp;lt;Iyy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; goal 0 100 300 160000 40000 40000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| goto || Similar to &amp;lt;tt&amp;gt;goal&amp;lt;/tt&amp;gt;, but only changes &amp;lt;tt&amp;gt;&amp;lt;Ix&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;&amp;lt;Iy&amp;gt;&amp;lt;/tt&amp;gt;. || &amp;lt;tt&amp;gt;goto &amp;lt;ID&amp;gt; &amp;lt;Ix&amp;gt; &amp;lt;Iy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; goto 0 100 300&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| deadb || Change the robot motor deadband.  The motors will only move for &amp;lt;br&amp;gt;speeds (wheel ticks per second) faster than this.  This removes some jittering at low speeds. || &amp;lt;tt&amp;gt;deadb &amp;lt;ID&amp;gt; &amp;lt;velocity&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; deadb 0 150&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| egain || Change the estimator gains.  || &amp;lt;tt&amp;gt;egain &amp;lt;ID&amp;gt; &amp;lt;KP&amp;gt; &amp;lt;KI&amp;gt; &amp;lt;Gamma&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; egain 0 0.7 0.1 0.05&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| cgain || Change the motion controller gains.  || &amp;lt;tt&amp;gt;cgain &amp;lt;ID&amp;gt; &amp;lt;KIx&amp;gt; &amp;lt;KIy&amp;gt; &amp;lt;KIxx&amp;gt; &amp;lt;KIxy&amp;gt; &amp;lt;KIyy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; cgain 0 2 2 0.001 0.001 0.001&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| commr || Change the communication radius distance.&amp;lt;br&amp;gt;The agent will discard any packets from other agents further away than this distance.  || &amp;lt;tt&amp;gt;commr &amp;lt;ID&amp;gt; &amp;lt;distance&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; commr 0 1500&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| speed || Change the maximum allowed speed for the robot.  || &amp;lt;tt&amp;gt;speed &amp;lt;ID&amp;gt; &amp;lt;speed&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; speed 0 300&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| safed || Change the obstacle avoidance threshold.  || &amp;lt;tt&amp;gt;speed &amp;lt;ID&amp;gt; &amp;lt;distance&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; safed 0 200&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Exiting the Program==&lt;br /&gt;
Press ESC to quit the program.&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Machine_Vision_Localization_System&amp;diff=10796</id>
		<title>Machine Vision Localization System</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Machine_Vision_Localization_System&amp;diff=10796"/>
		<updated>2009-03-07T23:11:23Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Computer Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Project Files=&lt;br /&gt;
*[[Image:vision_system_localization_project.zip]] (Project files with source code)&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
This is a machine vision system that tracks multiple targets and can send out the positions via the serial port.  It was developed specifically for the [[Swarm_Robot_Project_Documentation|Swarm Robotics project]], but can be adapted for other uses.  It is based upon the [[Indoor_Localization_System]], but has several enhancements and bug fixes.  Refer to [[Indoor_Localization_System]] for a basic overview of the setup of the system and the workings of the patter identification algorithm.&lt;br /&gt;
==Major Enhancements/Changes==&lt;br /&gt;
* The system will now mark the targets with an overlay and display coordinate data onscreen.&lt;br /&gt;
* The serial output is now formatted for the XBee radio using the XBee&amp;#039;s API mode with escape characters.&lt;br /&gt;
* The calibration routine has been improved, and only needs to be performed once.&lt;br /&gt;
* A command interface for sending out commands via the serial port has been added.&lt;br /&gt;
* The system will discard targets too close to the edge of the camera frame to prevent misidentification due to clipping.&lt;br /&gt;
* The origin of the world coordinate is now in the middle, not the lower left corner.&lt;br /&gt;
* The GUI displaying the camera frames is now full sized instead of a thumbnail.  However, if your monitor isn&amp;#039;t big enough, you can resize them.&lt;br /&gt;
&lt;br /&gt;
==Major Bug Fixes==&lt;br /&gt;
* Two major memory leaks fixed.&lt;br /&gt;
* Calibration matricies are now calculated correctly.&lt;br /&gt;
* File handling bug that causes an off-by-one error in &amp;#039;&amp;#039;&amp;#039;LoadTargetData()&amp;#039;&amp;#039;&amp;#039; fixed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Target Patterns==&lt;br /&gt;
The target patterns and preprocessor can be downloaded at [[Indoor_Localization_System#Pre-processing_program_source_with_final_patterns:]].&lt;br /&gt;
&lt;br /&gt;
=OpenCV Documentation=&lt;br /&gt;
[http://opencv.willowgarage.com/wiki/ OpenCV Wiki]&lt;br /&gt;
&lt;br /&gt;
=Operation=&lt;br /&gt;
==Setting up the Cameras==&lt;br /&gt;
[[Image:camera_setup.png|300px|thumb|left]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cameras should be set up according to [[Indoor_Localization_System]] with one caveat: targets at the edge of the camera frame will now be discarded.  This prevents misidentification of patterns if one or more dots in the pattern fall off the screen, but it also means that there must be enough overlap that when the target is in the dead-zone of one camera, it is picked up by another camera.&lt;br /&gt;
&lt;br /&gt;
The height of the cameras will determine how small your patterns can be before becoming indistinguishable.  Changing the height also changes the focus, so be sure to adjust the focus when the height is changed.&lt;br /&gt;
&lt;br /&gt;
[[Image:machine_vision_single_frame.png|300px|thumb|left|Targets found in the margin are discarded.]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
[[Image:machine_vision_four_frames.png|300px|thumb|left|The frames must overlap; overlap by the width of one target to ensure that it will never be discarded by both cameras.]]&lt;br /&gt;
&amp;lt;br clear=&amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
== How to Use The System ==&lt;br /&gt;
=== Camera Setup ===&lt;br /&gt;
The four cameras used were standard Logitech QuickCam Communicate Deluxes.  For future use, the videoInput library used is very compatible and works with most capture devices.  As measured, the viewing angle (from center) of the Logitech cameras was around 30 degrees (horizontal plane) and 25 degrees (vertical plane).&lt;br /&gt;
&lt;br /&gt;
[[Image:visual_localization_viewing_angle.jpg|right|thumb|300px|Approximate Viewing Angle of Logitech Cameras]]&lt;br /&gt;
&lt;br /&gt;
Before attaching the cameras, several considerations must be made.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;1.  Choose a desired ALL WHITE area to cover.&amp;#039;&amp;#039;&amp;#039;  &amp;#039;&amp;#039;&amp;#039;***IMPORTANT: If you want to be able to cover an continuous region, the images as seen by the cameras must overlap to ensure a target is at least fully visible in one frame of a camera***&amp;#039;&amp;#039;&amp;#039; Keep in mind that there is a trade-off between area, and resolution.  In addition, the size of the patterns will have to be increased above the threshold of noise.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;2.  Ensure that the cameras are all facing the same direction. &amp;#039;&amp;#039;&amp;#039; As viewed from above, the &amp;quot;top&amp;quot; of the cameras should all be facing the same direction (N/S/E/W).  For future use, if these directions must be variable, the image reflection and rotation parameters can be adjusted in software (though this has not been implemented).&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;3.  Try to mount the cameras as &amp;quot;normal&amp;quot; as possible.&amp;#039;&amp;#039;&amp;#039;  Although the camera calibration should determine the correct pose information, keeping the lenses of the cameras as normal as possible will reduce the amount of noise at the edges of the images.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Computer Setup ==&lt;br /&gt;
In the current implementation, this system has been developed for a Windows based computer (as restricted by the videoInput library).  The system should run in Windows XP or Vista.  To setup the computer to develop and run the software, the three required libraries must be installed.&lt;br /&gt;
&lt;br /&gt;
1.  Download and install the Logitech QuickCam Deluxe Webcam Drivers - http://www.logitech.com/index.cfm/435/3057&amp;amp;cl=us,en&lt;br /&gt;
&lt;br /&gt;
2.  Install Microsoft Visual Studio Professional&lt;br /&gt;
&lt;br /&gt;
3.  Download and install Microsoft Windows Platform SDK - http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&amp;amp;displaylang=en&lt;br /&gt;
&lt;br /&gt;
4.  Download and install Microsoft DirectX 9+ SDK - http://www.microsoft.com/downloads/details.aspx?FamilyId=572BE8A6-263A-4424-A7FE-69CFF1A5B180&amp;amp;displaylang=en&lt;br /&gt;
&lt;br /&gt;
5.  Download and install Intel OpenCV Library - http://sourceforge.net/projects/opencvlibrary/&lt;br /&gt;
&lt;br /&gt;
6.  Download and install the videoInput Library - http://muonics.net/school/spring05/videoInput/&lt;br /&gt;
&lt;br /&gt;
7.  Download the source code for the vision system here: [[Media: Vision_localization_system_project.zip]]&lt;br /&gt;
&lt;br /&gt;
The project will probably not compile right after you open it.  You will have to put the correct directories into the environment.  In Visual C++, go to &lt;br /&gt;
&lt;br /&gt;
Tools&amp;gt;Options&amp;gt;Project and Solutions&amp;gt;VC++ directories&lt;br /&gt;
&lt;br /&gt;
and select &amp;#039;&amp;#039;&amp;#039;Include files&amp;#039;&amp;#039;&amp;#039; in the drop-down menu.  Add &amp;#039;&amp;#039;&amp;#039;(the directory paths on your computer may be different depending on your system, and the versions you installed.)&amp;#039;&amp;#039;&amp;#039;:&lt;br /&gt;
* C:\Program Files\OpenCV\otherlibs\highgui&lt;br /&gt;
* C:\Program Files\OpenCV\otherlibs\cvcam\include&lt;br /&gt;
* C:\Program Files\OpenCV\cvaux\include&lt;br /&gt;
* C:\Program Files\OpenCV\cxcore\include&lt;br /&gt;
* C:\Program Files\OpenCV\cv\include&lt;br /&gt;
* C:\Program Files\Microsoft SDKs\Windows\v6.1\Include&lt;br /&gt;
&lt;br /&gt;
select &amp;#039;&amp;#039;&amp;#039;Library files&amp;#039;&amp;#039;&amp;#039; from the drop-down menu and add:&lt;br /&gt;
* C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\videoInputSrcAndDemos\libs\DShow\lib&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\compiledLib\compiledByVS2005&lt;br /&gt;
* C:\Users\LIMS\Documents\Visual Studio 2005\Libraries\videoInput0.1991\videoInputSrcAndDemos\libs\videoInput&lt;br /&gt;
&lt;br /&gt;
==Starting the Program==&lt;br /&gt;
# Compile and run the program.&lt;br /&gt;
# When you first run the program, it will open up a console window and ask you to enter a COM port number.  This is the number of the serial port that will be used to send out data.  Enter the number, and press Enter.  (e.g. &amp;lt;tt&amp;gt;Enter COM number: 4&amp;lt;enter&amp;gt;&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The program should now connect to the cameras, and will open two new windows: one with numbered quadrants (the GUI window), and one displaying the view of one of the cameras.  Use you mouse to click on the quadrant that corresponds to the camera view.  Repeat until all four cameras have been matched to the quadrants.&lt;br /&gt;
# Make sure the GUI window is selected, and press Enter.&lt;br /&gt;
# Go back to the console window, and you should now see a message asking you if you want to recalibrate your cameras.  Press &amp;#039;&amp;#039;&amp;#039;&amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt;&amp;#039;&amp;#039;&amp;#039; for yes and &amp;#039;&amp;#039;&amp;#039;&amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;&amp;#039;&amp;#039;&amp;#039; for no, then press Enter.  To recalibrate your cameras, see the calibration section.&lt;br /&gt;
# The GUI window should now show a thresholded image, and the console will display how many dots the camera sees.  [[Indoor_Localization_System#Real_time_Adjustable_Parameters| Adjust the thresholding parameters]] (+ and - for black/white, z and x for area) until you are satisfied with the thresholded image.&lt;br /&gt;
# Make sure the GUI window is selected, then hit Enter.&lt;br /&gt;
# Remove any calibration patterns, and hit Enter.  The program should now be running.&lt;br /&gt;
# When you turn on the robots, they will be in &amp;#039;&amp;#039;&amp;#039;sleep&amp;#039;&amp;#039;&amp;#039; mode.  Use the &amp;#039;&amp;#039;&amp;#039;wake&amp;#039;&amp;#039;&amp;#039; command to start them.&lt;br /&gt;
&lt;br /&gt;
==Camera Calibration==&lt;br /&gt;
The camera calibration routine used is explained in the document [[Media:Image_Formation_and Camera_Calibration.pdf | Image_Formation_and Camera_Calibration.pdf]] by Professor Ying Wu.&lt;br /&gt;
&lt;br /&gt;
The calibration routine uses 9 equally-spaced points per camera to find a mapping from the image coordinates to the real-world coordinates.  The field of view of the four cameras must overlap the center horizontal and vertical dots that form a &amp;#039;+&amp;#039; shape.&lt;br /&gt;
&lt;br /&gt;
The center dot should be seen by all four cameras.&lt;br /&gt;
&lt;br /&gt;
The size of the dots is not very important; the center of mass of each of the dots will be used.&lt;br /&gt;
&lt;br /&gt;
[[Image:machine_vision_calibration.png|300px|thumb|left|Twenty-five points are used to calibrate the cameras.  The field of view must overlap the dots that form a &amp;#039;+&amp;#039;.]]&lt;br /&gt;
&amp;lt;br clear = &amp;#039;all&amp;#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To calibrate:&lt;br /&gt;
# Place the 25 equally spaced dots on the testbed.  The dots should be well distributed throughout the testbed (don&amp;#039;t bunch the dots all up in a small area).&lt;br /&gt;
# Start the program, and type in &amp;#039;y&amp;#039; at the prompt that asks whether or not you wish to calibrate.  &lt;br /&gt;
# Enter the horizontal spacing (parameter A in the diagram) and vertical spacing (parameter B in the diagram) when prompted.  These numbers are recorded in the file &amp;lt;tt&amp;gt;calibration_dot_spacing.txt&amp;lt;/tt&amp;gt;.  &lt;br /&gt;
# The GUI window will then display a thresholded image and the console will display the number of dots seen by each camera.  Adjust the thresholding values until each camera sees only the nine dots being used to calibrate the camera. &lt;br /&gt;
# Select the GUI window and hit Enter. &lt;br /&gt;
# Remove the dots.&lt;br /&gt;
# Select the GUI window and hit Enter.&lt;br /&gt;
&lt;br /&gt;
The program should now be running.  Your calibration information will be recorded in &amp;lt;tt&amp;gt;Quadrant0.txt, Quadrant1.txt, Quadrant2.txt, Quadrant3.txt,&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;calibration_dot_spacing.txt&amp;lt;/tt&amp;gt;.  If you choose not to recalibrate your cameras next time, the data in these files will be used to generate the calibration matrices.&lt;br /&gt;
&lt;br /&gt;
When calibrating, the dots should be raised to the same height as the patterns on the robots.  It is possible to calibrate one camera at a time using only 9 dots by placing the dots under one camera at a time and running the calibration routine four times, making a copy of the &amp;lt;tt&amp;gt;Quadrant_.txt&amp;lt;/tt&amp;gt; file generated by the calibration routine for that camera (the other three files will be garbage) each time so that it will not be overwritten.  You can then copy the four good files back into the directory.&lt;br /&gt;
&lt;br /&gt;
==Pausing==&lt;br /&gt;
Hit &amp;#039;p&amp;#039; to pause the program, and hit &amp;#039;p&amp;#039; again to resume.&lt;br /&gt;
&lt;br /&gt;
==Using the Command Console==&lt;br /&gt;
To enter the command mode, hit &amp;#039;c&amp;#039;.  When in the command mode, the main loop is not running; the command mode must be exited to resume.  Type &amp;#039;exit&amp;#039; to exit the command mode and resume the main loop.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:  There is no guarantee that all of the robots will receive the command, due to packet loss.  It is advisable to send the command out multiple times to make sure the robots all receive it.  You can use the arrow keys to find previously sent messages.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Enter commands in the following syntax: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;&amp;lt;command name&amp;gt; &amp;lt;target ID&amp;gt; &amp;lt;parameter 1&amp;gt; &amp;lt;parameter 2&amp;gt; ... &amp;lt;parameter N&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;To broadcast the message, use ID 0.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
You can also enter multiple commands at a time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;sleep 1 sleep 2 wake 4 goto 0 100 -100 deadb 0 150&amp;lt;/tt&amp;gt;&lt;br /&gt;
===Commands===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;3&amp;quot;&lt;br /&gt;
|+&amp;#039;&amp;#039;&amp;#039;Commands Table&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
! Command !! Description !! Parameters !! Example&lt;br /&gt;
|-&lt;br /&gt;
| sleep || The robot will stop moving and stop sending data. || &amp;lt;tt&amp;gt;sleep &amp;lt;ID&amp;gt;&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; sleep 0 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| wake || The robot will wake from sleep and resume moving and sending data || &amp;lt;tt&amp;gt;wake &amp;lt;ID&amp;gt;&amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; wake 0 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| goal || Change the swarm&amp;#039;s goal state. || &amp;lt;tt&amp;gt;goal &amp;lt;ID&amp;gt; &amp;lt;Ix&amp;gt; &amp;lt;Iy&amp;gt; &amp;lt;Ixx&amp;gt; &amp;lt;Ixy&amp;gt; &amp;lt;Iyy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; goal 0 100 300 160000 40000 40000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| goto || Similar to &amp;lt;tt&amp;gt;goal&amp;lt;/tt&amp;gt;, but only changes &amp;lt;tt&amp;gt;&amp;lt;Ix&amp;gt;&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;&amp;lt;Iy&amp;gt;&amp;lt;/tt&amp;gt;. || &amp;lt;tt&amp;gt;goto &amp;lt;ID&amp;gt; &amp;lt;Ix&amp;gt; &amp;lt;Iy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; goto 0 100 300&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| deadb || Change the robot motor deadband.  The motors will only move for &amp;lt;br&amp;gt;speeds (wheel ticks per second) faster than this.  This removes some jittering at low speeds. || &amp;lt;tt&amp;gt;deadb &amp;lt;ID&amp;gt; &amp;lt;velocity&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; deadb 0 150&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| egain || Change the estimator gains.  || &amp;lt;tt&amp;gt;egain &amp;lt;ID&amp;gt; &amp;lt;KP&amp;gt; &amp;lt;KI&amp;gt; &amp;lt;Gamma&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; egain 0 0.7 0.1 0.05&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| cgain || Change the motion controller gains.  || &amp;lt;tt&amp;gt;cgain &amp;lt;ID&amp;gt; &amp;lt;KIx&amp;gt; &amp;lt;KIy&amp;gt; &amp;lt;KIxx&amp;gt; &amp;lt;KIxy&amp;gt; &amp;lt;KIyy&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; cgain 0 2 2 0.001 0.001 0.001&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| commr || Change the communication radius distance.&amp;lt;br&amp;gt;The agent will discard any packets from other agents further away than this distance.  || &amp;lt;tt&amp;gt;commr &amp;lt;ID&amp;gt; &amp;lt;distance&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; commr 0 1500&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| speed || Change the maximum allowed speed for the robot.  || &amp;lt;tt&amp;gt;speed &amp;lt;ID&amp;gt; &amp;lt;speed&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; speed 0 300&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| safed || Change the obstacle avoidance threshold.  || &amp;lt;tt&amp;gt;speed &amp;lt;ID&amp;gt; &amp;lt;distance&amp;gt; &amp;lt;/tt&amp;gt; || &amp;lt;tt&amp;gt; safed 0 200&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Exiting the Program==&lt;br /&gt;
Press ESC to quit the program.&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=PIC_PWM_Motor_Driver&amp;diff=10270</id>
		<title>PIC PWM Motor Driver</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=PIC_PWM_Motor_Driver&amp;diff=10270"/>
		<updated>2009-02-10T18:25:23Z</updated>

		<summary type="html">&lt;p&gt;NealEhardt: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
DO NOT USE THIS PAGE.   USE [[PIC18F4520: PWM Motor Control|THE OTHER PWM PAGE]].&lt;br /&gt;
&lt;br /&gt;
This motor controller was designed for use as cheap, simple motor controller for [[Brushed DC Motor Theory|brushed DC motors]].  It uses a [[PIC Microcontroller]] to convert a low-power analog control signal to a [[Pulse Width Modulation|PWM]] duty cycle which is amplified using a full-bridge to drive a motor.  A block diagram of this is shown below.  This document gives the circuitry and programming needed to make such a controller.  &lt;br /&gt;
&lt;br /&gt;
[[image:PIC PWM block.png|center]]&lt;br /&gt;
&lt;br /&gt;
==PIC PWM==&lt;br /&gt;
&lt;br /&gt;
The first thing you need is a PIC microcontroller set up to convert an analog input to a PWM signal.  The PIC used here is the [[PIC16F684]].  It only has one input, the analog control signal.  It has two outputs: two opposite pulse width modulated pulse trains.  The two PWM signals activate the two halves of the H-bridge to control the direction of the motor.&lt;br /&gt;
&lt;br /&gt;
===PIC Code===&lt;br /&gt;
&lt;br /&gt;
Code can be downloaded [[media:picpwmcode.zip|&amp;#039;&amp;#039;&amp;#039;here&amp;#039;&amp;#039;&amp;#039;]].&lt;br /&gt;
&lt;br /&gt;
The zip file contains the following files:&lt;br /&gt;
&lt;br /&gt;
* main.asm - the program&lt;br /&gt;
* macros.inc - contains macros (quick code)&lt;br /&gt;
* PIC16F684.INC - assigns names to register addresses&lt;br /&gt;
* PICPWM.mcw and PICPWM.mcp - MPLAB workspaces&lt;br /&gt;
&lt;br /&gt;
==Circuit==&lt;br /&gt;
&lt;br /&gt;
The circuit consists of the PWM-enabled PIC chip, an amplifier and some protection circuitry.  There are two versions of the circuit, one for low-power motors (1A continuous) and one for high-power motors (4A continuous).&lt;br /&gt;
&lt;br /&gt;
===Low Power===&lt;br /&gt;
&lt;br /&gt;
The low-power circuit uses the L293B push-pull driver ([[media:L293.pdf|datasheet]]).  This circuit can be used for the 6W Maxon motors in the lab.&lt;br /&gt;
&lt;br /&gt;
[[image:PIC PWM L293.png|center]]&lt;br /&gt;
&lt;br /&gt;
[[image:PIC PWM L293 CIRCUIT.jpg|center|400px]]&lt;br /&gt;
&lt;br /&gt;
===High Power===&lt;br /&gt;
&lt;br /&gt;
A more high-power circuit makes use of the L298N ([[media:L298N.pdf|datasheet]]) full bridge amplifier.&lt;br /&gt;
&lt;br /&gt;
[[image:PIC PWM L298.png|center]]&lt;br /&gt;
&lt;br /&gt;
===Signal Conditioner (Optional)===&lt;br /&gt;
&lt;br /&gt;
There is a problem with leaving out the signal conditioner part of the circuit.  Sure you can program your controller to output your control signal scaled to 0 to +5v, but when it will likely reset to 0v at some point.  0v to the PIC corresponds to full speed in one direction.  You want 0v to the circuit to mean 0 speed to the motor, or 0v (IN) = 2.5v (PIC).  For this you can build a simple op-amp circuit.&lt;br /&gt;
&lt;br /&gt;
[[image:PWM PIC Input Conditioner.png|center]]&lt;br /&gt;
&lt;br /&gt;
[[image:PWM PIC Input Circuit.jpg|400px|center]]&lt;br /&gt;
&lt;br /&gt;
This circuit can accomodate inputs of either &amp;lt;math&amp;gt;\pm\,&amp;lt;/math&amp;gt;5V or &amp;lt;math&amp;gt;\pm\,&amp;lt;/math&amp;gt;10V.  The two potentiometers can be adjusted to give the correct gain.  Diodes were added to protect the PIC from too low or too high voltage inputs.&lt;br /&gt;
&lt;br /&gt;
Another way around this is to add an enabling input.  Whenever the controller isn&amp;#039;t running, the circuit can be disabled so the motors won&amp;#039;t be accidentally driven in either direction.&lt;br /&gt;
&lt;br /&gt;
==PCB Example==&lt;br /&gt;
&lt;br /&gt;
You can download CircuitMaker and TraxMaker files here for this circuit using the L293.  The PCB design is shown below.  It is not optimized for space, but to be easy to read.  You can edit it as you like.  It is suited to use with the PC/104 stack.&lt;br /&gt;
&lt;br /&gt;
* [[media:PIC PWM Circuit Files.zip]]&lt;br /&gt;
&lt;br /&gt;
[[image:PIC PWM Traxmaker.jpg|center|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==TO DO==&lt;br /&gt;
&lt;br /&gt;
# Find out why circuit causes motors to make high-pitch noise.&lt;br /&gt;
# Add &amp;quot;brake&amp;quot; functionality to the PIC.  This will require at least one additional input.  For example, a single digital input pin could cause the motor to &amp;quot;brake&amp;quot; when it&amp;#039;s set high.  To &amp;quot;brake&amp;quot;, the PIC will have to disable the PWM mode and set the two output pins equal to eachother.&lt;br /&gt;
# Add &amp;quot;sensing&amp;quot; capability for better control.&lt;/div&gt;</summary>
		<author><name>NealEhardt</name></author>
	</entry>
</feed>