100% found this document useful (1 vote)
181 views

Hexatron Manual

Build a programmable, six legged walking robot that responds to its environment. The hexapod robot uses two direct current gear motors contained in one unit. The robot controller circuit is designed around the PIC 16F819 microcontroller.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
181 views

Hexatron Manual

Build a programmable, six legged walking robot that responds to its environment. The hexapod robot uses two direct current gear motors contained in one unit. The robot controller circuit is designed around the PIC 16F819 microcontroller.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

CHAPTER 1

Hexatron: Build Your Own Six Legged Walking Robot

Build a programmable, six legged walking robot that responds to its environment and demonstrates artificial intelligence! This autonomous robotic lifeform is the perfect platform to carry out your own experiments and explore the world of robotics.

FIGURE 1.1 Hexatron autonomous walking robot.

Thinkbotics Technologies Project Book

2005 Karl P. Williams

Hexatron: Build Your Own Six Legged Walking Robot

Walking robots: They are one of the most interesting results of today's advanced technology. With the popularity of Microchip's PIC microcontrollers and the development of compilers to support them, building mobile robots with brains on board has never been easier. In the past, a big problem with mobile robots was that they were often tethered to their computers. The support electronics, microprocessors and batteries were too large to carry onboard. The robots, like the computers that controlled them were large, power hungry machines. Keeping the robots close to their host computers placed limitations on the environments that the robots could operate in and the real world experiments that could be carried out. The robots were restricted to university laboratories, out of the hands of the electronics experimenters and enthusiasts. That has all changed... Building the hexapod robot presented in Figure 1.1 will allow you to experience the excitement of creating your own artificial lifeform that can walk, explore its environment and react to sensory feedback. This hexapod robot is unique because it uses two direct current gear motors contained in one unit to power the six legs. One gear motor drives the 3 legs on the left side of the robots' body and the other gear motor drives the 3 legs on the right side. The robots' body and legs are constructed with standard aluminum pieces and fasteners that are available at most hardware stores. The robot controller circuit is designed around the PIC 16F819, which contains 16 I/O pins and five 12-bit analog-to-digital converters. Another feature of this device is a software selectable internal oscillator that can be configured to run between 2 - 8 MHz. With the sophistication of the new PIC microcontrollers, the robot controller board uses fewer parts than would have been required a couple of years ago. The instructions for building and programming the robot will be divided into two sections - the body and the brain. The first section will deal with the mechanical aspect of the construction and the second part will deal with the electronics, programming, walking gaits and experiments. The complete list of parts necessary to build the robot is shown in Table 1.1.
TABLE 1.1 Complete list of parts necessary to build the robot
Part Semiconductors U1 U2 Q1 - Q4 Q5 - Q8 D1, D2 D3 - D10 78L05 5-volt regulator PIC 16F819 microcontroller 2N4401 NPN general purpose transistor 2N4403 PNP general purpose transistor Light emitting diodes 1N4148 diodes 1 1 4 4 2 8 Description Quantity

Thinkbotics Technologies Project Book

TABLE 1.1

Complete list of parts necessary to build the robot


Part Description 4.7 K 1/4 watt 5 K potentiometer with a 1/8" diameter and 5/8" length shaft 470 K 1/4 watt 0.1 fd Sharp infrared sensor module Piezo speaker On/off toggle switch SPST 3V battery holder (2 x AA) Tamiya dual motor gearbox - item 70097 2 connector female header 2.5 mm spacing 2 post male header connector 2.5 mm spacing 3 connector female header 2.5 mm spacing 3 post male header connector 2.5 mm spacing 3 strand 2 strand 18 gauge plastic coated 2-56 x 1 1/4-inch 2-56 x 1/4-inch 6/32 x 1-inch 6/32 x 1/2-inch 6/32 6/32 1/4 x 5/16-inch 2-56 x 1/4-inch 2-56 9 volt battery connector - PCB mount Non slip rubber 1/8-inch diameter Quantity 1 2 2 5 1 1 1 2 1 4 10 3 4 8 inches 16 inches 2 feet 4 8 14 2 16 40 6 2 2 1 6 10 inches

Resistors R1 R2 - R3 R4,R5 Capacitors C1,C2,C3,C4,C5 Miscellaneous Sharp GP2D12 module PZ1 SW1 BT1 M1-M2 Connectors JP1-JP10 Connectors JP11-JP14 Ribbon wire Ribbon wire Hookup wire Standoffs Machine screws for standoffs Machine screws Machine screws Locking nuts Nylon washers Nylon spacers Machine screws Nuts BT2 Rubber feet Heat shrink tubing

2005 Karl P. Williams

Hexatron: Build Your Own Six Legged Walking Robot

TABLE 1.1

Complete list of parts necessary to build the robot


Part Description Available at www.thinkbotics.com 9 volt 1.5 volt type AA 1/2 x 1/8-inch 1/4 x 1/4-inch 1/16-inch thick 1/16-inch thick Quantity 1 1 4 4 feet-3 inches 5 inches 4-1/2 x 6 1-3/4 x 3-1/2

