m.a.d. dog - ucsb · m.a.d. dog is an autonomous robot that was designed to navigate various office...

24
M.A.D. Dog -----Mobile Area Defense--------------------------------- Nicholas Maddy Timothy Dayley Kevin Liou ECE 189, 2013 UC Santa Barbara M.A.D. Dog 1 | 24

Upload: others

Post on 17-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

M.A.D. Dog -----Mobile Area Defense---------------------------------

Nicholas MaddyTimothy Dayley

Kevin Liou

ECE 189, 2013UC Santa Barbara

M.A.D. Dog 1 | 24

Page 2: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Table Of Contents

Page

Introduction........................................................................................................ 3

Controls, Indicators, and Interconnects.............................................................. 4

Device Description............................................................................................. 13

IR Sensor.................................................................................................... 13

Sonar.......................................................................................................... 13

Compass..................................................................................................... 14

PIR Sensor................................................................................................. 15

Wi-Fi.......................................................................................................... 15

Motor Controller........................................................................................ 17

Motor......................................................................................................... 18

Power......................................................................................................... 18

Software Description............................................................................................ 19

Main Loop................................................................................................... 19

Interrupts..................................................................................................... 21

Graphical User Interface.............................................................................. 23

M.A.D. Dog 2 | 24

Page 3: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Introduction

M.A.D. Dog is an autonomous robot that was designed to navigate various office environments.

It does this with the help of two infrared range detectors, a sonar range finder, and its motor’s

built in hall encoders. As it navigates the office space, it will periodically detect for intruders

using a set of passive infrared sensors, positioned to give it nearly 360° of view. Upon detection

of an animate entity, it will use its Wi-Fi module to contact a designated computer about the

intrusion. While it is sending out the alert message, it will proceed to set off its own alarm by

generating a siren on a speaker and flashing high-luminosity LEDs, with the intent of deterring

the intruder. This project also includes a custom GUI which would allow a user to observe the

current location and status of M.A.D. Dog, as well as set priorities and direct the robot to various

locations.

M.A.D. Dog 3 | 24

Page 4: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

M.A.D. Dog Controls, Indicators, and Interconnects

1. SpeakerConnect a speaker here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Speaker PWM0[1] 185 P1[2]● Pin 2 Ground Digital GND - -

2. SonarConnect the SRF05 Sonar range finder here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Ground Digital GND - -● Pin 2 Echo Capture CAP3[1] 16 P0[24]● Pin 3 Trigger P0[25] 14 P0[25]

M.A.D. Dog 4 | 24

Page 5: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 4 Power Digital 5V - -

3. IR Ranger #1Connect a Sharp GP2D120 infrared range detector here.

Pin Purpose Interface Processor Pin Port ● Pin 1lef Ground Analog GND - -● Pin 2 Vir AD0[5] 40 P1[31]● Pin 3 Power Analog 5V - -

4. Motor Encoder #1Connect a motor encoder here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Encoder A P0[9] 158 P0[9]● Pin 2 Encoder B P0[8] 160 P0[8]● Pin 3 Ground Digital GND - -● Pin 4 Power Digital 5V - -

5. Motor ControllerConnect the Solarbotics L298 motor controller here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Enable L PWM0[5] 153 P1[7]● Pin 2 L1 P0[7] 162 P0[7]● Pin 3 L2 P0[6] 164 P0[6]● Pin 4 L3 P0[5] 166 P0[5]● Pin 5 L4 P0[4] 168 P0[4]● Pin 6 Enable R PWM1[1] 154 P2[0]

6. PIR #1Connect one of the Zilog Z8FS040 PIR sensors here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Ground Digital GND - -● Pin 2 Power Digital 3.3V - -● Pin 3 Recieve RXD2 132 P2[9]● Pin 4 Transmit TXD2 134 P2[8]● Pin 5 Motion Detect P0[18] 124 P0[18]● Pin 6 Light Gate Digital 3.3V - -● Pin 7 Sleep P0[21] 118 P0[21]● Pin 8 Ground Digital GND - -● Pin 9 Power Digital 3.3V - -● Pin 10 Test Header P2[30] 31 P2[30]

