<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Alexander Robotics</title>
 <link href="http://alexanderrobotics.com/blog/atom.xml" rel="self"/>
 <link href="http://alexanderrobotics.com/blog/"/>
 <updated>2011-10-10T22:30:59-05:00</updated>
 <id>http://alexanderrobotics.com/blog/</id>
 <author>
   <name>Brandon Alexander</name>
   <email>baalexander at gmail</email>
 </author>

 
 <entry>
   <title>The AVR and the Arduino</title>
   <link href="http://alexanderrobotics.com/blog/2011/10/avr-and-the-arduino"/>
   <updated>2011-10-10T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2011/10/avr-and-the-arduino</id>
   <content type="html">&lt;h3 id='introduction'&gt;Introduction&lt;/h3&gt;

&lt;p&gt;The beauty of the Arduino lies in its simplicity. A look under the covers of the Arduino and its IDE, however, reveals a fascinating chipset and an open, extensive toolchain.&lt;/p&gt;

&lt;h3 id='from_a_to_z_with_the_avr'&gt;From A to Z with the AVR&lt;/h3&gt;

&lt;p&gt;The MCU on the Arduino is an 8-bit RISC chip called the AVR. I&amp;#8217;ll get to the Arduino component of the chip shortly (hint: the bootloader plays a big role), but first, let&amp;#8217;s focus on what happens from programming on a computer to executing the program on the AVR. While there&amp;#8217;s an 8-bit AVR and 32-bit AVR variety, we&amp;#8217;ll assume 8-bit for this post.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2011/10/avr-toolchain.png' alt='The AVR toolchain processes source files using the compiler
    (avr-gcc), then the assembler (avr-as), and finally the linker (avr-ln) to
    generate a runnable HEX file.' /&gt;
  &lt;figcaption&gt;
    Overview of the AVR toolchain
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;One reason for the popularity of the AVR is the free (as in beer and speech) toolchain. At the second highest level of this toolchain is the compiler: AVR-GCC. AVR-GCC converts C code into assembly language files. Although AVR-GCC compiles C, it&amp;#8217;s basic C, which means referencing registers by memory address, lack of floating-point support, and so forth.&lt;/p&gt;

&lt;p&gt;Luckily AVR-GCC is only the second highest level; at the top of the toolchain is the AVR Libc. This is the C library all AVR programs use. The library takes care of naming all the registers, supporting floating-point, adding helpful AVR-macros, and plenty more. The AVR Libc library can be included with:&lt;/p&gt;
&lt;figure&gt;

&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='cpp'&gt;&lt;span class='cp'&gt;#include &amp;lt;avr/io.h&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;/figure&gt;
&lt;p&gt;After writing C code that references the AVR Libc library, AVR-GCC compiles the code into individual assembly files, which the Assembler turns into object files (files in a format runnable by the AVR), the linker then combines the multiple object files into a single object file that, finally, is converted into a HEX file. Whoa, let&amp;#8217;s take a breather.&lt;/p&gt;

&lt;p&gt;&amp;#8230;and breather over. The resulting file after this compile process is an &lt;a href='https://secure.wikimedia.org/wikipedia/en/wiki/Intel_HEX'&gt;Intel formatted HEX file&lt;/a&gt;. This HEX file is the executable instructions and, once uploaded to the AVR, will be processed as is.&lt;/p&gt;

&lt;p&gt;How do we upload the HEX file to the AVR? An 8-bit AVR by itself cannot communicate over the USB protocol. An &lt;a href='http://www.ladyada.net/learn/avr/programmers.html'&gt;In-System Programmer&lt;/a&gt; connects from the computer (via USB or Serial port) to the AVR. When starting the upload, the programmer activates the AVR&amp;#8217;s reset pin, which puts the microcontroller in Programming mode. Once in Programming mode, the AVR can accept the instructions from the programmer, which allows for writing the file to the AVR&amp;#8217;s flash memory.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2011/10/in-system-programmer.png' alt='The AVRISP mkII In-System Programmer from Atmel' /&gt;
  &lt;figcaption&gt;
    In-System Programmer for the AVR
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The final piece of the AVR toolchain is &lt;a href='http://www.ladyada.net/learn/avr/avrdude.html'&gt;AVRDUDE&lt;/a&gt;, a command line utility that sends the compiled code to the In-System Programmer or Development board for execution.&lt;/p&gt;

&lt;h3 id='the_arduino'&gt;The Arduino&lt;/h3&gt;

&lt;p&gt;The AVR has up to 2KB of flash memory dedicated to a bootloader, a special region of memory that always executes after a reset. A bootloader combined with the AVR&amp;#8217;s ability to write to its own flash memory allows the AVR to program itself over serial. Yep, a bootloader negates the need for the In-System Programmers and Development boards, requiring only a simple serial connection to the computer to program it. The bootloader can perform this serial programming by listening to the Tx/Rx (transmit and receive) lines on the AVR and write the instructions it receives to memory.&lt;/p&gt;

&lt;p&gt;The Arduino comes with such a bootloader burned onto the AVR chip. See, even though a bootloader allows for programming via a serial connection, the bootloader itself needs to be programmed into the board initially using an In-System Programmer.&lt;/p&gt;

&lt;p&gt;While any serial connection should work with the AVR chip and the bootloader, most Arduinos contain a USB interface. USB&amp;#8217;s protocol is different than the simple serial protocol the AVR expects. Instead of doing the conversion on the AVR, a separate chip converts from USB to serial. On boards like the Duemilanove and earlier, this was an FTDI chip. On boards starting with the Uno, an Atmega8U2 is used to convert USB to serial. This 8U2 is more capable than the FTDI chip, allowing for the Arduino to broadcast itself as other devices, like a USB keyboard.&lt;/p&gt;

&lt;h3 id='the_optional_arduino_ide'&gt;The (optional!) Arduino IDE&lt;/h3&gt;

&lt;p&gt;The Arduino IDE actually uses the same AVR toolchain described earlier. The IDE hides the complexity and presents a simple interface to the user.&lt;/p&gt;

&lt;p&gt;But guess what? Any plain old text editor or IDE can be used to program the Arduino. Since the brain of the Arduino is simply the AVR chip with a booatloader, the exact same toolchain described in the AVR section can be used. AVRDUDE even comes with presets for dealing with the Arduino bootloader.&lt;/p&gt;

&lt;p&gt;In addition to wrapping up the toolcahin, the Arduino IDE also includes useful C libraries that build on top of AVR Libc. The libraries included with each program can be found in the &lt;a href='https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino'&gt;hardware/cores/arduino directory&lt;/a&gt; of the IDE.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Getting started with the TurtleBot</title>
   <link href="http://alexanderrobotics.com/blog/2011/08/getting-started-with-turtlebot"/>
   <updated>2011-08-21T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2011/08/getting-started-with-turtlebot</id>
   <content type="html">&lt;p&gt;My &lt;a href='http://www.turtlebot.com/'&gt;TurtleBot&lt;/a&gt; arrived! I pre-ordered the robot from &lt;a href='http://clearpathrobotics.com/turtlebot'&gt;Clearpath Robotics&lt;/a&gt; in June and their robotsmiths sent it out last week. I&amp;#8217;m ecstatic.&lt;/p&gt;

&lt;h3 id='wait_whats_a_turtlebot'&gt;Wait, what&amp;#8217;s a TurtleBot?&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2011/08/turtlebot.jpg' alt='Fully assembled TurtleBot.' /&gt;
&lt;/figure&gt;
&lt;p&gt;The TurtleBot is a robot consisting of an iRobot Create (a Roomba, without the vacuum), a Kinect, a gyro sensor, and a netbook computer.&lt;/p&gt;

&lt;p&gt;The TurtleBot represents the most advanced and complete robot platform to reach the thousand-dollar price point yet. While all the components of the TurtleBot have been available for almost a year, the TurtleBot platform brings everything together in one standard package.&lt;/p&gt;

&lt;p&gt;The &lt;a href='http://willowgarage.com'&gt;creators of the TurtleBot&lt;/a&gt; are also the maintainers of the &lt;a href='http://ros.org'&gt;Robot Operating System&lt;/a&gt; (ROS), which the TurtleBot runs. ROS is a popular, extensible collection of libraries and tools for robotics. The beauty of ROS is anyone can contribute a package for it. Need the ability to interpret Kinect sensor data? There&amp;#8217;s a package for that. Looking for an algorithm to intelligently navigate a room? Yep, there&amp;#8217;s a package for that.&lt;/p&gt;

&lt;h3 id='the_turtlebot_arrived_now_what'&gt;The TurtleBot arrived, now what?&lt;/h3&gt;

&lt;h4 id='assembling'&gt;Assembling&lt;/h4&gt;