Printed circuit board Controller board battery Motor supply batteries Aluminum stock Aluminum stock Flat aluminum stock Flat aluminum stock

Mechanical Construction
The Chassis

The first step in creating the robot is to construct the aluminum base to which the legs, electronics, gearmotors, batteries and the controller circuit board will be fastened. This will require the use of a hacksaw (or a band saw with a metal cutting blade), a power drill, table vice and a metal file. Cut and drill a piece of 1/16-inch thick flat aluminum (4 1/2-inches wide x 6-inches long) to the dimensions shown in Figure 1.2. Drill all of the holes indicated in Figure 1.3 using a 5/32 inch drill bit except for the two holes that are marked as being drilled with a 1/4-inch bit. Use a metal file to smooth the edges and remove any burs from the drill holes. Bend the aluminum inward on 90-degree angles according to the bending lines shown in Figure 1.2. Use a bench vice or the edge of a table to bend the pieces. Locate the two 3-volt battery packs (2 x AA) and fasten them to the bottom of the body chassis with two 2-56 x 1/4-inch machine screws and nuts. Use Figure 1.4 and Figure 1.5 as a guide when attaching the battery packs to the body chassis. Next, wire the battery packs together in series to achieve a 6-volt output by following the wiring guide shown in Figure 1.4. Note that the 6-volt output wires are fed through the hole in the bottom of the chassis up to the top side as indicated in Figure 1.4. If the lengths of the wires, measured from the top of the robot chassis, are not at least 5 inches long then add extension wire. Solder a 2 connector female header to the end of the 6-volt output wires. Insulate each of the connections with a 1/2-inch piece of heat shrink tubing. At this point in the construction, the body chassis with

Thinkbotics Technologies Project Book

Mechanical Construction

the two 3-volt (2 x AA) battery packs fastened to the underside should look like the one pictured in Figure 1.6.

FIGURE 1.2 Body Chassis aluminum cutting and bending guide.

2005 Karl P. Williams

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.3 Body Chassis aluminum drilling guide.

Thinkbotics Technologies Project Book

Mechanical Construction

FIGURE 1.4 Battery wiring and power lead routing diagram.

FIGURE 1.5 Underside view of the chassis.

2005 Karl P. Williams

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.6 Battery packs fastened to the body chassis - top view.

The Gearbox

Next, assemble the Tamiya twin motor gearbox using the instructions supplied with the motor kit for a gear ratio of 203:1. Apply the supplied lubrication to the gears so that they mesh smoothly and run quietly when the motors are in operation. Use a hack saw to cut each of the motor output shafts to a length of 5/8 of an inch as indicated in Figure 1.7. Cut two pieces of 2-strand connector wire to a length of eight inches each. On one end of each of the cables solder a two connector female header and use heat shrink tubing to protect the solder joints. Solder the first wire of the first connector cable to one of the power terminals of the left motor. Solder the second wire of the first connector cable to the remaining power terminal of the left motor. Repeat this procedure for the second connector cable and the right motor. Solder a 0.1 f capacitor (C4,C5) across the terminals of each motor, shown in Figure 1.7, to reduce RF (radio frequency) interference.
Feedback Potentiometers

Locate the two 5 K potentiometers and attach a 4-inch long, 3 strand connector wire to each one according to Figure 1.8. Solder a 3-connector female header to the other end of each wire as shown in Figure 1.9. Insulate each of the connections with a 1/2-inch piece of heat

Thinkbotics Technologies Project Book

Mechanical Construction

shrink tubing. Before the legs are attached to the chassis, each of the potentiometer shafts must be set to their middle positions. This is accomplished by the procedure that follows. Use Figure 1.10 as a guide to attach a 5-volt DC supply to the outer terminals of the first potentiometer. Attach the leads of a multimeter to the middle terminal and ground so that the voltage can be read. Turn the potentiometer shaft until you get a reading of 2.5 volts. Calibrate the second potentiometer using the same procedure.

FIGURE 1.7 Tamiya dual motor gearbox configuration.

FIGURE 1.8 Potentiometer wiring diagram.

2005 Karl P. Williams

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.9 Potentiometers with connector wires attached.

FIGURE 1.10 Procedure to center the potentiometer shafts.

Now that the gear-motors and potentiometers are wired, it is time to attach them to the robots body chassis. Position the gearmotor as shown in Figure 1.11 and secure it to the chassis using the two machine screws and nuts that came with the motor kit. Mount each of the potentiometers in the 1/4-inch holes at the back of the robot chassis as shown in Figure 1.11.

10

Thinkbotics Technologies Project Book

Constructing the Legs and motor shaft mounts

Make sure that the nuts are secured tightly so that the potentiometers do not move out of position when the robot is in operation.

FIGURE 1.11 Twin motor gearbox and Potentiometers attached to the chassis.