M.A.D. Dog 5 | 24

Page 6: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

7. Motor Encoder #2Connect a motor encoder here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Encoder A P0[11] 100 P0[11]● Pin 2 Encoder B P0[10] 98 P0[10]● Pin 3 Ground Digital GND - -● Pin 4 Power Digital 5V - -

8. PowerConnect a power source here.

Pin Purpose Interface Processor Pin Port ● Pin 1top Ground Analog GND - -● Pin 2 Board Power 7.4 V Battery - -

9. IR_Ranger #2Connect a Sharp GP2D120 infrared range detector here.

Pin Purpose Interface Processor Pin Port ● Pin 1right Ground Analog GND - -● Pin 2 Vir AD0[4] 42 P1[30]● Pin 3 Power Analog 5V - -10. GPIO Test Pins

These (10) pins can be used for testing and alternative operations.Pin Purpose Interface Processor Pin Port

● Pin 1left Power Digital 3.3V - -● Pin 2 Power Digital 3.3V - -● Pin 3 Test/optional P3[31] 25 P3[31]● Pin 4 RTC alarm ALARM 37 ALARM● Pin 5 Test/optional P2[25] 54 P2[25]● Pin 6 Test/optional P3[26] 55 P3[26]● Pin 7 Test/optional P3[25] 56 P2[25]● Pin 8 Ground Digital GND - -● Pin 9 Ground Digital GND - -● Pin 10 Ground Digital GND - -

11. CompassConnect a compass here.

Pin Purpose Interface Processor Pin Port ● Pin 1top None No Connect - -● Pin 2 None No Connect - -● Pin 3 Optional P0[30] 62 P0[30]

M.A.D. Dog 6 | 24

Page 7: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 4 Optional P0[29] 61 P0[29]● Pin 5 Optional P0[31] 51 P0[31]● Pin 6 I2C Data SDA0 50 P0[27]● Pin 7 I2C Clock SCL0 48 P0[28]● Pin 8 Ground Digital GND - -● Pin 9 None No Connect - -● Pin 10 Power Digital 5V - -

12. PIR#2Connect one of the Zilog Z8FS040 PIR sensors here.

Pin Purpose Interface Processor Pin Port ● Pin 1left Ground Digital GND - -

● Pin 2 Power Digital 3.3V - -● Pin 3 Receive RXD3 176 P4[29]● Pin 4 Transmit TXD3 170 P4[28]● Pin 5 Motion Detect P0[19] 122 P0[19]● Pin 6 Light Gate Digital 3.3V - -● Pin 7 Sleep P0[22] 116 P0[22]● Pin 8 Ground Digital GND - -● Pin 9 Power Digital 3.3V - -● Pin 10 Test/Optional P2[31] 39 P2[31]

13. GPIO Test PinsThese (10) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1left Test/optional P2[26] 57 P2[26]● Pin 2 Test/optional P3[24] 58 P3[24]● Pin 3 Test/optional P2[23] 64 P2[23]● Pin 4 Test/optional P3[23] 65 P3[23]● Pin 5 Test/optional P1[18] 66 P1[18]● Pin 6 Test/optional P2[19] 67 P2[19]● Pin 7 Test/optional P1[19] 68 P1[19]● Pin 8 Test/optional P1[20] 70 P1[20]● Pin 9 Test/optional P1[21] 72 P1[21]● Pin 10 Test/optional P2[20] 73 P2[20]

14. SDRAM Test PinsThese (10) pins are used to observe test signals from the SDRAM.

Pin Purpose Interface Processor Pin Port ● Pin 1left Power Digital 3.3V - -● Pin 2 Ground Digital GND - -

M.A.D. Dog 7 | 24