&lt;p&gt;I&amp;#8217;m going to assume the TurtleBot arrived fully assembled with ROS installed. If a TurtleBot kit was ordered instead, the &lt;a href='http://www.turtlebot.com/documentation.html'&gt;documentation&lt;/a&gt; includes detailed instructions on assembling and the &lt;a href='http://www.ros.org/wiki/turtlebot'&gt;ROS TurtleBot page&lt;/a&gt; contains TurtleBot-specific ROS installation.&lt;/p&gt;

&lt;p&gt;However, even an assembled TurtleBot requires a few extra build instructions before beginning.&lt;/p&gt;

&lt;p&gt;First, the &lt;a href='http://store.iheartengineering.com/TurtleBot-Kit-Power-Sensor-Board/dp/B005CDNI9U'&gt;gyro sensor&lt;/a&gt; must be connected to the Create, as pictured. The gyro sensor aids in providing better odometry to the robot. In other words, the sensor provides more accurate sense of direction and speed.&lt;/p&gt;

&lt;p&gt;USB cannot supply the 12V the Kinect requires. The TurtleBot includes an adapter cable that splits the Kinect cable into a USB adapter and a power adapter. The power adapter connects to the gyro sensor and draws its power from the Create.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2011/08/turtlebot-power-adapter-with-kinect-cable.jpg' alt='The power adapter and gyro sensor board connected to the iRobot Create
    with Kinect power cable inserted.' /&gt;
  &lt;figcaption&gt;
    Gyro sensor/Power adapter. Black cable is the Kinect power cable.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Finally, while tempting to leave the netbook open on top of the robot, be sure to secure it! The TurtleBot can jitter when being teleoperated, which will cause the laptop to fall off the top. Secure the netbook to the top (bungee cords? velcro? I&amp;#8217;m open to suggestions) or leave the computer snug in the bottom deck.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2011/08/turtlebot-with-laptop-in-bottom-deck.jpg' alt='The TurtleBot with the laptop secure in the bottom deck.' /&gt;
  &lt;figcaption&gt;
    Netbook snug in bottom deck.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h4 id='network_configuration'&gt;Network Configuration&lt;/h4&gt;

&lt;p&gt;When logging in to the TurtleBot netbook the TurtleBot stack will start up in the background. The network will need to be configured the first time logging into the laptop as most interaction with the robot will happen over SSH from the workstation.&lt;/p&gt;

&lt;p&gt;Before continuing any further, &lt;a href='http://www.iheartrobotics.com/2011/01/please-secure-your-robot-part-2-of-5.html'&gt;&lt;strong&gt;change the default passwords&lt;/strong&gt;&lt;/a&gt;. Seriously, someone will SSH into the robot at the least opportune time. Treat the robot like any server and secure it.&lt;/p&gt;

&lt;p&gt;The following instructions will change the password for the turtlebot user and root user.&lt;/p&gt;
&lt;figure&gt;

&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='c'&gt;# Changes the password for the user turtlebot&lt;/span&gt;
passwd
&lt;span class='c'&gt;# Changes the password for root&lt;/span&gt;
sudo passwd
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;/figure&gt;
&lt;p&gt;To test the network configuration, SSH from the workstation into the netbook. ROS does not have to be installed on the workstation for SSH-only sessions.&lt;/p&gt;
&lt;figure&gt;

&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='c'&gt;# SSH into the TurtleBot&lt;/span&gt;
&lt;span class='c'&gt;# The IP address of the TurtleBot can be found using ifconfig&lt;/span&gt;
ssh turtlebot@10.0.1.18
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;/figure&gt;
&lt;h4 id='run_an_app'&gt;Run an &amp;#8220;app&amp;#8221;&lt;/h4&gt;

&lt;p&gt;Okay, the boring stuff is over, time to get the TurtleBot to do something. A simple app to start with is the Keyboard Teleoperation app, which allows the TurtleBot to be controlled by the workstation&amp;#8217;s keyboard. To begin, run the keyboard_teleop.launch in the SSH shell:&lt;/p&gt;
&lt;figure&gt;

&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;roslaunch turtlebot_teleop keyboard_teleop.launch
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;/figure&gt;
&lt;p&gt;Now, pressing the arrow keys from the workstation should move the robot forward or backward, or turn left or right.&lt;/p&gt;

&lt;p&gt;What does roslaunch do? Well, ROS is based on the idea of connecting separate, specialized programs called nodes. One node can process data from a Kinect while another node computes a navigation route. A launch file is an XML file describing which nodes to run. &lt;a href='http://www.ros.org/wiki/roslaunch'&gt;Roslaunch&lt;/a&gt; reads in the launch file and executes the nodes with any specified parameters.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href='https://kforge.ros.org/turtlebot/trac/browser/turtlebot_apps/turtlebot_teleop/keyboard_teleop.launch'&gt;keyboard_teleop.launch&lt;/a&gt; sets the velocity of the TurtleBot and listens to the keyboard for direction instructions (referenced as &lt;code&gt;cmd_vel&lt;/code&gt; in the file).&lt;/p&gt;

&lt;p&gt;Most of the TurtleBot &amp;#8220;apps&amp;#8221; are launch files and their associated nodes. Running these apps is a matter of running roslaunch on the launch file.&lt;/p&gt;

&lt;h3 id='where_to_go_from_here'&gt;Where to go from here?&lt;/h3&gt;

&lt;p&gt;There are more advanced apps ready to play with on the TurtleBot. Following the &lt;a href='http://www.ros.org/wiki/turtlebot/Tutorials/Networking%20Setup'&gt;Network Setup&lt;/a&gt; and &lt;a href='http://www.ros.org/wiki/turtlebot_bringup/Tutorials/TurtleBot%20Bringup'&gt;Bring Up&lt;/a&gt; tutorials will be necessary before running the advanced apps.&lt;/p&gt;

&lt;p&gt;The &lt;a href='http://www.ros.org/wiki/turtlebot_navigation/Tutorials/Build%20a%20map%20with%20SLAM'&gt;gmapping app&lt;/a&gt; creates a 3D map of the robot&amp;#8217;s environment. It may look simple from videos, but actually navigating the TurtleBot around and seeing it update the map in real-time is nerdtastic. The Gmapping app also serves as an excellent introduction to the &lt;a href='http://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping'&gt;SLAM&lt;/a&gt; technique, which helps a robot understand its surroundings.&lt;/p&gt;

&lt;p&gt;A list of apps configured for the TurtleBot are available on the &lt;a href='http://www.ros.org/wiki/turtlebot'&gt;TurtleBot wiki&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Digging deeper into the robot&amp;#8217;s capabilities will involve digging into the Robot Operating System. Luckily, ROS has exceptional documentation, including a &lt;a href='http://www.ros.org/wiki/ROS/Introduction'&gt;start guide&lt;/a&gt; and &lt;a href='http://www.ros.org/wiki/ROS/Tutorials'&gt;tutorials covering developing for ROS&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='what_if_i_have_a_question'&gt;What if I have a question?&lt;/h3&gt;

&lt;p&gt;The first place I recommend for support is the &lt;a href='http://www.ros.org/wiki/turtlebot'&gt;TurtleBot wiki pages&lt;/a&gt; on ros.org. The answer may be a couple links in, or simply be a matter of re-reading the instructions (which has helped me a few times already).&lt;/p&gt;

&lt;p&gt;If you need to ask a question, &lt;a href='http://answers.ros.org'&gt;answers.ros.org&lt;/a&gt; is a Stack Overflow-like Q&amp;amp;A site with many knowledgeable and friendly roboticists.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Open Hardware Summit 2010</title>
   <link href="http://alexanderrobotics.com/blog/2010/10/open-hardware-summit"/>
   <updated>2010-10-03T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/10/open-hardware-summit</id>
   <content type="html">&lt;figure&gt;
  &lt;img src='/blog/images/2010/10/open-hardware-summit-organizers.jpg' alt='Organizers of the Open Hardware Summit.' /&gt;
  &lt;figcaption&gt;
    Organizers of the Open Hardware Summit. Images by &lt;a href='http://www.flickr.com/photos/open_hardware_summit/'&gt;Bill Ward&lt;/a&gt;.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;It was a big week for the open source hardware movement, starting with the first conference dedicated to open hardware: the &lt;a href='http://www.openhardwaresummit.org/'&gt;Open Hardware Summit&lt;/a&gt;. Yep, a conference just for open hardware. And it sold out. Big name presenters in the rather nascent field include Limor Fried of &lt;a href='http://www.adafruit.com'&gt;Adafruit&lt;/a&gt;, Chris Anderson of &lt;a href='http://diydrones.com/'&gt;DIYdrones&lt;/a&gt;, Massimo Banzi of &lt;a href='http://arduino.cc/'&gt;Arduino&lt;/a&gt;, and Bunnie Huang of &lt;a href='http://www.chumby.com/'&gt;Chumby&lt;/a&gt;. The OHS was followed by the New York Maker Faire.&lt;/p&gt;

&lt;p&gt;While plenty happened, two big announcements were new Arduino boards and an updated draft for the Open Source Hardware (OSHW) Definition.&lt;/p&gt;

&lt;h3 id='new_arduino_boards'&gt;New Arduino boards&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/10/arduino-uno.jpg' alt='Arduino Uno board.' /&gt;
  &lt;figcaption&gt;
    Arduino Uno
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Massimo and the rest of the Arduino team announced the successor to the &lt;a href='http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove'&gt;Duemilanove&lt;/a&gt;: the &lt;a href='http://arduino.cc/en/Main/ArduinoBoardUno'&gt;Uno&lt;/a&gt;. The Uno and the more recent Duemilanoves share the same ATmega328 chip with 32 KB of flash memory (for storing programs), 2 KB of SRAM (for storing variables), and 1 KB of EEPROM (for storing &amp;#8220;long-term&amp;#8221; data). The Uno is also FCC certified, opening the door for using the Arduino in new fields with regulation requirements.&lt;/p&gt;

&lt;p&gt;The biggest change is a new USB-to-Serial chip. When you plug an Arduino into the computer using a USB cable, the computer sees the Arduino as a serial device. This allows sending commands and getting feedback between the computer and the Arduino. The previous chip &amp;#8212; the FTDI FT232RL &amp;#8212; has been replaced with the Atmel Atmega8u2 chip. Before, the computer only saw the Arduino as a serial device, with the Atmega8u2 the computer can see the Arduino as a keyboard, or a mouse, or whatever the developer decides.&lt;/p&gt;

&lt;p&gt;The flagship Arduino &amp;#8212; the Mega &amp;#8212; was also updated to the &lt;a href='http://arduino.cc/en/Main/ArduinoBoardMega2560'&gt;Mega 2560&lt;/a&gt;. The ATmega2560 chip used in the Meaga 2560 has 256 KB of flash memory, twice that of the Mega while keeping the same size of SRAM and EEPROM. The Mega 2560 also uses the Atmega8u2 USB-to-Serial chip found in the Uno.&lt;/p&gt;

&lt;p&gt;Though capable of speeds up to 20 Mhz, both the Uno and the Mega 2560 remain calibrated at the previous speed of 16 Mhz.&lt;/p&gt;

&lt;h3 id='updated_open_source_hardware_draft_definition'&gt;Updated Open Source Hardware Draft Definition&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/10/open-hardware-summit-gnu.jpg' alt='Participant discussing the Open Source Hardware Definition' /&gt;
  &lt;figcaption&gt;
    Discussing the Open Source Hardware Definition.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Back in July, several news outlets &lt;a href='http://www.engadget.com/2010/07/14/open-source-hardware-community-finally-gets-its-constitution/'&gt;reported&lt;/a&gt; OSHW ratified a constitution. What was agreed upon was version &lt;a href='http://freedomdefined.org/OSHW'&gt;0.3&lt;/a&gt; of the definition of Open Source Hardware by several players in the community. While &lt;em&gt;ratified&lt;/em&gt;, the definition/license is still evolving, as &lt;a href='http://www.bunniestudios.com/blog/?p=1224'&gt;Bunnie Huang&lt;/a&gt; described in his post.&lt;/p&gt;

&lt;p&gt;Version &lt;a href='http://freedomdefined.org/OSHW_draft'&gt;0.4&lt;/a&gt; came out during the week with some minor changes and clarifications. These changes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding a Scope criteria specifying what part of the hardware falls under the license&lt;/li&gt;

&lt;li&gt;Preferring native file formats as documentation, for example, the CAD files over a PNG&lt;/li&gt;

&lt;li&gt;Requiring sufficient documentation on how to interface with the hardware in software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Honestly, when I started this post, I was expecting more changes between the drafts. Diffing the two definitions showed otherwise. Oh well, that&amp;#8217;s a good sign there&amp;#8217;s still a general consensus.&lt;/p&gt;

&lt;h3 id='to_the_future'&gt;To the future&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/10/open-hardware-summit-thank-you-banner.jpg' alt='OHS Thank You banner' /&gt;
&lt;/figure&gt;
&lt;p&gt;The Open Hardware Summit was the culmination of the growing OSHW movement. Yet the summit is just the beginning. There&amp;#8217;s a strong community of hardware hackers, not only online, but in your city. &lt;a href='http://hackerspaces.org/wiki/'&gt;Hackerspaces&lt;/a&gt; are forming, meetups are starting, and the local community is growing. It&amp;#8217;s an exciting time to get started!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Voltage Regulators</title>
   <link href="http://alexanderrobotics.com/blog/2010/09/voltage-regulators"/>
   <updated>2010-09-10T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/09/voltage-regulators</id>
   <content type="html">&lt;p&gt;An issue quickly became apparent after setting up the &lt;a href='http://alexanderrobotics.com/blog/2010/08/idea-to-prototype-brains/'&gt;Arduino and motor driver&lt;/a&gt;: the robot could not roam farther than the length of the USB cable powering the Arduino. A longer AC-to-DC power adapter cable would extend the range, but still keep the robot tethered. To truly roam free, the Arduino needed a battery supply.&lt;/p&gt;

&lt;p&gt;The Arduino features a 5V on-board voltage regulator. A voltage regulator takes a higher voltage power source and regulates the power to its specified voltage. The remaining voltage is dissipated as heat.&lt;/p&gt;

&lt;p&gt;While the Arduino&amp;#8217;s ideal operating voltage is 5V, the &lt;a href='http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove'&gt;recommended external input voltage&lt;/a&gt; is between 7 and 12V. The higher voltage required compensates for the dropout voltage - the smallest voltage difference between the input power supply and the rated output of the voltage regulator. A dropout voltage can range from 100mV for a low-dropout regulator to 2V and more for regulators like the &lt;a href='http://en.wikipedia.org/wiki/78xx'&gt;common 78xx series&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The robot already has a 12V battery pack for the motors. Realistically, I could plug that unregulated power into the Arduino&amp;#8217;s Vin and Gnd inputs and be okay because of the Arduino&amp;#8217;s built-in voltage regulator. But a fresh charge of the battery actually produces around 14V &amp;#8212; still acceptable, but that would generate more heat on the Arduino&amp;#8217;s board than I am comfortable with. Enter the &lt;a href='http://www.mouser.com/Search/Refine.aspx?Keyword=L7809'&gt;7809&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The 7809 is part of the 78xx series of linear regulators. The 7805 has an output voltage of 5V, the 7809 has an output voltage of 9V, and so forth. Connecting a 7809 between the unregulated 12V power supply and the Arduino moves the power regulation task away from the microcontroller and onto its own circuit. This modular approach allows for easier improvements to the power supply circuit, like a more efficient voltage regulator or reverse-battery protection.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/09/arduino-voltage-regulator-and-motor-driver.png'&gt;
    &lt;img src='/blog/images/2010/09/arduino-voltage-regulator-and-motor-driver-small.png' alt='Fritzing schematic of Arduino and motor driver, highlighting the voltage regulator' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Arduino and Motor Driver with Voltage Regulator
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The 7809 is rather straightforward to hook up, consisting of a positive input terminal for the unregulated power supply, a ground terminal, and an output terminal that outputs 9V to the Arduino&amp;#8217;s Vin pin. A 100uF capacitor was added between the input terminal and ground and a 10uF capacitor was added between the output terminal and the Arduino. Capacitors act as mini-power supplies, smoothing current and providing quicker discharges when the connected circuit needs power faster than the battery can supply.&lt;/p&gt;

&lt;h3 id='read_the_specifications'&gt;Read the specifications&lt;/h3&gt;

&lt;p&gt;I have made &lt;em&gt;plenty&lt;/em&gt; of mistakes while learning robotics. And will continue to do so. Before writing this post, I actually had a 7805 linear regulator between the unregulated power supply and the Arduino. Even though I knew about the dropout voltages, I still thought that since the Arduino operates at 5V, I should supply 5V. The &lt;a href='http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove'&gt;specifications&lt;/a&gt; clearly state a recommended input voltage of 7 to 12V. While the robot ran okay with the 7805 now, I could have had a tough time debugging an incorrect voltage from the Arduino later.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>From Idea to Prototype: Brains</title>
   <link href="http://alexanderrobotics.com/blog/2010/08/idea-to-prototype-brains"/>
   <updated>2010-08-24T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/08/idea-to-prototype-brains</id>
   <content type="html">&lt;p&gt;The machine has a &lt;a href='http://alexanderrobotics.com/blog/2010/06/idea-to-prototype-chassis/'&gt;chassis&lt;/a&gt; and &lt;a href='http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-motor-selection/'&gt;motors&lt;/a&gt; now, but still remains the Scarecrow of robots. There are two directions to take when giving a robot a brain: analog circuits or a microcontroller. &lt;a href='http://en.wikipedia.org/wiki/BEAM_robotics'&gt;BEAM robotics&lt;/a&gt; is the best example of analog circuits for logic, using transistors and comparators to determine the robot&amp;#8217;s behavior. The schematic is the program. A microcontroller consists of a processor, input and output pins, voltage regulators, and some method to connect it to a computer for programming. The right microcontroller depends on your price and performance needs.&lt;/p&gt;

&lt;p&gt;I went with an &lt;a href='http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove'&gt;Arduino Duemillanove&lt;/a&gt; (&lt;a href='http://arduino.cc/en/uploads/Main/Arduino_Duemilanove.mp3'&gt;pronunciation&lt;/a&gt;) microcontroller because at $30 it&amp;#8217;s affordable and offers enough performance. And to get the &lt;a href='http://xkcd.com/730/'&gt;blog cred&lt;/a&gt;. I bought the Arduino from &lt;a href='http://www.adafruit.com/index.php?main_page=product_info&amp;amp;products_id=68'&gt;Adafruit.com&lt;/a&gt;. I like what Lady Ada (Limor Fried) is doing for the Open Source Hardware movement and am happy to support the business.&lt;/p&gt;

&lt;p&gt;The Arduino&amp;#8217;s purpose in this iteration is simply to tell the two motors which direction to turn. Because an Arduino cannot provide the necessary power for &lt;a href='http://www.pololu.com/catalog/product/1103'&gt;these 12V motors&lt;/a&gt;, it controls a motor driver, which supplies the higher power.&lt;/p&gt;

&lt;p&gt;A basic motor driver consist of an &lt;a href='http://alexanderrobotics.com/blog/2010/06/visualizing-h-bridges/'&gt;H-bridge&lt;/a&gt; and some supporting capacitors and diodes to help smooth the current. The SN754410 is a quad half H-bridge. If an H-bridge can control a single motor, the quad half H-bridge can power two motors (4 (quad) * .5 (half) * 1 = 2). The motor driver in this robot uses the SN754410 because it&amp;#8217;s a popular chip with good documentation, can drive up to 36V at 1A continuous current, and is cheap at around $2 per chip.&lt;/p&gt;

&lt;h3 id='hardware'&gt;Hardware&lt;/h3&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/08/arduino-and-motor-driver.png'&gt;
    &lt;img src='/blog/images/2010/08/arduino-and-motor-driver-small.png' alt='Fritzing schematic of Arduino and Motor Driver' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Arduino and Motor Driver
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The image of a completed motor driver connected to an Arduino may seem daunting. Let&amp;#8217;s break it down into easier-to-digest chunks.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/SN754410-datasheet.png' alt='Diagram of the SN754410 motor driver.' /&gt;
  &lt;figcaption&gt;
    SN754410
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The core component in this motor driver is Texas Instrument&amp;#8217;s SN754410. The &lt;a href='http://www.ti.com/lit/gpn/sn754410'&gt;datasheet&lt;/a&gt; tells us what each pin on the chip is for, what the voltage requirements of that pin are, and so forth. The datasheet is &lt;em&gt;the&lt;/em&gt; reference when building a circuit.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/SN754410-unregulated-power-supply.png' alt='Fritzing schematic of motor driver with an unregulated power supply.' /&gt;
  &lt;figcaption&gt;
    Unregulated Power Supply
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The motor driver uses a 12V unregulated power supply. Regulated power is a clean, steady voltage, usually from a component known as a Voltage Regulator. Unregulated power is the raw output from the power supply. Motors are thirsty beasts and need access to the raw power, which is why the 12V battery connects directly into the SN754410&amp;#8217;s supply voltage (Vcc).&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/SN754410-enable-inputs.png' alt='Fritzing schematic showing wiring to enable inputs on the motor
    driver.' /&gt;
  &lt;figcaption&gt;
    Enable Inputs
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The Arduino provides a constant 5V supply to three inputs on the SN754410. The top right input of the SN754410 (pin 16) supplies the power for the logic circuitry on the chip. The SN754410 avoids the noisy, unregulated supply for the more precise logic functionality.&lt;/p&gt;

&lt;p&gt;The bottom right input (pin 9) enables the right motor, and the top left input (pin 1) enables the left motor. The two enable inputs are always set to High (5V) so, you guessed it, the two motors will always be enabled. To be clear here, &lt;em&gt;enabled&lt;/em&gt; does not mean the motors will be on; it means they are allowed to turn on.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/arduino-pwm-pins-to-SN754410.png' alt='Fritzing schematic showing Arduino PWM pins connecting to the SN754410.' /&gt;
  &lt;figcaption&gt;
    Arduino PWM pins to SN754410
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The Arduino uses two pins for each motor to control that motor&amp;#8217;s direction. The &lt;a href='http://alexanderrobotics.com/blog/2010/06/visualizing-h-bridges/'&gt;H-Bridge post&lt;/a&gt; brings some insight into why; essentially, one pin will be Low and one will be High for turning clockwise. To switch directions, simply switch the pins&amp;#8217; output voltage. To stop the motor (a coast stop, not an electronic brake), both pins should be set to Low.&lt;/p&gt;

&lt;p&gt;When I use Low or High, I&amp;#8217;m usually referencing Arduino&amp;#8217;s &lt;a href='http://www.arduino.cc/en/Reference/DigitalWrite'&gt;digitalWrite function&lt;/a&gt;, which can write a 0V (Low) or 5V (High). It&amp;#8217;s binary.&lt;/p&gt;

&lt;p&gt;A quick note here: When using a function like digitalWrite or analogWrite, that pin will output the selected value until told otherwise. In other words, when you set pin 5 to Low and pin 6 to High, the motor will spin until you change the values of pin 5 and 6.&lt;/p&gt;

&lt;p&gt;Now what if we want more control over speed, rather than Off and Fast? Enter &lt;a href='http://www.arduino.cc/en/Tutorial/PWM'&gt;Pulse Width Modulation (PWM)&lt;/a&gt;. PWM still sends a High voltage through its pin, but in configurable bursts known as duty cycles. Calling &lt;a href='http://arduino.cc/en/Reference/AnalogWrite'&gt;analogWrite&lt;/a&gt; with a scale of 0&amp;#8211;255 sets the PWM duty cycle. For example, analogWrite(pin, 255) is equivalent to digitalWrite(pin, High) and analogWrite(pin, 127) is about half the speed of the digitalWrite with High.&lt;/p&gt;

&lt;p&gt;Only some pins on the Arduino support PWM; the pins used in this layout (5, 6, 9, 10) all do. A pin that supports PWM can be used with analogWrite or digitalWrite. Also &amp;#8212; a point that confused me at first &amp;#8212; since only one pin per motor is set to High or whatever PWM value, the other pin is still set to Low or 0 if using digitalWrite or analogWrite respectively.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/08/SN754410-to-motors.png'&gt;
    &lt;img src='/blog/images/2010/08/SN754410-to-motors-small.png' alt='Fritzing schematic of SN754410 output to motors' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    SN754410 output to motors
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;For the final hardware chunk, let&amp;#8217;s look at how the SN754410 powers the motor. SN754410&amp;#8217;s outputs 3 and 6 power the left motor, and outputs 11 and 14 power the right motor. You should be okay connecting these outputs directly to the motor leads. Still, motors are noisy and thirsty, so let&amp;#8217;s alleviate these issues some.&lt;/p&gt;

&lt;p&gt;A 0.1 μF capacitor sits between ground and each motor terminal. The capacitor serves two purposes: smooth the voltage to the motor and provide quick power when the battery can&amp;#8217;t catch up (usually happens when the motor starts).&lt;/p&gt;

&lt;p&gt;Another simple task to reduce motor noise is twist the wires connecting to the motor leads. Twisting &lt;a href='http://www.stefanv.com/rcstuff/qf200406.html'&gt;reduces the &amp;#8220;electromagnetic radiation&amp;#8221; interference&lt;/a&gt; produced from the motor.&lt;/p&gt;

&lt;h3 id='software'&gt;Software&lt;/h3&gt;

&lt;p&gt;A brief history of the Arduino is in order to answer a simple question: What language do you program an Arduino with?&lt;/p&gt;

&lt;p&gt;&lt;a href='http://processing.org/'&gt;Processing&lt;/a&gt; is an open source Java-based language with its own IDE (a programming environment). Processing was designed as a language for non-programmers to pick up. It hides a lot of the boilerplate code from the programmer.&lt;/p&gt;

&lt;p&gt;The Wiring project came along as an affordable development board (sound familiar?). Wiring used the Processing IDE and a simplified C/C++ language for programming the board, which was based on an Atmel AVR chip.&lt;/p&gt;

&lt;p&gt;The Arduino was originally derived from the Wiring project, using the Processing IDE and Wiring language. The original Arduino used a cheaper Atmel AVR chip than the wiring board, the ATmega 8.&lt;/p&gt;

&lt;p&gt;Okay, to answer the question: The Arduino is programmed with the Wiring language, a language similar to C and C++ with some extra functionality for dealing with hardware and extras like Libraries. The IDE used to write the code and upload it to the Arduino is based on Processing. Phew. Oh, and an Arduino program is called a &amp;#8220;sketch.&amp;#8221;&lt;/p&gt;

&lt;p&gt;The sketch below moves the robot forward for 10 seconds, then backwards, turns left, turns right, and repeats. The code uses Pulse Width Modulation when controlling the motors.&lt;/p&gt;
&lt;figure&gt;

&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='cpp'&gt;&lt;span class='c1'&gt;// Sets the Left motor to pins 5 and 6&lt;/span&gt;
&lt;span class='kt'&gt;int&lt;/span&gt; &lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='mi'&gt;6&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;5&lt;/span&gt;&lt;span class='p'&gt;};&lt;/span&gt;
&lt;span class='c1'&gt;// Sets the Right motor to pins 9 and 10&lt;/span&gt;
&lt;span class='kt'&gt;int&lt;/span&gt; &lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='mi'&gt;10&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='mi'&gt;9&lt;/span&gt;&lt;span class='p'&gt;};&lt;/span&gt;