Constructing the Legs and motor shaft mounts


The Legs

Using the 1/2 x 1/8-inch aluminum stock, cut and drill 6 leg pieces labeled A, four outer leg linkage pieces labeled B, two middle leg linkage pieces labeled C and two leg sensor linkage pieces labeled D according to the dimensions shown in Figure 1.12. Use a 5/32-inch bit to drill the holes.
The Motor Shaft Mounts

Fabricate the motor output shaft mounts and potentiometer shaft mounts using 1/4-inch x 1/ 4-inch aluminum square stock according to the dimensions shown in Figure 1.13. The motor shaft mounts are labeled as parts E and the potentiometer shaft mounts are labeled as parts F.

2005 Karl P. Williams

11

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.12 Cutting and drilling guide for the leg and linkage pieces.

When the pieces are finished, thread a 6/32 diameter x 3/16-inch set screw in each of the holes that were threaded with the 6/32-inch tap. Figure 1.14 shows a completed motor shaft mount and potentiometer shaft mount.

12

Thinkbotics Technologies Project Book

Constructing the Legs and motor shaft mounts

FIGURE 1.13 Motor and potentiometer shaft mount fabrication diagram.

FIGURE 1.14 Completed motor and potentiometer shaft mounts.

2005 Karl P. Williams

13

Hexatron: Build Your Own Six Legged Walking Robot

Assembling The Legs

Now that the individual pieces for the legs and linkages have been constructed, it is time to put them all together to form the mechanical part of the walking machine. Refer to Figure 1.15 and Figure 1.16 when assembling the legs. Start by attaching one of the motor shaft mount pieces labeled E to the shaft of the right motor with the flat edge facing away from the motor. Make sure that the end of the shaft is flush with the face of the motor linkage and secure it in place by tightening the set screw. Attach piece A to motor mount piece E with a 6/32 x 1-inch machine screw with a nylon washer separating the two. On the same machine screw, place another washer, then linkage piece B, then a washer and then another linkage piece B. Secure all of the pieces together with a 6/32-inch locking nut. Attach two leg pieces A and linkage piece C to the chassis at the locations shown in Figure 1.15 and Figure 1.16. Attach potentiometer shaft mount F to the potentiometer shaft, but do not fasten the set screw at this time. Attach linkage piece D to piece F by placing a 6/32-inch nylon washer between the pieces and secure with a 6/32 x 1-inch machine screw and locking nut. Starting from the front of the robot, attach leg piece A to linkage B with a 6/32 x 1-inch machine screw and locking nut. Separate the pieces with a 6/32 x 5/16-inch plastic spacer. Do the same with middle leg piece A and linkage piece C but add two nylon washers along with the 6/32 x 5/16inch plastic spacer. Attach the back leg piece A to pieces D and B, with a 6/32 x 5/16-inch plastic spacer between pieces A and D and a nylon washer between pieces D and B. Tighten all of the locking nuts with enough pressure to hold the parts in place but still allow them to move freely without any resistance. Perform the above procedure for the left side of the robot. When everything is in place, use your finger to manually rotate the gearboxes so that the middle leg on each side is in the downward position and perpendicular to the chassis. Tighten the set screw on both of the potentiometer shaft mount pieces F. If you suspect that the potentiometer shafts have been moved from their middle positions, then re-calibrate each one before tightening the set screw (see Figure 1.10). When the mechanics are complete, add a rubber foot to the end of each leg. This will give the feet more friction and help to grip when the robot is walking on slippery or uneven surfaces.
Head And Infrared Sensor Mount

Fabricate the robot's head using a 1 3/4-inch x 3 1/2-inch piece of flat 1/16-inch thick aluminum. Follow the cutting, drilling and bending diagram shown in Figure 1.17. Locate the Sharp IR detector module and secure it to the head section with the mounting machine screws and nuts that came with it. See Figure 1.18 for orientation. Attach the head to the body using two 6/32 x 1/2-inch machine screws and locking nuts as shown in Figure 1.18.

14

Thinkbotics Technologies Project Book

Constructing the Legs and motor shaft mounts

FIGURE 1.15 Leg and linkage parts assembly diagram - outside view.

2005 Karl P. Williams

15

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.16 Leg and linkage parts assembly diagram - inside view.

16

Thinkbotics Technologies Project Book

Constructing the Legs and motor shaft mounts

FIGURE 1.17 Cutting, drilling and bending guide for the robots head section.

2005 Karl P. Williams

17

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.18 Finished mechanical assembly of the robot.

The mechanics and sensors of the walking robot are now assembled into place. All that is needed to bring the robot to life are the electronics and microcontroller programming. In the next section of this chapter, the electronics, wiring, sensors (infrared and leg position) and programming of the PIC16F819 microcontroller will be covered.

18

Thinkbotics Technologies Project Book

Constructing the electronics

Constructing the electronics