Page 8: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 3 Write Enable WE 179 P4[25]● Pin 4 Row strobe RAS 95 P2]17]● Pin 5 Column strobeCAS 87 P2[16]● Pin 6 (static) Chip select CS0 187 P4[30]● Pin 7 Clock enable CKEOUT0 53 P2[24]● Pin 8 Clock CLKOUT0 59 P2[18]● Pin 9 Data Mask L DQMOUT0 49 P2[28]● Pin 10 Data Mask H DQMOUT1 43 P2[29]

15. Reset LEDThis LED, when lit, confirms that the processor is reset. This LED should light when the

reset button (23) is pressed, setting the reset signal low. LED Purpose Interface Processor Pin Port

● #1 Reset Notify RSTOUT 29 RSTOUT

16. Test LEDsThese (8) LEDs are used to visually observe test output from the processor.

Pin Purpose Interface Processor Pin Port ● #1left Display P0[0] 94 P0[0]● #2 Display P0[1] 96 P0[1]● #3 Display P0[12] 41 P0[12]● #4 Display P0[13] 45 P0[13]● #5 Display P0[14] 69 P0[14]● #6 Display P0[15] 128 P0[15]● #7 Display P0[16] 130 P0[16]● #8 Display P0[23] 18 P0[23]

17. GPIO Test PinsThese (20) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1left Test/optional P1[22] 74 P1[22]● Pin 2 Test/optional P1[23] 76 P1[23]● Pin 3 Test/optional P1[24] 78 P1[24]● Pin 4 Test/optional P1[25] 80 P1[25]● Pin 5 Test/optional P2[21] 81 P2[21]● Pin 6 Test/optional P1[26] 82 P1[26]● Pin 7 Test/optional P2[22] 85 P2[22]● Pin 8 Test/optional P1[27] 88 P1[27]● Pin 9 Test/optional P1[28] 90 P1[28]● Pin 10 Test/optional P2[14] 91 P2[14]● Pin 11 Test/optional P1[29] 92 P1[29]

M.A.D. Dog 8 | 24

Page 9: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 12 Test/optional P2[15] 99 P2[15]● Pin 13 Test/optional P4[16] 101 P4[16]● Pin 14 Test/optional P2[13] 102 P2[13]● Pin 15 Test/optional P4[17] 104 P5[17]● Pin 16 Test/optional P4[18] 105 P5[18]● Pin 17 Test/optional P2[12] 106 P2[12]● Pin 18 Test/optional P2[11] 108 P2[11]● Pin 19 Test/optional P4[20] 109 P4[20]● Pin 20 Test/optional P4[19] 111 P4[19]

18. Wi-Fi Connect a WiFi module here.

Pin Purpose Interface Processor Pin Port ● Pin 1bot.left Power Digital 3.3V - -● Pin 2 Transmit TXD1 137● Pin 3 Receive RXD1 143● Pin 4 GPIO Wi-Fi GPIO8 - -● Pin 5 Wi-Fi Reset RESET - -● Pin 6 GPIO GPIO5 - -● Pin 7 GPIO7 - -● Pin 8 GPIO GPIO9 - -● Pin 9 GPIO GPIO1 - -● Pin 10 Ground Digital GND - -● Pin 11top.right GPIO GPIO14 - -● Pin 12 None NC - -● Pin 13 None NC - -● Pin 14 None NC - -● Pin 15 None NC - -● Pin 16 None NC - -● Pin 17 None NC - -● Pin 18 None NC - -● Pin 19 None NC - -● Pin 20 None NC - -

19. GPIO Test PinsThese (20) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1right Test/optional P4[21] 115 P4[21]● Pin 2 Test/optional P4[26] 119 P4[26]● Pin 3 Test/optional P4[22] 123 P4[22]● Pin 4 Test/optional P4[23] 129 P4[23]

M.A.D. Dog 9 | 24

