1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Hacking Roomba - Tod E.Kurt Part 10 pot

30 270 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 30
Dung lượng 695,05 KB

Nội dung

252 Part III — More Complex Interfacing Listing 12-2 Continued } else if( $cmd == ‘spinright’ ) { roomba_spin_right( $vel ); } else if( $cmd == ‘sensors’ ) { $sensors = roomba_read_sensors(); $c = count($sensors); for( $i=1; $i<=$c; $i++ ) { printf(“sensors[$i]: %x\n”, $sensors[$i]); } } else if( $cmd == “drive” ) { $vel = $_GET[‘velocity’]; $rad = $_GET[‘radius’]; roomba_drive( $vel, $rad ); } ?> </pre> </body> </html> Figure 12-12 shows what the script looks like in the browser when run. F IGURE 12-12: Using the PHP Roomba program roombacmd.php 253 Chapter 12 — Going Wireless with Wi-Fi As you can see, the Roomba functions seem very similar compared to the RoombaComm func- tions. The only strange statements are the pack() statements, like: pack(“C*”, 137, $vhi,$vlo, $rhi,$rlo) In PHP, in order to send raw bytes with no string or numeric translation (which is normally what you want), you need to pack the bytes into a variable according to some packing rules. In the preceding statement, C* means to pack a series of unsigned bytes. The asterisk means an unknown number of bytes. In the preceding case you could use C5 since you’re packing five bytes. When receiving data from Roomba, you need to use a corresponding unpack() method. If you expand roombacmd.php to more fully control Roomba, the first thing to do is to move the Roomba functions into their own file to build a Roomba PHP library called, for example, roombalib.php. You can then use this separate file with include ‘roombalib.php’ at the top of your main PHP file. The HTML user interface is an example of using multiple Submit buttons for a single form. Each button sends a different value for cmd. You could have just as easily created multiple links and set the cmd query argument yourself. Putting It All Together Now that you have a working PHP page to control Roomba, you can run it anywhere you can find a working LAMP system. This includes virtually all web hosting services on the Internet. In order to run roombacmd.php from one of them, you’ll need to poke a hole in your firewall to allow computers outside your home network to connect. Most home routers have a special configuration page just for such changes. Your home network looks like a single IP address to the rest of the Internet, but that IP address can have many dif- ferent ports. What your router can do is translate one IP:port pair on the outside part of your network to another IP:port pair on the inside of your network. This is called port mapping or port forwarding and is often used to allow online gaming or P2P file sharing to work, so you may already have some port maps in place. For example, if your external IP address to the Internet (WAN IP address) is 12.34.56.78 and the IP address of your Roomba is 192.168.0.1, then you’d configure your router to map port 10001 from one IP address to the other. This can be written in documentation as 12.34.56.78:10001 > 192.168.0.1:10001. If you don’t know your external WAN IP address, go to http://whatsmyip.org — you should be able to see it. A final task is to make an enclosure for the WiMicro and carrier board. Having an exposed cir- cuit board looks cool but as the WiMicro is expensive it’s a good idea to protect it. Any small enclosure of the right size can be used. Figure 12-13 shows one example using a small project box. Small cut-aways on the sides are made where the antenna and Roomba cable come out. Figure 12-14 shows the finished enclosure mounted on the Roomba. 254 Part III — More Complex Interfacing F IGURE 12-13: Enclosure for WiMicro and carrier board F IGURE 12-14: The completed Wi-Fi Roomba 255 Chapter 12 — Going Wireless with Wi-Fi Going Further with LAMP The M part of LAMP hasn’t been touched on yet. The preceding PHP script shows the basics of how to receive sensor data, but the script doesn’t do anything with the data besides printing it. With PHP and MySQL it’s pretty easy to record the sensor data to a database table. With enough sensor data you can do an analysis on it to figure out things like: Ⅲ When is the house the dirtiest? Compare historical dirt sensor readings with time and date. Ⅲ Approximately how big or cluttered is the living room? Average out time between bump sensors to determine the mean free path of your rooms. Ⅲ How long are my walls? Analyze the wall sensor readings to find walls; then create a histogram to find the different wall sizes. Ⅲ How long does it take for the dustbin to fill up? Average the time from when the Roomba starts to when the vacuum motor over-current bit is set. Collect enough data, and you can determine a great many things about the environment within which Roomba moves. Roomba may not be a very accurate sensor platform, but its sensors cover the same area again and again. Good data can often be recovered from noise with repeated measurements. Summary A Wi-Fi Roomba coupled with a LAMP application is pretty powerful. You can create not just web pages to control the robot, but dynamic database-driven web pages. Having the ability to tie a database into the robot enables you to create for an entirely different level of interaction as Roomba can now have a huge historical memory. You could create complex robotic logic based on this elephantine memory located on a server anywhere and remotely command one or sev- eral Roombas simultaneously. Or you could create a social networking site for Wi-Fi Roomba users and collect real-time Roomba stats from all over the world. As the price of the Wi-Fi modules continues to fall due to cell phones and portable game sys- tems having Wi-Fi, making a Wi-Fi Roomba will become even more attractive. To make the extra cost of the current devices more palatable, you can hook up the extra serial port offered to the microcontrollers discussed in the next chapter. Then you can get the best of both worlds: localized computation backed with a huge storehouse of previous knowledge. Giving Roomba a New Brain and Senses T he projects presented so far have all been based on having the new brains of Roomba located remotely to it. From an RS-232 serial tether to a Wi-Fi connection, in all cases, Roomba is more of a tele- presence device than a true robot. The term robot has come to have a flexible definition with the rising popularity of various telepresence/remote-control devices. The most egregious use of robot to mean remote-controlled machine are the battle bot programs on television. The contestants are billed as robots, but they’re all controlled by humans through radio-control transmitters. Perhaps in a few years we’ll have true robot battle shows where the machines are programmed, given a strategy, and let loose to fend for themselves. This chapter shows a few ways to sever the connection with a controlling computer and instead replace the microcontroller brain of Roomba with one you can program. You’ll turn your Roomba into a truly autonomous re- programmable robot. Like all projects in this book, this chapter doesn’t harm Roomba and its original brain is available when you remove the new one you create. In theory you could reprogram the microcontroller chip inside the Roomba, as that’s what the OSMO//hacker device does to upgrade a Roomba’s firmware. iRobot has yet to release specifications on the protocol used to upgrade firmware. They likely never will. Allowing anyone to re-program Roomba is a sure way to brick it, resulting in unhappy customers. There has been some effort in reverse engineering the upgrade protocol, but with the release of the ROI it’s become less of an issue, since it addresses most of what was wanted once you add your own microcontroller that speaks the ROI protocol. Microcontroller vs. Microprocessor A microcontroller is simply a small, integrated computer system designed for a particular purpose. Microcontrollers are pervasive in your life, yet almost totally invisible. You may be unfamiliar with the term and never realized there is a substantial difference between the computer in your laptop and the one in your coffee maker.  Understand microcontrollers  Build circuits without soldering  Make a stand-alone robot out of Roomba  Use the Basic Stamp with Roomba  Use Arduino with Roomba  Build a RoombaRoach  Build a mobile mood light chapter in this chapter 258 Part III — More Complex Interfacing In the 1970s, when computers started to become small and cheap enough for everyday use, engineers realized that the modular architecture of microprocessor computer systems was too complex and cumbersome for designs that didn’t need all the processing power and input/out- put of a normal computer. There were many tasks that needed computation but didn’t need a powerful microprocessor, let alone a screen, keyboard, or printer. So smaller, less powerful CPUs were joined with a few simple I/O devices onto a single chip. These new creations were called microcontrollers. Figure 13-1 is a diagrammatic view of the difference between a normal computer system and a microcontroller system. In a standard computer setup, different physical chips provided different functions: computation, memory, timing, input, and output. These separate devices were joined together by a collection of wires called a bus. The modern PCI bus is a descendant of this com- mon system bus. In a microcontroller, reduced-functionality versions of the distinct devices were placed inside a single physical chip and connected by an internal bus that was usually not acces- sible to the outside. The lack of this bus may seem like a limitation, but in fact it means getting a microcontroller system working is much easier due to the so many fewer connections needed. With a single small device containing everything needed to run algorithms, microcontrollers were embedded in all sorts of devices. This practice has come to be called embedded systems, and designing such systems is an engineering discipline in its own right. Embedded systems are what is responsible for all the exciting advances in our everyday objects becoming smart objects. Modern home computer systems are a kind of hybrid approach. The CPU is still separate, but instead of many separate chips serving different functions, the functionality is consolidated into one or two large bridge chips. Similarly, some microcontrollers are so advanced now as to be able to run modern operating systems like Linux. The best magazine about embedded systems is Circuit Cellar, available at http:// circuitcellar.com/ . It is written by engineers for engineers and can get complex quickly for the uninitiated. But if you want to learn about the newest developments in tiny computa- tional devices, it is a great resource. Parts and Tools There are many microcontroller development kits available that can be used with Roomba. The first shown here, the Basic Stamp, is a standard, easy-to-use, and well-known device. The sec- ond, Arduino, is a newcomer to the scene, but is based on standard parts, is becoming as easy to use as the Basic Stamp, and is much cheaper and more powerful than the Stamp. If you have the time, try out both microcontroller styles. For both styles of projects, you’ll need: Ⅲ Mini-DIN 8-pin cable, Jameco part number 10604 Ⅲ Several 220-ohm resistors (red-red-brown color code), Jameco part number 107941 Ⅲ Jumper wire kit, Jameco part number 19289 Ⅲ Several LEDs, Jameco part number 156961 or similar 259 Chapter 13 — Giving Roomba a New Brain and Senses F IGURE 13-1: Typical computer architecture vs. microcontroller architecture For the Basic Stamp projects, you’ll need: Ⅲ Basic Stamp Board of Education Full Kit, Jameco part number 283101 Ⅲ Two 0.1 µF capacitors, Jameco part number 545561 Ⅲ Two photocells, Jameco part number 202403 For the Arduino projects, you’ll need: Ⅲ Arduino USB board, Sparkfun part number Arduino-USB Ⅲ 8mm Red LED, Quickar part number 8R4DHCB-H or similar Ⅲ 8mm Green LED, Quickar part number 8G4DHCB-H or similar Ⅲ 8mm Blue LED, Quickar part number 8B4DHCB-H or similar Ⅲ Two 8-pin header receptacles, Jameco part number 70754 Ⅲ Single line wire wrap socket, Jameco part number 101282 Ⅲ Small solderless breadboard, Digikey part number 923273-ND or Sparkfun PType-BBM Ⅲ General-purpose circuit board, Radio Shack part number 276-150 Typical Computer Architecture Typical Microcontroller Architecture CPU RAM CLOCK ROM INPUT DEVICE OUTPUT DEVICE INPUT DEVICE OUTPUT DEVICE System bus CPU RAM CLOCK BUS interface ROM INPUT DEVICE OUTPUT DEVICE Internal bus External bus 260 Part III — More Complex Interfacing Additionally, you’ll need the various tools described in Chapter 3. For the Basic Stamp projects, you’ll need the USB-to-serial adapter used in the previous projects. Quickar Electronics ( http://quickar.com ) is one of several small companies that specialize in high-power LEDs and also sell in small quantities to hobbyists. Besides PC-board mount LEDs, they stock the blindingly bright LEDs used in flashlights and traffic lights as well as a wide variety of surplus components. Solderless Breadboards The previous construction projects were all interfaces of one sort or another and thus benefited from the level of sturdiness that you get from soldering a circuit. However when prototyping, it’s usually quicker to sketch out circuit ideas on a solderless breadboard before committing them to solder. If you’re unfamiliar with solderless breadboards, Figure 13-2 shows a typical one with parts plugged in and a kit of pre-cut jumper wires behind it. In a solderless bread- board, groups of five holes are connected together. In the figure, each vertical line of five is con- nected together, and at the top and bottom board between the red and blue strips, each horizontal line of five is connected. The holes are like the holes of an IC socket or header in that they have a spring-loaded metal connection that grabs a wire or part when inserted. And like a socket, repeated insertions wear it out. If you prototype a lot using solderless bread- boards, you eventually collect them as your old ones become flaky. F IGURE 13-2: Medium-sized solderless breadboard with pre-cut jumper wire kit 261 Chapter 13 — Giving Roomba a New Brain and Senses It’s tempting to skimp and not get a box of pre-cut jumper wires. Don’t do it. It’s possible to cut and strip wires yourself (and necessary if you run out of pre-cut wires), but using just any sized wire makes for an ugly and hard-to-read circuit. The ill-fitting wires move around, put- ting stress on the breadboard holes. Making jumper wires takes a lot of time, which is kind of beside the point of using a solderless breadboard. Get a box of pre-cut jumper wires and you’ll be a much happier hacker. Alternatives Although the circuits presented in this chapter are both simpler and easier to build than the pre- vious projects, even easier ways to re-program your Roomba are emerging. RoombaDevTools .com is working on two boards that are functionally very similar to the Basic Stamp and Arduino boards. They are: Ⅲ RooStamp: A carrier board for Basic Stamp 2 that interfaces to Roomba. It is Bluetooth-optional with servo ports and GPIOs exposed to the user, and it is powered by the Roomba battery. Ⅲ RooAVR: A high-end 16-bit Atmel AVR processor with plenty of I/Os, Bluetooth onboard, A2Ds, URART, JTAG, and servo ports, also powered by the Roomba. Both of these boards can also be powered externally if your project needs to draw more current than Roomba can supply. The RooAVR uses the same type of microcontroller as Arduino, so it should be possible to use the Arduino programming environment with it. If wiring up a microcontroller to your Roomba is not your cup of tea and you want to get started immediately making an autonomous robot, check out RoombaDevTools.com for these devices. But hooking up a little computer to Roomba isn’t so hard really, as you’ll see. Adding a New Brain with the Basic Stamp The Basic Stamp was created by Parallax in the early 1990s to address a persistent problem of embedded systems design: making it easy to use. Because microcontrollers are so self-contained, you couldn’t just add a monitor and keyboard to them to see what’s going on. Instead you needed some sort of development system, usually costing thousands of dollars. When you got the development system, learning the strange non-standard languages used to program the microcontroller was daunting. It could be months before you get a working system. And even if you could get all that working, acquiring the microcontrollers themselves was quite difficult unless you were a large company that wanted to buy 10,000 of them. Parallax solved these problems by taking a common microcontroller, placing it on a hobbyist- friendly carrier board and writing a BASIC language interpreter for it. Now anyone who could program in BASIC could buy a single Basic Stamp and get a tiny stamp-sized microcontroller running a program they wrote, and do it in an afternoon. It was a revolutionary way of thinking about microcontrollers and for the past decade the Basic Stamp has been the standard in microcontrollers for hackers. [...]... the Roomba Vpwr (approx 16VDC) line and regulate it to 5 VDC Vin Chapter 13 — Giving Roomba a New Brain and Senses LED1 1 2 3 4 5 6 7 8 9 10 11 R1 12 Vss SOUT SIN ATN GND P0 P1 P2 P3 P4 P5 P6 P7 VIN VSS RES VDD P15 P14 P13 P12 P11 P10 P9 P8 24 23 22 21 20 19 18 17 16 15 14 13 Vss 220 DD TXD RXD +16VDC Vss 8 mini-din 8pin 7 6 5 4 3 2 1 X1 FIGURE 1 3-8 : Schematic for Basic Stamp Roomba Figure 1 3-9 shows... BAUDFAST, [R_START] PAUSE 100 SEROUT RXD, BAUDFAST, [R_BAUD, 3] ‘ 3 == 2400 bps PAUSE 100 SEROUT RXD, BAUDSLOW, [R_START] PAUSE 100 SEROUT RXD, BAUDSLOW, [R_CONTROL] PAUSE 100 Main: DEBUG “at the top”,CR GOSUB Update_Sensors IF BUMP_RIGHT THEN GOSUB Spin_Left Continued 271 272 Part III — More Complex Interfacing Listing 1 3-1 Continued PAUSE 100 0 ELSEIF BUMP_LEFT THEN GOSUB Spin_Right PAUSE 100 0 ENDIF GOSUB... attach a little bit of Velcro between the Board of Education and Roomba 273 274 Part III — More Complex Interfacing Figure 1 3-1 1: The RoombaRoach brain built on the Board of Education FIGURE 1 3-1 2: RoombaRoach scurrying for the dark Chapter 13 — Giving Roomba a New Brain and Senses In order to measure a variable resistor like a photocell or potentiometer, you would usually create a voltage divider with... GND P0 P1 P2 P3 P4 P5 P6 P7 24 23 22 21 20 19 18 17 16 15 14 13 VIN VSS RES VDD P15 P14 P13 P12 P11 P10 P9 P8 Vss 220 DD TXD Vss Vss Vin RXD Vss +16VDC Vss 8 mini-din 8pin 7 6 5 4 3 2 1 X1 FIGURE 1 3-1 0: Adding light sensors for the RoombaRoach Figure 1 3-1 2 shows the Board of Education plugged into Roomba and positioned correctly for the front and back orientation of the photocells To anchor the Board... uploaded to the Stamp and start running Figure 1 3-7 shows a typical setup and a running blink program (although the light looks like a simple white circle when shown in a black-and-white photograph) If the Stamp isn’t detected, make sure the 0-1 -2 power switch on the Board of Education is set to position 1 or 2 265 266 Part III — More Complex Interfacing FIGURE 1 3-7 : Typical setup when programming a Basic... Stamp by using inexpensive parts and having an open-source design Anyone can build an Arduino board like in Figure 1 3-1 4 or build an entirely different-looking one that still abides by the Arduino standards If you do want to purchase a pre-built board, they only cost $29 This is for an entire board, not just a chip An Arduino-capable chip, like the one shown in Figure 1 3-1 5, is a standard Atmel AVR... Hooking Up a Basic Stamp to Roomba Since any pin on the BS2 can do serial input or output and the BS2 uses the same 0–5V signaling that the Roomba does, the circuit is really simple and can be done in a number of ways One possibility is shown in Figure 1 3-8 To implement this circuit, the easiest thing to do is create (or re-use) a Roomba ROI prototyping plug (as shown in Figure 1 1-8 ) You may want to add... not inverted BAUDSLOW CON 396 SEROUT RXD, BAUDFAST, [R_START] PAUSE 100 SEROUT RXD, BAUDFAST, [R_BAUD, 3] ‘ 3 == 2400 bps PAUSE 100 SEROUT RXD, BAUDSLOW, [R_START] PAUSE 100 SEROUT RXD, BAUDSLOW, [R_CONTROL] PAUSE 100 At this point you can send commands to Roomba like normal, but at a low level like in Chapter 3 For example, to tell Roomba to drive forward, the PBASIC command is: SEROUT RXD,BAUDSLOW,... plug and with a few extra components from another experiment For now, ignore the parts below the LED Thanks to the solderless breadboard, the Board of Education, and the Roomba prototyping plug, wiring up this circuit takes just a few jumper wires FIGURE 1 3-9 : Roomba control circuit wired up on the Board of Education 267 268 Part III — More Complex Interfacing The Basic Stamp nomenclature uses Vss to mean... it into Roomba Roomba will wake up and start driving around, avoiding any obstacles it finds One of the nice things about the Board of Education is that you can keep it connected through the serial cable while it’s plugged into Roomba Listing 1 3-1 : BumpTurn.bs2 ‘ {$STAMP BS2} ‘ {$PBASIC 2.5} ‘ what pins DD RXD TXD LED LSRB LSRF INPUT TXD are PIN PIN PIN PIN PIN PIN being used, named as in the Roomba . solderless bread- board, groups of five holes are connected together. In the figure, each vertical line of five is con- nected together, and at the top and bottom board between the red and blue. styles. For both styles of projects, you’ll need: Ⅲ Mini-DIN 8-pin cable, Jameco part number 106 04 Ⅲ Several 220-ohm resistors (red-red-brown color code), Jameco part number 107 941 Ⅲ Jumper wire. connection, in all cases, Roomba is more of a tele- presence device than a true robot. The term robot has come to have a flexible definition with the rising popularity of various telepresence/remote-control devices.

Ngày đăng: 10/08/2014, 04:21

TỪ KHÓA LIÊN QUAN