In the second part of this project, the electronics, printed circuit board fabrication, wiring, and PIC microcontroller programming will be covered. This is where building the robot gets fun!
Circuit Description

Hexatron's controller board schematic is shown in Figure 1.19. The circuit is designed around Microchip's PIC 16F819 microcontroller. The main part of the circuit is made up of two H-bridge motor controller configurations that consist of two 2N4401(NPN) and two 2N4403 (PNP) transistors each. The 1N4148 diodes create a voltage path to ground to protect the transistors from any transient high voltage spikes produced by the DC motors when they are first turned on. The H-bridges are used to control the two direct current motors contained in the Tamiya gearbox that drives the legs. The left motor drives the leg mechanism on the left side of the robot's body and the right motor drives the legs on the right side of the body. By coordinating the movement of each set of legs, the robot is capable of walking forward, walking in reverse, turning to the left, and turning to the right. The regular I/O on Port B pins 0,1,2 and 3 of the pic 16F819 are used to control the H-bridge circuits that drive the DC gear motors. PortB pins 4 and 5 are used to control light emitting diodes. PortB pin 6 is used to output sound to a piezoelectric element. All of the other unused pins have header connectors attached so that they can be used to interface other sensors or output devices that you may want to add during experimentation. Three of the analog-to-digital converters on Port A (pins 0,1, and 2) of the 16F819 are used to read the voltages produced by the two leg position potentiometers (R2 and R3) and the output voltage produced by the Sharp GP2D12 Infrared ranger module. The Sharp GP2D12 ranger is an inexpensive sensor that takes a continuous distance reading and reports the distance as an analog voltage (0V to 3V) with a range of 10cm (~4") to 80cm (~30"). The interface is 3-wire with power, ground and the output voltage. The module requires a JST 3-pin connector, which is included with each detector package. The GP2D12 is shown in Figure 1.20. This circuit relies on the PIC 16F819 microcontroller, which functions according to its internal software. Programming the microcontroller will be discussed after the circuit board is completed and the robot is wired.

2005 Karl P. Williams

19

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.19 Hexatron's controller board schematic.

FIGURE 1.20 GP2D12 infrared ranger module.

20

Thinkbotics Technologies Project Book

Constructing the electronics

Fabricating The Controller Printed Circuit Board

The circuit is easiest built by fabricating a circuit board using the artwork shown in Figure 1.21. The circuit board can be produced using whatever method you are comfortable with. To use the artwork for the photofabricaton process, photocopy it onto a transparency. When you are ready to expose the copper board, orient the transparency exactly as shown in Figure 1.21. The exact size of the board should be 1 1/2 x 5-inches. If you are going to use the iron-on transfer method you will need to scan the foil pattern and then mirror the image so that the artwork is properly oriented when it is printed on to the transfer sheet and then ironed onto the copper board. The finished printed circuit board is also available to purchase from the authors web site located at www.thinkbotics.com. You can also download the image file free at the same location. If you don't want to fabricate a printed circuit board, the circuit is simple enough to construct on a 1 1/2 x 5-inch piece of standard perforated circuit board using point-to-point wiring.

FIGURE 1.21 Hexatron's printed circuit board foil pattern.

FIGURE 1.22 Printed circuit board component side parts placement.

2005 Karl P. Williams

21

Hexatron: Build Your Own Six Legged Walking Robot

Once the circuit board has been etched, drilled, and cut, use Figure 1.22 and Table 1.1 as a guide to place the parts on the board. Solder an 18-pin I.C. socket where part U2 (PIC 16F819) is shown. The PIC will need to be programmed before it is inserted into the socket (more about programming later). Solder all parts in place after they have been positioned on the board. Attach four 2-56 x 1 1/4-inch standoffs to the mounting holes on the circuit board and then mount the board to the back of the robot with the 9 volt battery closest to the head as shown in Figure 1.18. Use Figure 1.23 as a guide to connect all of the components to the controller circuit board. Mount the power switch (SW1) in the 1/4-inch hole on the top of the robot's head. Note that the left potentiometer (R2) is attached to JP13 and the right pot (R3) is attached to JP12. The Sharp GP2D12 is attached to JP11. The left motor is connected to JP2 and the right motor is connected to JP1.

FIGURE 1.23 Robot wiring connections diagram.

22

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

Programming the PIC 16F819 microcontroller