Page 10: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 5 Test/optional P2[7] 136 P2[7]● Pin 6 Test/optional P2[6] 138 P2[6]● Pin 7 Test/optional P4[27] 139 P4[27]● Pin 8 Test/optional P2[5] 140 P2[5]● Pin 9 Test/optional P2[4] 142 P2[4]● Pin 10 Test/optional P2[3] 144 P2[3]● Pin 11 Test/optional P1[13] 147 P1[13]● Pin 12 Test/optional P2[2] 150 P2[2]● Pin 13 Test/optional P3[18] 151 P3[18]● Pin 14 Test/optional P2[1] 152 P2[1]● Pin 15 Test/optional P1[5] 156 P1[5]● Pin 16 Test/optional P1[12] 157 P1[12]● Pin 17 Test/optional P4[12] 149 P4[12]● Pin 18 Test/optional P3[19] 161 P3[19]● Pin 19 Test/optional P1[11] 163 P1[11]● Pin 20 Test/optional P3[20] 167 P3[20]

20. GPIO Test PinsThese (10) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1right Test/optional P1[6] 171 P1[6]● Pin 2 Test/optional P4[15] 173 P4[15]● Pin 3 Test/optional P3[21] 175 P3[21]● Pin 4 Test/optional P1[3] 177 P1[3]● Pin 5 Test/optional P1[17] 178 P1[17]● Pin 6 Test/optional P1[16] 180 P1[16]● Pin 7 Test/optional P1[15] 182 P1[15]● Pin 8 Test/optional P4[24]183 P4[24]● Pin 9 Test/optional P1[14] 184 P1[14]● Pin 10 Test/optional P1[10] 186 P1[10]

21. GPIO Test PinsThese (10) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1right Test/optional P1[9] 188 P1[9]● Pin 2 Test/optional P1[8] 190 P1[8]● Pin 3 Test/optional P1[4] 192 P1[4]● Pin 4 Test/optional P4[31] 193 P4[31]● Pin 5 Test/optional P1[1] 194 P1[1]● Pin 6 Test/optional P3[22] 195 P3[22]

M.A.D. Dog 10 | 24

Page 11: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 7 Test/optional P1[10] 196 P1[10]● Pin 8 Test/optional P3[27] 203 P3[27]● Pin 9 JTAG RTCK RTCK 206 RTCK

● Pin 10 Ground Digital GND - -

22. Bootloader Button (right)This button, when held during reset process, the processor will enter bootloader mode. Purpose Interface Processor Pin Port

● UI/Bootloader P2[10] 110 P2[10]

23. Reset Button (left)This button, when pressed, resets the processor. Purpose Interface Processor Pin Port

● Board reset RESET 35 RESET

24. Bootloader/PIR #3 UART Switch*Switch has been replaced by header pins*This switch has two possible configurations.

Header pins PIR Configuration RS232 Configuration

25. RS232 ConnectorAn RS232 cable is used to connect a computer to the board here for programming

and debugging purposes.Pin Purpose Interface Processor Pin Port

● Pin 1top.right None NC - -● Pin 2 Receive RXD0 204 P0[3]● Pin 3 Transmit TXD0 202 P0[2]● Pin 4 None NC - -● Pin 5 Ground Digital GND - -● Pin 6 None NC - -● Pin 7 None NC - -

M.A.D. Dog 11 | 24

Page 12: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

● Pin 8 None NC - -● Pin 9 None NC - -

26. PIR #3Connect one of the Zilog Z8FS040 PIR sensors here.

Pin Purpose Interface Processor Pin Port ● Pin 1right Ground Digital GND - -● Pin 2 Power Digital 3.3V - -● Pin 3 Receive RXD0 204 P0[3]● Pin 4 Transmit TXD0 202 P0[2]● Pin 5 Motion Detect P0[17] 126 P0[17]● Pin 6 Light Gate Digital 3.3V - -● Pin 7 Sleep P0[20] 120 P0[20]● Pin 8 Ground Digital GND - -● Pin 9 Power Digital 3.3V - -● Pin 10 Test/Optional P2[27] 47 P2[27]