&lt;span class='c1'&gt;// Run when the Arduino starts up or is reset.&lt;/span&gt;
&lt;span class='c1'&gt;// Configures initial values for the first run.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;setup&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='c1'&gt;// Sets up Serial communication with the computer.&lt;/span&gt;
  &lt;span class='c1'&gt;// Not used in this sketch, but useful when printing&lt;/span&gt;
  &lt;span class='c1'&gt;// to the computer screen when debugging.&lt;/span&gt;
  &lt;span class='n'&gt;Serial&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;begin&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;9600&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  
  &lt;span class='c1'&gt;// Sets the Arduino&amp;#39;s pins to OUTPUT for controlling&lt;/span&gt;
  &lt;span class='c1'&gt;// the motor. A pin can be used to INPUT or OUTPUT.&lt;/span&gt;
  &lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kt'&gt;int&lt;/span&gt; &lt;span class='n'&gt;i&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='n'&gt;i&lt;/span&gt; &lt;span class='o'&gt;&amp;lt;&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt; &lt;span class='n'&gt;i&lt;/span&gt;&lt;span class='o'&gt;++&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;pinMode&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;i&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='n'&gt;OUTPUT&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;pinMode&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;i&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='n'&gt;OUTPUT&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='c1'&gt;// The loop runs as long as the Arduino is on.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;loop&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='c1'&gt;// Stops each motor&lt;/span&gt;
  &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='c1'&gt;// Delays in milliseconds, so 5000 = 5 seconds.&lt;/span&gt;
  &lt;span class='c1'&gt;// Added a delay here because I wanted a few seconds&lt;/span&gt;
  &lt;span class='c1'&gt;// for the robot to pause before each run.&lt;/span&gt;
  &lt;span class='n'&gt;delay&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;5000&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  
  &lt;span class='c1'&gt;// Drive forward for 10 seconds. drive_forward()&lt;/span&gt;
  &lt;span class='c1'&gt;// sets the motion of the motion of the motors, the&lt;/span&gt;
  &lt;span class='c1'&gt;// delay sets the duration of the movement.&lt;/span&gt;
  &lt;span class='n'&gt;drive_forward&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='n'&gt;delay&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;10000&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

  &lt;span class='c1'&gt;// Drives backwards for 10 seconds&lt;/span&gt;
  &lt;span class='n'&gt;drive_backward&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='n'&gt;delay&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;10000&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

  &lt;span class='c1'&gt;// Turns Left&lt;/span&gt;
  &lt;span class='n'&gt;turn_left&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='n'&gt;delay&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;5000&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

  &lt;span class='c1'&gt;// Turns right&lt;/span&gt;
  &lt;span class='n'&gt;turn_right&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='n'&gt;delay&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='mi'&gt;5000&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;