To program the microcontroller you will need a hardware programmer such as the EPIC Plus programmer and a compiler such as PicBasic Pro shown in Figure 1.24. Both the compiler and programmer are available from a company called microEngineering Labs (www.melabs.com). The program listings shown are produced for use with the PicBasic Pro compiler but can be translated to work with any PIC microcontroller compiler that you like. When the code has been compiled, a standard 8-bit Merged Intel HEX (.hex) file is created that can be used with any PICmicro programmer. This machine code file is then loaded into the EPIC Plus programming software and then transferred to the PIC. Once the PIC 16F819 has been programmed and inserted into the 18-pin socket on the controller board, it will start executing the code when power is supplied. Program 1.1 is called robot-test.bas and will be used to test all of the robot's functions. Once the program has been compiled, program the PIC16F819 with the robot-test.hex file listed in Program 1.2. For your convenience you can download the Basic and Hex files for this project from www.thinkbotics.com. When the 16F819 is programmed, insert it into the 18-pin socket on the controller board with pin 1 facing the notch in the socket (located closest to the transistors of the h-bridge section of the circuit). Make sure that a fresh 9-volt battery and four 1.5-volt AA batteries are placed in the battery holders. When the power is turned on the robot should produce sound from the piezo element, flash the light emitting diodes on and off in sequence, run the legs in a forward direction for 10 cycles and then go into a loop to test the infrared ranger. If you find one or both of the motors are moving in reverse then unplug the motor connector and reverse the pin connections. To test the ranger, move your hand in front of the robot at a distance of 4 to 5 inches. Because the output of this sensor module is nonlinear there is a dead zone of 2 inches directly in front of the robot. This is not a problem because the robot walks at a relatively slow speed and the program is looking at a wide range of values. If you want to accurately interpret the nonlinear voltages produced by the sensor a routine can be written that uses a lookup table to correlate all of the voltages to actual distances.

2005 Karl P. Williams

23

Hexatron: Build Your Own Six Legged Walking Robot

FIGURE 1.24 EPIC Plus programmer and PicBasic Pro compiler.

PROGRAM 1.1 robot-test.bas program listing. ' Name : robot-test.bas ' Compiler : PicBasic Pro - MicroEngineering Labs ' Notes : Program to test the robot's functions @ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF INCLUDE "modedefs.bas" TRISA = %00011111 TRISB = %00000000 DEFINE OSC 8 OSCCON = $70 M1 M2 M3 VAR PORTB.0 VAR PORTB.1 VAR PORTB.2

24

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

M4 LED1 LED2 PIEZO LCD

VAR PORTB.3 VAR PORTB.4 VAR PORTB.5 VAR PORTB.6 VAR PORTB.7

LCD_BAUD CON N2400 LEFT_POT VAR PORTA.0 RIGHT_POT VAR PORTA.1 LOW M1 LOW M2 LOW M3 LOW M4 LOW LED1 LOW LED2 LOW PIEZO VAL_LEFT VAL_RIGHT LEG_STOP INFRARED TEMP VAR BYTE VAR BYTE VAR BYTE VAR BYTE VAR BYTE

' Set up the analog to digital converters DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 1 ' Set clock source (01 = Fosc/8) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds ADCON1 = 0 LEG_STOP = 136 START: SOUND PIEZO,[100,10,90,5,80,5,110,10] FOR TEMP = 1 TO 10 LOW LED1 HIGH LED2 PAUSE 100 ' Set porta pins to analog ' Leg stop potentiometer value

2005 Karl P. Williams

25

Hexatron: Build Your Own Six Legged Walking Robot

LOW LED2 HIGH LED1 PAUSE100 NEXT TEMP LOW LED1 FOR TEMP = 1 TO 10 GOSUB LEFT_FORWARD GOSUB RIGHT_FORWARD NEXT TEMP RANGER: ADCIN 2,INFRARED IF INFRARED > 100 AND INFRARED < 130 THEN SOUND PIEZO,[100,10,90,5] ENDIF GOTO RANGER END LEFT_FORWARD: VAL_LEFT = 0 LOW M1 LOW M2 HIGH M2 PAUSE 300 WHILE VAL_LEFT < (LEG_STOP - 3) OR VAL_LEFT > (LEG_STOP + 3) ADCIN 1,VAL_LEFT WEND LOW M2 RETURN RIGHT_FORWARD: VAL_RIGHT = 0 lOW M3 LOW M4 HIGH M3 PAUSE 300

26

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

WHILE VAL_RIGHT < (LEG_STOP - 3) OR VAL_RIGHT > (LEG_STOP + 3) ADCIN 0,VAL_RIGHT WEND LOW M3 RETURN PROGRAM 1.2 robot-test.hex file listing. :100000009F28A3003A088400380931208413A308EC :1000100003199A28F030A50022088038A400F03097 :10002000A5030319A5000319A30303199A2820089F :10003000A6002108A700163061202608A000270886 :10004000A1004520030120183808A21F3808A20883 :1000500003190301A40F2E2880060C282F28000066 :100060000F28841780059A28A000A00DA00D200D50 :10007000383941389F000030A100323062201F150E :100080001F194028A1011E089A28210820040319DD :10009000A00A8030201AA1062019A106A018A106E6 :1000A000210DA00DA10D9A28A301A200FF30A207E7 :1000B000031CA307031C9A280330A100E33062202D :1000C0005628A101F43EA000A109FE30031C6B28B4 :1000D000A00703186828A0076400A10F6828000083 :1000E00020187228201874280800A101A301A2007A :1000F00001307F28A101A301A20004307F28A800BD :1001000023082102031D8628220820020430031838 :100110000130031902302805031DFF309A280038EA :10012000031DFF300405031DFF309A280404031D3E :10013000FF309A2883130313831264000800831688 :100140001F308500860170308F00831206108316E1 :1001500006108312861083168610831206118316EA :1001600006118312861183168611831206128316D6 :1001700006128312861283168612831206138316C2 :1001800006139F0183128830BD000630BA0040304C :10019000B8006430A2000A3001205A30A2000530B5 :1001A00001205030A200053001206E30A2000A303C :1001B00001200130BE0064000B303E020318F62817 :1001C0000612831606128312861683168612643070 :1001D0008312542086128316861283120616831603 :1001E0000612643083125420BE0FDB2806128316D9 :1001F000061283120130BE0064000B303E02031869 :1002000005292C216D21BE0FFC2802303420BC00B2 :100210003C08A00064307520B2003C08A000823089