27. GPIO Test PinsThese (10) pins can be used to observe test signals on the processor.

Pin Purpose Interface Processor Pin Port ● Pin 1right JTAG TDO 2 -● Pin 2 JTAG TDI 4 -● Pin 3 Test/Optional P3[28] 5 P3[28]● Pin 4 JTAG TMS 6 -● Pin 5 JTAG TRST 8 -● Pin 6 JTAG DBGEN 9 -● Pin 7 JTAG TCK 10 -● Pin 8 Test/Optional P3[29] 11 P3[29]● Pin 9 Audio? AOUT 12 P0[26]● Pin 10 Test/Optional P3[30] 19 P3[30]

M.A.D. Dog 12 | 24

Page 13: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Device Description

IR Sensor

The IR sensors we used were the Sharp GP2D120 Infrared Range Finders. They operated at 5 volts and constantly outputs an analog voltage that approximated O(1/distance). The output was at its maximum of about 3 volts at a distance of roughly 3 centimeters, dropping to around 0.2 volts.

This device was used to provide course alterations that would keep M.A.D. Dog from running into an obstacle from the side or allowing it to navigate along the wall at a safe but readable distance. We used these IR sensors in particular to create a “bouncing” effect off a wall M.A.D. Dog is approaching from the side, while also obtaining data for the map. The response time is extremely fast and we were able to use these with the sonar in order to avoid corners or other odd shaped obstacles.

Sonar

The sonar that was used was a Devantech SRF05 sonar range finder. This device operates by emitting a high-frequency sound pulse, setting its echo pulse pin high when at the start and back low when either 30 mS has passed or the echo returns. This happens when a falling edge signal is seen on the input trigger pin of the module. The echo pulse can be analyzed using a capture timer

M.A.D. Dog 13 | 24

Page 14: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

on the processor in order to determine the amount of time it took the pulse to return, and thus how far the nearest obstruction is to the front of M.A.D. Dog.

While an IR sensor would have sufficed for this operation, we decided to use a sonar so that we can read objects that are farther away from M.A.D. Dog, therefore giving us time to make decisions. The sonar would work together with the IR sensors in order to completely avoid any obstacle in its way and be able to map out its current environment.

Compass

The LSM303DLHC can provide our robot with a tri-axial reading using its magnetometer, thus providing M.A.D. Dog with a sense of direction. This uses an I2C interface that operates on an interrupt basis. Additionally, it has an accelerometer which would allow M.A.D. Dog to determine if it is, or isn’t, moving the way it intends.

If M.A.D. Dog runs into a wall somehow and our other sensors are not working properly, the compass would be able to figure out that the motors are moving but M.A.D. Dog isn’t, alerting the system of a faulty state. This module also adds another layer in tracking and mapping. We use the compass to confirm turn radius and distance traveled, and with the map, we can easily traverse our environment without having to rely on the other modules heavily.

M.A.D. Dog 14 | 24

Page 15: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

PIR Sensor

M.A.D. Dog uses three ZEPIR0AxS02MODG Passive Infrared Sensors for intruder detection. These three modules are placed in strategic places around the robots tower in order to provide them with an unobstructed view with nearly 360° of detection. This device uses a serial interface connected to uart0, uart2, and uart3, which allows for configuration and status messages, as well as the use of a motion detect pin that goes low when motion is detected.

As these are passive infrared sensors, M.A.D. Dog must come to a stop before beginning detection, otherwise it will set itself off. This is a feature that would be a good place to improve upon, should this robot be upgraded.

Wi-Fi

The Wi-Fi module on M.A.D. Dog is used to communicate commands and data back to the server in order to keep the server updated while M.A.D. Dog is running. This module automatically turns on, and has a configuration file that is set up to work with a specific router with a specific SSID and password. At the time of this project the SSID was “SwellAlert” and the password was “swellalert”. In order to change this, you need to access the Wi-Fi command mode using UART and use the commands:

M.A.D. Dog 15 | 24