&lt;span class='c1'&gt;// Sets each motor lead to 0V, causing the motor to&lt;/span&gt;
&lt;span class='c1'&gt;// coast to a stop.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;motor_stop&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='c1'&gt;// Sets the motors to both go forward at a little&lt;/span&gt;
&lt;span class='c1'&gt;// over half speed. 150 is the Pulse Width Modulation&lt;/span&gt;
&lt;span class='c1'&gt;// setting, 255 is max, 0 is minimum.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;drive_forward&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
 
  &lt;span class='c1'&gt;// The digitalWrite equivalent&lt;/span&gt;
  &lt;span class='c1'&gt;//digitalWrite(motor_left[0], HIGH);&lt;/span&gt;
  &lt;span class='c1'&gt;//digitalWrite(motor_left[1], LOW);&lt;/span&gt;
  &lt;span class='c1'&gt;//digitalWrite(motor_right[0], HIGH);&lt;/span&gt;
  &lt;span class='c1'&gt;//digitalWrite(motor_right[1], LOW);  &lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='c1'&gt;// Sets the motors to drive backwards.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;drive_backward&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='c1'&gt;// Turns left by turning one motor clockwise and the&lt;/span&gt;
&lt;span class='c1'&gt;// other counterclockwise.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;turn_left&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='c1'&gt;// Turns Right by turning one motor counterclockwise&lt;/span&gt;
&lt;span class='c1'&gt;// and the other clockwise.&lt;/span&gt;
&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;turn_right&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_left&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='n'&gt;analogWrite&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;motor_right&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='p'&gt;],&lt;/span&gt; &lt;span class='mi'&gt;150&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;/figure&gt;
&lt;h3 id='downloads'&gt;Downloads&lt;/h3&gt;