2005 Karl P. Williams

27

Hexatron: Build Your Own Six Legged Walking Robot

:100220007A20B4003208840034088F20B400B5006E :10023000640034083504031929290630BA00403017 :10024000B8006430A2000A3001205A30A200053004 :100250000120052963002A29BF0106108316061014 :1002600083128610831686108312861483168610D6 :1002700083120130A3002C305520FE303D07B20020 :10028000FF300318013EB3003F08A000A10133086E :10029000A30032087C20B20002303D07B400B50153 :1002A000B50D3F08A000A1013508A3003408772050 :1002B000B4003208840034089620B400B50064000D :1002C000340835040319682901303420BF003D2962 :1002D00086108316861083120800C001061183164B :1002E0000611831286118316861183120615831652 :1002F000061183120130A3002C305520FC303D073D :10030000B200FF300318013EB3004008A000A10175 :100310003308A30032087C20B20004303D07B4004B :10032000B501B50D4008A000A1013508A3003408AF :100330007720B4003208840034089620B400B50059 :100340006400340835040319A92900303420C000A2 :0C0350007E290611831606118312080096 :02400E00303F41 :00000001FF

When the robot is functioning properly, turn it off and remove the PIC16F819 from the 18pin socket on the controller board. In the next program, subroutines will be added to control the reverse movement of the legs. To enable the robot to turn left or right, the left legs move in one direction and the right legs move in the opposite direction. The robot's behavior will be to explore its environment by walking forward until it senses an object. When an object is sensed the robot will stop, make an alert noise, back itself up and then turn either to the left or right. Whether the robot turns to the left or the right will be determined by the action that it took the last time it encountered an object, alternating between a left or right turn. To make things interesting, the robot will blink its light emitting diodes and make insect noises with every step that it takes. Compile explore.bas listed in Program 1.3 and then program the PIC 16F819 with the explore.hex file listed in Program 1.4. Insert the PIC back into the socket and turn on the power. Also included at the end of this program is a subroutine to display the values produced by the analog-to-digital converters on a serial LCD display at 2400 baud. To use the subroutine, call it in a loop at the start of the program. The serial input of the LCD display is connected to PortB, pin 7.

28

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

PROGRAM 1.3 Explore.bas program listing. ' Name : explore.bas ' Compiler : PicBasic Pro - MicroEngineering Labs ' Notes : Hexatron Robot exploration program @ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF INCLUDE "modedefs.bas" TRISA = %00011111 TRISB = %00000000 DEFINE OSC 8 OSCCON = $70 M1 VAR PORTB.0 M2 VAR PORTB.1 M3 VAR PORTB.2 M4 VAR PORTB.3 LED1 VAR PORTB.4 LED2 VAR PORTB.5 PIEZO VAR PORTB.6 LCD VAR PORTB.7 LCD_BAUD CON N2400 LEFT_POT VAR PORTA.0 RIGHT_POT VAR PORTA.1 LOW M1 LOW M2 LOW M3 LOW M4 LOW LED1 LOW LED2 LOW PIEZO VAL_LEFT VAL_RIGHT LEG_STOP INFRARED TEMP VAR BYTE VAR BYTE VAR BYTE VAR BYTE VAR BYTE

2005 Karl P. Williams

29

Hexatron: Build Your Own Six Legged Walking Robot

FLAG

VAR BIT

LEG_STOP = 136 FLAG = 0 ' Set up the analog to digital converters DEFINE ADC_BITS 8 DEFINE ADC_CLOCK 1 DEFINE ADC_SAMPLEUS 50 ADCON1 = 0 ' Set number of bits in result ' Set clock source (01 = Fosc/8) ' Set sampling time in microseconds ' Set porta pins to analog

