Friday, January 4, 2013

Explorer Bot

This was another project based off the book Arduino Robotics (click here for the Amazon link), and is my most elaborate accomplishment to date.  The idea is a high powered, maneuverable robot with a wireless camera mounted on-top allowing someone to move the robot without actually seeing it.  My original idea was to add a squirt gun on the front to allow me to drive around school and shoot people without them knowing who was doing the driving!  I've settled for mounting a laser pointer on the front rather than a squirt gun.

In this project CAD was integral to fitting together many components without needing to do a lot of mockup.  I made extensive use of PCB technologies to make two high-current H-bridges with built in current sensing and protection.  I learned about LiPo (lithium polymer) batteries, voltage regulators, and how to drive multiple electronic devices safely from the same power supply.  And I learned a lot about AX12s, a high-end servomotor with precision control over position and speed which I used to make a flexible turret on the front of the robot.

The robot drives using two wheelchair motors, off of a Merits MP-3C Red, which I ordered on eBay.  These are driven through two H-bridges constructed using the schematic shown at left.  H-bridges use four power mosfets, two P type (Q5, Q6, Q9, Q10) and two N type (Q1, Q3, Q7, Q8), arranged in an X pattern.  This particular schematic doubles up each transistor with a partner to allow higher current flow.  One "leg" of the X, either the \   or the /  represents a current path with the motor in the center.  If the \ pattern is applied, the motor turns one direction.  If the / pattern is applied, the motor turns in the other direction.  Active deceleration can be applied by switching the direction of current flow while the motor is still turning.  Check out this tutorial on H-bridges:  http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/.

This H-bridge can control speed by accepting a PWM signal from the Arduino.   An IR4427 chip reads the TTL signal from the Arduino, and then rapidly switches on and off the N-channel mosfets.  The P-channels just stay high because you only need to turn off either the P or the N channels to open the circuit and stop the motor from seeing voltage which regulates its speed.

Each H-bridge has an integrated current sensor.  The Arduino Robotics book suggests a surface mount chip, but I went ahead and ordered the chip on a breakout board to simplify my life.  The program reads the current, and shuts off the motors if a thresh-hold is exceeded.    The Arduino book came with a layout for making the H-bridge printed circuit boards.  The book described how to etch the patterns into copper clad plastic, but I chose to use a Roland milling machine to make the boards instead of etching.  You can find the author's Eagle files here.  I modified them slightly to increase the spacing between components... here are the milling machine files which I used to make the PCB boards.

The Merits MP-3C electric wheelchair motors have been great; they have a lot of torque.  I bought ones with wheels already attached to save myself a lot of trouble.  The electric motors came with four electric leads, which was quite confusing at first till I dug around online to find out that the smaller two wires were for an electric brake (a solenoid).  I simply removed the brake using some excellent directions online.


Just like the book suggested, I used a FlySky FS-CT6A remote control.  The system eventually worked great, but I really struggled with it for a while.  I got really erratic pulse readings when fitting female headers over the pins in the receiver; my ability to read a pulse (using the PulseIn function in the Arduino language) was contingent upon pressing the female headers in a certain direction to make electrical contact.  Eventually I just soldered wires directly to the output pins of the receiver, and have had very reliable and consistent performance since then.  The receiver is mounted on the back of the robot in a protective acrylic box.

I bought a nice wireless 900MHz SecurityMan security camera which has infrared capabilities for seeing in the dark.  Finally, I purchased some AX12a servomotors from Trossen Robotics.  These are higher end servos (better than normal hobby servos) because they allow better precision of motion including control over speed.   Here is the manual for the AX12a.  Unlike normal servos, which take a pulse between 1000 and 2000 microseconds (us), the AX12a servomotors use a serial protocol where packets are passed to it.  The Arduino has the capability to send and receive serial packets on pins 0 and 1, but this is a half duplex setup (half the info goes on one pin, the other half on the second pin), whereas the AX12a use a single pin for all the information (full duplex).  Fortunately, there are several very smart people out there who have written Arduino libraries to send packets to the AX12a, and who know how to use tristate buffer chips to convert from half to full duplex.  The other problem is that the AX12a's will tie-up your serial ports completely when in use, which means that you cannot also use them to transmit new code or to send debugging information to an attached computer via USB.  Fortunately my experience has been that you can still upload new code because of the tristate buffer chip.  The bottom line is that the AX12a's work great.