&lt;p&gt;The &lt;a href='/blog/downloads/2010/08/arduino_and_motor_driver.fz'&gt;source&lt;/a&gt; for the Arduino to Motor Driver image requires the open source program &lt;a href='http://fritzing.org/'&gt;Fritzing&lt;/a&gt; to view. The Arduino source code is &lt;a href='/blog/downloads/2010/08/pwm_motors.pde'&gt;available&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;As this entire website is stored in source control &amp;#8212; including posts, images, and files &amp;#8212; you can check out &lt;a href='http://github.com/baalexander/alexanderrobotics.com'&gt;GitHub&lt;/a&gt; for updates and history on any these files.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Robot Books for Beginners</title>
   <link href="http://alexanderrobotics.com/blog/2010/08/beginner-robot-books"/>
   <updated>2010-08-09T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/08/beginner-robot-books</id>
   <content type="html">&lt;h3 id='robot_building_for_beginners'&gt;Robot Building For Beginners&lt;/h3&gt;

&lt;p&gt;My strategy for finding books is go to Amazon, search for a topic, then browse based on reviews and what others bought. This strategy lead me to the appropriately titled &lt;a href='http://www.amazon.com/Robot-Building-Beginners-Technology-Action/dp/1430227486/'&gt;&lt;em&gt;Robot Building for Beginners&lt;/em&gt;&lt;/a&gt;. If you&amp;#8217;re new to robotics or electronics in general, buy this book. Right now.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/robot-building-for-beginners.jpg' alt='Cover of Robot Building for Beginners' /&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href='http://www.robotroom.com/'&gt;David Cook&lt;/a&gt; walks through a variety of topics, from understanding tools like a multimeter to motors, wheels, and couplers. The book centers around building a basic line following robot, with each chapter covering a new feature of the robot. There is no mention of an Arduino &amp;#8212; or any microcontroller for that matter &amp;#8212; it&amp;#8217;s all transistors, resistors, and comparators.&lt;/p&gt;

&lt;p&gt;Cook&amp;#8217;s writing eases you into what can be intimidating topics, holding your hand along the way. You&amp;#8217;re left with a broad understanding of the mechanical and electrical components involved in a robot. Still, this is a beginner book and really serves to wet your appetite for more.&lt;/p&gt;

&lt;p&gt;Intermediate version: &lt;a href='http://www.amazon.com/intermediate-robot-building-technology-action/dp/1430227540/'&gt;&lt;em&gt;Intermediate Robot Building&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3 id='electronics_for_dummies'&gt;Electronics for Dummies&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/electronics-for-dummies.jpg' alt='Cover of Electronics for Dummies' /&gt;
&lt;/figure&gt;
&lt;p&gt;When I first started learning robotics, I went to &lt;a href='http://www.frys.com/'&gt;Fry&amp;#8217;s&lt;/a&gt; for a few capacitors and diodes to build a circuit I saw on Instructables. While scouring, I saw &lt;a href='http://www.amazon.com/Electronics-Dummies-Cathleen-Shamieh/dp/0470286970'&gt;&lt;em&gt;Electronics for Dummies&lt;/em&gt;&lt;/a&gt;. &amp;#8220;Ha, I am far too smart for this book,&amp;#8221; I said aloud, and then &amp;#8212; when nobody was looking &amp;#8212; I grabbed the book and ran to the checkout counter.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m glad I did.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re new to electronics, &lt;em&gt;Electronics for Dummies&lt;/em&gt; gives a good overview of why a component behaves a certain way. The book answers several questions like: How does a capacitor work? What happens when resistors are in parallel? What are the different types of semiconductors? And so forth.&lt;/p&gt;