SOUND PIEZO,[100,10,90,5,80,5,110,10] START: SOUND PIEZO,[100,5,110,5] LOW LED1 HIGH LED2 GOSUB LEFT_FORWARD SOUND PIEZO,[80,5,90,5] LOW LED2 HIGH LED1 GOSUB RIGHT_FORWARD ADCIN 2,INFRARED IF INFRARED > 100 AND INFRARED < 130 THEN SOUND PIEZO,[100,10,90,5,100,5,110,10,80,20,90,20] FLAG = FLAG + 1 FOR TEMP = 1 TO 5 GOSUB LEFT_REVERSE GOSUB RIGHT_REVERSE NEXT TEMP IF FLAG THEN FOR TEMP = 1 TO 5 GOSUB LEFT_REVERSE GOSUB RIGHT_FORWARD NEXT TEMP ELSE

30

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

FOR TEMP = 1 TO 5 GOSUB RIGHT_REVERSE GOSUB LEFT_FORWARD NEXT TEMP ENDIF ENDIF GOTO START END ' motor control subroutines start here '------------------------------------------------------------LEFT_FORWARD: VAL_LEFT = 0 LOW M1 LOW M2 HIGH M2 PAUSE 300 WHILE VAL_LEFT < (LEG_STOP - 1) OR VAL_LEFT > (LEG_STOP + 1) ADCIN 1,VAL_LEFT WEND LOW M2 RETURN LEFT_REVERSE: VAL_LEFT = 0 LOW M1 LOW M2 HIGH M1 PAUSE 300 WHILE VAL_LEFT < (LEG_STOP - 1) OR VAL_LEFT > (LEG_STOP + 1) ADCIN 1,VAL_LEFT WEND LOW M1 RETURN

2005 Karl P. Williams

31

Hexatron: Build Your Own Six Legged Walking Robot