Page 16: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

set wlan ssid [the SSID of your Wi-Fi network]set wlan phrase [your wpa password]

Also make sure that you are using the WPA2-PSK WLAN authentication type. If there is something wrong with the connection of the Wi-Fi to the server then you can read more about the Wi-Fi commands using Roving Networks “WiFly Command Reference, Advanced Features & Applications” manual.

We also set up a simple TCP server using Java with a user friendly GUI. All the user has to do is open the GUI using either Eclipse or through the Window's command prompt and type:

java MADDogGUI

If using the command prompt does not immediately work, then the user should make sure they are in the correct directory and that the java file has been previously compiled. With the GUI now running, the user just has to click on the button to open the desired port number and M.A.D. Dog should be able to connect using its Wi-Fi functions. When we made this robot, we used the IP address 192.168.1.69 and port number 4845 to run all our tests, and the software for M.A.D. Dog should have that port number hard coded into it. To change that number, all you would need to do is go in the Wi-Fi initialization function and find where the command “open 192.168.1.69 xxxx” is and change 'xxxx' to the port number you used with the server.We did not accomplish much on the robot side of the Wi-Fi, although we left a lot of room for improvement open and it should not be to difficult to write more code to incorporate the server more regularly. We wanted to make our robot turn on through a Wi-Fi command, and also be able to be controlled remotely from the server so that someone could tell M.A.D. Dog where to go in it's patrol area.

M.A.D. Dog 16 | 24

Page 17: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Motor Controller

The motor controller we used was the Solarbotics L298. This motor controller acts as the gateway between the processor and the motors (the motors cannot be controlled directly by the processor). The motor controller uses PWM to control the speed of the motors and GPIO to control the direction of the motors. The PWM is applied directly to the motors in order to maintain the desired speed. The GPIO controls the forward and backward direction of the left and right motor, ultimately giving it full control to go forwards, backwards, and turn left and right.

There are 10 total interconnects used to interface the motor controller with the motors, encoders, and the board. The two female header pins are used for communication between the board and motor controller, and the two blue connectors on either side of the controller are used to power the motors. The blue connector in the middle of the motor controller is used to power the motor controller and through it, the motors.

M.A.D. Dog 17 | 24

Page 18: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Motors

M.A.D. Dog is driven using two 6 V Pololu gearmotors with hall encoders. These, as mentioned above, are controlled by our Solarbotics L298 motor controller. The motors also have a direct interface with the M.A.D. Dog board providing the processor with the motors encoder information. This allows M.A.D. Dog to keep track of how far it has moved or turned. There are a total of five wires coming from each motor. Two are for power and are connected directly to the motor controller, and the other three are PWM and encoder information that are connected to molex connectors which snap onto the top of our board (as indicated in Controls, Indicators, and Interconnects).

Power

We used two 7.4V with 2200mAh to power our motor controller and board separately. It is extremely important that the grounds of the batteries are connected together, tying all the grounds together. When connecting the batteries, it is also important to not let the leads come in contact with the chassis or each other.

M.A.D. Dog 18 | 24

Page 19: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Software Description

M.A.D. Dog has a large number of peripherals and controls that must be used concurrently in order to perform its functions. In order to achieve this, the sampling of sensors and the handling of communication are interrupt based while the main loop handles navigation and operation. Additionally, a GUI was setup to provide the security personnel an interface which provides location, error, and alert status. Each of these sections will be explained, followed by an explanation of the various functions being used.