&lt;p&gt;As &lt;em&gt;Electronics for Dummies&lt;/em&gt; covers the fundamentals well, I recommend it for anyone wanting a foundation for working with electronics. If you know how to calculate an RC time constant, a &amp;#8220;for Dummies&amp;#8221; book can probably be skipped. Also be warned, the book does not go into detail about using this electronics knowledge in creating your own circuits.&lt;/p&gt;

&lt;p&gt;Intermediate version: &lt;a href='http://www.amazon.com/Electronics-Self-Teaching-Guide-Teaching-Guides/dp/0470289619'&gt;&lt;em&gt;Electronics Self-Teaching Guide&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='practical_arduino_cool_projects_for_open_source_hardware'&gt;Practical Arduino: Cool Projects for Open Source Hardware&lt;/h3&gt;
&lt;figure&gt;
  &lt;img src='/blog/images/2010/08/practical-arduino.jpg' alt='Cover of Practical Arduino: Cool Projects for Open Source Hardware' /&gt;
&lt;/figure&gt;
&lt;p&gt;I discovered &lt;a href='http://www.amazon.com/Practical-Arduino-Projects-Hardware-Technology/dp/1430224770'&gt;&lt;em&gt;Practical Arduino: Cool Projects for Open Source Hardware&lt;/em&gt;&lt;/a&gt; when searching Amazon for, surprise surprise, &amp;#8220;Arduino.&amp;#8221; The top result is &lt;a href='http://www.amazon.com/Getting-Started-Arduino-Make-Projects/dp/0596155514'&gt;&lt;em&gt;Getting Started with Arduino&lt;/em&gt;&lt;/a&gt;, by one of the founders of the project. I had picked up &lt;em&gt;Getting Started with Arduino&lt;/em&gt; from the &lt;a href='http://makerfaire.com/'&gt;Maker Faire&lt;/a&gt; a couple years back and found it a good absolute beginners book, but left me wanting more.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Practical Arduino&lt;/em&gt; features 14 Arduino projects &amp;#8212; not a single one is a robot. While at first off put by this revelation, I came to appreciate the book more for focusing on everything else an Arduino can do.&lt;/p&gt;

&lt;p&gt;Projects include an RFID security system, a weather station, and even a device to monitor your car&amp;#8217;s on-board computer. Reading the book provides a strong insight into the Arduino and microcontrollers in general with topics like Interrupt Service Routine and Pulse Width Modulation. &lt;em&gt;Practical Arduino&lt;/em&gt; is similar to &lt;em&gt;Robot Building for Beginners&lt;/em&gt; in the way electronic components are explained (both are also Apress books). For example, when a setup requires an extra capacitor, the authors take the time to explain their motivations for doing so.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Visualizing H-bridges</title>
   <link href="http://alexanderrobotics.com/blog/2010/06/visualizing-h-bridges"/>
   <updated>2010-06-20T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/06/visualizing-h-bridges</id>
   <content type="html">&lt;h3 id='introduction'&gt;Introduction&lt;/h3&gt;

&lt;p&gt;While writing an upcoming post for the Idea to Prototype series covering &amp;#8220;Brains&amp;#8221;, it became clear a significant portion of the topic is the motor driver &amp;#8212; a circuit to control the movement of the robot&amp;#8217;s motors. The critical component of the motor driver is the H-bridge, enough so, I felt it deserves its own post.&lt;/p&gt;

&lt;p&gt;There are &lt;a href='http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/index.html'&gt;solid resources&lt;/a&gt; available on H-bridges already. The goal here is to cover the H-bridge from a high-level, to help visualize its purpose.&lt;/p&gt;

&lt;p&gt;A motor has two leads. Each lead has three possible states: connected to positive voltage, connected to ground, or open. The value of each lead not only controls the movement of the shaft clockwise or counterclockwise, but also allows for braking or coasting.&lt;/p&gt;
&lt;figure&gt;
  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Left Lead&lt;/th&gt;
        &lt;th&gt;Right Lead&lt;/th&gt;
        &lt;th&gt;Result&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Open&lt;/td&gt;
        &lt;td&gt;Open&lt;/td&gt;
        &lt;td&gt;Coast&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Positive&lt;/td&gt;
        &lt;td&gt;Positive&lt;/td&gt;
        &lt;td&gt;Brake&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Positive&lt;/td&gt;
        &lt;td&gt;Ground&lt;/td&gt;
        &lt;td&gt;Counterclockwise&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Ground&lt;/td&gt;
        &lt;td&gt;Ground&lt;/td&gt;
        &lt;td&gt;Brake&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Ground&lt;/td&gt;
        &lt;td&gt;Positive&lt;/td&gt;
        &lt;td&gt;Clockwise&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;figcaption&gt;
    H-Bridge lead connections and their affect on the motor.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The H-bridge circuit can connect each lead to ground or positive (and sometimes open). So what? A microcontroller can too.&lt;/p&gt;

&lt;p&gt;The big deal is that an H-bridge can connect a motor&amp;#8217;s leads to a higher voltage unregulated power, like 9, 12, and 24 volts. A microcontroller or logic chip may supply up to 5V, but many motors require 6V or more. A motor may also use 150 mA, 300 mA, on up &amp;#8212; a current microcontrollers cannot provide. When working with an H-bridge, a lower powered signal &amp;#8212; like the pins of a microcontroller &amp;#8212; configures how the H-bridge supplies the motor with the awesome power connected to it.&lt;/p&gt;

&lt;h3 id='circuit_scenarios'&gt;Circuit Scenarios&lt;/h3&gt;

&lt;p&gt;An H-bridge, in its most high level view, is four switches: two for each motor lead. One switch on each side connects to positive, the other switch on each side connects to ground.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/h-bridge-coast.png'&gt;
    &lt;img src='/blog/images/2010/06/h-bridge-coast.png' alt='H-bridge with all switches open for coasting.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Coasting
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;When all the switches are open, there is an open circuit and the motor is free to coast. Coasting is also called &amp;#8220;slow decay&amp;#8221; as the motor&amp;#8217;s energy is consumed slowly due to friction.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/h-bridge-counterclockwise.png'&gt;
    &lt;img src='/blog/images/2010/06/h-bridge-counterclockwise.png' alt='H-bridge with left switch to positive closed and right switch to
      ground closed, causing motor to sping counterclockwise.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Counterclockwise
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;When the left switch connected to positive is closed and the right switch to ground is closed, a closed circuit occurs and the motor spins counterclockwise.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/h-bridge-clockwise.png'&gt;
    &lt;img src='/blog/images/2010/06/h-bridge-clockwise.png' alt='H-bridge with left switch to ground closed and right switch to
      positive closed, causing motor to sping clockwise.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Clockwise
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;As expected, the motor spins clockwise when the switches are reversed.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/h-bridge-brake-low.png'&gt;
    &lt;img src='/blog/images/2010/06/h-bridge-brake-low.png' alt='H-bridge with left and right side connected to ground, causing the
      motor to brake.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Brake low
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;With both sides&amp;#8217; switches connected to ground, motor energy is quickly drained. Ground to ground and positive to positive creates what is called an &amp;#8220;electronic brake&amp;#8221; or &amp;#8220;fast decay&amp;#8221;. An electronic brake dissipates the energy from a motor quickly to help slow it down. It does not serve as a physical brake to the motor. Ground to ground is called &amp;#8220;braking low&amp;#8221; and positive to positive is called &amp;#8220;braking high.&amp;#8221;&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/h-bridge-short-circuit.png'&gt;
    &lt;img src='/blog/images/2010/06/h-bridge-short-circuit.png' alt='H-bridge with left side connected to positive and ground, causing a
      short circuit.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Short circuit
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The more observant readers may have noticed a possible predicament. What if the switch connected to positive and the switch connected ground are both closed on the same side? Exactly what you would expect to happen. The electricity travels the path of least resistance, and a motor is certainly more resistant than a wire, so a short circuit is formed. Many H-bridge implementations prevent the ability to close both positive and ground on the same side, and thus prevent the short circuits.&lt;/p&gt;

&lt;h3 id='chips'&gt;Chips&lt;/h3&gt;

&lt;p&gt;Two popular H-bridge chips (technically quad half H-Bridge chips) are the &lt;a href='http://www.sparkfun.com/commerce/product_info.php?products_id=315'&gt;SN754410&lt;/a&gt; and its predecessor, the L293D. The two chips are identical in pin layout, but the SN754410 is capable of 1A continuous output current at higher voltages. Plenty of resources are online for using the chips as part of a robot&amp;#8217;s motor driver, including my next post.&lt;/p&gt;