RIGHT_FORWARD: VAL_RIGHT = 0 LOW M3 LOW M4 HIGH M3 PAUSE 300 WHILE VAL_RIGHT < (LEG_STOP - 1) OR VAL_RIGHT > (LEG_STOP + 1) ADCIN 0,VAL_RIGHT WEND LOW M3 RETURN RIGHT_REVERSE: VAL_RIGHT = 0 LOW M3 LOW M4 HIGH M4 PAUSE 300 WHILE VAL_RIGHT < (LEG_STOP - 1) OR VAL_RIGHT > (LEG_STOP + 1) ADCIN 0,VAL_RIGHT WEND LOW M4 RETURN ' Display analog-to-digital converter values on serial LCD '------------------------------------------------------------CALIBRATE: ADCIN 0,VAL_RIGHT ' read A/D converter - porta.pin 0 serout LCD,LCD_BAUD,[254,128,"R:",#VAL_RIGHT," "] ADCIN 1,VAL_LEFT ' read A/D converter - porta.pin 1 serout LCD,LCD_BAUD,[254,134,"L:",#VAL_LEFT," "] ADCIN 2,INFRARED ' read A/D converter - porta.pin 2 serout LCD,LCD_BAUD,[254,192,"IR:",#INFRARED," "] RETURN

32

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

PROGRAM 1.4 Explore.hex file listing. :100000001529A501A400B7172730A300103014202C :100010000330A300E8301420A30164301420A301AE :100020000A30142024081F28A2002508A100240853 :10003000A000F4202008031DB713B71B0800303EB2 :10004000A6003A0884000930A70003102C20A60C53 :10005000A70B262803142C288413B71D3B2800085F :100060003804371D38068000841700083804031C44 :1000700038068000462800083804031C3806371963 :10008000380680008417380980054628370D063960 :10009000A0004F20A100A00A4F200000BC28003083 :1000A0008A002008820701348B3403342B34003457 :1000B00052340C34EF34A3003A08840038098B2002 :1000C0008413A30803191029F030A50022088038F2 :1000D000A400F030A5030319A5000319A303031915 :1000E00010292008A6002108A7001630BB202608EA :1000F000A0002708A1009F20030120183808A21F94 :100100003808A20803190301A40F8828800666286E :10011000892800006928841780051029A000A00DF7 :10012000A00D200D383941389F000030A100323039 :10013000BC201F151F199A28A1011E08102921088B :1001400020040319A00A8030201AA1062019A10654 :10015000A018A106210DA00DA10D1029A301A20038 :10016000FF30A207031CA307031C10290330A100C2 :10017000E330BC20B028A101F43EA000A109FE306C :10018000031CC528A0070318C228A0076400A10FFC :10019000C22800002018CC282018CE280800A10171 :1001A000A301A2000130D928A101A301A2000430BB :1001B000D928A80023082102031DE02822082002D4 :1001C000043003180130031902302805031DFF30E5 :1001D00010290038031DFF300405031DFF301029CE :1001E0000404031DFF301029A501A4011030A6004E :1001F000210DA40DA50D2208A4022308031C230F22 :10020000A50203180A292208A40723080318230FAC :10021000A5070310A00DA10DA60BF8282008102992 :100220008313031383126400080083161F308500B4 :10023000860170308F008312061083160610831219 :1002400086108316861083120611831606118312F8 :1002500086118316861183120612831606128312E4 :1002600086128316861283120613831606138312D0 :100270007E30BE003F1083169F0106308312BA0005

2005 Karl P. Williams

33

Hexatron: Build Your Own Six Legged Walking Robot

:100280004030B8006430A2000A305B205A30A2002F :1002900005305B205030A20005305B206E30A2009C :1002A0000A305B20E62252290630BA004030B800FE :1002B0006430A20005305B206E30A20005305B2068 :1002C000061283160612831286168316861283126E :1002D00064220630BA004030B8005030A200053029 :1002E0005B205A30A20005305B20861283168612EE :1002F00083120616831606128312E2215229023057 :100300008E20BC003C08A0006430CF20B2003C0826 :10031000A0008230D420B400320884003408E920E0 :10032000B400B5006400340835040319DF29063031 :10033000BA004030B8006430A2000A305B205A3066 :10034000A20005305B206430A20005305B206E30D7 :10035000A2000A305B205030A20014305B205A30DB :10036000A20014305B2083103F1C831483183F14B9 :10037000831C3F100130C1006400063041020318A5 :10038000C529A5222322C10FBC2964003F1CD42902 :100390000130C1006400063041020318D329A522B0 :1003A000E221C10FCA29DF290130C10064000630F3 :1003B00041020318DF2923226422C10FD6295229C2 :1003C0006300E029C0010610831606108312861010 :1003D00083168610831286148316861083120130CA :1003E000A3002C30AF20FF303E07B200FF300318CF :1003F000013EB3004008A000A1013308A300320869 :10040000D620B20001303E07B400B501B50D40085A :10041000A000A1013508A3003408D120B40032089F :1004200084003408F020B400B500640034083504BA :1004300003191E2A01308E20C000F329861083166E :10044000861083120800C00106108316061083125E :1004500086108316861083120614831606108312E4 :100460000130A3002C30AF20FF303E07B200FF3038 :100470000318013EB3004008A000A1013308A30007 :100480003208D620B20001303E07B400B501B50DE8 :100490004008A000A1013508A3003408D120B40011 :1004A000320884003408F020B400B5006400340839 :1004B000350403195F2A01308E20C000342A06104B :1004C0008316061083120800BD010611831606115B :1004D0008312861183168611831206158316061160 :1004E00083120130A3002C30AF20FF303E07B20052 :1004F000FF300318013EB3003D08A000A1013308FE :10050000A3003208D620B20001303E07B400B50186 :10051000B50D3D08A000A1013508A3003408D12085

34

Thinkbotics Technologies Project Book

Programming the PIC 16F819 microcontroller

:10052000B400320884003408F020B400B500640040 :10053000340835040319A02A00308E20BD00752A26 :1005400006118316061183120800BD0106118316D9 :10055000061183128611831686118312861583165F :10056000861183120130A3002C30AF20FF303E07EC :10057000B200FF300318013EB3003D08A000A10106 :100580003308A3003208D620B20001303E07B40081 :10059000B501B50D3D08A000A1013508A300340840 :1005A000D120B400320884003408F020B400B50033 :1005B0006400340835040319E12A00308E20BD00A0 :1005C000B62A8611831686118312080000308E2009 :1005D000BD000630BA008030B8000430B700FE30ED :1005E000202080302020523020203A3020203D082A :1005F0000120203020202030202001308E20C0001B :100600000630BA008030B8000430B700FE30202039 :10061000863020204C3020203A3020204008012015 :10062000203020202030202002308E20BC000630D8 :10063000BA008030B8000430B700FE302020C0304F :10064000202049302020523020203A3020203C0801 :0C06500001202030202020302020080055 :02400E00303F41 :00000001FF

Conclusion

The Hexatron robot should now be walking around, exploring its environment and avoiding obstacles as it goes. There are many other sensors that can be added to the robot such as a sonar rangefinder, cds light sensors, phototransistors, a compass module, wireless data linking, remote control, etc. There are still 5 unused I/O pins including 2 analog-to-digital converters that can be used for your own experiments. Have fun building and modifying the robot!
About The Author

Karl P. Williams is an independent robotics researcher, electronics experimenter, and software developer. He is with AGFA HealthCare Informatics, a leading medical imaging software company. He is the author of three robotics books titled Insectronics: Build your own six legged walking robot (ISBN: 0-07-141241-7), Amphibionics: Build your own biologically inspired robots (ISBN: 0-07-141245-x) and Build Your own Humanoid Robots (ISBN:0-07142274-9) all published by McGraw-Hill. A resident of Ontario, Canada, he has written for

2005 Karl P. Williams

35

Hexatron: Build Your Own Six Legged Walking Robot

the magazines Nuts and Volts, SERVO and Conformity. He hosts a couple of robotics web sites at (http://home.golden.net/~kpwillia) and (www.thinkbotics.com).

36

Thinkbotics Technologies Project Book

You might also like