Main loop:The code that was submitted is a demo version which was designed to demonstrate the robots movement and alert functionalities. This demo sets the robot to move forward in a straight line, avoiding forward obstacles and maintaining the straightness using its motor encoders, for a set distance. It then turns 90° to the right and continues forward a new distance. Once it reaches its destination, it enters intruder detection mode triggering an alarm sequence and activating its high-luminosity lights. The GUI was not interfaced with the demo as the server was not available to display, however there are functions available to communicate between the two systems. (simply calling uart1Puts(“string”) will transmit to the server after its initialization.) This section of code demonstrates the parts of the intended software structure, where M.A.D. dog will navigate to various points along a route to its destination. The motor drive speed is determined using a PID control loop with the front sonar module, allowing it to stop and reverse away from objects in front of the device. The encoders also provide a PID with a smaller level of influence in order to keep the robot straight while also keeping track of how far the robot has moved. During right and left turns, the encoder target difference is set to the degree of the turn and used from that point in order to correct for under and overshoots once the it starts moving forward in that direction.

The following PID functions are meant to provide calculated pwm adjustments according to the sensors read. void pid_init(void);

Initialize the tuning variables for each sensor’s PID calculation.

void pid_update(pid* sensor); Update integral and derivative terms and provide the PWM adjustment for the motors

according to the sensor passed in the parameters list.

The functions below are used to handle detection and alert sequences.

M.A.D. Dog 19 | 24

Page 20: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

void init_PIR(void);This function will configure the PIRs to detect mode and will block if any of the PIRs are

not connected.

void detect_PIR(int time);This functionality will set M.A.D. dog to watch its PIRs until a timer set to the passed in

time expires. If it determines that any of the PIRs has an interrupt, then it will begin the alert sequence in the following function.

void alarm(int time);This function will activate the high-luminosity LEDs while sounding its alarm for the

amount of time specified.

Next, are the uart interrupt initialization functions and handlers. The functions provided for uart0 in the original “hello world” program were replicated for each of the other uarts as well. void UART0IntInit(void);void UART1IntInit(void);

These functions will configure the board to call the Interrupt service routines whenever there is information in the receive buffer.

The next set of functions used in the main loop are the motor control functions. void motor_set(int Lspeed, int Rspeed);

This will set the speed and direction of both motors to the desired speeds(pulse widths). This uses the void pwm_set(int pwm0, int pwm1); which sets each of the PWMs at the same time.

void turn_left(); and void turn_right(); These functions are designed to turn the robot 90° either left or right, and keeping this

encoder difference so that “straight” is in that direction from then on. This allows any mistakes in the turn to be corrected once the robot continues forward.

The following functions are designed to configure the peripherals in question for operation. void adc_init(); void dac_init(); void pwm_init();

The program can use adc_sample(char chan); to sample the desired adc channel, though this is done in the interrupt section below.Interrupts:

The various sensors and peripherals used on our robot are configured to provide information as it becomes available or be controlled on a timed basis. The encoders use edge triggered interrupts to keep track of the rising and falling edges of the encoder bits allowing it to

M.A.D. Dog 20 | 24

Page 21: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

update the encoder count for each motor asynchronously. The Wi-Fi module also uses interrupts to grab data from the uart buffer as it becomes available. M.A.D. Dogs other sensors are controlled using a timer interrupt in order to trigger sample acquisitions. The timer will interrupt at the start to trigger a sonar echo, resulting in two edge triggered interrupts that capture the start and return of the echo allowing M.A.D. dog to determine forward distance. The next timer interrupt samples both of the IR range detectors in order to provide distance data on the sides of M.A.D. dog. Each of these interrupts update globally accessible variables that are used for PID controls in the main loop.

Next are the functions used to set up timed interrupts and handle sampling of the sensors.

void prox_sense_init(void);This function will set up a timer with two match registers (two interrupts). The two

interrupts will switch the handler from one to the other so that the one timer can have two functionalities. The first interrupt is to trigger the sonar echo and capture.

void snr_echo_trig(void);This function will clear any recent sonar calculations that weren’t completed and set the

sonar trigger pin low, which will trigger the sonar range detection. It will then switch the interrupt handler to void sensor_sample(void) for the second timer interrupt.

void snr_echo_ISR(void); This function will capture the rising edge and then the falling edge time, where it will

calculate the difference and update the sonars position variable (snr.position)

void sensor_sample(void);In this function, the two infrared range finders are sampled using int adc_sample(chan).