&lt;h3 id='further_reading'&gt;Further Reading&lt;/h3&gt;

&lt;p&gt;The objective here was a gentle introduction to H-bridges. The switches shown can be implemented using transistors (bipolar or MOSFET). When dealing with motors, a flyback diode for each transistor is a good idea to help control any voltage generated by the motor. In addition, the Driving Miss Motor and Driving Mister Motor chapters in the &lt;a href='http://www.amazon.com/Intermediate-Robot-Building-David-Cook/dp/1430227540'&gt;Intermediate Robot Building&lt;/a&gt; book provide an excellent overview of H-bridges and motor drivers.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>From Idea to Prototype: Chassis</title>
   <link href="http://alexanderrobotics.com/blog/2010/06/idea-to-prototype-chassis"/>
   <updated>2010-06-05T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/06/idea-to-prototype-chassis</id>
   <content type="html">&lt;h3 id='cad'&gt;CAD&lt;/h3&gt;

&lt;p&gt;While &lt;a href='http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-drive-train/'&gt;designing the drive train&lt;/a&gt;, I also started drafting the chassis in a CAD program. Using a 3D CAD tool helped determine the fit of each drive train component within the set boundaries of the chassis. I highly recommend taking the time to draw your robot in a CAD program before ordering parts. Pairing the v-belt for a pulley of the right diameter with the bore size to fit the bearings and shaft requires a precision computers are simply better at.&lt;/p&gt;

&lt;p&gt;I used &lt;a href='http://sketchup.google.com/'&gt;Google Sketchup&lt;/a&gt; for the CAD program. SketchUp is a free, entry level CAD program that runs on both Windows and Mac OS X. Of course I would like to use &lt;a href='http://www.solidworks.com/'&gt;Solidworks&lt;/a&gt; or &lt;a href='http://usa.autodesk.com/adsk/servlet/pc/index?siteID=123112&amp;amp;id=13717655'&gt;AutoDesk Inventor&lt;/a&gt;, but the cost is too high for a hobbyist. Plus, SketchUp meets all my needs at this stage.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/chassis_with_caster_wheels_iso.png'&gt;
    &lt;img src='/blog/images/2010/06/chassis_with_caster_wheels_iso_small.png' alt='CAD drawing of the chassis with two motorized wheels and two caster wheels.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    CAD drawing of the chassis with two motorized wheels and two caster wheels.
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id='build'&gt;Build&lt;/h3&gt;

&lt;p&gt;After I was happy with the design and ordered the parts for the drive train, I set out to create a physical chassis. For some, the steps may be obvious, but coming from a computer science background, I have found the transition from idea on paper to tangible object non-trivial.&lt;/p&gt;

&lt;p&gt;The overall layout was simple enough to make out of wood, but I wanted a more precise chassis. I needed the holes bored in the correct place and each component to line up. And really, a fabricated chassis would just look cooler. I decided on the routes of &lt;a href='http://computer.howstuffworks.com/stereolith.htm'&gt;3D printing&lt;/a&gt; or &lt;a href='http://en.wikipedia.org/wiki/Milling_machine'&gt;CNC milling&lt;/a&gt;. 3D printing essentially prints plastic along three axes. The cost of a low-end 3D printer has dropped significantly thanks to projects like &lt;a href='http://www.makerbot.com/'&gt;MakerBot&lt;/a&gt; and &lt;a href='http://reprap.org/'&gt;RepRap&lt;/a&gt;. Milling is a subtractive process, taking a block of plastic and cutting to form.&lt;/p&gt;

&lt;p&gt;Most companies that do stereolithography (3D printing) or milling require an STL file. An STL file represents the surfaces of the 3D drawing. SketchUp does not export to the STL format natively, but &lt;a href='http://www.cadspan.com/'&gt;CADspan&lt;/a&gt; has a free plugin to do just that. An excellent tutorial can be found &lt;a href='http://www.aec3dp.com/tutorial-convert-google-sketchup-file-solid-3d-printable-stl-cadspan-toolset'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I contacted a few rapid prototype companies in Austin for quotes on printing the chassis. I had no idea how much to expect. The first quote back was for a &amp;#8220;Stereolithography Apparatus Prototype&amp;#8221; and cost $1,989. &lt;strong&gt;Whoa.&lt;/strong&gt; Roughly $2,000 was far more than I expected to spend.&lt;/p&gt;

&lt;p&gt;Another response from a Mr. Allison at &lt;a href='http://www.atirapid.com'&gt;ATi&lt;/a&gt; recommended a local milling company to try. As milling carves from a solid block of plastic, it would be sturdier and the chassis design is simple enough for the operation. Hopeful now, I contacted the milling company and got a quote for $1,155 ($480.00 set-up + $675.00 per part). The contact explained the cost of the 3&amp;#8221; ABS plastic was $175.00 per sq.&lt;/p&gt;

&lt;p&gt;Needless to say, I had to reevaluate my options. With no access to a 3D printer like the RepRap (though a new &lt;a href='http://www.austinhackerspace.org/'&gt;Austin HackerSpace&lt;/a&gt; may change that soon) and professional services proving too expensive, I decided to go the cheapest, simplest route: wood. It&amp;#8217;s an initial prototype after all.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/original_wooden_chassis_prototype.jpg'&gt;
    &lt;img src='/blog/images/2010/06/original_wooden_chassis_prototype_small.jpg' alt='Basic wooden platform of the robot.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Basic wooden platform. 
  &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I know, the result is even simpler than the CAD drawings. Let&amp;#8217;s call it a prototype of the prototype. I wanted to move on to the brains of the robot instead of focusing too long on the drive train for this iteration of the prototype.&lt;/p&gt;

&lt;p&gt;For those curious, I attached the inline skate wheel to the motor hub by drilling the same plank of wood to both the wheel and the hub. It worked surprisingly well.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/06/motor_to_inline_skate_wheel_coupler.jpg'&gt;
    &lt;img src='/blog/images/2010/06/motor_to_inline_skate_wheel_coupler_small.jpg' alt='Motor hub to wheel coupling.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;
    Motor hub to wheel coupling. The job looks a bit messier in high resolution.
  &lt;/figcaption&gt;
&lt;/figure&gt;</content>
 </entry>
 
 <entry>
   <title>From Idea to Prototype: Drive Train</title>
   <link href="http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-drive-train"/>
   <updated>2010-05-31T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-drive-train</id>
   <content type="html">&lt;p&gt;After &lt;a href='http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-sketching/'&gt;sketching&lt;/a&gt; the robot and &lt;a href='http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-motor-selection/'&gt;selecting a motor&lt;/a&gt;, my next step was planning out how to connect the motors to the wheels for propulsion. In other words, figuring out the robot&amp;#8217;s drive train. The motor selection step and drive train design can be switched or worked in parallel.&lt;/p&gt;

&lt;h3 id='initial_design__and_failure'&gt;Initial design &amp;#8212; and failure&lt;/h3&gt;

&lt;p&gt;My original plans for the robot called for mounting a motor directly to each of the two back wheels and placing two caster wheels in the front. I crafted a rudimentary prototype by screwing a pneumatic model airplane wheel to a &lt;a href='http://www.pololu.com/catalog/product/1083'&gt;mounting hub&lt;/a&gt;, coupled to the motor shaft. I mounted the two motors to a frame of thin slabs of wood using Polulu&amp;#8217;s &lt;a href='http://www.pololu.com/catalog/product/1084'&gt;motor bracket&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='http://www.amazon.com/exec/obidos/ASIN/0071408509/aecnetwork'&gt;
    &lt;img src='/blog/images/2010/05/building_robot_drive_trains.jpg' alt='Building Robot Drive Trains book' /&gt;
  &lt;/a&gt;
&lt;/figure&gt;
&lt;p&gt;Around the time of building this prototype, the rather self-explanatorily titled book &amp;#8221;&lt;a href='http://www.amazon.com/exec/obidos/ASIN/0071408509/aecnetwork'&gt;Building Robot Drive Trains&lt;/a&gt;&amp;#8221; arrived at my doorstep. Early in the book, the flaws in coupling a wheel to a motor directly became obvious, too often invoking the &amp;#8220;Duh, what was I thinking?&amp;#8221; response. The biggest flaw in direct coupling is the robot&amp;#8217;s requirement to carry a payload around 14 kg. The &lt;a href='http://science.howstuffworks.com/bearing2.htm'&gt;radial load&lt;/a&gt; &amp;#8212; the perpendicular force on the motor&amp;#8217;s shaft &amp;#8212; would be too much if the shafts had to support the weight of the robot. A high radial load stresses the motor&amp;#8217;s bearing and wears down its life expectancy.&lt;/p&gt;

&lt;h3 id='decoupling'&gt;Decoupling&lt;/h3&gt;

&lt;p&gt;I needed to decouple the motor from the wheel. Back to sketching.&lt;/p&gt;

