DIY Virtual Wall for Roomba – Part One

Last weekend, we finally decided it was time to get a Roomba robotic vacuum.  This decision was made easier by the relatively good price and availability of the iRoomba 585 at Sam’s Club.  While this isn’t a product review, I’ll take a moment to say that so far the results are excellent.

Included with the unit was one “virtual wall“, a little black box that shoots out an infrared beam, creating an invisible line you don’t want the robot to cross.  This allows you to keep it from going somewhere you don’t want it to go without physically placing some obstruction in its path.  The virtual wall works great, but one just isn’t enough in our case.  Luckily, it took just a bit of Googling before I was ready to build my own.

Circuit

It turns out that the virtual wall isn’t too complex.  Basically, it sends out a repeating pattern of ON/OFF infrared signals, each one a millisecond long.  These signals ride on a 38kHz carrier frequency, just like most infrared remote controls, meaning that an ON signal is actually being pulsed ON/OFF about 38,000 times per second.  I won’t go into more detail here, especially because it’s beyond the scope of my expertise, but please see the references for more information on carrier frequencies.

Only a few parts were required to start building my own virtual wall, all of which I was lucky enough to have on-hand.  Here I’ll put out my standard disclaimer that my electronics knowledge is pretty limited, and anything that I cobble together runs mostly on dreams and good intentions.  I did my best to throw some math into this circuit, but I’m always open to helpful hints as to how to improve things.

 

I used a PIC12F683 microcontroller because I have a bunch of them.  They’re inexpensive and pretty robust, so I bought a pack of ten a while back on eBay.  In this simple circuit, I use the PIC’s pulse-width modulation (PWM) capabilities to generate the 38kHz carrier frequency.  The PWM pulses are output through the GP2 pin, which turns on the transistor, letting current flow through the infrared LED, thus generating the required signals.

Circuit Diagram

Components

  • PIC12F683 Microcontroller
  • R1 – 330 ohm 1/4-watt
  • R2 – 12 ohm, 1/4-watt
  • Q1 – 2N3904 (Datasheet)
  • L1 – Infrared LED (Datasheet)

 

Source Code

The source code is written for the HI-TECH C compiler, which is included in the older version of the MPLAB IDE I’m still using.  I first tested sending a steady stream ON/OFF pulses, which had the desired effect of making the robot stop and turn.  In an attempt to extend battery life, however, I’ve settled on sending out a blast of pulses, then putting the microcontroller to sleep for a couple hundred milliseconds.  My assumption is that the robot won’t travel too far in that time.  So far, the results look positive.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

#include <htc.h>

 

__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF &

    CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF);

 

#ifndef _XTAL_FREQ

 #define _XTAL_FREQ 2000000

#endif

 

#define PWM_OFF CCP1CON = 0x10

#define PWM_ON CCP1CON = 0x1c

 

#define BURST_COUNT 10                  // How many IR bursts to send

 

// GP2 - PWM output

void main() {

 

    int i;

 

    OSCCON = 0x51;                      // Internal 2MHz osc.

 

    ADCON0 = 0;                         // all pins digital

    ANSEL = 0;                          // all pins digital

    CMCON0 = 7;                         // Comparators off.

    TRISIO = 0;                         // all output

    GPIO = 0;                           // all pins low

 

    PR2 = 0b00001100 ;                  // Set up PWM for roughly 38kHz

    T2CON = 0b00000100 ;

    CCPR1L = 0b00000110 ;

    PWM_OFF;

 

    PSA = 0;                            // Don't use Timer0 prescalar

    WDTCON = 0b00010000;                // Prescalar = 1000 = 8192 = 272ms

 

    while (1){

 

        // Send a few IR bursts

        i = BURST_COUNT;

        while( i-- )

        {

            // Virtual wall is 1ms on, and 1ms off

            PWM_ON;

            __delay_us(1000);

            PWM_OFF;

            __delay_us(1000);

        }

 

        // Then sleep for a moment

        SWDTEN = 1;     // Enable watch dog timer

        asm("sleep");

        SWDTEN = 0;     // Disable watch dog timer

    }

}

Next Step

I’ve got the microcontroller programmed and the components permanently soldered onto a perma-proto board.  I’ve tested it using a CR2032 coin cell battery as the 3-volt source, and positioning it just right in a doorway with a small piece of a drinking straw over the infrared LED to make it more directional.  The next step, and the one most likely to confound me, will be finding a suitable enclosure, especially one pretty enough to be left out in the open and not look like I made it.

References

http://www.enide.net/webcms/index.php?page=virtual-wall-for-roomba
https://sites.google.com/site/irobotcreate2/createanirbeacon
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html
http://led.linear1.org/1led.wiz

 

Update 8/9/2014:  I posted a second part to this article here that includes the final product.

http://misc.ws/2014/02/27/diy-virtual-wall-for-roomba/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章