Here is the schematic for this robot.  Three Arduino pins (0, 1, 2) are dedicated to the 74LS241 tristate buffer chip.  Eight Arduino pins (3-5, 7-11) are dedicated to the two H-bridges (four pins for each of the transistors).  Five pins are dedicated to reading pulses from the RC transmitter (pins 6, 12, 13, A2, A0).  Analog pins 4-5 read the current sensors on the H-bridge.  And A1 is used as a digital output to drive a relay which turns on and off the attached laser.  I made a custom PCB board, this time using the correct spacing for the Arduino header pins, connected up the H-bridges and current sensors, the RC receiver inputs, and soldered the relay into place.

Here are the PCB Eagle files for my custom PCB breakout board for the Arduino.  You can see what the board looks like below.


Powering all the components of this robot was a big challenge.  Most of the components ran on different voltages, but I wanted only a few batteries.  I chose to use LiPo batteries because they are very stiff supplies and have a high energy density.  I ordered three Traxxas 25C 11.1V 3S 3-Cell 6400mAh LiPo Battery Packs along with hextronik three-cell battery monitors from HobbyKing.  Two of the LiPo batteries are wired in series to power the H-bridges for the 24V wheelchair motors as well as two 12V cooling fans for the power mosfets (the fans are wired in series to match the two lipo batteries).  The other LiPo battery powers the Arduino (6-16V), the SecurityMan camera (8V), the AX12a's (11.1V recommended), and the laser pointer (3V) or the bubble gun (6V).   This arrangement allows me to turn on and off the wheels separate from everything else.

I used LM317 voltage regulators to deal with the mismatched power requirements you see above.  The 11.1V LiPo battery was used to drive the Arduino and the AX12a's directly.  I then used two LM317 circuits to drop the 11.1V down to 8V for the camera, and down to 6V for my external modular device (laser pointer, bubble gun).  The laser pointer was fitted with three diodes to allow an addition 2.1V to drop, bringing the supply voltage down to 3.9V which was acceptable as a replacement for a CR132A battery as was supplied with the laser pointer.  This link is what I used to calculate resistors to use with the LM317.  I left a potentiometer in the circuit for the external modular device in case I later want to put something else on the turret.
I made one more circuit board for the voltage regulators.  The Eagle files can be downloaded here.  A systems check showed that everything was working as expected, so I could move on to putting all the electronics into a robot.



 CAD played a huge part in visualizing the robot before putting it together.
I used a piece of angle iron steel as the body for this robot.  With a couple cuts, the angle iron could be bent into the shape shown at left.  Then two cross beams of flat steel were added and the three pieces attached with bolts.  The electric motors were attached to the frame with bolts.













I cut a small piece of 1" square mild steel stock, and bent a bracket for the caster.  I attached this to the frame of the robot.














I used a laser cutter to fashion an acrylic bracket for the SecurityMan camera, and mounted this on a set of two AX12a's arranged to make a turret.   This turret was then mounted on a piece of PVC affixed to the robot's frame.  I routed the wires for the AX12a carefully down the back of the PVC inside corrugated tubing.








On the front of the robot, I made another turret using some custom acrylic, an old bearing from a CD-ROM drive, and two gears from a VEX robotics kit.  I used two AX12a's originally hoping that this, along with the bearing, would allow me to mount  a squirt gun on the front of the robot.  But the torque of the gun turned out to be too much, so I used the laser pointer instead.  The whole front turret system is major overkill, but it looks cool.














The code for this project was mostly taken from the Arduino Robotics book.    I made minor adjustments to add code to control the AX12a's, and to easily add or remove certain parts of the robot from the code (eg debug, servo, gun, motors can be set to 0 or 1 to turn them off or on).  I also had to use a running average because the servos "jittered" without it.  There was some noise in the input pulses, and the servos were sensitive enough to respond to it.

The code makes used of mixed steering, meaning that the x and y axes on a single joystick are used to control the robot.  It struggled at first to understand how the code from the book worked, and so recently I used Processing to create a program which helps me to visualize the steering.  The picture is of a coordinate system which represents the possible positions of the joystick.  Each point on the coordinate system has two vectors which represent the left motor power (in red) and the right motor power (in blue).  The robot will turn in the direction opposite the larger vector.    In the triangles labelled "1", the robot moves forward but is steered to one side or the other.  In the locations labelled "B", the robot moves directly forward or backwards.  A deadband is used in the program and is represented on the coordinate axes by light vertical lines.  In the locations labelled "2", the robot does a "swing turn" with the motors moving in opposite directions but with different powers.  In the locations labelled "A", the robot executes a pivot turn (as though on a dime), with the speed varying according to how far the joystick is pressed.  There is a deadband in the horizontal direction as well, represented by the two light horizontal lines.  The square in the middle is where the joystick is centered so neither wheel turns.  The Processing code which generated the picture can be seen here.

You can check out the code here, or download the Arduino file directly by clicking here.