&lt;p&gt;My three options from a high-level view were: connect the motor and wheels via gears, using belt and pulley, or via an extended shaft. Hehe. I ruled out gears because I did not want to deal with the precision necessary in placing the gears and lining up the teeth. It was a toss-up between belt and pulley versus putting another shaft between the motor and wheel. I ended up drawing plans for both.&lt;/p&gt;

&lt;p&gt;The belt and pulley design involved coupling the motor to a pulley and another pulley to a shaft, which spun the wheel, and then connecting the two pulleys using a belt.&lt;/p&gt;
&lt;figure&gt;
  &lt;a href='/blog/images/2010/05/cad_of_belt_and_pulley_drive_train.png'&gt;
    &lt;img src='/blog/images/2010/05/cad_of_belt_and_pulley_drive_train_small.png' alt='CAD drawing of the belt and pulley drive train.' /&gt;
  &lt;/a&gt;
  &lt;figcaption&gt;CAD drawing of the belt and pulley drive train&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The big choice on a belt and pulley setup is v-belt or timing belt. A v-belt is smooth and shaped like a stunted letter V. The tension turns the pulleys. A timing belt is notched and lines up with the timing pulley&amp;#8217;s teeth. The timing belt has the benefits of transferring torque more efficiently and allowing less slippage. I consider the v-belt&amp;#8217;s property of allowing slippage a feature. For example, if the robot is being stopped by an outside force while the motor is still going, the slippage lets the motor still spin rather than burn up from the resistance. I decided to try both a v-belt and timing belt setup and test empirically.&lt;/p&gt;

&lt;p&gt;To extend the motor&amp;#8217;s shaft, I connected a shaft between the wheel and motor&amp;#8217;s shaft. I used &lt;a href='http://en.wikipedia.org/wiki/Pillow_block_bearing'&gt;pillow blocks&lt;/a&gt; to support the shaft and handle the radial load from the wheels. A pillow block is a mount, bored through with a ball bearing. The perpendicular stress on the shaft is distributed to each bearing. To connect the motor shaft to the extended shaft, I utilized &lt;a href='http://www.mcmaster.com/#shaft-couplings'&gt;shaft couplings&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='where_to_buy'&gt;Where to buy&lt;/h3&gt;

&lt;p&gt;My biggest complaint about building robots, a complaint that does not apply to the world of software, is where to find parts. I hope when the Personal Robot market matures, more standardization will take place with the hardware aspects. Perhaps when the term PR becomes as prevalent as PC.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.mcmaster.com'&gt;McMaster.com&lt;/a&gt;. McMaster-Carr is an industrial parts supplier, complete with a wide selection of pulleys, belts, bearings, wheels, and thousands of other components. McMaster-Carr is to hardware what &lt;a href='http://www.digikey.com'&gt;DigiKey&lt;/a&gt; and &lt;a href='http://www.mouser.com'&gt;Mouser&lt;/a&gt; are to electronics. To boot, the website is impressively easy to navigate (please take some notes, DigiKey) and includes helpful explanations detailing what to look for in each component. The downside: a substantial markup for each part.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>From Idea to Prototype: Motor Selection</title>
   <link href="http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-motor-selection"/>
   <updated>2010-05-20T00:00:00-05:00</updated>
   <id>http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-motor-selection</id>
   <content type="html">&lt;p&gt;After &lt;a href='http://alexanderrobotics.com/blog/2010/05/idea-to-prototype-sketching/'&gt;sketching&lt;/a&gt; my idea for a robot, I was left with several unknowns: what to use for the brains, the muscle, the power, the frame. I opted to approach the &amp;#8220;muscle&amp;#8221; first.&lt;/p&gt;

&lt;p&gt;After reading the exceptional &lt;a href='http://www.amazon.com/Robot-Building-Beginners-David-Cook/dp/1893115445'&gt;Robot Building for Beginners&lt;/a&gt; and several robot building tutorials online, I was still left perplexed when selecting a DC motor. How much torque is needed and what&amp;#8217;s an acceptable RPM were my two top questions. A helpful tutorial by Society of Robots, &lt;a href='http://www.societyofrobots.com/mechanics_dynamics.shtml'&gt;Robot Dynamics&lt;/a&gt;, helped me calculate the specifications I would need in a motor.&lt;/p&gt;

&lt;h3 id='motor_calculations'&gt;Motor calculations&lt;/h3&gt;

&lt;p&gt;Rather than repeat the knowledge expressed in Robot Dynamics, I present to you my actual calculations and decisions that influenced them.&lt;/p&gt;

&lt;p&gt;The first specification to calculate was the RPM of the motor.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;RPM = velocity / wheel circumference&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;My target speed for the robot was slightly faster than an adult&amp;#8217;s &lt;a href='http://en.wikipedia.org/wiki/Walking'&gt;average walking speed&lt;/a&gt; (approximately 80 m/min). I added an arbitrary 20 m/min to be &amp;#8220;slightly&amp;#8221; faster. I also assumed a wheel diameter of 0.076 m, roughly the size of an inline skate wheel.&lt;/p&gt;

&lt;p&gt;The resulting RPM calculations were&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;RPM = (100 m/min) / (3.14 * 0.076 m) = 419 RPM&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;Next, I needed to calculate the torque requirements.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;torque = force * distance&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;A Newton is a measurement of force, which I tackled first.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;force = mass * acceleration&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;I expected the robot to weigh about 14 kg with payload. For acceleration, I summed two values: the acceleration on a flat surface and the acceleration on an incline. I took the tutorial&amp;#8217;s advice for the flat acceleration.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;acceleration for flat plane &amp;asymp; half velocity &amp;asymp; 0.080 m/sec^2&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;The incline formula calculates the acceleration needed to overcome gravity at an angle so the robot won&amp;#8217;t fall backwards.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;acceleration for incline = gravity * sin (theta * pi/180)&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;I assumed an angle of 20°.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;9.81 m/sec^2 * sin (20 * pi / 180) = 0.335 m/sec^2&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;The final calculation was 0.80 m/sec^2 + 3.355 m/sec^2 giving a total acceleration of 4.155 m/sec^2. As can be seen, an incline drastically impacts the force required.&lt;/p&gt;

&lt;p&gt;With the mass and acceleration, I calculated the force requirements.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;force = 14 kg * 4.155 m/sec^2 = 30.17 newtons&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;The distance in the torque value derives from the distance between the wheels axis and where the force is applied. In other words, the distance is the wheel&amp;#8217;s radius.&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;distance = wheel's radius = 0.038 m&lt;/pre&gt;
&lt;/figure&gt;
&lt;p&gt;I estimated the total torque and the torque per motor at&lt;/p&gt;
&lt;figure&gt;
  &lt;pre&gt;torque = 30.17 N * 0.038 m = 1.146 N m torque per motor = 1.145 N m / 2 = 0.573 N m &lt;/pre&gt;
&lt;/figure&gt;
&lt;h3 id='motor_selection'&gt;Motor selection&lt;/h3&gt;

&lt;p&gt;With the required RPM and torque (419 RPM and 0.573 N m, respectively), I had the criteria needed to select a motor.&lt;/p&gt;

&lt;p&gt;I started with basic googling for robot motor, robot motor store, and so forth. A few good sites in terms of selection and details were &lt;a href='http://www.robotmarketplace.com/products/motors_main.html'&gt;Robot Market Place&lt;/a&gt;, &lt;a href='http://www.pololu.com/catalog/category/22'&gt;Pololu&lt;/a&gt;, and &lt;a href='http://www.lynxmotion.com/Category.aspx?CategoryID=50'&gt;Lynxmotion&lt;/a&gt;. These pages often use different units for measuring torque, like kg-cm or oz-in. An &lt;a href='http://www.numberfactory.com/nf_torque.html'&gt;online torque conversion chart&lt;/a&gt; will help.&lt;/p&gt;

&lt;p&gt;I ended up selecting the motor from Pololu. Pololu had the same motor with different gear ratios, allowing me to choose more torque or more speed. The closest matching motor was the &lt;a href='http://www.pololu.com/catalog/product/1103'&gt;29:1 geared DC motor&lt;/a&gt;. (Full disclosure: I actually bought two 67:1 geared motors because of an original miscalculation.)&lt;/p&gt;

&lt;p&gt;An important motor selection criteria I did not use in my above calculations was voltage. Honestly, I didn&amp;#8217;t care at this stage. If a 6 V motor met my requirements, perfect. Ideally, I wanted a motor between 6 and 12 V, but I would be willing to go up to 24 V. My power supply planning would come later.&lt;/p&gt;

&lt;p&gt;Please &lt;a href='http://alexanderrobotics.com/contact/'&gt;contact me&lt;/a&gt; if you notice an inaccuracy in the calculations. I&amp;#8217;ll update the post as needed.&lt;/p&gt;</content>
 </entry>
 
 
</feed>


