<?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=Hwang</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=Hwang"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/Hwang"/>
	<updated>2026-05-21T14:19:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=RC_and_RL_Exponential_Responses&amp;diff=15339</id>
		<title>RC and RL Exponential Responses</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=RC_and_RL_Exponential_Responses&amp;diff=15339"/>
		<updated>2010-01-27T03:15:40Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Charging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
==Summary of Equations==&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Exponential responses of capacitors and inductors&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
!  !!Discharging !! Charging !! Time Constant&lt;br /&gt;
|-&lt;br /&gt;
!Capacitor !! &amp;lt;math&amp;gt;v_C(t)=V_0e^{-\frac{t}{RC}}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;v_C(t)=V_0(1-e^{-\frac{t}{RC}})&amp;lt;/math&amp;gt; ||&amp;lt;math&amp;gt;RC\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!Inductor !! &amp;lt;math&amp;gt;i_L(t)=I_0e^{-\frac{R}{L}t}&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;i_L(t)=I_0(1-e^{-\frac{R}{L}t})&amp;lt;/math&amp;gt; || &amp;lt;math&amp;gt;\frac{L}{R}&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==RC Circuits==&lt;br /&gt;
===Charging===&lt;br /&gt;
If the capacitor is initially uncharged and we want to charge it with a voltage source &amp;lt;math&amp;gt;V_s&amp;lt;/math&amp;gt; in the RC circuit:&lt;br /&gt;
&lt;br /&gt;
[[Image:RC_charge_schematic.gif]]&lt;br /&gt;
&lt;br /&gt;
Current flows into the capacitor and accumulates a charge there.  As the charge increases, the voltage rises, and eventually the voltage of the capacitor equals the voltage of the source, and current stops flowing.  The voltage across the capacitor is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;v_C(t)=V_0(1-e^{-\frac{t}{RC}})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;V_0=V_S&amp;lt;/math&amp;gt;, the final voltage across the capacitor.&lt;br /&gt;
&lt;br /&gt;
===Discharging===&lt;br /&gt;
Consider the following circuit:&lt;br /&gt;
&lt;br /&gt;
[[Image:RC_discharge_schematic.gif]]&lt;br /&gt;
&lt;br /&gt;
In the circuit, the capacitor is initially charged and has voltage &amp;lt;math&amp;gt;V_0&amp;lt;/math&amp;gt; across it, and the switch is initially open.  At time &amp;lt;math&amp;gt;t=0&amp;lt;/math&amp;gt;, we close the circuit and allow the capacitor to discharge through the resistor.  The voltage across a capacitor discharging through a resistor as a function of time is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;v_C(t)=V_0e^{-\frac{t}{RC}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;V_0&amp;lt;/math&amp;gt; is the initial voltage across the capacitor.&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;RC&#039;&#039; is the resistance of the resistor multiplied by the capacitance of the capacitor, and known as the &#039;&#039;time constant&#039;&#039;, which is a unit of time.  The function completes 63% of the transition between the initial and final states at &amp;lt;math&amp;gt;t=1RC&amp;lt;/math&amp;gt;, and completes over 99.99% of the transition at &amp;lt;math&amp;gt;t=5RC&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The voltage and current of the capacitor in the circuits above are shown in the graphs below, from &#039;&#039;t=0&#039;&#039; to &#039;&#039;t=5RC&#039;&#039;.  Note the polaritiy&amp;amp;mdash;the voltage is the voltage measured at the &amp;quot;+&amp;quot; terminal of the capacitor relative to the ground (0V).  A positive current flows into the capacitor from this terminal; a negative current flows out of this terminal.:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Capacitor&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
!  !!Voltage!! Current&lt;br /&gt;
|-&lt;br /&gt;
!Charge !! [[Image:RC_charge_voltage.gif]] || [[Image:RC_charge_current.gif]]&lt;br /&gt;
|-&lt;br /&gt;
!Discharge !! [[Image:RC_discharge_voltage.gif]] || [[Image:RC_discharge_current.gif]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Remember that for capacitors, &amp;lt;math&amp;gt;i(t)=C*dv/dt&amp;lt;/math&amp;gt;.  Note that the current through the capacitor can change instantly at &#039;&#039;t=0&#039;&#039;, but the voltage changes slowly.&lt;br /&gt;
&lt;br /&gt;
==RL Circuits==&lt;br /&gt;
===Charging===&lt;br /&gt;
If the inductor is initially uncharged and we want to charge it by inserting a voltage source &amp;lt;math&amp;gt;V_s&amp;lt;/math&amp;gt; in the RL circuit:&lt;br /&gt;
&lt;br /&gt;
[[Image:RL_charge_schematic.gif]]&lt;br /&gt;
&lt;br /&gt;
The inductor initially has a very high resistance, as energy is going into building up a magnetic field.  Once the magnetic field is up and no longer changing, the inductor acts like a short circuit.  The current at steady state is equal to &amp;lt;math&amp;gt;I_0=V_s/R&amp;lt;/math&amp;gt;.  Since the inductor is acting like a short circuit at steady state, the voltage across the inductor then is 0.  The current through the inductor is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;i_L(t)=I_0(1-e^{-\frac{R}{L}t})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Discharging===&lt;br /&gt;
In the following circuit, the inductor initially has current &amp;lt;math&amp;gt;I_0=V_s/R&amp;lt;/math&amp;gt; flowing through it; we replace the voltage source with a short circuit at &amp;lt;math&amp;gt;t=0&amp;lt;/math&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
[[Image:RL_discharge_schematic.gif]]&lt;br /&gt;
&lt;br /&gt;
After we cut out the voltage source, the voltage across the inductor is &amp;lt;math&amp;gt;I_0*R&amp;lt;/math&amp;gt;, but the higher voltage is now at the negative terminal of the inductor.  Thus, &amp;lt;math&amp;gt;I_0=-V/R&amp;lt;/math&amp;gt;.  The current flowing through the inductor at time &#039;&#039;t&#039;&#039; is given by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;i_L(t)=I_0e^{-\frac{R}{L}t}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;I_0=-V_s/R&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;time constant&#039;&#039; for the RL circuit is equal to &amp;lt;math&amp;gt;L/R&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The voltage and current of the inductor for the circuits above are given by the graphs below, from &#039;&#039;t=0&#039;&#039; to &#039;&#039;t=5L/R&#039;&#039;.  The voltage is measured at the &amp;quot;+&amp;quot; terminal of the inductor, relative to the ground.  A positive current flows into the inductor from this terminal; a negative current flows out of this terminal:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;5&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|+&#039;&#039;&#039;Inductor&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
!  !!Voltage !! Current &lt;br /&gt;
|-&lt;br /&gt;
!Charge !! [[Image:RL_charge_voltage.gif]] || [[Image:RL_charge_current.gif]]&lt;br /&gt;
|-&lt;br /&gt;
!Discharge !! [[Image:RL_discharge_voltage.gif]] || [[Image:RL_discharge_current.gif]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Remember that for an inductor, &amp;lt;math&amp;gt;v(t)=L*di/dt&amp;lt;/math&amp;gt;.  Note that the voltage across the inductor can change instantly at &#039;&#039;t=0&#039;&#039;, but the current changes slowly.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
Hayt, William H. Jr., Jack E. Kemmerly, and Steven M. Durbin. &amp;lt;u&amp;gt;Engineering Circuit Analysis&amp;lt;/u&amp;gt;. 6th ed. New York:McGraw-Hill, 2002.&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13632</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13632"/>
		<updated>2009-07-06T09:34:39Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{j=1}^N(\frac{1}{N}x_j[n]) + K_I\sum_{j=1}^N(\frac{1}{N}w_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{j=1}^N(\frac{1}{N}x_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  \dot u_x \\&lt;br /&gt;
  \dot u_y \\ &lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
= &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  1 &amp;amp; 0 &amp;amp; 2(R_x-x_{Mx}) &amp;amp; (R_y-x_{My}) &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; 1 &amp;amp; 0 &amp;amp; (R_x-x_{Mx}) &amp;amp; 2(R_y-x_{My})\\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  k_{Mx} &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; k_{My} &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; 0 &amp;amp; k_{Mxx} &amp;amp; 0 &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; 0 &amp;amp; 0 &amp;amp; k_{Myy} &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; k_{Mxy} \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  g_{Mx}-x_{Mx} \\&lt;br /&gt;
  g_{My}-x_{My}\\&lt;br /&gt;
  g_{Mxx}-x_{Mxx} \\&lt;br /&gt;
  g_{Myy}-x_{Myy} \\&lt;br /&gt;
  g_{Mxy}-x_{Mxy} \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13631</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13631"/>
		<updated>2009-07-06T09:05:15Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{j=1}^N(\frac{1}{N}x_j[n]) + K_I\sum_{j=1}^N(\frac{1}{N}w_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{j=1}^N(\frac{1}{N}x_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  \dot u_x \\&lt;br /&gt;
  \dot u_y \\ &lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
= &lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  1 &amp;amp; 0 &amp;amp; 2(R_x-x_{Mx}) &amp;amp; (R_y-x_{My}) &amp;amp; 0 \\&lt;br /&gt;
  0 &amp;amp; 1 &amp;amp; 0 &amp;amp; (R_x-x_{Mx}) &amp;amp; 2(R_y-x_{My})\\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13630</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13630"/>
		<updated>2009-07-06T08:47:24Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{j=1}^N(\frac{1}{N}x_j[n]) + K_I\sum_{j=1}^N(\frac{1}{N}w_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{j=1}^N(\frac{1}{N}x_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
  \dot u_x      &amp;amp; \cdots \\&lt;br /&gt;
  \vdots &amp;amp; \ddots \\ &lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13629</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13629"/>
		<updated>2009-07-06T05:39:14Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{j=1}^N(\frac{1}{N}x_j[n]) + K_I\sum_{j=1}^N(\frac{1}{N}w_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{j=1}^N(\frac{1}{N}x_j[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13628</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13628"/>
		<updated>2009-07-06T05:38:37Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{j=1}^N(\frac{1}{N}x_m[n]) + K_I\sum_{j=1}^N(\frac{1}{N}w_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{j=1}^N(\frac{1}{N}x_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13627</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13627"/>
		<updated>2009-07-05T18:37:22Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{m=1}^N(\frac{1}{N}x_m[n]) + K_I\sum_{m=1}^N(\frac{1}{N}w_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] - K_I\sum_{m=1}^N(\frac{1}{N}x_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13626</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13626"/>
		<updated>2009-07-05T07:57:04Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{m=1}^N(\frac{1}{N}x_m[n]) + K_I\sum_{m=1}^N(\frac{1}{N}w_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
w[n+1] = w[n] K_I\sum_{m=1}^N(\frac{1}{N}x_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13625</id>
		<title>The sandbox</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=The_sandbox&amp;diff=13625"/>
		<updated>2009-07-05T07:01:28Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==test==&lt;br /&gt;
&amp;lt;math&amp;gt;(-3dB point) = \frac{1}{2\pi}(R1*R2*C1*C2)^\frac{1}{2} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
x[n+1] = x[n] + \gamma(u[n]-x[n]) - K_P\sum_{m=1}^N(\frac{1}{N}x_m[n]) + K_I*\sum_{m=1}^N(\frac{1}{N}w_m[n])&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Spur Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:spur gears.png|125px|center]] !! [[image:gear-spurgearhead.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Rack and Pinion===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:rack and pinion.png|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Bevel Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:bevel gears.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Helical Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:helical gears.png|125px|center]] !! [[image:gear-helical2.jpg|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Worm Drives===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:worm drive.png|125px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Planetary Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-planetarystage.jpg|125px|center]] !! [[image:gear-planetary.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ball Screw===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:gear-ballscrew.gif|125px|center]] !! [[image:gear-ballscrew2.jpg|125px|center]] &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Harmonic Drive Gears===&lt;br /&gt;
&lt;br /&gt;
{| align=&amp;quot;left&amp;quot; cellpadding = &amp;quot;25&amp;quot; &lt;br /&gt;
! [[image:harmonic gears.png|400px|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive.gif|center]]&lt;br /&gt;
|-&lt;br /&gt;
| [[image:gear-harmonicdrive2aligned.jpg|400px|center]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13086</id>
		<title>XBee radio communication between PICs</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13086"/>
		<updated>2009-04-21T07:15:29Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Reading Packets with MATLAB in API Modes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Typically, two pics communicate by [http://en.wikipedia.org/wiki/RS-232 RS-232], a wired transmission.  However, it may be desirable to communicate via a wireless link.  This wiki page demonstrates using XBee radio modems which conform to the IEEE 802.15.4 protocol.  These radios will allow for wireless communication between two PICs and between a PIC and a computer. &lt;br /&gt;
&lt;br /&gt;
[[Image:XBeePinOut.jpg |thumb|300px|right| XBee Manual]]&lt;br /&gt;
&lt;br /&gt;
The IEEE 802.15.4 is a [http://en.wikipedia.org/wiki/IEEE_802.15.4 point-point/point-multipoint] communications protocol (similar to Bluetooth) designed for low-power devices.  Like Bluetooth, the IEEE 802.15.4 specification also uses the 2.4 GHz ISM band.  The ZigBee protocol, which deals with mesh networking and routing, is built upon the IEEE 802.15.4 specification.&lt;br /&gt;
&lt;br /&gt;
The XBee radios, made by Digi (formerly Maxstream), are shipped with firmware implementing the IEEE 802.15.4 protocol, but can be loaded with the ZigBee protocol stack, which can be downloaded from the Digi website.  Note that ZigBee is still in its infancy and devices from different manufacturers may not be compatible.  The range for an XBee Pro indoors is up to 300 feet while line of site, outdoor communication is up to a mile. ([http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual])&lt;br /&gt;
 &lt;br /&gt;
The XBee chip is designed to be mounted in specific sockets (Note: These sockets don&#039;t fit in a standard bread board!)  We soldered wires directly to the socket, which were then placed in a breadboard.  (Printed circuit boards are being created to fix this issue.)  The Xbee also requires a 3.3 voltage regulator.&lt;br /&gt;
&lt;br /&gt;
For the pin locations, see page 7 of [http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual] or the figure to the right.&lt;br /&gt;
&lt;br /&gt;
For PIC to computer interface, a terminal program such as X-CTU needs to be used. Although other terminal programs might work as well, X-CTU software was designed specifically for the XBee, and in addition to its terminal functions, it also has functions for testing signal strength, reading, saving, and writing the state of the XBee, and updating firmware. The X-CTU program is run on the PC while connected to a X-Bee via a serial port. The X-CTU software can be downloaded from [http://www.oricomtech.com/download.htm X-CTU Site].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Circuit ==&lt;br /&gt;
[[Image:pictopic.jpg |thumb|300px|left| Communicating Pic to Pic]] [[Image:pctopic.jpg |thumb|left|300px| Communicating Computer to Pic]]&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The XBee module can be connected directly to the UART port on the PIC.  To connect it to a RS-232 port, one must use a voltage shifting transceiver chip because RS232 signals are from -15V to + 15V.  The MAX232/ST232 chip will convert voltage level from RS-232 to TTL logic levels and vice versa.  The chip requires 4 external capacitors (the fifth is a bypass capacitor) in order to operate.&lt;br /&gt;
The transceiver data sheet can be found [http://www.tranzistoare.ro/datasheets/105/502490_DS.pdf here].&lt;br /&gt;
&lt;br /&gt;
In the circuit shown above, the serial port uses a DE9F 9-pin connector (Digikey part number 	209FE-ND), which is used to connect the computer&#039;s serial port to the circuit. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to PIC, two of the circuits shown on the left should be used. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to computer, one of each of the circuits should be used.  A better solution to connecting a PC to an XBee module is to use a cable that connects to the PC&#039;s USB port and converts to RS-232, as described on this [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
==XBee Interface Board==&lt;br /&gt;
[[Image:xbee_board_with_radio.jpg|thumb|right]]&lt;br /&gt;
[[XBee_Interface_Board| XBee Interface Board]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Communication PIC to Computer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First you will need to get your PC speaking RS-232.  You can try hyperterminal (standard on the PC) or [http://homepage.mac.com/dalverson/zterm/ zterm] or similar for the Mac for simple interactive RS-232.  See [[Serial communication with Matlab|this page]] for an example of RS-232 communication using matlab.  Or you can try [http://www.codeproject.com/KB/system/cserialport.aspx this C++ library] from within a Win32 C++ program.  In any case, you are likely to need a special adapter cable to connect your PC to the XBee as described on the [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
The PIC code below will wait for the character &#039;+&#039; to appear on the serial port, and when it does, it will add the next two single digit numbers that are entered and return the result back to the computer. In order to connect with the PIC, the program X-CTU must be used on the computer as discussed above. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a;&lt;br /&gt;
char abuff[2]={0};&lt;br /&gt;
int b;&lt;br /&gt;
char bbuff[2]={0};&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
int sum;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;+&#039;){&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         abuff[0] = getc();&lt;br /&gt;
         a = atoi(abuff);&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         bbuff[0] = getc();&lt;br /&gt;
         b = atoi(bbuff);&lt;br /&gt;
         &lt;br /&gt;
         sum = a+b;&lt;br /&gt;
         printf(&amp;quot;sum=%u\r\n&amp;quot;,sum);&lt;br /&gt;
         x=0;&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;
&#039;&#039;&#039;Communication PIC to PIC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In this communication, each PIC has its own code, which is shown below. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Transmitter&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* pic2pic_transmit.c&lt;br /&gt;
ME333 Lab 5&lt;br /&gt;
The transmitter checks to see if PIN A0 is high or low. &lt;br /&gt;
If the  pin is high, the transmitter sends the signal &#039;a&#039; to the receiver and &lt;br /&gt;
turns on an LED. If the pins is low, the transmitter sends the signal &#039;b&#039;. &lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
      if (input(PIN_A0)){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         printf(&amp;quot;a&amp;quot;); //sends signal a&lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         printf(&amp;quot;b&amp;quot;); //sends signal b&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;
&#039;&#039;Receiver&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* pic2pic_receive&lt;br /&gt;
ME 333 Lab 5&lt;br /&gt;
The receiver checks the signal from the XBEE and if the signal is &#039;a&#039;, the receiver turns on an LED.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;a&#039;){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         &lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         &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;
==Using the XBee Radio==&lt;br /&gt;
===Using X-CTU===&lt;br /&gt;
Note: Setting up the radios will require the X-CTU terminal program.  Select your settings under the &#039;&#039;&#039;PC Settings&#039;&#039;&#039; tab and click on &#039;&#039;&#039;Test/Query&#039;&#039;&#039;.  Unfortunately, there is no easy way to tell what the current baud rate of the radio is set at (default is 9600), so you might have to try them all.  Whoever had the radio before you may have changed the settings of the radio, so after your radio is successfully detected, you may wish to use command &#039;&#039;&#039;ATRE&#039;&#039;&#039; to reset the radio to factory defaults, and &#039;&#039;&#039;ATWR&#039;&#039;&#039; to save your settings.&lt;br /&gt;
&lt;br /&gt;
===Parameters AT Commands===&lt;br /&gt;
AT commands enable you to set the parameters of the XBee radio.  To enter AT command mode, open X-CTU (program discussed in overview), make sure your radio is detected, click on the &#039;&#039;&#039;terminal&#039;&#039;&#039; tab, and type in &amp;quot;+++&amp;quot; (without the quotes).  The chip should respond with an &amp;quot;OK&amp;quot;.  Then, you can enter the commands. If the radio doesn&#039;t receive a commands for a while (default 10s), then it will exit command mode and return to normal operation mode; you can also force a return to normal operation mode with a ATCN command.  &#039;&#039;&#039;All parameters are in hexadecimal format.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Commands are usually entered in the following formats (after entering command mode):&lt;br /&gt;
&lt;br /&gt;
To read parameters: AT&amp;lt;parameter&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To write parameters: AT&amp;lt;parameter&amp;gt; &amp;lt;value&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to read the ID of the radio, you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY&lt;br /&gt;
&lt;br /&gt;
To set the value of the radio&#039;s ID to 1 you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY 1&lt;br /&gt;
&lt;br /&gt;
The radio will start using the updated parameters after exiting the command mode, or if an ATAC (apply changes) command is given.  &#039;&#039;&#039;If you want your changes to persist after rebooting the radio, make sure you use the ATWR command).&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Specific instructions and descriptions of allowable parameters to send can be found in Section 3 of the XBee Product Manual.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some commonly used commands:&lt;br /&gt;
&amp;lt;table border=1 cellpadding=2 width=75%&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Parameter&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Command&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Value&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;Basic Commands&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Enter command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;+++&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;N/A&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&amp;gt;Exit command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCN&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&amp;gt;Apply changes&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAC&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&amp;gt;Write current parameter values to non-volatile memory (must reset or use ATAC for changes to take effect)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATWR&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&amp;gt;Restore defaults&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATRE&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&amp;gt;Reset&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATFR&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 colspan=4 align=center&amp;gt;&amp;lt;b&amp;gt;For items below, type command followed by a value to set the parameter or without a value to check the current value.&amp;lt;/b&amp;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 align=center&amp;gt;Baud Rate&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;&amp;lt;p&amp;gt;Sets the baud rate at which the XBee communicates with the serial device it is physically connected to.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;See the XBee manual for information on setting non-standard baud rates&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATBD&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0-7 (standard baud rates)&amp;lt;br&amp;gt;&lt;br /&gt;
	0 = 1200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = 2400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = 4800 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	3 = 9600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	4 = 19200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	5 = 38400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	6 = 57600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	7 = 115200 bps&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 align=center&amp;gt;Radio Channel&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The XBee can only communicate with other radios using the same channel.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCH&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;Uses 802.15.4 protocol channel numbers.&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0B - 0x1A (XBee)&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0C - 0x17 (XBee-PRO)&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 align=center&amp;gt;Personal Area Network (PAN) ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The radio can transmit to a specific network number, or use 0xFFFF to broadcast messages to all PANs&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Serial Number&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;Every radio has a 64-bit, read-only serial number. It can be identified by other radios using this number.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATSH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATSL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit Device ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;You can identify a specific XBee using a 16-bit Device ID instead of the 64-bit serial number. See Destination ID for more information.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATMY&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Destination ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;&amp;lt;p&amp;gt;Specify the device ID of a specific XBee to transmit to or use 0x000000000000FFFF to broadcast to the entire PAN.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To use 16-bit addressing, set the high byte to 0 and the low byte to the 16-bit Device ID of the XB you are transmitting to.&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATDH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATDL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;API Mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Gives you more control over communications between XBees, including non-standard packet sizes. Refer to the XBee manual for more information on API/Transparent Mode.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAP&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0 = API disabled (use Transparent Mode)&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = API enabled&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = API enabled (w/ escaped control characters)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Transparent Operation===&lt;br /&gt;
By default, the radios are set to work in transparent mode (as opposed to API mode).&lt;br /&gt;
&lt;br /&gt;
====Unicast/Multicast Mode====&lt;br /&gt;
(see section 2.4.1 in the manual)&lt;br /&gt;
&lt;br /&gt;
A radio will be able to send send data to any other radio having the same channel (CH parameters), PAN-ID (ID parameter), and has a source address (MY in 16-bit address mode, SL+SH parameters in 64-bit address mode; see 2.4 in the manual for more about 16-bit versus 64-bit addressing) equal to the destination address (DL parameter in 16-bit addressing mode, DL+DH in 64-bit addressing mode) of the sending radio.  You can set these parameters using the AT commands.&lt;br /&gt;
&lt;br /&gt;
====Broadcast Mode====&lt;br /&gt;
(see section 2.4.2 in the manual)&lt;br /&gt;
&lt;br /&gt;
To make your XBee broadcast packets, set the DL parameters to FFFF and the DH parameter to 0.&lt;br /&gt;
&lt;br /&gt;
===Proprietary API Mode===&lt;br /&gt;
To use the API mode, set the AP parameter to 1 or 2, depending on whether you will need escape characters (see 3.4 in the manual for more information).&lt;br /&gt;
&lt;br /&gt;
The API mode allows users to send data in a packet structure.  Commands and specific destination addresses can be embedded into packets, which allows you to give the radio commands without having to enter the AT command mode.  The packet also inclues a checksum (the packet won&#039;t be sent/received if this is wrong), and receiving packets will have things like source address and signal strength embedded.&lt;br /&gt;
&lt;br /&gt;
Writing software for the API mode may be more difficult, as you have to assemble a packet and calculate a checksum.  You may wish to use API mode if you need to be able to detect corrupt data or if you need to communicate to many different radios individually.&lt;br /&gt;
&lt;br /&gt;
====Reading Packets with MATLAB in API Modes====&lt;br /&gt;
You can read XBee API packets with MATLAB using the &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; function if you are using API Mode 1, if your packets are the same length.  When using &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt;, you can specify how many bytes to read, and which data type the bytes should be interpreted as (integer, float, etc.).  However, when using API Mode 2, &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; becomes tricky to use because the escape characters will insert another byte into your packet.  One way around this is to read all the data as chars, process the escape characters, and then use the MEX function fourChar2Float to convert the chars into a 32-bit floating point number.  (See the comments in fourChar2Float.c for usage details).&lt;br /&gt;
&lt;br /&gt;
Download fourChar2Float here: [[Image:fourChar2Float.zip]]&lt;br /&gt;
&lt;br /&gt;
===ZigBee Mode===&lt;br /&gt;
Maxstream provides a ZigBee stack for the XBee, but the firmware must be changed.  The firmware can be changed with X-CTU, X-CTU can uplink to a server and download the correct firmware.&lt;br /&gt;
&lt;br /&gt;
==Setting up Your XBee Network==&lt;br /&gt;
Although the XBee radios will be able to communicate with each other straight out of the box, they will be in broadcast mode, which means that your radio will be sending data to every other radio in the room, which is in most cases undesirable.  Your radio will also be transmitting in broadcast mode, which could interfere with someone else&#039;s communications.&lt;br /&gt;
&lt;br /&gt;
In order for two or more XBee radios to communicate, they must&lt;br /&gt;
#Have the same &#039;&#039;&#039;channel ID&#039;&#039;&#039;&lt;br /&gt;
#Have the same &#039;&#039;&#039;network ID&#039;&#039;&#039;&lt;br /&gt;
#The &#039;&#039;&#039;source ID&#039;&#039;&#039; on the receiving radio must match the &#039;&#039;&#039;destination ID&#039;&#039;&#039; of the sending radio.&lt;br /&gt;
&lt;br /&gt;
To set the radios for point-to-point communication, there are four things to consider:&lt;br /&gt;
*Source ID - The Source ID is the ID number of your particular radio.  You can read or write this parameter using the AT command &#039;&#039;&#039;ATMY&#039;&#039;&#039;.&lt;br /&gt;
*Destination ID - The Destination ID is the ID of the radio that you want to send to.&lt;br /&gt;
*PAN (Personal Area Network) ID is the ID of the network.  Your radio will only send to radios with the same PAN ID unless you set your own ID to 0xFFFF, which will make you broadcast across all networks on the same channel.&lt;br /&gt;
*Channel - This is the radio channel of your XBee radio.  Radios must be on the same channel in order to communicate.  You can reduce interference between different XBee networks by using a different channel.&lt;br /&gt;
&lt;br /&gt;
Your radio has two source IDs:&lt;br /&gt;
*A unique 64-bit serial number that is set at the factory and cannot be changed.&lt;br /&gt;
*A 16-bit ID that you can change.&lt;br /&gt;
&lt;br /&gt;
===Example: Serial Cable Replacement (2 radios)===&lt;br /&gt;
If you simply want a pair of radios to communicate, the best way is to use the unique 64-bit serial number of your radio, which will eliminate the problem of someone else using the same channel, PAN ID, and IDs that you are using.  Configure your radios by doing the following:&lt;br /&gt;
&lt;br /&gt;
For both radios, &lt;br /&gt;
#Set the channels to be the same.&lt;br /&gt;
#Set the PAN ID to be the same.&lt;br /&gt;
#Set DH and DL to be equal to the SH and SL of the other radio, respectively.&lt;br /&gt;
#Set the MY parameter to 0xFFFF.  This will block any messages with a 16-bit destination address.&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
In this example, we set the channel, PAN ID, source ID, and destination ID. (The things that you type into the terminal are bold, the reply from the radio is plain.) &lt;br /&gt;
&lt;br /&gt;
Radio1:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200 &#039;&#039;Note: This serial number will be unique to your hardware&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B78&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go to your other radio.&lt;br /&gt;
&lt;br /&gt;
Radio2:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B96&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to Radio1:&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Round Trip Latency Testing==&lt;br /&gt;
A test measuring the round trip time of the Xbee radio was performed to gain a sense of the average latency of the XBee radios communicating over the 802.15.4 protocol.&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
One XBee radio was connected to a computer running Windows XP with a standard USB-&amp;gt;RS232 cable.  As programmed in Visual Studio C++ Express, the computer performed a &amp;quot;loopback&amp;quot; protocol; the computer wrote the data it received (to the serial port) upon the receipt of a byte (from the serial port).  In this sense, the computer simply echoes the data it receives on the serial port.&lt;br /&gt;
&lt;br /&gt;
A second XBee radio was connected to a PIC184520 with a 40MHz crystal.  Using the PIC-C programming language, the XBee radio is controlled using the pic&#039;s hardware EUSART.  A variety of baud rates were tested as listed in the table below.&lt;br /&gt;
&lt;br /&gt;
To capture the round trip time, the pic was programmed to set a digital output high, and send a byte of data.  Upon receipt of the data (from the loopbacked PC), the pic subsequently set the digital output low.  By viewing the digital output on an oscilloscope, the width of the pulse was measured to determine the amount of time between sending and receiving a single byte of data.&lt;br /&gt;
&lt;br /&gt;
*Note that the latency of the computer is included in this test.  For this test, it was assumed that the latency of the computer would be insignificant relative to the radios&#039; communication time.  To remove this additional latency in the future, one should create a hardware loopback by powering the first Xbee radio and physically connecting this radio&#039;s Rx and Tx line via a wire (no computer or PIC needed).&lt;br /&gt;
&lt;br /&gt;
===Results===&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;Baud Rate (bps)&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;Round Trip Latency (ms)&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;9600&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;numbers coming soon!&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;19200&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;numbers coming soon!&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;38400&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;numbers coming soon!&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;57600&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;numbers coming soon!&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;115200&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;numbers coming soon!&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;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13085</id>
		<title>XBee radio communication between PICs</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13085"/>
		<updated>2009-04-21T07:14:27Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Reading Packets with MATLAB in API Modes= */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Typically, two pics communicate by [http://en.wikipedia.org/wiki/RS-232 RS-232], a wired transmission.  However, it may be desirable to communicate via a wireless link.  This wiki page demonstrates using XBee radio modems which conform to the IEEE 802.15.4 protocol.  These radios will allow for wireless communication between two PICs and between a PIC and a computer. &lt;br /&gt;
&lt;br /&gt;
[[Image:XBeePinOut.jpg |thumb|300px|right| XBee Manual]]&lt;br /&gt;
&lt;br /&gt;
The IEEE 802.15.4 is a [http://en.wikipedia.org/wiki/IEEE_802.15.4 point-point/point-multipoint] communications protocol (similar to Bluetooth) designed for low-power devices.  Like Bluetooth, the IEEE 802.15.4 specification also uses the 2.4 GHz ISM band.  The ZigBee protocol, which deals with mesh networking and routing, is built upon the IEEE 802.15.4 specification.&lt;br /&gt;
&lt;br /&gt;
The XBee radios, made by Digi (formerly Maxstream), are shipped with firmware implementing the IEEE 802.15.4 protocol, but can be loaded with the ZigBee protocol stack, which can be downloaded from the Digi website.  Note that ZigBee is still in its infancy and devices from different manufacturers may not be compatible.  The range for an XBee Pro indoors is up to 300 feet while line of site, outdoor communication is up to a mile. ([http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual])&lt;br /&gt;
 &lt;br /&gt;
The XBee chip is designed to be mounted in specific sockets (Note: These sockets don&#039;t fit in a standard bread board!)  We soldered wires directly to the socket, which were then placed in a breadboard.  (Printed circuit boards are being created to fix this issue.)  The Xbee also requires a 3.3 voltage regulator.&lt;br /&gt;
&lt;br /&gt;
For the pin locations, see page 7 of [http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual] or the figure to the right.&lt;br /&gt;
&lt;br /&gt;
For PIC to computer interface, a terminal program such as X-CTU needs to be used. Although other terminal programs might work as well, X-CTU software was designed specifically for the XBee, and in addition to its terminal functions, it also has functions for testing signal strength, reading, saving, and writing the state of the XBee, and updating firmware. The X-CTU program is run on the PC while connected to a X-Bee via a serial port. The X-CTU software can be downloaded from [http://www.oricomtech.com/download.htm X-CTU Site].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Circuit ==&lt;br /&gt;
[[Image:pictopic.jpg |thumb|300px|left| Communicating Pic to Pic]] [[Image:pctopic.jpg |thumb|left|300px| Communicating Computer to Pic]]&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The XBee module can be connected directly to the UART port on the PIC.  To connect it to a RS-232 port, one must use a voltage shifting transceiver chip because RS232 signals are from -15V to + 15V.  The MAX232/ST232 chip will convert voltage level from RS-232 to TTL logic levels and vice versa.  The chip requires 4 external capacitors (the fifth is a bypass capacitor) in order to operate.&lt;br /&gt;
The transceiver data sheet can be found [http://www.tranzistoare.ro/datasheets/105/502490_DS.pdf here].&lt;br /&gt;
&lt;br /&gt;
In the circuit shown above, the serial port uses a DE9F 9-pin connector (Digikey part number 	209FE-ND), which is used to connect the computer&#039;s serial port to the circuit. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to PIC, two of the circuits shown on the left should be used. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to computer, one of each of the circuits should be used.  A better solution to connecting a PC to an XBee module is to use a cable that connects to the PC&#039;s USB port and converts to RS-232, as described on this [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
==XBee Interface Board==&lt;br /&gt;
[[Image:xbee_board_with_radio.jpg|thumb|right]]&lt;br /&gt;
[[XBee_Interface_Board| XBee Interface Board]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Communication PIC to Computer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First you will need to get your PC speaking RS-232.  You can try hyperterminal (standard on the PC) or [http://homepage.mac.com/dalverson/zterm/ zterm] or similar for the Mac for simple interactive RS-232.  See [[Serial communication with Matlab|this page]] for an example of RS-232 communication using matlab.  Or you can try [http://www.codeproject.com/KB/system/cserialport.aspx this C++ library] from within a Win32 C++ program.  In any case, you are likely to need a special adapter cable to connect your PC to the XBee as described on the [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
The PIC code below will wait for the character &#039;+&#039; to appear on the serial port, and when it does, it will add the next two single digit numbers that are entered and return the result back to the computer. In order to connect with the PIC, the program X-CTU must be used on the computer as discussed above. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a;&lt;br /&gt;
char abuff[2]={0};&lt;br /&gt;
int b;&lt;br /&gt;
char bbuff[2]={0};&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
int sum;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;+&#039;){&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         abuff[0] = getc();&lt;br /&gt;
         a = atoi(abuff);&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         bbuff[0] = getc();&lt;br /&gt;
         b = atoi(bbuff);&lt;br /&gt;
         &lt;br /&gt;
         sum = a+b;&lt;br /&gt;
         printf(&amp;quot;sum=%u\r\n&amp;quot;,sum);&lt;br /&gt;
         x=0;&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;
&#039;&#039;&#039;Communication PIC to PIC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In this communication, each PIC has its own code, which is shown below. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Transmitter&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* pic2pic_transmit.c&lt;br /&gt;
ME333 Lab 5&lt;br /&gt;
The transmitter checks to see if PIN A0 is high or low. &lt;br /&gt;
If the  pin is high, the transmitter sends the signal &#039;a&#039; to the receiver and &lt;br /&gt;
turns on an LED. If the pins is low, the transmitter sends the signal &#039;b&#039;. &lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
      if (input(PIN_A0)){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         printf(&amp;quot;a&amp;quot;); //sends signal a&lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         printf(&amp;quot;b&amp;quot;); //sends signal b&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;
&#039;&#039;Receiver&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* pic2pic_receive&lt;br /&gt;
ME 333 Lab 5&lt;br /&gt;
The receiver checks the signal from the XBEE and if the signal is &#039;a&#039;, the receiver turns on an LED.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;a&#039;){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         &lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         &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;
==Using the XBee Radio==&lt;br /&gt;
===Using X-CTU===&lt;br /&gt;
Note: Setting up the radios will require the X-CTU terminal program.  Select your settings under the &#039;&#039;&#039;PC Settings&#039;&#039;&#039; tab and click on &#039;&#039;&#039;Test/Query&#039;&#039;&#039;.  Unfortunately, there is no easy way to tell what the current baud rate of the radio is set at (default is 9600), so you might have to try them all.  Whoever had the radio before you may have changed the settings of the radio, so after your radio is successfully detected, you may wish to use command &#039;&#039;&#039;ATRE&#039;&#039;&#039; to reset the radio to factory defaults, and &#039;&#039;&#039;ATWR&#039;&#039;&#039; to save your settings.&lt;br /&gt;
&lt;br /&gt;
===Parameters AT Commands===&lt;br /&gt;
AT commands enable you to set the parameters of the XBee radio.  To enter AT command mode, open X-CTU (program discussed in overview), make sure your radio is detected, click on the &#039;&#039;&#039;terminal&#039;&#039;&#039; tab, and type in &amp;quot;+++&amp;quot; (without the quotes).  The chip should respond with an &amp;quot;OK&amp;quot;.  Then, you can enter the commands. If the radio doesn&#039;t receive a commands for a while (default 10s), then it will exit command mode and return to normal operation mode; you can also force a return to normal operation mode with a ATCN command.  &#039;&#039;&#039;All parameters are in hexadecimal format.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Commands are usually entered in the following formats (after entering command mode):&lt;br /&gt;
&lt;br /&gt;
To read parameters: AT&amp;lt;parameter&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To write parameters: AT&amp;lt;parameter&amp;gt; &amp;lt;value&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to read the ID of the radio, you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY&lt;br /&gt;
&lt;br /&gt;
To set the value of the radio&#039;s ID to 1 you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY 1&lt;br /&gt;
&lt;br /&gt;
The radio will start using the updated parameters after exiting the command mode, or if an ATAC (apply changes) command is given.  &#039;&#039;&#039;If you want your changes to persist after rebooting the radio, make sure you use the ATWR command).&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Specific instructions and descriptions of allowable parameters to send can be found in Section 3 of the XBee Product Manual.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some commonly used commands:&lt;br /&gt;
&amp;lt;table border=1 cellpadding=2 width=75%&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Parameter&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Command&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Value&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;Basic Commands&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Enter command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;+++&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;N/A&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&amp;gt;Exit command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCN&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&amp;gt;Apply changes&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAC&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&amp;gt;Write current parameter values to non-volatile memory (must reset or use ATAC for changes to take effect)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATWR&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&amp;gt;Restore defaults&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATRE&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&amp;gt;Reset&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATFR&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 colspan=4 align=center&amp;gt;&amp;lt;b&amp;gt;For items below, type command followed by a value to set the parameter or without a value to check the current value.&amp;lt;/b&amp;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 align=center&amp;gt;Baud Rate&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;&amp;lt;p&amp;gt;Sets the baud rate at which the XBee communicates with the serial device it is physically connected to.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;See the XBee manual for information on setting non-standard baud rates&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATBD&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0-7 (standard baud rates)&amp;lt;br&amp;gt;&lt;br /&gt;
	0 = 1200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = 2400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = 4800 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	3 = 9600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	4 = 19200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	5 = 38400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	6 = 57600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	7 = 115200 bps&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 align=center&amp;gt;Radio Channel&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The XBee can only communicate with other radios using the same channel.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCH&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;Uses 802.15.4 protocol channel numbers.&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0B - 0x1A (XBee)&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0C - 0x17 (XBee-PRO)&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 align=center&amp;gt;Personal Area Network (PAN) ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The radio can transmit to a specific network number, or use 0xFFFF to broadcast messages to all PANs&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Serial Number&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;Every radio has a 64-bit, read-only serial number. It can be identified by other radios using this number.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATSH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATSL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit Device ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;You can identify a specific XBee using a 16-bit Device ID instead of the 64-bit serial number. See Destination ID for more information.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATMY&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Destination ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;&amp;lt;p&amp;gt;Specify the device ID of a specific XBee to transmit to or use 0x000000000000FFFF to broadcast to the entire PAN.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To use 16-bit addressing, set the high byte to 0 and the low byte to the 16-bit Device ID of the XB you are transmitting to.&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATDH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATDL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;API Mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Gives you more control over communications between XBees, including non-standard packet sizes. Refer to the XBee manual for more information on API/Transparent Mode.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAP&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0 = API disabled (use Transparent Mode)&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = API enabled&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = API enabled (w/ escaped control characters)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Transparent Operation===&lt;br /&gt;
By default, the radios are set to work in transparent mode (as opposed to API mode).&lt;br /&gt;
&lt;br /&gt;
====Unicast/Multicast Mode====&lt;br /&gt;
(see section 2.4.1 in the manual)&lt;br /&gt;
&lt;br /&gt;
A radio will be able to send send data to any other radio having the same channel (CH parameters), PAN-ID (ID parameter), and has a source address (MY in 16-bit address mode, SL+SH parameters in 64-bit address mode; see 2.4 in the manual for more about 16-bit versus 64-bit addressing) equal to the destination address (DL parameter in 16-bit addressing mode, DL+DH in 64-bit addressing mode) of the sending radio.  You can set these parameters using the AT commands.&lt;br /&gt;
&lt;br /&gt;
====Broadcast Mode====&lt;br /&gt;
(see section 2.4.2 in the manual)&lt;br /&gt;
&lt;br /&gt;
To make your XBee broadcast packets, set the DL parameters to FFFF and the DH parameter to 0.&lt;br /&gt;
&lt;br /&gt;
===Proprietary API Mode===&lt;br /&gt;
To use the API mode, set the AP parameter to 1 or 2, depending on whether you will need escape characters (see 3.4 in the manual for more information).&lt;br /&gt;
&lt;br /&gt;
The API mode allows users to send data in a packet structure.  Commands and specific destination addresses can be embedded into packets, which allows you to give the radio commands without having to enter the AT command mode.  The packet also inclues a checksum (the packet won&#039;t be sent/received if this is wrong), and receiving packets will have things like source address and signal strength embedded.&lt;br /&gt;
&lt;br /&gt;
Writing software for the API mode may be more difficult, as you have to assemble a packet and calculate a checksum.  You may wish to use API mode if you need to be able to detect corrupt data or if you need to communicate to many different radios individually.&lt;br /&gt;
&lt;br /&gt;
====Reading Packets with MATLAB in API Modes====&lt;br /&gt;
You can read XBee API packets with MATLAB using the &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; function if you are using API Mode 1, if your packets are the same length.  When using &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt;, you can specify how many bytes to read, and which data type the bytes should be interpreted as (integer, float, etc.).  However, when using API Mode 2, &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; becomes tricky to use because the escape characters will insert another byte into your packet.  One way around this is to read all the data as chars, process the escape characters, and then use the MEX function fourChar2Float to convert the chars into a 32-bit floating point number.&lt;br /&gt;
&lt;br /&gt;
Download fourChar2Float here: [[Image:fourChar2Float.zip]]&lt;br /&gt;
&lt;br /&gt;
===ZigBee Mode===&lt;br /&gt;
Maxstream provides a ZigBee stack for the XBee, but the firmware must be changed.  The firmware can be changed with X-CTU, X-CTU can uplink to a server and download the correct firmware.&lt;br /&gt;
&lt;br /&gt;
==Setting up Your XBee Network==&lt;br /&gt;
Although the XBee radios will be able to communicate with each other straight out of the box, they will be in broadcast mode, which means that your radio will be sending data to every other radio in the room, which is in most cases undesirable.  Your radio will also be transmitting in broadcast mode, which could interfere with someone else&#039;s communications.&lt;br /&gt;
&lt;br /&gt;
In order for two or more XBee radios to communicate, they must&lt;br /&gt;
#Have the same &#039;&#039;&#039;channel ID&#039;&#039;&#039;&lt;br /&gt;
#Have the same &#039;&#039;&#039;network ID&#039;&#039;&#039;&lt;br /&gt;
#The &#039;&#039;&#039;source ID&#039;&#039;&#039; on the receiving radio must match the &#039;&#039;&#039;destination ID&#039;&#039;&#039; of the sending radio.&lt;br /&gt;
&lt;br /&gt;
To set the radios for point-to-point communication, there are four things to consider:&lt;br /&gt;
*Source ID - The Source ID is the ID number of your particular radio.  You can read or write this parameter using the AT command &#039;&#039;&#039;ATMY&#039;&#039;&#039;.&lt;br /&gt;
*Destination ID - The Destination ID is the ID of the radio that you want to send to.&lt;br /&gt;
*PAN (Personal Area Network) ID is the ID of the network.  Your radio will only send to radios with the same PAN ID unless you set your own ID to 0xFFFF, which will make you broadcast across all networks on the same channel.&lt;br /&gt;
*Channel - This is the radio channel of your XBee radio.  Radios must be on the same channel in order to communicate.  You can reduce interference between different XBee networks by using a different channel.&lt;br /&gt;
&lt;br /&gt;
Your radio has two source IDs:&lt;br /&gt;
*A unique 64-bit serial number that is set at the factory and cannot be changed.&lt;br /&gt;
*A 16-bit ID that you can change.&lt;br /&gt;
&lt;br /&gt;
===Example: Serial Cable Replacement (2 radios)===&lt;br /&gt;
If you simply want a pair of radios to communicate, the best way is to use the unique 64-bit serial number of your radio, which will eliminate the problem of someone else using the same channel, PAN ID, and IDs that you are using.  Configure your radios by doing the following:&lt;br /&gt;
&lt;br /&gt;
For both radios, &lt;br /&gt;
#Set the channels to be the same.&lt;br /&gt;
#Set the PAN ID to be the same.&lt;br /&gt;
#Set DH and DL to be equal to the SH and SL of the other radio, respectively.&lt;br /&gt;
#Set the MY parameter to 0xFFFF.  This will block any messages with a 16-bit destination address.&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
In this example, we set the channel, PAN ID, source ID, and destination ID. (The things that you type into the terminal are bold, the reply from the radio is plain.) &lt;br /&gt;
&lt;br /&gt;
Radio1:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200 &#039;&#039;Note: This serial number will be unique to your hardware&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B78&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go to your other radio.&lt;br /&gt;
&lt;br /&gt;
Radio2:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B96&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to Radio1:&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Round Trip Latency Testing==&lt;br /&gt;
A test measuring the round trip time of the Xbee radio was performed to gain a sense of the average latency of the XBee radios communicating over the 802.15.4 protocol.&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
One XBee radio was connected to a computer running Windows XP with a standard USB-&amp;gt;RS232 cable.  As programmed in Visual Studio C++ Express, the computer performed a &amp;quot;loopback&amp;quot; protocol; the computer wrote the data it received (to the serial port) upon the receipt of a byte (from the serial port).  In this sense, the computer simply echoes the data it receives on the serial port.&lt;br /&gt;
&lt;br /&gt;
A second XBee radio was connected to a PIC184520 with a 40MHz crystal.  Using the PIC-C programming language, the XBee radio is controlled using the pic&#039;s hardware EUSART.  A variety of baud rates were tested as listed in the table below.&lt;br /&gt;
&lt;br /&gt;
To capture the round trip time, the pic was programmed to set a digital output high, and send a byte of data.  Upon receipt of the data (from the loopbacked PC), the pic subsequently set the digital output low.  By viewing the digital output on an oscilloscope, the width of the pulse was measured to determine the amount of time between sending and receiving a single byte of data.&lt;br /&gt;
&lt;br /&gt;
*Note that the latency of the computer is included in this test.  For this test, it was assumed that the latency of the computer would be insignificant relative to the radios&#039; communication time.  To remove this additional latency in the future, one should create a hardware loopback by powering the first Xbee radio and physically connecting this radio&#039;s Rx and Tx line via a wire (no computer or PIC needed).&lt;br /&gt;
&lt;br /&gt;
===Results===&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;Baud Rate (bps)&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;Round Trip Latency (ms)&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;9600&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;numbers coming soon!&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;19200&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;numbers coming soon!&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;38400&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;numbers coming soon!&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;57600&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;numbers coming soon!&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;115200&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;numbers coming soon!&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;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:FourChar2Float.zip&amp;diff=13084</id>
		<title>File:FourChar2Float.zip</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:FourChar2Float.zip&amp;diff=13084"/>
		<updated>2009-04-21T04:45:12Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13083</id>
		<title>XBee radio communication between PICs</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=XBee_radio_communication_between_PICs&amp;diff=13083"/>
		<updated>2009-04-21T04:44:46Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Proprietary API mode */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Typically, two pics communicate by [http://en.wikipedia.org/wiki/RS-232 RS-232], a wired transmission.  However, it may be desirable to communicate via a wireless link.  This wiki page demonstrates using XBee radio modems which conform to the IEEE 802.15.4 protocol.  These radios will allow for wireless communication between two PICs and between a PIC and a computer. &lt;br /&gt;
&lt;br /&gt;
[[Image:XBeePinOut.jpg |thumb|300px|right| XBee Manual]]&lt;br /&gt;
&lt;br /&gt;
The IEEE 802.15.4 is a [http://en.wikipedia.org/wiki/IEEE_802.15.4 point-point/point-multipoint] communications protocol (similar to Bluetooth) designed for low-power devices.  Like Bluetooth, the IEEE 802.15.4 specification also uses the 2.4 GHz ISM band.  The ZigBee protocol, which deals with mesh networking and routing, is built upon the IEEE 802.15.4 specification.&lt;br /&gt;
&lt;br /&gt;
The XBee radios, made by Digi (formerly Maxstream), are shipped with firmware implementing the IEEE 802.15.4 protocol, but can be loaded with the ZigBee protocol stack, which can be downloaded from the Digi website.  Note that ZigBee is still in its infancy and devices from different manufacturers may not be compatible.  The range for an XBee Pro indoors is up to 300 feet while line of site, outdoor communication is up to a mile. ([http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual])&lt;br /&gt;
 &lt;br /&gt;
The XBee chip is designed to be mounted in specific sockets (Note: These sockets don&#039;t fit in a standard bread board!)  We soldered wires directly to the socket, which were then placed in a breadboard.  (Printed circuit boards are being created to fix this issue.)  The Xbee also requires a 3.3 voltage regulator.&lt;br /&gt;
&lt;br /&gt;
For the pin locations, see page 7 of [http://ftp1.digi.com/support/documentation/manual_xb_oemrfmodules_802.15.4.pdf XBee Manual] or the figure to the right.&lt;br /&gt;
&lt;br /&gt;
For PIC to computer interface, a terminal program such as X-CTU needs to be used. Although other terminal programs might work as well, X-CTU software was designed specifically for the XBee, and in addition to its terminal functions, it also has functions for testing signal strength, reading, saving, and writing the state of the XBee, and updating firmware. The X-CTU program is run on the PC while connected to a X-Bee via a serial port. The X-CTU software can be downloaded from [http://www.oricomtech.com/download.htm X-CTU Site].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Circuit ==&lt;br /&gt;
[[Image:pictopic.jpg |thumb|300px|left| Communicating Pic to Pic]] [[Image:pctopic.jpg |thumb|left|300px| Communicating Computer to Pic]]&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The XBee module can be connected directly to the UART port on the PIC.  To connect it to a RS-232 port, one must use a voltage shifting transceiver chip because RS232 signals are from -15V to + 15V.  The MAX232/ST232 chip will convert voltage level from RS-232 to TTL logic levels and vice versa.  The chip requires 4 external capacitors (the fifth is a bypass capacitor) in order to operate.&lt;br /&gt;
The transceiver data sheet can be found [http://www.tranzistoare.ro/datasheets/105/502490_DS.pdf here].&lt;br /&gt;
&lt;br /&gt;
In the circuit shown above, the serial port uses a DE9F 9-pin connector (Digikey part number 	209FE-ND), which is used to connect the computer&#039;s serial port to the circuit. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to PIC, two of the circuits shown on the left should be used. &lt;br /&gt;
&lt;br /&gt;
In order to communicate PIC to computer, one of each of the circuits should be used.  A better solution to connecting a PC to an XBee module is to use a cable that connects to the PC&#039;s USB port and converts to RS-232, as described on this [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
==XBee Interface Board==&lt;br /&gt;
[[Image:xbee_board_with_radio.jpg|thumb|right]]&lt;br /&gt;
[[XBee_Interface_Board| XBee Interface Board]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=&amp;quot;all&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Communication PIC to Computer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First you will need to get your PC speaking RS-232.  You can try hyperterminal (standard on the PC) or [http://homepage.mac.com/dalverson/zterm/ zterm] or similar for the Mac for simple interactive RS-232.  See [[Serial communication with Matlab|this page]] for an example of RS-232 communication using matlab.  Or you can try [http://www.codeproject.com/KB/system/cserialport.aspx this C++ library] from within a Win32 C++ program.  In any case, you are likely to need a special adapter cable to connect your PC to the XBee as described on the [[PIC RS232]] page.&lt;br /&gt;
&lt;br /&gt;
The PIC code below will wait for the character &#039;+&#039; to appear on the serial port, and when it does, it will add the next two single digit numbers that are entered and return the result back to the computer. In order to connect with the PIC, the program X-CTU must be used on the computer as discussed above. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int a;&lt;br /&gt;
char abuff[2]={0};&lt;br /&gt;
int b;&lt;br /&gt;
char bbuff[2]={0};&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
int sum;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;+&#039;){&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         abuff[0] = getc();&lt;br /&gt;
         a = atoi(abuff);&lt;br /&gt;
         while (!kbhit()){}&lt;br /&gt;
         bbuff[0] = getc();&lt;br /&gt;
         b = atoi(bbuff);&lt;br /&gt;
         &lt;br /&gt;
         sum = a+b;&lt;br /&gt;
         printf(&amp;quot;sum=%u\r\n&amp;quot;,sum);&lt;br /&gt;
         x=0;&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;
&#039;&#039;&#039;Communication PIC to PIC&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In this communication, each PIC has its own code, which is shown below. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Transmitter&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* pic2pic_transmit.c&lt;br /&gt;
ME333 Lab 5&lt;br /&gt;
The transmitter checks to see if PIN A0 is high or low. &lt;br /&gt;
If the  pin is high, the transmitter sends the signal &#039;a&#039; to the receiver and &lt;br /&gt;
turns on an LED. If the pins is low, the transmitter sends the signal &#039;b&#039;. &lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
      if (input(PIN_A0)){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         printf(&amp;quot;a&amp;quot;); //sends signal a&lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         printf(&amp;quot;b&amp;quot;); //sends signal b&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;
&#039;&#039;Receiver&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* pic2pic_receive&lt;br /&gt;
ME 333 Lab 5&lt;br /&gt;
The receiver checks the signal from the XBEE and if the signal is &#039;a&#039;, the receiver turns on an LED.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;18f4520.h&amp;gt;&lt;br /&gt;
#fuses HS,NOLVP,NOWDT,NOPROTECT        &lt;br /&gt;
#use delay(clock=20000000)       // 20 MHz crystal on PCB&lt;br /&gt;
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...&lt;br /&gt;
#use rs232(baud=9600, UART1)       // hardware uart much better; uses  RC6/TX and RC7/RX &lt;br /&gt;
// characters tranmitted faster than the pic eats them will cause UART to hang.&lt;br /&gt;
&lt;br /&gt;
#define LED_0 PIN_D0&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
char x;&lt;br /&gt;
&lt;br /&gt;
void main() {&lt;br /&gt;
   while (TRUE) { &lt;br /&gt;
       if (kbhit()) {&lt;br /&gt;
         x = getc();&lt;br /&gt;
       }&lt;br /&gt;
       if (x==&#039;a&#039;){&lt;br /&gt;
         output_high(LED_0);&lt;br /&gt;
         &lt;br /&gt;
       }&lt;br /&gt;
       else{&lt;br /&gt;
         output_low(LED_0);&lt;br /&gt;
         &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;
==Using the XBee Radio==&lt;br /&gt;
===Using X-CTU===&lt;br /&gt;
Note: Setting up the radios will require the X-CTU terminal program.  Select your settings under the &#039;&#039;&#039;PC Settings&#039;&#039;&#039; tab and click on &#039;&#039;&#039;Test/Query&#039;&#039;&#039;.  Unfortunately, there is no easy way to tell what the current baud rate of the radio is set at (default is 9600), so you might have to try them all.  Whoever had the radio before you may have changed the settings of the radio, so after your radio is successfully detected, you may wish to use command &#039;&#039;&#039;ATRE&#039;&#039;&#039; to reset the radio to factory defaults, and &#039;&#039;&#039;ATWR&#039;&#039;&#039; to save your settings.&lt;br /&gt;
&lt;br /&gt;
===Parameters AT Commands===&lt;br /&gt;
AT commands enable you to set the parameters of the XBee radio.  To enter AT command mode, open X-CTU (program discussed in overview), make sure your radio is detected, click on the &#039;&#039;&#039;terminal&#039;&#039;&#039; tab, and type in &amp;quot;+++&amp;quot; (without the quotes).  The chip should respond with an &amp;quot;OK&amp;quot;.  Then, you can enter the commands. If the radio doesn&#039;t receive a commands for a while (default 10s), then it will exit command mode and return to normal operation mode; you can also force a return to normal operation mode with a ATCN command.  &#039;&#039;&#039;All parameters are in hexadecimal format.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Commands are usually entered in the following formats (after entering command mode):&lt;br /&gt;
&lt;br /&gt;
To read parameters: AT&amp;lt;parameter&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To write parameters: AT&amp;lt;parameter&amp;gt; &amp;lt;value&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to read the ID of the radio, you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY&lt;br /&gt;
&lt;br /&gt;
To set the value of the radio&#039;s ID to 1 you could enter:&lt;br /&gt;
&lt;br /&gt;
+++&lt;br /&gt;
ATMY 1&lt;br /&gt;
&lt;br /&gt;
The radio will start using the updated parameters after exiting the command mode, or if an ATAC (apply changes) command is given.  &#039;&#039;&#039;If you want your changes to persist after rebooting the radio, make sure you use the ATWR command).&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Specific instructions and descriptions of allowable parameters to send can be found in Section 3 of the XBee Product Manual.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Some commonly used commands:&lt;br /&gt;
&amp;lt;table border=1 cellpadding=2 width=75%&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Parameter&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Command&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;th&amp;gt;Value&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;Basic Commands&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Enter command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;+++&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=6 align=center&amp;gt;N/A&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&amp;gt;Exit command mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCN&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&amp;gt;Apply changes&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAC&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&amp;gt;Write current parameter values to non-volatile memory (must reset or use ATAC for changes to take effect)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATWR&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&amp;gt;Restore defaults&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATRE&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&amp;gt;Reset&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATFR&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 colspan=4 align=center&amp;gt;&amp;lt;b&amp;gt;For items below, type command followed by a value to set the parameter or without a value to check the current value.&amp;lt;/b&amp;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 align=center&amp;gt;Baud Rate&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;&amp;lt;p&amp;gt;Sets the baud rate at which the XBee communicates with the serial device it is physically connected to.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;See the XBee manual for information on setting non-standard baud rates&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATBD&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0-7 (standard baud rates)&amp;lt;br&amp;gt;&lt;br /&gt;
	0 = 1200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = 2400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = 4800 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	3 = 9600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	4 = 19200 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	5 = 38400 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	6 = 57600 bps&amp;lt;br&amp;gt;&lt;br /&gt;
	7 = 115200 bps&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 align=center&amp;gt;Radio Channel&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The XBee can only communicate with other radios using the same channel.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATCH&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;Uses 802.15.4 protocol channel numbers.&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0B - 0x1A (XBee)&amp;lt;br&amp;gt;&lt;br /&gt;
	0x0C - 0x17 (XBee-PRO)&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 align=center&amp;gt;Personal Area Network (PAN) ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;The radio can transmit to a specific network number, or use 0xFFFF to broadcast messages to all PANs&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Serial Number&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;Every radio has a 64-bit, read-only serial number. It can be identified by other radios using this number.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATSH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATSL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;N/A&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit Device ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;You can identify a specific XBee using a 16-bit Device ID instead of the 64-bit serial number. See Destination ID for more information.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATMY&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&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 rowspan=2 align=center&amp;gt;Destination ID&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td rowspan=2&amp;gt;&amp;lt;p&amp;gt;Specify the device ID of a specific XBee to transmit to or use 0x000000000000FFFF to broadcast to the entire PAN.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To use 16-bit addressing, set the high byte to 0 and the low byte to the 16-bit Device ID of the XB you are transmitting to.&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATDH (high byte)&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;	&amp;lt;td align=center&amp;gt;ATDL (low byte)&amp;lt;/td&amp;gt;&amp;lt;td align=center&amp;gt;16-bit&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;API Mode&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td&amp;gt;Gives you more control over communications between XBees, including non-standard packet sizes. Refer to the XBee manual for more information on API/Transparent Mode.&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;ATAP&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;td align=center&amp;gt;0 = API disabled (use Transparent Mode)&amp;lt;br&amp;gt;&lt;br /&gt;
	1 = API enabled&amp;lt;br&amp;gt;&lt;br /&gt;
	2 = API enabled (w/ escaped control characters)&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Transparent Operation===&lt;br /&gt;
By default, the radios are set to work in transparent mode (as opposed to API mode).&lt;br /&gt;
&lt;br /&gt;
====Unicast/Multicast Mode====&lt;br /&gt;
(see section 2.4.1 in the manual)&lt;br /&gt;
&lt;br /&gt;
A radio will be able to send send data to any other radio having the same channel (CH parameters), PAN-ID (ID parameter), and has a source address (MY in 16-bit address mode, SL+SH parameters in 64-bit address mode; see 2.4 in the manual for more about 16-bit versus 64-bit addressing) equal to the destination address (DL parameter in 16-bit addressing mode, DL+DH in 64-bit addressing mode) of the sending radio.  You can set these parameters using the AT commands.&lt;br /&gt;
&lt;br /&gt;
====Broadcast Mode====&lt;br /&gt;
(see section 2.4.2 in the manual)&lt;br /&gt;
&lt;br /&gt;
To make your XBee broadcast packets, set the DL parameters to FFFF and the DH parameter to 0.&lt;br /&gt;
&lt;br /&gt;
===Proprietary API Mode===&lt;br /&gt;
To use the API mode, set the AP parameter to 1 or 2, depending on whether you will need escape characters (see 3.4 in the manual for more information).&lt;br /&gt;
&lt;br /&gt;
The API mode allows users to send data in a packet structure.  Commands and specific destination addresses can be embedded into packets, which allows you to give the radio commands without having to enter the AT command mode.  The packet also inclues a checksum (the packet won&#039;t be sent/received if this is wrong), and receiving packets will have things like source address and signal strength embedded.&lt;br /&gt;
&lt;br /&gt;
Writing software for the API mode may be more difficult, as you have to assemble a packet and calculate a checksum.  You may wish to use API mode if you need to be able to detect corrupt data or if you need to communicate to many different radios individually.&lt;br /&gt;
&lt;br /&gt;
====Reading Packets with MATLAB in API Modes=====&lt;br /&gt;
You can read XBee API packets with MATLAB using the &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; function if you are using API Mode 1, if your packets are the same length.  When using &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt;, you can specify how many bytes to read, and which data type the bytes should be interpreted as (integer, float, etc.).  However, when using API Mode 2, &amp;lt;tt&amp;gt;fread()&amp;lt;/tt&amp;gt; becomes tricky to use because the escape characters will insert another byte into your packet.  One way around this is to read all the data as chars, process the escape characters, and then use the MEX function fourChar2Float to convert the chars into a 32-bit floating point number.&lt;br /&gt;
&lt;br /&gt;
Download fourChar2Float here: [[Image:fourChar2Float.zip]]&lt;br /&gt;
&lt;br /&gt;
===ZigBee Mode===&lt;br /&gt;
Maxstream provides a ZigBee stack for the XBee, but the firmware must be changed.  The firmware can be changed with X-CTU, X-CTU can uplink to a server and download the correct firmware.&lt;br /&gt;
&lt;br /&gt;
==Setting up Your XBee Network==&lt;br /&gt;
Although the XBee radios will be able to communicate with each other straight out of the box, they will be in broadcast mode, which means that your radio will be sending data to every other radio in the room, which is in most cases undesirable.  Your radio will also be transmitting in broadcast mode, which could interfere with someone else&#039;s communications.&lt;br /&gt;
&lt;br /&gt;
In order for two or more XBee radios to communicate, they must&lt;br /&gt;
#Have the same &#039;&#039;&#039;channel ID&#039;&#039;&#039;&lt;br /&gt;
#Have the same &#039;&#039;&#039;network ID&#039;&#039;&#039;&lt;br /&gt;
#The &#039;&#039;&#039;source ID&#039;&#039;&#039; on the receiving radio must match the &#039;&#039;&#039;destination ID&#039;&#039;&#039; of the sending radio.&lt;br /&gt;
&lt;br /&gt;
To set the radios for point-to-point communication, there are four things to consider:&lt;br /&gt;
*Source ID - The Source ID is the ID number of your particular radio.  You can read or write this parameter using the AT command &#039;&#039;&#039;ATMY&#039;&#039;&#039;.&lt;br /&gt;
*Destination ID - The Destination ID is the ID of the radio that you want to send to.&lt;br /&gt;
*PAN (Personal Area Network) ID is the ID of the network.  Your radio will only send to radios with the same PAN ID unless you set your own ID to 0xFFFF, which will make you broadcast across all networks on the same channel.&lt;br /&gt;
*Channel - This is the radio channel of your XBee radio.  Radios must be on the same channel in order to communicate.  You can reduce interference between different XBee networks by using a different channel.&lt;br /&gt;
&lt;br /&gt;
Your radio has two source IDs:&lt;br /&gt;
*A unique 64-bit serial number that is set at the factory and cannot be changed.&lt;br /&gt;
*A 16-bit ID that you can change.&lt;br /&gt;
&lt;br /&gt;
===Example: Serial Cable Replacement (2 radios)===&lt;br /&gt;
If you simply want a pair of radios to communicate, the best way is to use the unique 64-bit serial number of your radio, which will eliminate the problem of someone else using the same channel, PAN ID, and IDs that you are using.  Configure your radios by doing the following:&lt;br /&gt;
&lt;br /&gt;
For both radios, &lt;br /&gt;
#Set the channels to be the same.&lt;br /&gt;
#Set the PAN ID to be the same.&lt;br /&gt;
#Set DH and DL to be equal to the SH and SL of the other radio, respectively.&lt;br /&gt;
#Set the MY parameter to 0xFFFF.  This will block any messages with a 16-bit destination address.&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
In this example, we set the channel, PAN ID, source ID, and destination ID. (The things that you type into the terminal are bold, the reply from the radio is plain.) &lt;br /&gt;
&lt;br /&gt;
Radio1:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200 &#039;&#039;Note: This serial number will be unique to your hardware&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B78&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, go to your other radio.&lt;br /&gt;
&lt;br /&gt;
Radio2:&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCH C&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATID 3332&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSH&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:13A200&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATSL&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:40088B96&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATMY FFFF&#039;&#039;&#039;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to Radio1:&lt;br /&gt;
:&#039;&#039;&#039;+++&#039;&#039;&#039;OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDH 13A200&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK &amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATDL 4088B78&#039;&#039;&#039; &amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATWR&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
:&#039;&#039;&#039;ATCN&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
:OK&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Round Trip Latency Testing==&lt;br /&gt;
A test measuring the round trip time of the Xbee radio was performed to gain a sense of the average latency of the XBee radios communicating over the 802.15.4 protocol.&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
One XBee radio was connected to a computer running Windows XP with a standard USB-&amp;gt;RS232 cable.  As programmed in Visual Studio C++ Express, the computer performed a &amp;quot;loopback&amp;quot; protocol; the computer wrote the data it received (to the serial port) upon the receipt of a byte (from the serial port).  In this sense, the computer simply echoes the data it receives on the serial port.&lt;br /&gt;
&lt;br /&gt;
A second XBee radio was connected to a PIC184520 with a 40MHz crystal.  Using the PIC-C programming language, the XBee radio is controlled using the pic&#039;s hardware EUSART.  A variety of baud rates were tested as listed in the table below.&lt;br /&gt;
&lt;br /&gt;
To capture the round trip time, the pic was programmed to set a digital output high, and send a byte of data.  Upon receipt of the data (from the loopbacked PC), the pic subsequently set the digital output low.  By viewing the digital output on an oscilloscope, the width of the pulse was measured to determine the amount of time between sending and receiving a single byte of data.&lt;br /&gt;
&lt;br /&gt;
*Note that the latency of the computer is included in this test.  For this test, it was assumed that the latency of the computer would be insignificant relative to the radios&#039; communication time.  To remove this additional latency in the future, one should create a hardware loopback by powering the first Xbee radio and physically connecting this radio&#039;s Rx and Tx line via a wire (no computer or PIC needed).&lt;br /&gt;
&lt;br /&gt;
===Results===&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;Baud Rate (bps)&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;Round Trip Latency (ms)&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;9600&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;numbers coming soon!&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;19200&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;numbers coming soon!&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;38400&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;numbers coming soon!&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;57600&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;numbers coming soon!&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;115200&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;numbers coming soon!&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;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=555_Servo_Circuit&amp;diff=12906</id>
		<title>555 Servo Circuit</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=555_Servo_Circuit&amp;diff=12906"/>
		<updated>2009-03-20T07:32:49Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Circuits]]&lt;br /&gt;
See also:[[555_Timer]]&lt;br /&gt;
&lt;br /&gt;
This page describes how to build a circuit for driving an RC Servo motor.  It uses two LM555 IC’s to create the pulse train that drives the motor.  For an RC Servo, the width of the “high” pulse determines the angle of the rotor.  Sample values for creating a working circuit are given.&lt;br /&gt;
&lt;br /&gt;
Two 555 timers are used to create the servo control signal.  The pinout for the LM555 is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:555_pinout.jpg|center|250px]]&lt;br /&gt;
&lt;br /&gt;
The first 555 timer creates a clock signal at our desired frequency.  The circuit for this is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:555_circuit1.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
This circuit is referred to as an “Astable Multivibrator” in the LM555 datasheet.  The sizes of Ra, Rb, and C1 determine the shape of the clock signal.  We want the clock signal to look something like this:&lt;br /&gt;
&lt;br /&gt;
[[image:555_clock.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
The values of T1 and T are given by&lt;br /&gt;
&lt;br /&gt;
T1=0.693*Rb*C&lt;br /&gt;
T=0.693*(Ra+2*Rb)*C&lt;br /&gt;
&lt;br /&gt;
We want T to be around 20ms and T1 to be smaller than the minimum pulse width we will send to the RC Servo (T1≤0.3ms).  Here’s some sample values:&lt;br /&gt;
&lt;br /&gt;
Ra=330kΩ, Rb=1.5 kΩ, C1=0.1 μF → &amp;lt;u&amp;gt;T1 = 0.1 ms, T=23 ms&amp;lt;/u&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second 555 Timer circuit is a “pulse width modulator”, shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:555_circuit2.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
The combination of Rc and C2 determines the time that the output is high.  Good values are&lt;br /&gt;
&lt;br /&gt;
Rc = 15 kΩ&lt;br /&gt;
C2 = 0.1 μF&lt;br /&gt;
&lt;br /&gt;
which give a time constant of τ = 1.5 ms.&lt;br /&gt;
&lt;br /&gt;
Using the values given in this document, you will get the following relationship:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;text-align:center;width:400px&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Analog In (V) !! Control Voltage (V) !! Pulse Width (ms) !! Servo Position&lt;br /&gt;
|-&lt;br /&gt;
| 1.1 || ~1.1 || ~0.388 || One end&lt;br /&gt;
|-&lt;br /&gt;
| 4.4 || ~4.0 || ~2.375 || Other end&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here is a picture of a circuit built using parts in the lab.  I replaced Rc with a 10kOhm resistor and a 10k POT to allow some fine tuning.&lt;br /&gt;
&lt;br /&gt;
[[image:555 servo photo.jpg|center]]&lt;br /&gt;
&amp;lt;nowiki&amp;gt;Insert non-formatted text here&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Indoor_Localization_System&amp;diff=10793</id>
		<title>Indoor Localization System</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Indoor_Localization_System&amp;diff=10793"/>
		<updated>2009-02-23T04:28:54Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is obsolete and should be used for reference only.  Go to [[Machine Vision Localization System]]&#039;&#039;&#039;&lt;br /&gt;
== Motivation ==&lt;br /&gt;
&lt;br /&gt;
For relatively simple autonomous robots, knowing an absolute position in the world frame is a very complex challenge.  Many systems attempt to approximate this positioning information using relative measurements from encoders, or local landmarks.  Opposed to an absolute system, these relativistic designs are subject to cumulating errors.  In this design, the positioning information is calculated by an external computer which then transmits data over a wireless module.&lt;br /&gt;
&lt;br /&gt;
This system can be envisioned as an indoor GPS, where positioning information of known patterns is transmitted over a wireless module available for anyone to read.  Unlike a GPS, this vision system is designed for indoor use on a smaller scale (in/cm).&lt;br /&gt;
&lt;br /&gt;
== Overview of Design ==&lt;br /&gt;
&lt;br /&gt;
This system uses four standard webcams to locate known patterns in a real time image, and transmit positioning information over a serial interface.  This serial interface is most often connected to a wireless Zigbee® module.  The cameras are mounted in fixed positions above the target area.  The height of the cameras can be adjusted to increase either the positioning resolution or the area of the world frame.  These constraints are a function of the field of view of the lenses.  Below is a diagram illustrating this system’s basic setup.&lt;br /&gt;
&lt;br /&gt;
[[Image:visual_localization_system.jpg|center|thumb|600px|Overview of System]]&lt;br /&gt;
&lt;br /&gt;
Here, we can see the four cameras are mounted rigidly above the world frame.  Note that the cameras actual placement must have an overlap along inside edges at least the size of one target.  This is necessary to ensure any given target is at least fully inside one camera’s frame.&lt;br /&gt;
&lt;br /&gt;
== Goals ==&lt;br /&gt;
•	To provide real-time (X, Y, θ) position information to an arbitrary number of targets (&amp;lt;20) in a fixed world frame using a home-made computer vision system.&lt;br /&gt;
&lt;br /&gt;
•	Maximize throughput and accuracy&lt;br /&gt;
&lt;br /&gt;
•	Minimize latency and noise&lt;br /&gt;
&lt;br /&gt;
•	Easy re-calibration of camera poses.&lt;br /&gt;
&lt;br /&gt;
•	Reduced cost (as compared to real-time operating systems and frame grabbing technology)&lt;br /&gt;
&lt;br /&gt;
== Tools Used ==&lt;br /&gt;
=== Software ===&lt;br /&gt;
•	IDE: Microsoft Visual C++ Express Edition – freeware (http://www.microsoft.com/express/default.aspx)&lt;br /&gt;
&lt;br /&gt;
•	Vision Library: Intel OpenCV – open source c++  (http://sourceforge.net/projects/opencvlibrary/) &lt;br /&gt;
&lt;br /&gt;
•	Camera Capture Library: VideoInput – open source c++ (http://muonics.net/school/spring05/videoInput/)&lt;br /&gt;
&lt;br /&gt;
=== Hardware ===&lt;br /&gt;
&lt;br /&gt;
•	Four Logitech QuickCam Communicate Deluxe USB2.0 webcams&lt;br /&gt;
&lt;br /&gt;
•	One 4-port USB2.0 Hub&lt;br /&gt;
&lt;br /&gt;
•	Computer to run algorithm&lt;br /&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;
&#039;&#039;&#039;1.  Choose a desired ALL WHITE area to cover.&#039;&#039;&#039;  &#039;&#039;&#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***&#039;&#039;&#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;
&#039;&#039;&#039;2.  Ensure that the cameras are all facing the same direction. &#039;&#039;&#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;
&#039;&#039;&#039;3.  Try to mount the cameras as &amp;quot;normal&amp;quot; as possible.&#039;&#039;&#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.  Download and install Microsoft Visual Studio Express - http://www.microsoft.com/express/default.aspx&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 program as listed at the end of this page.&lt;br /&gt;
&lt;br /&gt;
=== How to Run the Program ===&lt;br /&gt;
&lt;br /&gt;
Open the project file as listed at the bottom of this page.  Compile and run the program from Visual Studio or as in the build folder.&lt;br /&gt;
&lt;br /&gt;
Once running, the program should outline what is necessary to setup and operate.  The steps are also outlined below.&lt;br /&gt;
&lt;br /&gt;
1.  Connect to cameras.  You will have to type the 4 numbers (in the command prompt) associated with the correct capture devices.  Most likely, these will be 0-3.&lt;br /&gt;
&lt;br /&gt;
2.  Orient cameras.  To correlate an individual camera with its position overhead, you must click once on the quadrant corresponding to the live camera image shown.  You will click 4 times, once for each camera.&lt;br /&gt;
&lt;br /&gt;
3.  Check.  Once you have selected the quadrants for each camera, you can look at the combined image in the main window to make sure the cameras are positioned correctly and that the background is all white.  Press the Enter button in the main window to continue.&lt;br /&gt;
&lt;br /&gt;
4.  Enter Calibration Parameters.  To calibrate the cameras to world coordinates, you must type in numbers relating to the patterns positions.  Ensure that you place the patterns down in a rectangular fashion (in the world frame not the images).  The numbers are typed into the command prompt.  You will enter three numbers as measured (they may be in inches or cm or whatever unit desired).&lt;br /&gt;
&lt;br /&gt;
5.  Capture Calibration Pattern.  To calibrate the cameras, you must now take a picture of the patterns as viewed by ALL FOUR Cameras.  By now, you should have the calibration pattern arranged on the surface.  ****ENSURE THAT THE ONLY VISIBLE OBJECTS IN THE IMAGE ARE THE DOTS FROM THE CALIBRATION PATTERN****  The program is designed to calibrate to the first 9 dots in each image that it sees.  If there are more than 9 dots in ANY camera image, the program will correlate the FIRST 9 dots to the measured positions.  If one camera sees more than one calibration pattern (fully or partially) it will NOT calibrate properly.  You may adjust the threshold with the + and - keys dynamically to remove any specular noise.&lt;br /&gt;
&lt;br /&gt;
[[Image:visual_localization_calibration_alignment.jpg|center|thumb|300px|Calibration Pattern Alignment]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6.  Remove the Calibration Pattern.  Now remove or cover up the calibration dots and press &#039;Enter&#039; to proceed to the real time operation of the program.  To quit the program, Press &#039;Esc&#039;.&lt;br /&gt;
[[Image:visual_localization_real_time.jpg|center|thumb|300px|Real-Time Processing]]&lt;br /&gt;
[[Image:visual_localization_data.jpg|center|thumb|300px|Real-Time Data]]&lt;br /&gt;
&lt;br /&gt;
=== Real time Adjustable Parameters ===&lt;br /&gt;
During the real time operation of the program, many of the algorithm parameters will need to be adjusted for the current setup.  These parameters and keys are listed below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;+&#039;&#039;&#039; and &#039;&#039;&#039;-&#039;&#039;&#039;: Binary Thresholding:  To adjust the black and white levels, use the + and - keys to increase or decrease the threshold.  Ideally, this should be increased as high as possible without producing random noise.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[&#039;&#039;&#039; and &#039;&#039;&#039;]&#039;&#039;&#039;: Target Size:  This measurement corresponds to the maximum distance between dots in a target.  If your 3x3 grid is spaced at 1 inch intervals, this value is ideally 1 inch.  This parameter should be decreased as much as possible before targets are lost.  If this parameter is too large, the algorithm will blend the patterns together.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;z&#039;&#039;&#039; and &#039;&#039;&#039;x&#039;&#039;&#039;: Area Thresholding:  This parameter controls the desired size of &#039;dots&#039;.  This is used to remove relatively large or small noise artifacts.  This parameter should be as large as possible to remove specular noise.&lt;br /&gt;
&lt;br /&gt;
== Algorithm Design ==&lt;br /&gt;
=== Overview ===&lt;br /&gt;
To identify different objects and transmit position and rotation information a 3x3 pattern of black circles is used for each object.  To create both position and orientation, each pattern must have at least 3 dots in a rotationally invariant configuration.  The algorithm identifies unique patterns by assuming dots within a certain adjustable distance are part of the same pattern.  It then identifies which pattern is associated with the dots via a comparison of the relative distances between the dots.&lt;br /&gt;
&lt;br /&gt;
=== Pre-Processing ===&lt;br /&gt;
==== Target Classification ====&lt;br /&gt;
Before the system is executed in real time, two tasks must be completed.  The first is pre-processing the possible targets to match (the patterns of 3x3 dots).  This is done by first creating a subset of targets from the master template.  Each target must be invariant in rotation, reflection, scale and translation.  A set of targets has been included in the final project, with sample patterns.  When the program is executed in real time, it will only identify targets from the trained subset of patterns.&lt;br /&gt;
&lt;br /&gt;
When the targets are pre-processed, unique information is recorded to identify each pattern.  In particular, the algorithm counts the number of dots and the relative spacing between each dot.  In this sense, the pattern is identified as a unique number (corresponding to the order of target patterns in the image directory), the number of dots in the pattern, and the normalized spacing between each dot.  Since the pattern is a fixed 3x3 grid, the only possible spacing between dots is 1, √2, 2, √5, or √8 units.  As in networking theory, this is a fully connected network and thus has at most n*(n-1)/2 links.  Since the most number of dots in a pattern is 9, the maximum number of interspacing distances is 9*8/2 = 36.&lt;br /&gt;
&lt;br /&gt;
The last piece of information recorded is the orientation of the target.  Below is a picture of this configuration.  *Note to change the target, various dots are removed.&lt;br /&gt;
&lt;br /&gt;
[[Image:visual_localization_patterns.jpg|center|thumb|300px|Pattern Recognition]]&lt;br /&gt;
&lt;br /&gt;
==== Camera Calibration ====&lt;br /&gt;
The second required step before the system can be used is training the cameras both their intrinsic parameters (focal length, geometric distortions, pixel to plane transformation) and their extrinsic pose parameters (rotation and translation of origins).  In other words, the pixels in the image must be correlated to the world frame in centimeters or inches.  This step is performed by using a simple linear least squares best fit model.  The calibration process needs at least 6 points as measured in the world and image frames to compute a 3x4 projection matrix.  In practice, we use more than these 6 points to add redundancy and help best compute an accurate projection matrix.  The method used is outlined in &#039;&#039;Multiple View Geometry in Computer Vision&#039;&#039; by Richard Harley and Andrew Zisserman.&lt;br /&gt;
&lt;br /&gt;
=== Real Time Operation ===&lt;br /&gt;
In the actual operation of the program, it flows in an infinite loop performing three basic tasks.  As soon as all four cameras have reported a new frame, the program follows the following outlined steps.&lt;br /&gt;
&lt;br /&gt;
==== Image Formation ====&lt;br /&gt;
First, the computer converts the image to a grayscale (0-255) image.  After this operation is performed, the algorithm thresholds the image based on a set level.  This converts the grayscale image to a binary image by converting colors above the threshold to white (255) and all other values to black (0).  After these two operations are performed, the resultant image is a black and white binary image.  The default threshold level is set to 80.&lt;br /&gt;
&lt;br /&gt;
==== Pattern Isolation ====&lt;br /&gt;
&lt;br /&gt;
After the image has been prepared in the binary format, all the contours must be outlined.  This process is known as connected-component-labeling (CCL) in computer vision.  This process identifies continuous “blobs” or regions of pixels that are adjacent.  In OpenCV the connected components are stored into a linked list data structure called a contour.&lt;br /&gt;
Fortunately, the connected component labeling process is a native function of OpenCV and we only have to process the resultant contour data structure.  To do this, the program iterates through each contour in the data structure, extracting position and area information (in pixels).  This data is stored into a custom data structure called dotData.  While processing each contour, the algorithm groups the individual dots into their 3x3 patterns by using a second custom data structure called a “target”.  The target data structure is a linked list and has elements for the number of dots in the pattern, dotData structures for each dot in the pattern, and other data to be generated later such as group position and orientation.  To group the dots into targets, the program follows the outlined algorithm.&lt;br /&gt;
&lt;br /&gt;
1.	For each new dot, check each dot inside each existing target.&lt;br /&gt;
&lt;br /&gt;
2.	If there exists a dot in any target such that the new dot is within the maximum spacing between dots, add the new dot to this target.&lt;br /&gt;
&lt;br /&gt;
3.	Else; create a new target and add the new dot to the new target.&lt;br /&gt;
&lt;br /&gt;
We can see that this is not necessary the best method for grouping dots together as it is based on a maximum distance between dots.  In fact, this forces the patterns to be a certain distance away from each other to avoid confusion.  In concept, the patterns should be at least half the size of the robot to avoid this conflict.  The benefits of this classification scheme are its simplicity and speed for computation.&lt;br /&gt;
&lt;br /&gt;
==== Pattern Identification ====&lt;br /&gt;
Once the contours (dots) have been grouped into the linked list of targets, the targets must be matched to the trained patterns.  This data appears extremely robust since the spacing between dots is at such clean and quantized intervals.  To match each target to a trained pattern, the algorithm compares all patterns with the same number of dots and searches for the best match.  The comparison between patterns with the same number of dots is done with a simple squared differences error calculation.  After this process, each region of dots is classified by the global number as trained by the pre-processing algorithm.&lt;br /&gt;
&lt;br /&gt;
==== Position and Angle ====&lt;br /&gt;
To calculate the position and orientation of each target, the camera calibration matrix comes into play.  First, the position is calculated by finding the center of mass of each dot in a target in the image frame (pixels).  For each dot, the camera calibration matrix is used to transform this data into world coordinates.  Finally, the world coordinates of the dots are summed to find the group center of mass.  This group center of mass becomes the world coordinates for the target position.  To calculate the angle, specific angle information is extracted from the patterns.  This angle information is then used in combination with the pre-processed offset angle to generate a group orientation.  These two vectors are then sent out to the user-specified serial port.&lt;br /&gt;
&lt;br /&gt;
==== Blind Spot Rejection ====&lt;br /&gt;
Since the images recorded by the cameras overlap by at least the size of one pattern, the algorithm will identify the same pattern for each overlapping section.  Ideally, the images of the cameras would be perfectly matched such that this information was redundant.  In practice, the simple camera calibration scheme results in slightly different data.  When the same pattern is identified in multiple images, it position information is averaged.  The other scenario for errors is if a pattern is only partially visible in one image (which can make it appear as a different pattern).  To correct this problem, the algorithm analyzes the individual outputs of each image at the same time.  If any two patterns are within the thresholded distance of each other, the program rejects the pattern with fewer dots.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Final Project Code ==&lt;br /&gt;
&lt;br /&gt;
===Real-time algorithm source:===&lt;br /&gt;
&lt;br /&gt;
http://hades.mech.northwestern.edu/wiki/images/8/85/TrackSysV1_6_20_08.zip&lt;br /&gt;
====Bugs====&lt;br /&gt;
# Line 694. &amp;quot;Select Capture Devices,&amp;quot; &#039;&#039;&#039;CameraID&#039;&#039;&#039; should be &#039;&#039;&#039;CaptureID&#039;&#039;&#039;.&lt;br /&gt;
# Program will hang if &amp;quot;target_classifiers.txt&amp;quot; is not found.&lt;br /&gt;
# Program will hang if &amp;quot;world_coord_template.jpg&amp;quot; is not found.&lt;br /&gt;
# World Coord Template will not redraw.&lt;br /&gt;
# Memory leak: Line 1158. &#039;&#039;&#039;cvFindContours&#039;&#039;&#039; is called in the &#039;&#039;&#039;while(1)&#039;&#039;&#039; loop, but the memory storage is never cleared.  Use &#039;&#039;&#039;cvClearMemStorage()&#039;&#039;&#039; before &#039;&#039;&#039;cvFindContours()&#039;&#039;&#039;  to discard old data.&lt;br /&gt;
# Memory leak: Line 1118,1279. &#039;&#039;&#039;targets_temp&#039;&#039;&#039; is pointing to a new object, but is reassigned on line 1279.  Comment out the &#039;&#039;&#039;for&#039;&#039;&#039; loop on lines 1118-1123.&lt;br /&gt;
# Camera Calibration does not seem to be robust.&lt;br /&gt;
# &#039;&#039;&#039;camScan&#039;&#039;&#039; flags are never rearmed.&lt;br /&gt;
# Line 1625: There is no check to see if &#039;&#039;&#039;temp-&amp;gt;ID&#039;&#039;&#039; has been assigned to -1 in the previous loop.&lt;br /&gt;
# In calibration, double subU = cvmGet(&amp;amp;U, i, 0);double subV = cvmGet(&amp;amp;U, i+1, 0); should be i*2?&lt;br /&gt;
# Camera calibration is broken.&lt;br /&gt;
# Function &#039;&#039;&#039;LoadTargetData()&#039;&#039;&#039; will not read the last data point because it can&#039;t find a comma at the end of the line.&lt;br /&gt;
# In &#039;&#039;&#039;LoadTargetData()&#039;&#039;&#039;, current-&amp;gt;num_idd = idd_num; should be new_classifier-&amp;gt;num_idd = idd_num; ?&lt;br /&gt;
# In &#039;&#039;&#039;LoadTargetData()&#039;&#039;&#039;, a newline at the end of the &#039;&#039;&#039;target_classifiers.txt&#039;&#039;&#039; will get read in, making the linked list 1 node longer than it should be.&lt;br /&gt;
&lt;br /&gt;
===Pre-processing program source with final patterns:===&lt;br /&gt;
&lt;br /&gt;
http://hades.mech.northwestern.edu/wiki/images/f/fe/TrackSysTraining_6_20_08.zip&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=10792</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Main_Page&amp;diff=10792"/>
		<updated>2009-02-23T04:27:50Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Northwestern University mechatronics design wiki provides reference material on the theory and applications of electronics, sensors, actuators, etc., for use in mechatronics-related research and projects.  Practical applications often refer to equipment and supplies available in the [http://mechatronics.mech.northwestern.edu/ Northwestern Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
The mechatronics wiki was initiated by undergraduate Ben Stephens in 2006, under the supervision of Profs. Kevin Lynch and Michael Peshkin.  Since then, many students have contributed content.&lt;br /&gt;
&lt;br /&gt;
Important:  Please be sure to read the [http://mechatronics.mech.northwestern.edu/mech-rules.pdf Rules for Using the Mechatronics Design Lab].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Design Competition 2008&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Wiki pages on sensors, actuators, programming, and microcontrollers: use pages below&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/QuickStart/ Parts in the DC2008 quick start pack]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/piccintro_2008-01-24.pdf PIC C intro slides, as presented 2008/01/24 (pdf)]&lt;br /&gt;
* [http://peshkin.mech.northwestern.edu/pic/info/picinterfacing_2008-01-28.pdf PIC interfacing slides, as presented 2008/01/28 (pdf)]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Sensors and actuators for DC&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Using Solderless Breadboard|Solderless Breadboard &amp;amp; wiring that works]]&lt;br /&gt;
* [[Using LEDs &amp;amp; IREDs]]&lt;br /&gt;
* [[Using a laser]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity]]&lt;br /&gt;
** Using phototransistors&lt;br /&gt;
** Sensing optical tape&lt;br /&gt;
* [[Comparators | Comparators : the analog digital interface]]&lt;br /&gt;
* [http://www.robotroom.com/FaulhaberGearmotor.html Faulhaber MiniMotor SA gearmotor with encoder], as well as [[Actuators_Available_in_the_Mechatronics_Lab#Faulhaber_1524E006S_motor_with_141:1_gearhead_and_HES164A_magnetic_quadrature_encoder|the local wiki page]]&lt;br /&gt;
* [[Adding a magnetic encoder to a GM3 Gearmotor]]&lt;br /&gt;
** Using magnetic switches (Hall Effect)&lt;br /&gt;
* [[High-current devices|Driving high-current devices: several options]]&lt;br /&gt;
* [[Driving a Stepper Motor]]&lt;br /&gt;
* [[Driving an RC Servo]]&lt;br /&gt;
* [[Accelerometers]]&lt;br /&gt;
* [[Strain gauges]]&lt;br /&gt;
* [[Using the Basic Stamp Microcontroller|Basic Stamp Microcontroller]] &amp;lt;b&amp;gt;Not recommended for DC2008&amp;lt;/b&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/Battery_NiMH/ NiMH rechargable batteries and chargers]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; [http://peshkin.mech.northwestern.edu/datasheets Prof. Peshkin&#039;s favorite datasheets]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC 18F4520 prototyping board &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[4520 Board intro|Prototyping board intro]]&lt;br /&gt;
*[[4520 Board construction|Assembling the 18F4520 prototyping board, circuit, parts]]&lt;br /&gt;
*[[4520 Board use|Using the 18F4520 prototyping board]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Programming with CCS C &amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[C language|The C language]]&lt;br /&gt;
*[[CCS C|CCS C, specifically for the 18F4520]]&lt;br /&gt;
*[[Embedded Programming Tips for CCS C]]&lt;br /&gt;
*[[CCS IDE|Using the CCS development environment]]&lt;br /&gt;
*[[Debugging C on a PIC]]&lt;br /&gt;
*[[More debugging tips]]&lt;br /&gt;
*[http://www.ccsinfo.com/forum/ CCS user forum]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Interfacing and skeleton code for the PIC 18F4520&amp;lt;/h3&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have wiki pages &amp;lt;i&amp;gt;and&amp;lt;/i&amp;gt; sample code available&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* [[Digital inputs &amp;amp; outputs]] (filename: DigitalIO)&lt;br /&gt;
* [[Analog Input]] (filename: AnalogInput)&lt;br /&gt;
** reading a trimpot&lt;br /&gt;
** reading a phototransistor&lt;br /&gt;
** amplified phototransistor, and IRED strobing&lt;br /&gt;
** using an instrumentation amp (example: for a strain gauge)&lt;br /&gt;
* [[Analog Output|Analog Output, and the I2C bus]] (filename: AnalogOutput)&lt;br /&gt;
* [[Waveform Generation with AD9833]] (filename: AD9833)&lt;br /&gt;
* [[SPI - Serial Peripheral Interface - on the PIC]]&lt;br /&gt;
*[[Pulse width modulation|Pulse width modulation (PWM) for driving motors or other high current devices]] (filename: MotorPWM)&lt;br /&gt;
** using H-bridges&lt;br /&gt;
* [[Interrupts]]&lt;br /&gt;
* [[Quadrature decoding in software]] (filename: QuadratureSoft)&lt;br /&gt;
* [[Quadrature decoding in hardware, or just counters]] (filename: QuadratureHard)&lt;br /&gt;
* [[Running RC servos]] (filename: RCservoSoft &amp;amp; RCservoHard)&lt;br /&gt;
* [[Watchdog timer]] (filename: Watchdog)&lt;br /&gt;
* [[PIC RS232|RS-232 serial communication between a PC and a PIC]] (filename: RS232)&lt;br /&gt;
* [[C Example: Serial LCD|Text output to a serial LCD display]]&lt;br /&gt;
* [[C Example: Parallel Interfacing with LCDs|Text output to a parallel LCD display]]&lt;br /&gt;
* [[Servo skeleton with fast &amp;amp; slow interrupts]]&lt;br /&gt;
* [[XBee radio communication between PICs]] (and between a PC and a PIC)&lt;br /&gt;
* [[I2C communication between PICs]]&lt;br /&gt;
* [[Serial communication with Matlab]]&lt;br /&gt;
* [[SPI communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested)&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Microphones]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Controlling a seven segment display]]&lt;br /&gt;
* [[Storing constant data in program memory]]&lt;br /&gt;
* [[PIC computation time benchmarks]]&lt;br /&gt;
* [[Stepper motor control with the PIC]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[IR communication between PICs]] &amp;lt;b&amp;gt; (Note:  this function has not been successfully tested) &amp;lt;/b&amp;gt;&lt;br /&gt;
* [[Interfacing to External EEPROM]]&lt;br /&gt;
* [[I2C Motor Controller]]&lt;br /&gt;
* [[Interfacing with a Photodiode Array]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics have sample code available, but no wiki pages yet&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Counter0 - Counting pulses with Timer0]&lt;br /&gt;
* Counter1 - Counting pulses with Timer1]&lt;br /&gt;
* Interrupt0 - Periodic servo cycles using interrupt routines, 10mS &amp;amp; slower; Timer 0]&lt;br /&gt;
* Interrupt2 - Periodic servo cycles using interrupt routines; 10mS &amp;amp; faster; Timer 2]&lt;br /&gt;
* InterruptExternal - Interrupts generated by an external pulse]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;These topics need more development&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://peshkin.mech.northwestern.edu/pic/code Link to all sample code here.]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* AnalogOutputParallel - Analog output using 8 digital lines]&lt;br /&gt;
* PIC-to-PIC communication &lt;br /&gt;
* Zigbee radio communication&lt;br /&gt;
* Modulated IR communication&lt;br /&gt;
* Strobing LEDs or IREDs for better range and immunity to background light&lt;br /&gt;
* I2C communication &lt;br /&gt;
* CAN bus&lt;br /&gt;
* Capturing data to Matlab&lt;br /&gt;
* Running stepper motors&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;PIC Microcontrollers&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with CCS Compiler]], for DC, 333, etc, using the CCS ICD-U40 device &amp;lt;b&amp;gt;[this section has been replaced by the material above]&amp;lt;/b&amp;gt;&lt;br /&gt;
* [[PIC Microcontrollers with C18 Compiler]], for e-puck, or using the Microchip ICD device or&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;e-puck Mobile Robot&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[e-puck Mobile Robot]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Printing Circuit Boards]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[PCB Artist | PCB Artist: Software provided by Advanced Circuits]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt; Electronics &amp;lt;/h3&amp;gt;&lt;br /&gt;
* [http://hades.mech.northwestern.edu/wiki/index.php/Category:Electronics Electronics]&lt;br /&gt;
* [[Phase-Sensitive Detection]]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Operational_amplifier_applications Op-Amp Applications]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Analog and Digital chips&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Comparators | Comparators: the analog to digital interface]]&lt;br /&gt;
* [[Filtering with the LMF100 | Filtering with the LMF100]]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Operational_amplifier_applications Opamps : building blocks of analog computation]&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/Writeups/InstAmp/instamp.htm Instrumentation amps, and NU circuit board for them]&lt;br /&gt;
* [[LED Drivers | Controlling large numbers of LEDs with LED drivers]]&lt;br /&gt;
* [[Opto-isolators | Opto-isolators: Signal transfer while electrically isolating circuits]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Sensors|Sensors]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Potentiometers|Angle, Linear Position: Potentiometers]]&lt;br /&gt;
* [[Optointerrupter|Beam Breaker: Optointerrupter]]&lt;br /&gt;
* [[Optoreflector|Proximity: Optoreflector]]&lt;br /&gt;
* [[Sensing optical tape|Infrared reflectivity : Sensing optical tape]]&lt;br /&gt;
* [[Reed Switch|Proximity: Reed Switch]]&lt;br /&gt;
* [[Hall Effect Sensor|Proximity, Angle: Hall Effect Sensor]]&lt;br /&gt;
* [[Rotary Encoder|Angle: Rotary Encoder]]&lt;br /&gt;
* Angular Velocity: Tachometer&lt;br /&gt;
* [[Photodiodes and Phototransistors|Light: Photodiodes and Phototransistors]]&lt;br /&gt;
* [[Photocell|Ambient Light: Photocell]]&lt;br /&gt;
* [[Thermistor|Temperature: Thermistor]]&lt;br /&gt;
* Temperature: Thermotransistor IC&lt;br /&gt;
* Audio: [[Microphones]]&lt;br /&gt;
* [[Accelerometers|Tilt, Acceleration: Accelerometers]]&lt;br /&gt;
* [[Strain Gauge|Force: Strain Gauge]]&lt;br /&gt;
* Current: Current Sense Resistor&lt;br /&gt;
* [[Limit Switch|Contact: Microswitch (Limit Switch)]]&lt;br /&gt;
* [[Ambient light color sensing]]&lt;br /&gt;
* [[Global Positioning System]]&lt;br /&gt;
* [[Optics]]&lt;br /&gt;
* [[Optical Locating]]&lt;br /&gt;
* [[Lateral-Effect Photodiode]]&lt;br /&gt;
* [[IR Target Illumination|IRED&#039;s]]&lt;br /&gt;
* [[Pressure Sensing]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[:Category:Actuators|Actuators]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[image:All-actuators-captions-small.jpg|thumb|300px|[[Actuators Available in the Mechatronics Lab|Some of the available actuators]]|right]]&lt;br /&gt;
&lt;br /&gt;
* [[Brushed DC Motor Theory|Brushed DC Motors]]&lt;br /&gt;
** [[Choosing a Motor and Gearing Combination|Choosing a Motor and Gearing Combination]]&lt;br /&gt;
** [[Linear Amplifier Motor Driver|Driving Using a Linear Amplifier]]&lt;br /&gt;
** [[Driving using a single MOSFET|Driving using a single MOSFET]]&lt;br /&gt;
** [[Pulse Width Modulation|Driving Using Pulse Width Modulation]]&lt;br /&gt;
** [[PIC PWM Motor Driver]]&lt;br /&gt;
** [[Gear Motor]]&lt;br /&gt;
** [[Pulse Width Modulation]]&lt;br /&gt;
** [[Pulse_width_modulation]]&lt;br /&gt;
** [[Driving using a single MOSFET | Driving a DC motor using a single MOSFET]]&lt;br /&gt;
** [[Driving a DC Motor using PWM]]&lt;br /&gt;
** [[Driving a high current DC Motor using an H-bridge]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/AddEncoderHobbyEngGearMotor Adding a rotation encoder to a gearmotor]&lt;br /&gt;
** [[Using Opto-Isolators to Prevent Interference]]&lt;br /&gt;
* [[Brushless DC Motors]]&lt;br /&gt;
** [[Driving Brushless DC Motors]]&lt;br /&gt;
* [[Stepper Motor Theory|Stepper Motors]]&lt;br /&gt;
** [[Stepper Motor Circuits|Driving Stepper Motors]]&lt;br /&gt;
** [[Unipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
** [[Bipolar Stepper Motor Driver Circuit]]&lt;br /&gt;
* [[RC Servo Theory|RC Servos]]&lt;br /&gt;
** [[555 Servo Circuit|Driving Your Servo Using a 555 Timer]]&lt;br /&gt;
* [[Solenoid Theory|Solenoids]]&lt;br /&gt;
** Practice: Driving Your Solenoid&lt;br /&gt;
* AC Motors&lt;br /&gt;
** [[Using the Yaskawa Motors]]&lt;br /&gt;
* [[Fans As Actuators|Fans As Actuators]]&lt;br /&gt;
* [[LIMS Air Hockey Table|LIMS Air Hockey Table]]&lt;br /&gt;
* [[Actuators Available in the Mechatronics Lab]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Mechanical Design&amp;lt;/h3&amp;gt;&lt;br /&gt;
*Mechanics of Materials&lt;br /&gt;
**Beam Mechanics&lt;br /&gt;
**[[Mohr&#039;s Circle]]&lt;br /&gt;
*Failure Theories&lt;br /&gt;
**Static Loading&lt;br /&gt;
**Variable Loading and Fatigue&lt;br /&gt;
*[[Attaching to a shaft]]&lt;br /&gt;
*Support&lt;br /&gt;
**Housings&lt;br /&gt;
**Shafts&lt;br /&gt;
**[[Bearings]]&lt;br /&gt;
*Transmission&lt;br /&gt;
**Rigid: [[Gears]]&lt;br /&gt;
**Flexible: Belts, Chains&lt;br /&gt;
**Motion Connection/Separation: Clutches, Brakes, Couplings&lt;br /&gt;
*Linkages&lt;br /&gt;
**Serial Chains&lt;br /&gt;
**Parallel and Closed-Loop Chains&lt;br /&gt;
*Other: springs/dampers, cams, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;The PC/104 Stack&amp;lt;/h3&amp;gt;&lt;br /&gt;
[[Image:Img0174.jpg|thumb|300px|[[PC104 Overview|The PC104 Stack]]|right]]&lt;br /&gt;
* [[PC104 Overview|Overview]]&lt;br /&gt;
* [[The PC/104 Lab Kit]]&lt;br /&gt;
* Hardware:&lt;br /&gt;
** [[Advantech CPU Card]]&lt;br /&gt;
** [[Sensoray 526 Data Aquisition Card]]&lt;br /&gt;
&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#power[Power Components]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#electrical[I/O Electronics: Analog I/O, Digital I/O, Encoder Connections]]&lt;br /&gt;
* Advanced: Creating a Working Stack from Parts&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm [Building the Breakout Board]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#ribboncables[Breakout Board Ribbon Cables]]&lt;br /&gt;
** [http://www.mech.northwestern.edu/courses/433/Writeups/PC104BoB/stack.htm#mechanical[Assembling the PC104 Stack]]&lt;br /&gt;
** &#039;&#039;&#039;[[Creating an xPC Flash Boot Disk]]&#039;&#039;&#039; &amp;lt;- when new version of MATLAB&lt;br /&gt;
* Custom Boards&lt;br /&gt;
** Dual PWM Motor Controller&lt;br /&gt;
** Dual Linear Amplifier Motor Controller&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;xPC Target Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[xPC Overview|Overview of Real-Time Programming with Simulink and xPC Target]]&lt;br /&gt;
* [[Configuring xPC Target PC|Configuring xPC Host/Target PC]]&lt;br /&gt;
* [[Creating a Simple xPC Program|&#039;&#039;&#039;Quickstart&#039;&#039;&#039;:Creating a simple xPC Program]]&lt;br /&gt;
* [[Common xPC Blocks|Commonly Used Blocks]]&lt;br /&gt;
* [[Using the Host Scope]]&lt;br /&gt;
*Advanced&lt;br /&gt;
** Model Properties&lt;br /&gt;
** [[XPC M-file Communication|M-file communication]]&lt;br /&gt;
** Using outside of the lab&lt;br /&gt;
** [[media:standalone.pdf|Standalone Mode]]&lt;br /&gt;
** Stateflow&lt;br /&gt;
* Code Examples&lt;br /&gt;
** [[Controlling a DC Motor with an Encoder]]&lt;br /&gt;
** Something With State Machine&lt;br /&gt;
** [[Using RS-232 and Printing to LCD]]&lt;br /&gt;
**[[UDP Communications between Target and Host PC]]&lt;br /&gt;
** M-functions and S-functions&lt;br /&gt;
** [[xPC Code From Student Projects]]&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;QNX Real-Time Operating System&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[media:qnxtemplate.zip|QNX Control Program with Interrupts]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Lab Supplies and Data Sheets&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [http://spreadsheets.google.com/pub?key=pa_bNAhFF-OvvxpSje1KDYg&amp;amp;output=html&amp;amp;gid=0&amp;amp;single=true Generally stocked lab inventory ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Vendors and Useful Links]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Other Software&amp;lt;/h3&amp;gt;&lt;br /&gt;
*[[List of Useful Software for Download]]&lt;br /&gt;
*Circuit Schematics and PCB Layout&lt;br /&gt;
*LaTex Document Preparation&lt;br /&gt;
** [http://meta.wikimedia.org/wiki/Help:Formula Mathematical Formulae]&lt;br /&gt;
** Document Formatting&lt;br /&gt;
** [[LaTeX Software Setup|Software Setup]]&lt;br /&gt;
** IEEE Styles&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;[[Other Lab Equipment]]&amp;lt;/h3&amp;gt;&lt;br /&gt;
* Prototyping Tools&lt;br /&gt;
** [[Tektronix TDS220 Oscilloscope]]&lt;br /&gt;
** [[Tektronix CFG253 Function Generator]]&lt;br /&gt;
** [[media:Mastech_power_supply_manual.pdf|Mastech Power Supply]]&lt;br /&gt;
** Fluke III Multimeter&lt;br /&gt;
** Benchtop Multimeter&lt;br /&gt;
** Powered Breadboard&lt;br /&gt;
** Soldering Iron&lt;br /&gt;
* [http://ediacaran.mech.northwestern.edu/neuromech/index.php/Lab_Equipment High Performance Neuromechatronics Benches]&lt;br /&gt;
* The Sensoray 626 DAQ Card&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Course Material&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[ME 224 Experimental Engineering]]&lt;br /&gt;
* [http://lims.mech.northwestern.edu/~lynch/courses/ME333/2009/index.html ME 333 Introduction to Mechatronics]&lt;br /&gt;
** [[Lab 5]]&lt;br /&gt;
** [[Suggested final projects]]&lt;br /&gt;
** [[ME 333 final projects]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [http://www.mech.northwestern.edu/hartmann/ME333_CourseInformation.html ME 333 Mechatronics]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
* [http://www.mech.northwestern.edu/courses/433/ ME 433 Advanced Mechatronics] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;Miscellaneous&amp;lt;/h3&amp;gt;&lt;br /&gt;
* [[Swarm Robot Project Documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[Machine Vision Localization System]]&lt;br /&gt;
* [[Indoor Localization System | Indoor Localization System (Obsolete)]]&lt;br /&gt;
* [[Robot Helicopter Project]]&lt;br /&gt;
* [[E-Puck Color Sensing Project]]&lt;br /&gt;
* [[Guitar Tunning Project]]&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10783</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=10783"/>
		<updated>2009-02-16T19:36:59Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 &#039;+&#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 &#039;+&#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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;GEN_MOV=0&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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&#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 &#039;&#039;&#039;Video&amp;gt;Direct Steam Copy&#039;&#039;&#039;, and then &#039;&#039;&#039;File&amp;gt;Save as AVI&#039;&#039;&#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 &#039;&#039;&#039;File&amp;gt;Export&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To use VirtualDub, select &#039;&#039;&#039;Video&amp;gt;Full Processing Mode&#039;&#039;&#039;, go to &#039;&#039;&#039;Video&amp;gt;Compression&#039;&#039;&#039; and select the compression you want to use (you must have the codecs installed on your system), and the go to &#039;&#039;&#039;File&amp;gt;Save as AVI&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10769</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=10769"/>
		<updated>2009-02-14T19:20:33Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Compressing the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 &#039;+&#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 &#039;+&#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 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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;GEN_MOV=0&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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&#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 &#039;&#039;&#039;Video&amp;gt;Direct Steam Copy&#039;&#039;&#039;, and then &#039;&#039;&#039;File&amp;gt;Save as AVI&#039;&#039;&#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 &#039;&#039;&#039;File&amp;gt;Export&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
To use VirtualDub, select &#039;&#039;&#039;Video&amp;gt;Full Processing Mode&#039;&#039;&#039;, go to &#039;&#039;&#039;Video&amp;gt;Compression&#039;&#039;&#039; and select the compression you want to use (you must have the codecs installed on your system), and the go to &#039;&#039;&#039;File&amp;gt;Save as AVI&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10768</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=10768"/>
		<updated>2009-02-14T18:59:32Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 &#039;+&#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 &#039;+&#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 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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;GEN_MOV=0&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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&#039;t be saved).&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10735</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=10735"/>
		<updated>2009-02-13T06:41:27Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Setting Configurations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;GEN_MOV=0&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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&#039;t be saved).&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10734</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=10734"/>
		<updated>2009-02-13T06:39:05Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;&#039;&#039;GEN_MOV=0&#039;&#039;&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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;
   &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&#039;t be saved).&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10733</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=10733"/>
		<updated>2009-02-13T06:22:42Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Generating the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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 &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;&#039;&#039;GEN_MOV=0&#039;&#039;&#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=&#039;&#039;TIME_IN_SECONDS&#039;&#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=&#039;&#039;FRAMES_PER_SECOND&#039;&#039; (default = 30) This is the frames per second of the video footage.&lt;br /&gt;
*GOAL =&#039;&#039;GOAL STATISTICS&#039;&#039; (default = [100 300 160000 40000 40000])  This is an array that contains the goal&#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 =&#039;&#039;COMMUNICATION_RADIUS&#039;&#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;
   &lt;br /&gt;
===Draw Options===&lt;br /&gt;
    DRAW_COMM_LINKS = 1;&lt;br /&gt;
    DRAW_SWARM_ELLIPSE = 1;&lt;br /&gt;
    DRAW_GOAL_ELLIPSE = 1;&lt;br /&gt;
    DRAW_INDIVIDUAL_ESTIMATES = 1;&lt;br /&gt;
    DRAW_ROBOT_MARKER_DOT = 1;&lt;br /&gt;
    &lt;br /&gt;
    COMM_LINE_THICKNESS = 2; %line thickness of communication lins&lt;br /&gt;
    DOT_MARKER_SIZE = 30;    %size of dot marker.&lt;br /&gt;
    &lt;br /&gt;
    %Make movie or movie frames&lt;br /&gt;
    GEN_MOV = 0;  %Generate a movie&lt;br /&gt;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10732</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=10732"/>
		<updated>2009-02-13T05:12:54Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Generating the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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;
===Generating the Video===&lt;br /&gt;
If you run the &#039;&#039;&#039;VIDEO_OVERLAY.m&#039;&#039;&#039; script with &#039;&#039;&#039;GEN_MOV=0&#039;&#039;&#039;, you can preview what the video will look like, but the video will not be save.&lt;br /&gt;
Set flags for plotting additional components&lt;br /&gt;
    DRAW_COMM_LINKS = 1;&lt;br /&gt;
    DRAW_SWARM_ELLIPSE = 1;&lt;br /&gt;
    DRAW_GOAL_ELLIPSE = 1;&lt;br /&gt;
    DRAW_INDIVIDUAL_ESTIMATES = 1;&lt;br /&gt;
    DRAW_ROBOT_MARKER_DOT = 1;&lt;br /&gt;
    &lt;br /&gt;
    COMM_LINE_THICKNESS = 2; %line thickness of communication lins&lt;br /&gt;
    DOT_MARKER_SIZE = 30;    %size of dot marker.&lt;br /&gt;
    &lt;br /&gt;
    %Make movie or movie frames&lt;br /&gt;
    GEN_MOV = 0;  %Generate a movie&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10731</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=10731"/>
		<updated>2009-02-13T04:27:37Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
===Aligning the Axes===&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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10730</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=10730"/>
		<updated>2009-02-13T04:21:07Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
===Aligning the Axes===&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&#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 spacing between 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 &#039;+&#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 &#039;+&#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 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;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10729</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=10729"/>
		<updated>2009-02-13T04:20:32Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
===Aligning the Axes===&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&#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 spacing between 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 &#039;+&#039; points in on top of the first frame.  Make sure the square is a true square, and not distorted.&lt;br /&gt;
#Adjust X_OFFSET and Y_OFFSET until the center &#039;+&#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 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;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10639</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=10639"/>
		<updated>2009-02-12T07:23:17Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Aligning the Axes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
===Aligning the Axes===&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&#039;t move the camera.  You can make a short 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 spacing between 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 &#039;+&#039; points in on top of the first frame.  Make sure the square is a true square, and not distorted.&lt;br /&gt;
#Adjust X_OFFSET and Y_OFFSET until the center &#039;+&#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 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;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10638</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=10638"/>
		<updated>2009-02-12T07:21:58Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Making Videos with Overlays */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
===Aligning the Axes===&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&#039;t move the camera.  You can make a short 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 spacing between 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 &#039;+&#039; points in on the screen.  Make sure the square is a true square, and not distorted.&lt;br /&gt;
#Adjust X_OFFSET and Y_OFFSET until the center &#039;+&#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, not the unit distance.&lt;br /&gt;
#The overlay axes should how match the real world axes in the video.&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10561</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=10561"/>
		<updated>2009-02-12T05:43:16Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Generating the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#039;ll need the footage, and the output file from the data logger.&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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
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 &#039;&#039;&#039;Frames&#039;&#039;&#039; folder holding the movie frames and &#039;&#039;&#039;main_log.m&#039;&#039;&#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;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_extract_frames.gif&amp;diff=10217</id>
		<title>File:Virtualdub extract frames.gif</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_extract_frames.gif&amp;diff=10217"/>
		<updated>2009-02-09T06:59:12Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_markout.gif&amp;diff=10216</id>
		<title>File:Virtualdub markout.gif</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_markout.gif&amp;diff=10216"/>
		<updated>2009-02-09T06:59:03Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_markin.gif&amp;diff=10215</id>
		<title>File:Virtualdub markin.gif</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Virtualdub_markin.gif&amp;diff=10215"/>
		<updated>2009-02-09T06:58:48Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10214</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=10214"/>
		<updated>2009-02-09T06:56:56Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Extracting Frames with VirtualDub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#039;ll need the footage, and the output file from the data logger.&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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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&#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 &#039;&#039;Mark In&#039;&#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 &#039;&#039;Mark Out&#039;&#039; button [[Image:virtualdub_markout.gif]] to indicate the end.&lt;br /&gt;
#Go to &#039;&#039;&#039;File&amp;gt;Export&amp;gt;Image Sequence...&#039;&#039;&#039;&lt;br /&gt;
#Enter &#039;&#039;frame&#039;&#039; for filename, &#039;&#039;.jpeg&#039;&#039; for the filename suffix, and &#039;&#039;1&#039;&#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;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10211</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=10211"/>
		<updated>2009-02-09T04:02:11Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Extracting Frames with VirtualDub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#039;ll need the footage, and the output file from the data logger.&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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_robot_simulation.zip&amp;diff=10068</id>
		<title>File:Swarm robot simulation.zip</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_robot_simulation.zip&amp;diff=10068"/>
		<updated>2009-02-04T04:45:44Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10066</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=10066"/>
		<updated>2009-02-03T06:34:04Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Making Videos with Overlays */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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&#039;ll need the footage, and the output file from the data logger.&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 &#039;a&#039; at the data logger window to close the file, and &#039;q&#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;
&lt;br /&gt;
&lt;br /&gt;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10065</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=10065"/>
		<updated>2009-02-03T04:27:14Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Recording the Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
==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;
&lt;br /&gt;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Swarm_plotting_files.zip&amp;diff=10050</id>
		<title>File:Swarm plotting files.zip</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Swarm_plotting_files.zip&amp;diff=10050"/>
		<updated>2009-01-30T05:02:52Z</updated>

		<summary type="html">&lt;p&gt;Hwang: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10049</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=10049"/>
		<updated>2009-01-30T04:58:46Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Compressing the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
==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.&lt;br /&gt;
&lt;br /&gt;
==Extracting Frames with VirtualDub==&lt;br /&gt;
&lt;br /&gt;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
==Compressing the Video==&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10048</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=10048"/>
		<updated>2009-01-30T04:58:35Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Generating the Video */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
==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.&lt;br /&gt;
&lt;br /&gt;
==Extracting Frames with VirtualDub==&lt;br /&gt;
&lt;br /&gt;
==Generating the Video==&lt;br /&gt;
&lt;br /&gt;
=Compressing the Video=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10047</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=10047"/>
		<updated>2009-01-30T04:58:24Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Extracting Frames with VirtualDub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
==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.&lt;br /&gt;
&lt;br /&gt;
==Extracting Frames with VirtualDub==&lt;br /&gt;
&lt;br /&gt;
=Generating the Video=&lt;br /&gt;
=Compressing the Video=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10046</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=10046"/>
		<updated>2009-01-30T04:58:16Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Recording the Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
==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.&lt;br /&gt;
&lt;br /&gt;
=Extracting Frames with VirtualDub=&lt;br /&gt;
=Generating the Video=&lt;br /&gt;
=Compressing the Video=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10045</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=10045"/>
		<updated>2009-01-30T04:57:55Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Making Videos with Overlays */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  &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;
=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.&lt;br /&gt;
&lt;br /&gt;
=Extracting Frames with VirtualDub=&lt;br /&gt;
=Generating the Video=&lt;br /&gt;
=Compressing the Video=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10044</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=10044"/>
		<updated>2009-01-30T04:56:43Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Making Videos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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.  You can download the MATLAB files you need here: [[Image:swarm_plotting_files.zip]]&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.&lt;br /&gt;
&lt;br /&gt;
=Extracting Frames with VirtualDub=&lt;br /&gt;
=Generating the Video=&lt;br /&gt;
=Compressing the Video=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10041</id>
		<title>Swarm Robot Quickstart Guide</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10041"/>
		<updated>2009-01-29T02:53:45Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Starting the Vision System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
This guide was written as a quickstart guide for the Swarm Robots Project, but contains general information about programming e-pucks.&lt;br /&gt;
=Checklist=&lt;br /&gt;
In order to run the system, you will need:&lt;br /&gt;
# e-puck robots, with XBee extension boards and [[Swarm_Robot_Project_Documentation#XBee_Radios|configured radios]].&lt;br /&gt;
# Bluetooth adapter on your computer, either internal or an external one such as the D-link DBT-120.&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Compiled .hex file found in e-puck code project]&lt;br /&gt;
# [http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm Tiny Bootloader]&lt;br /&gt;
# [[Machine_Vision_Localization_System|Compiled program for Machine Vision Localization System]].&lt;br /&gt;
# You may also want to use one or more of the [[#Analysis_Tools|Analysis Tools]] such as the real-time display.&lt;br /&gt;
&lt;br /&gt;
==Items needed to edit the e-puck code==&lt;br /&gt;
If you want to edit the e-puck code, you will need the following:&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] (for editing code, not needed to run)&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en535363 C compiler for dsPICs] (for editing code, not needed to run)&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Code for e-pucks]&lt;br /&gt;
&lt;br /&gt;
===Compiling the project===&lt;br /&gt;
To open the project, extract the directory and double-click on the &#039;&#039;&#039;&amp;lt;tt&amp;gt;.mcp&amp;lt;/tt&amp;gt;&#039;&#039;&#039; file; this is the project file.  Because the directory it is in is probably different from the original directory from the computer on which the code was written, you may need to remove and re-add the sources, library, and/or linker files to the project.  The source files are in the &#039;&#039;&#039;source&#039;&#039;&#039; folder.  The library and linker files are in the Microhip compiler&#039;s install directory(try searching for &amp;lt;tt&amp;gt;libp30F6014A-coff.a&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;p30f6014A.gld&amp;lt;/tt&amp;gt;).  Press f10 to compile the program.  This should generate a .hex file, which is the binary file that you will load onto the e-Puck.&lt;br /&gt;
&lt;br /&gt;
=Programming the e-pucks=&lt;br /&gt;
You will need to get the compiled .hex file for the e-puck, and then load it onto the PIC with Tiny Bootloader over the bluetooth radio.  The compiled .hex file can be found here: [[Image:Swarm_epucks_code.zip]].&lt;br /&gt;
==Connecting to the e-puck==&lt;br /&gt;
To program the e-puck, you first need to connect to the e-puck.  Go to the Control Panel, and open Bluetooth Devices, and go to &#039;&#039;&#039;Devices&amp;gt;Add...&#039;&#039;&#039;.  Turn on the e-puck, check &#039;&#039;&#039;My device is set up and ready to be found&#039;&#039;&#039;, then click next.  When the computer has found the e-puck, select it (the ID of the epuck is a four-digit number found on a sticker on top of the bluetooth chip on the e-puck).  When the prompt asks you for a passkey, enter the 4-digit ID number.  The computer should then reserve a COM (serial) port to communicate with this particular e-puck.  The computer will set up different COM ports for different e-pucks; this is normal.  Go back to Bluetooth Devices in the Control Panel, and select the COM Ports tab, and see port is assigned &#039;&#039;&#039;Outgoing&#039;&#039;&#039; to the e-puck.  This is the COM port you will use to program this particular e-puck when using Tiny Bootloader.  &#039;&#039;&#039;If you&#039;re using a USB bluetooth dongle, if you unplug it and replug it into a different USB port, or use a different dongle, you may need to reconnect to the e-pucks.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Image:BT_COM_ports.png]]&lt;br /&gt;
&lt;br /&gt;
==Programming the e-puck==&lt;br /&gt;
A bootloader is a type of program that is loaded onto a microcontroller which allows one to re-program the microcontroller in the field without having to use an special flash programmer (the programmer is still needed to load the bootloader onto the microcontroller in the first place).  The Bootloader has two components: a programmer that runs on your computer, and a program that runs on the e-puck&#039;s PIC.  When the PIC is turned on, bootloader will check to see if someone is attempting to re-program the PIC; if yes, the bootloader will overwrite its old program with the new program; if not, or if it times out while waiting for the new data stream, it will simply run the current program.&lt;br /&gt;
&lt;br /&gt;
To program the e-puck, start the Tiny Bootloader program on your computer.  (Although you can also use a flash programmer such as the ICD2 to program the e-puck, it will take much longer and can&#039;t be done wirelessly.)  Click on &#039;&#039;&#039;Browse&#039;&#039;&#039; and select the .hex file that you want to load.  The .hex file is the compiled code from Microchip&#039;s C compiler.  Under &#039;&#039;&#039;Comm&#039;&#039;&#039;, use 115200 for the baud rate, and type in the outgoing COM port assigned to this e-puck (e.g. COM10, COM11, etc.).  Turn on the e-puck, and click on the Write Flash button.  The blue bar underneath the button should start counting down.  Now, hit the blue reset button on the e-puck, before the blue bar reaches zero and times out.  If the e-puck is successfully connected, an orange LED on the e-puck will turn on, and the bootloader will start to program the PIC on the e-puck.  &lt;br /&gt;
&lt;br /&gt;
===Troubleshooting===&lt;br /&gt;
* If Tiny Bootloader cannot connect to the COM port, make sure your e-puck is on, and that you&#039;ve selected the correct COM port assigned to the e-puck (the ID of the e-puck is on a sticker on top of the bluetooth chip on the e-puck&#039;s PCB.&lt;br /&gt;
* If Tiny Bootloader can connect to the e-puck but cannot find the PIC, it may be that someone has overwritten the bootloader with another program.  See the section below [[#Re-loading the Bootloader|Re-loading the Bootloader]] to see how to restore the bootloader with the ICD2 programmer and MPLAB.&lt;br /&gt;
&lt;br /&gt;
====Re-loading the Bootloader====&lt;br /&gt;
The e-pucks require that a special bootloader program be loaded on it if you want to program the e-puck over a bluetooth radio.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can download the .hex file you need at [http://www.e-puck.org http://www.e-puck.org].  On the website, go to Download&amp;gt;Software&amp;gt;Library and download the zip file.  Extract the archive, and navigate to &#039;&#039;&#039;e-puck-lib\tool\bootloader\epuck_side&#039;&#039;&#039;.  The file &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt; is the one we will use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need Microchip&#039;s [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] and ICD2 to program in the bootloader on the PIC.  After opening MPLAB, select to &#039;&#039;&#039;Programmer&amp;gt;Select Programmer&amp;gt;ICD2&#039;&#039;&#039;.  Then, go to &#039;&#039;&#039;File&amp;gt;Import&amp;gt;&#039;&#039;&#039; and navigate to &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt;.  Then, connect to the ICD and program the PIC.&lt;br /&gt;
&lt;br /&gt;
=Starting the Vision System=&lt;br /&gt;
The vision system is needed to track the position of the robots and send out commands.  You can get the compiled program here:[[Image:vision_system_localization_project.zip]]&lt;br /&gt;
# Connect an XBee radio with ID 0 to the computer.  The ID must be 0 so that the robots can tell that the packet is from the computer and not another robot.&lt;br /&gt;
# Follow the directions on the [[Machine_Vision_Localization_System#Operation | Machine Vision Localization]] page to set up and calibrate the system.&lt;br /&gt;
# Make sure the robots are in the field of view of the vision system.&lt;br /&gt;
# Let the system run for a few seconds so that the robot&#039;s positions will be updated.&lt;br /&gt;
# Select the GUI window and hit &#039;c&#039; to enter the command mode.&lt;br /&gt;
# Select the console window and enter the goal statistics that you want using the &#039;&#039;&#039;goal&#039;&#039;&#039; command.  You can skip this step if you want to use the default [100 300 160000 40000 40000] goal statistics.  Send the command 2 or three times in case one or more of the robots doesn&#039;t get the message.&lt;br /&gt;
# Use the &#039;&#039;&#039;wake&#039;&#039;&#039; command (&amp;lt;tt&amp;gt;wake 0&amp;lt;/tt&amp;gt;) to start the robots.&lt;br /&gt;
# Exit the console by typing &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;.  The system should now be running.&lt;br /&gt;
&lt;br /&gt;
Try moving the swarm to another configuration:&lt;br /&gt;
#press &#039;c&#039; at the GUI window.&lt;br /&gt;
#enter the command &amp;lt;tt&amp;gt;goal 0 -100 -200 120000 0 120000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
#type &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt; and hit enter.&lt;br /&gt;
&lt;br /&gt;
=Using the Real-Time Display=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Real-time_Display]]&lt;br /&gt;
&lt;br /&gt;
=Using the Packet Parser with Timestamp=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Using_the_Data_Logger_with_Timestamp]]&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10040</id>
		<title>Swarm Robot Quickstart Guide</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10040"/>
		<updated>2009-01-29T02:53:37Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Starting the Vision System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
This guide was written as a quickstart guide for the Swarm Robots Project, but contains general information about programming e-pucks.&lt;br /&gt;
=Checklist=&lt;br /&gt;
In order to run the system, you will need:&lt;br /&gt;
# e-puck robots, with XBee extension boards and [[Swarm_Robot_Project_Documentation#XBee_Radios|configured radios]].&lt;br /&gt;
# Bluetooth adapter on your computer, either internal or an external one such as the D-link DBT-120.&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Compiled .hex file found in e-puck code project]&lt;br /&gt;
# [http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm Tiny Bootloader]&lt;br /&gt;
# [[Machine_Vision_Localization_System|Compiled program for Machine Vision Localization System]].&lt;br /&gt;
# You may also want to use one or more of the [[#Analysis_Tools|Analysis Tools]] such as the real-time display.&lt;br /&gt;
&lt;br /&gt;
==Items needed to edit the e-puck code==&lt;br /&gt;
If you want to edit the e-puck code, you will need the following:&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] (for editing code, not needed to run)&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en535363 C compiler for dsPICs] (for editing code, not needed to run)&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Code for e-pucks]&lt;br /&gt;
&lt;br /&gt;
===Compiling the project===&lt;br /&gt;
To open the project, extract the directory and double-click on the &#039;&#039;&#039;&amp;lt;tt&amp;gt;.mcp&amp;lt;/tt&amp;gt;&#039;&#039;&#039; file; this is the project file.  Because the directory it is in is probably different from the original directory from the computer on which the code was written, you may need to remove and re-add the sources, library, and/or linker files to the project.  The source files are in the &#039;&#039;&#039;source&#039;&#039;&#039; folder.  The library and linker files are in the Microhip compiler&#039;s install directory(try searching for &amp;lt;tt&amp;gt;libp30F6014A-coff.a&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;p30f6014A.gld&amp;lt;/tt&amp;gt;).  Press f10 to compile the program.  This should generate a .hex file, which is the binary file that you will load onto the e-Puck.&lt;br /&gt;
&lt;br /&gt;
=Programming the e-pucks=&lt;br /&gt;
You will need to get the compiled .hex file for the e-puck, and then load it onto the PIC with Tiny Bootloader over the bluetooth radio.  The compiled .hex file can be found here: [[Image:Swarm_epucks_code.zip]].&lt;br /&gt;
==Connecting to the e-puck==&lt;br /&gt;
To program the e-puck, you first need to connect to the e-puck.  Go to the Control Panel, and open Bluetooth Devices, and go to &#039;&#039;&#039;Devices&amp;gt;Add...&#039;&#039;&#039;.  Turn on the e-puck, check &#039;&#039;&#039;My device is set up and ready to be found&#039;&#039;&#039;, then click next.  When the computer has found the e-puck, select it (the ID of the epuck is a four-digit number found on a sticker on top of the bluetooth chip on the e-puck).  When the prompt asks you for a passkey, enter the 4-digit ID number.  The computer should then reserve a COM (serial) port to communicate with this particular e-puck.  The computer will set up different COM ports for different e-pucks; this is normal.  Go back to Bluetooth Devices in the Control Panel, and select the COM Ports tab, and see port is assigned &#039;&#039;&#039;Outgoing&#039;&#039;&#039; to the e-puck.  This is the COM port you will use to program this particular e-puck when using Tiny Bootloader.  &#039;&#039;&#039;If you&#039;re using a USB bluetooth dongle, if you unplug it and replug it into a different USB port, or use a different dongle, you may need to reconnect to the e-pucks.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Image:BT_COM_ports.png]]&lt;br /&gt;
&lt;br /&gt;
==Programming the e-puck==&lt;br /&gt;
A bootloader is a type of program that is loaded onto a microcontroller which allows one to re-program the microcontroller in the field without having to use an special flash programmer (the programmer is still needed to load the bootloader onto the microcontroller in the first place).  The Bootloader has two components: a programmer that runs on your computer, and a program that runs on the e-puck&#039;s PIC.  When the PIC is turned on, bootloader will check to see if someone is attempting to re-program the PIC; if yes, the bootloader will overwrite its old program with the new program; if not, or if it times out while waiting for the new data stream, it will simply run the current program.&lt;br /&gt;
&lt;br /&gt;
To program the e-puck, start the Tiny Bootloader program on your computer.  (Although you can also use a flash programmer such as the ICD2 to program the e-puck, it will take much longer and can&#039;t be done wirelessly.)  Click on &#039;&#039;&#039;Browse&#039;&#039;&#039; and select the .hex file that you want to load.  The .hex file is the compiled code from Microchip&#039;s C compiler.  Under &#039;&#039;&#039;Comm&#039;&#039;&#039;, use 115200 for the baud rate, and type in the outgoing COM port assigned to this e-puck (e.g. COM10, COM11, etc.).  Turn on the e-puck, and click on the Write Flash button.  The blue bar underneath the button should start counting down.  Now, hit the blue reset button on the e-puck, before the blue bar reaches zero and times out.  If the e-puck is successfully connected, an orange LED on the e-puck will turn on, and the bootloader will start to program the PIC on the e-puck.  &lt;br /&gt;
&lt;br /&gt;
===Troubleshooting===&lt;br /&gt;
* If Tiny Bootloader cannot connect to the COM port, make sure your e-puck is on, and that you&#039;ve selected the correct COM port assigned to the e-puck (the ID of the e-puck is on a sticker on top of the bluetooth chip on the e-puck&#039;s PCB.&lt;br /&gt;
* If Tiny Bootloader can connect to the e-puck but cannot find the PIC, it may be that someone has overwritten the bootloader with another program.  See the section below [[#Re-loading the Bootloader|Re-loading the Bootloader]] to see how to restore the bootloader with the ICD2 programmer and MPLAB.&lt;br /&gt;
&lt;br /&gt;
====Re-loading the Bootloader====&lt;br /&gt;
The e-pucks require that a special bootloader program be loaded on it if you want to program the e-puck over a bluetooth radio.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can download the .hex file you need at [http://www.e-puck.org http://www.e-puck.org].  On the website, go to Download&amp;gt;Software&amp;gt;Library and download the zip file.  Extract the archive, and navigate to &#039;&#039;&#039;e-puck-lib\tool\bootloader\epuck_side&#039;&#039;&#039;.  The file &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt; is the one we will use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need Microchip&#039;s [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] and ICD2 to program in the bootloader on the PIC.  After opening MPLAB, select to &#039;&#039;&#039;Programmer&amp;gt;Select Programmer&amp;gt;ICD2&#039;&#039;&#039;.  Then, go to &#039;&#039;&#039;File&amp;gt;Import&amp;gt;&#039;&#039;&#039; and navigate to &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt;.  Then, connect to the ICD and program the PIC.&lt;br /&gt;
&lt;br /&gt;
=Starting the Vision System=&lt;br /&gt;
The vision system is needed to track the position of the robots and send out commands.  You can get the compiled program here:[[Image:vision_system_localization_project.zip]&lt;br /&gt;
# Connect an XBee radio with ID 0 to the computer.  The ID must be 0 so that the robots can tell that the packet is from the computer and not another robot.&lt;br /&gt;
# Follow the directions on the [[Machine_Vision_Localization_System#Operation | Machine Vision Localization]] page to set up and calibrate the system.&lt;br /&gt;
# Make sure the robots are in the field of view of the vision system.&lt;br /&gt;
# Let the system run for a few seconds so that the robot&#039;s positions will be updated.&lt;br /&gt;
# Select the GUI window and hit &#039;c&#039; to enter the command mode.&lt;br /&gt;
# Select the console window and enter the goal statistics that you want using the &#039;&#039;&#039;goal&#039;&#039;&#039; command.  You can skip this step if you want to use the default [100 300 160000 40000 40000] goal statistics.  Send the command 2 or three times in case one or more of the robots doesn&#039;t get the message.&lt;br /&gt;
# Use the &#039;&#039;&#039;wake&#039;&#039;&#039; command (&amp;lt;tt&amp;gt;wake 0&amp;lt;/tt&amp;gt;) to start the robots.&lt;br /&gt;
# Exit the console by typing &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;.  The system should now be running.&lt;br /&gt;
&lt;br /&gt;
Try moving the swarm to another configuration:&lt;br /&gt;
#press &#039;c&#039; at the GUI window.&lt;br /&gt;
#enter the command &amp;lt;tt&amp;gt;goal 0 -100 -200 120000 0 120000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
#type &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt; and hit enter.&lt;br /&gt;
&lt;br /&gt;
=Using the Real-Time Display=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Real-time_Display]]&lt;br /&gt;
&lt;br /&gt;
=Using the Packet Parser with Timestamp=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Using_the_Data_Logger_with_Timestamp]]&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10039</id>
		<title>Swarm Robot Quickstart Guide</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10039"/>
		<updated>2009-01-29T02:53:23Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Starting the Vision System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
This guide was written as a quickstart guide for the Swarm Robots Project, but contains general information about programming e-pucks.&lt;br /&gt;
=Checklist=&lt;br /&gt;
In order to run the system, you will need:&lt;br /&gt;
# e-puck robots, with XBee extension boards and [[Swarm_Robot_Project_Documentation#XBee_Radios|configured radios]].&lt;br /&gt;
# Bluetooth adapter on your computer, either internal or an external one such as the D-link DBT-120.&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Compiled .hex file found in e-puck code project]&lt;br /&gt;
# [http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm Tiny Bootloader]&lt;br /&gt;
# [[Machine_Vision_Localization_System|Compiled program for Machine Vision Localization System]].&lt;br /&gt;
# You may also want to use one or more of the [[#Analysis_Tools|Analysis Tools]] such as the real-time display.&lt;br /&gt;
&lt;br /&gt;
==Items needed to edit the e-puck code==&lt;br /&gt;
If you want to edit the e-puck code, you will need the following:&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] (for editing code, not needed to run)&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en535363 C compiler for dsPICs] (for editing code, not needed to run)&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Code for e-pucks]&lt;br /&gt;
&lt;br /&gt;
===Compiling the project===&lt;br /&gt;
To open the project, extract the directory and double-click on the &#039;&#039;&#039;&amp;lt;tt&amp;gt;.mcp&amp;lt;/tt&amp;gt;&#039;&#039;&#039; file; this is the project file.  Because the directory it is in is probably different from the original directory from the computer on which the code was written, you may need to remove and re-add the sources, library, and/or linker files to the project.  The source files are in the &#039;&#039;&#039;source&#039;&#039;&#039; folder.  The library and linker files are in the Microhip compiler&#039;s install directory(try searching for &amp;lt;tt&amp;gt;libp30F6014A-coff.a&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;p30f6014A.gld&amp;lt;/tt&amp;gt;).  Press f10 to compile the program.  This should generate a .hex file, which is the binary file that you will load onto the e-Puck.&lt;br /&gt;
&lt;br /&gt;
=Programming the e-pucks=&lt;br /&gt;
You will need to get the compiled .hex file for the e-puck, and then load it onto the PIC with Tiny Bootloader over the bluetooth radio.  The compiled .hex file can be found here: [[Image:Swarm_epucks_code.zip]].&lt;br /&gt;
==Connecting to the e-puck==&lt;br /&gt;
To program the e-puck, you first need to connect to the e-puck.  Go to the Control Panel, and open Bluetooth Devices, and go to &#039;&#039;&#039;Devices&amp;gt;Add...&#039;&#039;&#039;.  Turn on the e-puck, check &#039;&#039;&#039;My device is set up and ready to be found&#039;&#039;&#039;, then click next.  When the computer has found the e-puck, select it (the ID of the epuck is a four-digit number found on a sticker on top of the bluetooth chip on the e-puck).  When the prompt asks you for a passkey, enter the 4-digit ID number.  The computer should then reserve a COM (serial) port to communicate with this particular e-puck.  The computer will set up different COM ports for different e-pucks; this is normal.  Go back to Bluetooth Devices in the Control Panel, and select the COM Ports tab, and see port is assigned &#039;&#039;&#039;Outgoing&#039;&#039;&#039; to the e-puck.  This is the COM port you will use to program this particular e-puck when using Tiny Bootloader.  &#039;&#039;&#039;If you&#039;re using a USB bluetooth dongle, if you unplug it and replug it into a different USB port, or use a different dongle, you may need to reconnect to the e-pucks.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Image:BT_COM_ports.png]]&lt;br /&gt;
&lt;br /&gt;
==Programming the e-puck==&lt;br /&gt;
A bootloader is a type of program that is loaded onto a microcontroller which allows one to re-program the microcontroller in the field without having to use an special flash programmer (the programmer is still needed to load the bootloader onto the microcontroller in the first place).  The Bootloader has two components: a programmer that runs on your computer, and a program that runs on the e-puck&#039;s PIC.  When the PIC is turned on, bootloader will check to see if someone is attempting to re-program the PIC; if yes, the bootloader will overwrite its old program with the new program; if not, or if it times out while waiting for the new data stream, it will simply run the current program.&lt;br /&gt;
&lt;br /&gt;
To program the e-puck, start the Tiny Bootloader program on your computer.  (Although you can also use a flash programmer such as the ICD2 to program the e-puck, it will take much longer and can&#039;t be done wirelessly.)  Click on &#039;&#039;&#039;Browse&#039;&#039;&#039; and select the .hex file that you want to load.  The .hex file is the compiled code from Microchip&#039;s C compiler.  Under &#039;&#039;&#039;Comm&#039;&#039;&#039;, use 115200 for the baud rate, and type in the outgoing COM port assigned to this e-puck (e.g. COM10, COM11, etc.).  Turn on the e-puck, and click on the Write Flash button.  The blue bar underneath the button should start counting down.  Now, hit the blue reset button on the e-puck, before the blue bar reaches zero and times out.  If the e-puck is successfully connected, an orange LED on the e-puck will turn on, and the bootloader will start to program the PIC on the e-puck.  &lt;br /&gt;
&lt;br /&gt;
===Troubleshooting===&lt;br /&gt;
* If Tiny Bootloader cannot connect to the COM port, make sure your e-puck is on, and that you&#039;ve selected the correct COM port assigned to the e-puck (the ID of the e-puck is on a sticker on top of the bluetooth chip on the e-puck&#039;s PCB.&lt;br /&gt;
* If Tiny Bootloader can connect to the e-puck but cannot find the PIC, it may be that someone has overwritten the bootloader with another program.  See the section below [[#Re-loading the Bootloader|Re-loading the Bootloader]] to see how to restore the bootloader with the ICD2 programmer and MPLAB.&lt;br /&gt;
&lt;br /&gt;
====Re-loading the Bootloader====&lt;br /&gt;
The e-pucks require that a special bootloader program be loaded on it if you want to program the e-puck over a bluetooth radio.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can download the .hex file you need at [http://www.e-puck.org http://www.e-puck.org].  On the website, go to Download&amp;gt;Software&amp;gt;Library and download the zip file.  Extract the archive, and navigate to &#039;&#039;&#039;e-puck-lib\tool\bootloader\epuck_side&#039;&#039;&#039;.  The file &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt; is the one we will use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need Microchip&#039;s [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] and ICD2 to program in the bootloader on the PIC.  After opening MPLAB, select to &#039;&#039;&#039;Programmer&amp;gt;Select Programmer&amp;gt;ICD2&#039;&#039;&#039;.  Then, go to &#039;&#039;&#039;File&amp;gt;Import&amp;gt;&#039;&#039;&#039; and navigate to &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt;.  Then, connect to the ICD and program the PIC.&lt;br /&gt;
&lt;br /&gt;
=Starting the Vision System=&lt;br /&gt;
The vision system is needed to track the position of the robots and send out commands.  You can get the compiled program here:[[Image:vision_system_localization_project.zip]][[Image:vision_localization.zip]]&lt;br /&gt;
# Connect an XBee radio with ID 0 to the computer.  The ID must be 0 so that the robots can tell that the packet is from the computer and not another robot.&lt;br /&gt;
# Follow the directions on the [[Machine_Vision_Localization_System#Operation | Machine Vision Localization]] page to set up and calibrate the system.&lt;br /&gt;
# Make sure the robots are in the field of view of the vision system.&lt;br /&gt;
# Let the system run for a few seconds so that the robot&#039;s positions will be updated.&lt;br /&gt;
# Select the GUI window and hit &#039;c&#039; to enter the command mode.&lt;br /&gt;
# Select the console window and enter the goal statistics that you want using the &#039;&#039;&#039;goal&#039;&#039;&#039; command.  You can skip this step if you want to use the default [100 300 160000 40000 40000] goal statistics.  Send the command 2 or three times in case one or more of the robots doesn&#039;t get the message.&lt;br /&gt;
# Use the &#039;&#039;&#039;wake&#039;&#039;&#039; command (&amp;lt;tt&amp;gt;wake 0&amp;lt;/tt&amp;gt;) to start the robots.&lt;br /&gt;
# Exit the console by typing &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;.  The system should now be running.&lt;br /&gt;
&lt;br /&gt;
Try moving the swarm to another configuration:&lt;br /&gt;
#press &#039;c&#039; at the GUI window.&lt;br /&gt;
#enter the command &amp;lt;tt&amp;gt;goal 0 -100 -200 120000 0 120000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
#type &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt; and hit enter.&lt;br /&gt;
&lt;br /&gt;
=Using the Real-Time Display=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Real-time_Display]]&lt;br /&gt;
&lt;br /&gt;
=Using the Packet Parser with Timestamp=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Using_the_Data_Logger_with_Timestamp]]&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10032</id>
		<title>Swarm Robot Quickstart Guide</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Quickstart_Guide&amp;diff=10032"/>
		<updated>2009-01-27T22:16:35Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Compiling the project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
This guide was written as a quickstart guide for the Swarm Robots Project, but contains general information about programming e-pucks.&lt;br /&gt;
=Checklist=&lt;br /&gt;
In order to run the system, you will need:&lt;br /&gt;
# e-puck robots, with XBee extension boards and [[Swarm_Robot_Project_Documentation#XBee_Radios|configured radios]].&lt;br /&gt;
# Bluetooth adapter on your computer, either internal or an external one such as the D-link DBT-120.&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Compiled .hex file found in e-puck code project]&lt;br /&gt;
# [http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm Tiny Bootloader]&lt;br /&gt;
# [[Machine_Vision_Localization_System|Compiled program for Machine Vision Localization System]].&lt;br /&gt;
# You may also want to use one or more of the [[#Analysis_Tools|Analysis Tools]] such as the real-time display.&lt;br /&gt;
&lt;br /&gt;
==Items needed to edit the e-puck code==&lt;br /&gt;
If you want to edit the e-puck code, you will need the following:&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] (for editing code, not needed to run)&lt;br /&gt;
# Microchip [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en535363 C compiler for dsPICs] (for editing code, not needed to run)&lt;br /&gt;
# [http://hades.mech.northwestern.edu/wiki/index.php/Swarm_Project_E-puck_Code Code for e-pucks]&lt;br /&gt;
&lt;br /&gt;
===Compiling the project===&lt;br /&gt;
To open the project, extract the directory and double-click on the &#039;&#039;&#039;&amp;lt;tt&amp;gt;.mcp&amp;lt;/tt&amp;gt;&#039;&#039;&#039; file; this is the project file.  Because the directory it is in is probably different from the original directory from the computer on which the code was written, you may need to remove and re-add the sources, library, and/or linker files to the project.  The source files are in the &#039;&#039;&#039;source&#039;&#039;&#039; folder.  The library and linker files are in the Microhip compiler&#039;s install directory(try searching for &amp;lt;tt&amp;gt;libp30F6014A-coff.a&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;p30f6014A.gld&amp;lt;/tt&amp;gt;).  Press f10 to compile the program.  This should generate a .hex file, which is the binary file that you will load onto the e-Puck.&lt;br /&gt;
&lt;br /&gt;
=Programming the e-pucks=&lt;br /&gt;
You will need to get the compiled .hex file for the e-puck, and then load it onto the PIC with Tiny Bootloader over the bluetooth radio.  The compiled .hex file can be found here: [[Image:Swarm_epucks_code.zip]].&lt;br /&gt;
==Connecting to the e-puck==&lt;br /&gt;
To program the e-puck, you first need to connect to the e-puck.  Go to the Control Panel, and open Bluetooth Devices, and go to &#039;&#039;&#039;Devices&amp;gt;Add...&#039;&#039;&#039;.  Turn on the e-puck, check &#039;&#039;&#039;My device is set up and ready to be found&#039;&#039;&#039;, then click next.  When the computer has found the e-puck, select it (the ID of the epuck is a four-digit number found on a sticker on top of the bluetooth chip on the e-puck).  When the prompt asks you for a passkey, enter the 4-digit ID number.  The computer should then reserve a COM (serial) port to communicate with this particular e-puck.  The computer will set up different COM ports for different e-pucks; this is normal.  Go back to Bluetooth Devices in the Control Panel, and select the COM Ports tab, and see port is assigned &#039;&#039;&#039;Outgoing&#039;&#039;&#039; to the e-puck.  This is the COM port you will use to program this particular e-puck when using Tiny Bootloader.  &#039;&#039;&#039;If you&#039;re using a USB bluetooth dongle, if you unplug it and replug it into a different USB port, or use a different dongle, you may need to reconnect to the e-pucks.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Image:BT_COM_ports.png]]&lt;br /&gt;
&lt;br /&gt;
==Programming the e-puck==&lt;br /&gt;
A bootloader is a type of program that is loaded onto a microcontroller which allows one to re-program the microcontroller in the field without having to use an special flash programmer (the programmer is still needed to load the bootloader onto the microcontroller in the first place).  The Bootloader has two components: a programmer that runs on your computer, and a program that runs on the e-puck&#039;s PIC.  When the PIC is turned on, bootloader will check to see if someone is attempting to re-program the PIC; if yes, the bootloader will overwrite its old program with the new program; if not, or if it times out while waiting for the new data stream, it will simply run the current program.&lt;br /&gt;
&lt;br /&gt;
To program the e-puck, start the Tiny Bootloader program on your computer.  (Although you can also use a flash programmer such as the ICD2 to program the e-puck, it will take much longer and can&#039;t be done wirelessly.)  Click on &#039;&#039;&#039;Browse&#039;&#039;&#039; and select the .hex file that you want to load.  The .hex file is the compiled code from Microchip&#039;s C compiler.  Under &#039;&#039;&#039;Comm&#039;&#039;&#039;, use 115200 for the baud rate, and type in the outgoing COM port assigned to this e-puck (e.g. COM10, COM11, etc.).  Turn on the e-puck, and click on the Write Flash button.  The blue bar underneath the button should start counting down.  Now, hit the blue reset button on the e-puck, before the blue bar reaches zero and times out.  If the e-puck is successfully connected, an orange LED on the e-puck will turn on, and the bootloader will start to program the PIC on the e-puck.  &lt;br /&gt;
&lt;br /&gt;
===Troubleshooting===&lt;br /&gt;
* If Tiny Bootloader cannot connect to the COM port, make sure your e-puck is on, and that you&#039;ve selected the correct COM port assigned to the e-puck (the ID of the e-puck is on a sticker on top of the bluetooth chip on the e-puck&#039;s PCB.&lt;br /&gt;
* If Tiny Bootloader can connect to the e-puck but cannot find the PIC, it may be that someone has overwritten the bootloader with another program.  See the section below [[#Re-loading the Bootloader|Re-loading the Bootloader]] to see how to restore the bootloader with the ICD2 programmer and MPLAB.&lt;br /&gt;
&lt;br /&gt;
====Re-loading the Bootloader====&lt;br /&gt;
The e-pucks require that a special bootloader program be loaded on it if you want to program the e-puck over a bluetooth radio.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can download the .hex file you need at [http://www.e-puck.org http://www.e-puck.org].  On the website, go to Download&amp;gt;Software&amp;gt;Library and download the zip file.  Extract the archive, and navigate to &#039;&#039;&#039;e-puck-lib\tool\bootloader\epuck_side&#039;&#039;&#039;.  The file &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt; is the one we will use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need Microchip&#039;s [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&amp;amp;nodeId=1406&amp;amp;dDocName=en019469&amp;amp;part=SW007002 MPLAB] and ICD2 to program in the bootloader on the PIC.  After opening MPLAB, select to &#039;&#039;&#039;Programmer&amp;gt;Select Programmer&amp;gt;ICD2&#039;&#039;&#039;.  Then, go to &#039;&#039;&#039;File&amp;gt;Import&amp;gt;&#039;&#039;&#039; and navigate to &amp;lt;tt&amp;gt;tinybld_ds6014A_7.37Mhz_115200uart1_8xPLL_with_LEDs.hex&amp;lt;/tt&amp;gt;.  Then, connect to the ICD and program the PIC.&lt;br /&gt;
&lt;br /&gt;
=Starting the Vision System=&lt;br /&gt;
The vision system is needed to track the position of the robots and send out commands.  You can get the compiled program here (no source code): [[Image:vision_localization.zip]]&lt;br /&gt;
# Connect an XBee radio with ID 0 to the computer.  The ID must be 0 so that the robots can tell that the packet is from the computer and not another robot.&lt;br /&gt;
# Follow the directions on the [[Machine_Vision_Localization_System#Operation | Machine Vision Localization]] page to set up and calibrate the system.&lt;br /&gt;
# Make sure the robots are in the field of view of the vision system.&lt;br /&gt;
# Let the system run for a few seconds so that the robot&#039;s positions will be updated.&lt;br /&gt;
# Select the GUI window and hit &#039;c&#039; to enter the command mode.&lt;br /&gt;
# Select the console window and enter the goal statistics that you want using the &#039;&#039;&#039;goal&#039;&#039;&#039; command.  You can skip this step if you want to use the default [100 300 160000 40000 40000] goal statistics.  Send the command 2 or three times in case one or more of the robots doesn&#039;t get the message.&lt;br /&gt;
# Use the &#039;&#039;&#039;wake&#039;&#039;&#039; command (&amp;lt;tt&amp;gt;wake 0&amp;lt;/tt&amp;gt;) to start the robots.&lt;br /&gt;
# Exit the console by typing &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt;.  The system should now be running.&lt;br /&gt;
&lt;br /&gt;
Try moving the swarm to another configuration:&lt;br /&gt;
#press &#039;c&#039; at the GUI window.&lt;br /&gt;
#enter the command &amp;lt;tt&amp;gt;goal 0 -100 -200 120000 0 120000 &amp;lt;/tt&amp;gt;&lt;br /&gt;
#type &amp;lt;tt&amp;gt;exit&amp;lt;/tt&amp;gt; and hit enter.&lt;br /&gt;
&lt;br /&gt;
=Using the Real-Time Display=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Real-time_Display]]&lt;br /&gt;
&lt;br /&gt;
=Using the Packet Parser with Timestamp=&lt;br /&gt;
See [[Swarm_Robot_Project_Documentation#Using_the_Data_Logger_with_Timestamp]]&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Swarm_Robot_Project_Documentation&amp;diff=10031</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=10031"/>
		<updated>2009-01-27T19:38:29Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Analysis Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
=Getting Started=&lt;br /&gt;
[[Swarm_E-puck_Quickstart_Guide|e-puck Quickstart Guide]]&lt;br /&gt;
&lt;br /&gt;
You can see the official documentation at [http://www.e-puck.org www.e-puck.org] and going to &#039;&#039;&#039;Download&amp;gt;Documentation&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=e-pucks=&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 e-puck’s size was ideal for the project, and its stepper motor driven wheels offered consistency and accuracy—highly desirable features for 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/]&lt;br /&gt;
==[[Swarm_Project_E-puck_Code|e-puck code]]==&lt;br /&gt;
The code on the e-puck was written in C and compiled using Microchip&#039;s &#039;&#039;MPLAB C Compiler for dsPIC DSCs&#039;&#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&#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 robots will start out in &#039;sleep&#039; mode.  Use the [[Machine_Vision_Localization_System#Commands| &#039;wake&#039; command]] on the visualization system to start the robots.&lt;br /&gt;
&lt;br /&gt;
The documentation for the code can be found at [[Swarm_Project_E-puck_Code]].&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&#039;s serial port.  The data frame, or payload, is unchanged, although it may be reformatted in the presence of escape characters.  See the XBee manual for detailed information on XBee API packets.&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 number is a 32-bit floating point, which means that the data frame is 60 bytes long, although it could be longer if escape characters are needed (see &#039;&#039;API Operation&#039;&#039; in the XBee Manual).&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;
&#039;&#039;&#039;Also see the [[XBee_radio_communication_between_PICs#Using_the_XBee_Radio|Using the XBee Radio]] page.&#039;&#039;&#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 &#039;&#039;&#039;+++&#039;&#039;&#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;
|+&#039;&#039;&#039;XBee AT Commands&#039;&#039;&#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.PCB]].  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=&#039;all&#039;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Assembling the Boards===&lt;br /&gt;
&#039;&#039;&#039;Parts:&#039;&#039;&#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;
=Localization Vision System=&lt;br /&gt;
A machine vision system was developed for robot localization, a la GPS.  The system uses cameras and pattern recognition algorithms to track the position and orientation of various targets 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;
The simulator attempts to model the robots in MATLAB.&lt;br /&gt;
Download the files here: [[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 &#039;COM1&#039; parameter in the &#039;&#039;&#039;initXBeeSerial&#039;&#039;&#039; function call with the serial that you are using.&lt;br /&gt;
#run the RT_Swarm_Plotter.m script.  Hit &#039;q&#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;
&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;
* &#039;&#039;&#039;It is important that you don&#039;t close the window while the parser is running, or it will not format the output files property and MATLAB won&#039;t be able to read it.  To stop logger, press &#039;a&#039;.  This will make it close the files correctly.&#039;&#039;&#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 &#039;&#039;&#039;agents&#039;&#039;&#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 &#039;&#039;&#039;agent_list&#039;&#039;&#039; contains the IDs of the agents whose data corresponds to the data in the &#039;&#039;&#039;agents&#039;&#039;&#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=&lt;/div&gt;</summary>
		<author><name>Hwang</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Machine_Vision_Localization_System&amp;diff=10030</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=10030"/>
		<updated>2009-01-27T19:36:25Z</updated>

		<summary type="html">&lt;p&gt;Hwang: /* Camera Calibration */&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&#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&#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 &#039;&#039;&#039;LoadTargetData()&#039;&#039;&#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=&#039;all&#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=&#039;all&#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=&#039;all&#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;
&#039;&#039;&#039;1.  Choose a desired ALL WHITE area to cover.&#039;&#039;&#039;  &#039;&#039;&#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***&#039;&#039;&#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;
&#039;&#039;&#039;2.  Ensure that the cameras are all facing the same direction. &#039;&#039;&#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;
&#039;&#039;&#039;3.  Try to mount the cameras as &amp;quot;normal&amp;quot; as possible.&#039;&#039;&#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.  Download and install Microsoft Visual Studio Express - http://www.microsoft.com/express/default.aspx&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 &#039;&#039;&#039;Include files&#039;&#039;&#039; in the drop-down menu.  Add &#039;&#039;&#039;(the directory paths on your computer may be different depending on your system, and the versions you installed.)&#039;&#039;&#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 &#039;&#039;&#039;Library files&#039;&#039;&#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 &#039;&#039;&#039;&amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt;&#039;&#039;&#039; for yes and &#039;&#039;&#039;&amp;lt;tt&amp;gt;n&amp;lt;/tt&amp;gt;&#039;&#039;&#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 &#039;&#039;&#039;sleep&#039;&#039;&#039; mode.  Use the &#039;&#039;&#039;wake&#039;&#039;&#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 &#039;+&#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 &#039;+&#039;.]]&lt;br /&gt;
&amp;lt;br clear = &#039;all&#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&#039;t bunch the dots all up in a small area).&lt;br /&gt;
# Start the program, and type in &#039;y&#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 &#039;p&#039; to pause the program, and hit &#039;p&#039; again to resume.&lt;br /&gt;
&lt;br /&gt;
==Using the Command Console==&lt;br /&gt;
To enter the command mode, hit &#039;c&#039;.  When in the command mode, the main loop is not running; the command mode must be exited to resume.  Type &#039;exit&#039; to exit the command mode and resume the main loop.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#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.&#039;&#039;&#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;
&#039;&#039;&#039;To broadcast the message, use ID 0.&#039;&#039;&#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;
|+&#039;&#039;&#039;Commands Table&#039;&#039;&#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&#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>Hwang</name></author>
	</entry>
</feed>