The values are stored in the ir_l.position and ir_r.position variables. It will also reset the timer and switch the interrupt handler back to snr_echo_trig(void) for the first interrupt.

Another source of interrupts key to this design is the motor encoders. The following two functions are used to asynchronously keep track of the wheel’s movements. void setup_Mtr_INT(void);

This function will set up the interrupts and handler for the motor encoders which will keep track of the robots movement.

void gpioISR(void);This function will trigger on every rising and falling edge of either encoder bits and will

determine which wheel has moved and which direction it has moved in. It will then clear the interrupt and increment/decrement that wheels counter variable. (r_mtr_cnt or l_mtr_cnt).

M.A.D. Dog 21 | 24

Page 22: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Lastly, the uart communication interrupt service routines. These were not yet integrated into our design, though they are available to use. The intention was to allow communication to proceed without blocking the processor in order to retrieve all of the data coming in with a 9600 baud.

void UART0ISR (void); void UART1ISR (void);

Each of these functions has an associated circular char buffer which will hold data for the main loop to use. This will set the data available flag in the MAD_flags global variable. At present, both of these functions will put the character to the screen over uart0.

M.A.D. Dog 22 | 24

Page 23: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

Graphical User Interface: M.A.D. Dog has the ability to communicate with the Graphical User Interface

implemented in the server through the Roving Networks Wi-Fi module. The GUI provides the functionality needed to receive and send messages to M.A.D. Dog, and provides an interactive map of the robot’s current environment.

The interactive map is a two dimensional grid of clickable buttons that visually represents the environment that M.A.D. Dog is current patrolling. Walls and obstacles are represented by grey icons, and open floor is represented as white icons. M.A.D. Dog’s location is represented by a red dot. As the robot patrols, it continuously sends updates to the server with changes in its location. These changes are reflected in real time as the red dot travels across the grid. Should the user wish to take control over M.A.D. Dog’s next destination, he may click on any white button, and a green dot will appear where the user has selected. The coordinates will be sent to M.A.D. Dog, who will then proceed to travel to the selected location in lieu of it’s own target.

The GUI also provides the ability to manually input messages to M.A.D. Dog and transmit them. These transmissions are recorded in the message log of the GUI. M.A.D. Dog can be programmed to accept many different messages to call a variety of functions. Some of these functions include starting and stopping the robot, to modifying some of the variables that control it. Currently the robot is only accepting messages in the format:

[PID_Sensor] [PID_Variable] [Value]

An example of this usage is, ir_r position 200. By inputting this command, the variable ir_r.position is assigned a value of 200, modifying the behavior of the PID feedback controller. This allowed for dynamic reprogramming of the robot’s motor behaviors, which simplified the fine tuning and measuring aspects of testing PID values.

Messages sent from M.A.D. Dog are received by the server and are displayed in the message log on the GUI. Messages include location, status, and intruder detection updates, and much more functionality can be implemented with this regard.

The relevant files for the GUI and server are:

Server.javaThis file contains the functionality for the server. It is a multithreaded server, capable of

communicating with multiple clients at once. This allows for the potential for one server to manage multiple M.A.D. Dogs. It contains the functionality to receive connections and send and receive messages.

MadDogGUI.javaThis file contains the GUI for the server. It contains all of the layout components of the

GUI, and communicates through the server.

M.A.D. Dog 23 | 24

Page 24: M.A.D. Dog - UCSB · M.A.D. Dog is an autonomous robot that was designed to navigate various office environments. It does this with the help of two infrared range detectors, a sonar

CapstoneMap.javaThis file contains a simple class definition of the map layout of the HFH 4th floor CE lab.

It contains the coordinates of the ground, the walls, and the tables of the lab. This class is called when the GUI is created, loaded into the two dimensional button grid.

To compile and run the server and GUI, the three files above can be compiled in Eclipse, by running MadDogGui.java.

M.A.D. Dog 24 | 24