2.11.2008

MouseBot Get's Brains - Software

Software for Wall Hugger Action:



Part 5 Software Makes it Go!


This is the basic wall follower software... This software makes the bot turn left to hug the wall, with the values given, you will find MouseBot is FUN!!!

There are routines for left and right turn and the object detection operation as well as a speaker (squeaker) for your mouse. I'm still waiting for the piezo-speaker to come in the mail... I had one, but it was already in use. By using pin0 as a multi-purpose pin, we can add a speaker, which gives us some noise when downloading, but allows the little picAxe m8 to serve of the brains for the BEAM style "Wall Hugging Mouse" conversion to BEAM with BRAINS...

I know you'll want to do crazy things with your bot, so have at it, put the link to your MouseBot with Brains video so we can all see it...

' ------------------------------------------------------------
' BEAM bot Brains
'
' Basic Operation of mouse as "wall hugger" just like original
' Except for:
' IR detector "whiskers" lets the mouse find it's way
' Follows walls without physically touching
' Still has basic motor control with microcontroller picAxe m8
' Copyright 2008 Jim Huffman
' Permission granted to experimenters to use all or part
' Note copyrighted material frequency chart at the end


' Basic Interpreter Directives
#picaxe 08m


' Microprocessor pinouts and layouts 08m
symbol LED = 0 '(leg 7) Serout/LED
symbol rightDrv = 1 '(leg 6) High = motor on
symbol pout = 2 '(leg 5) PWMout2
symbol IRin = 3 '(leg 4) Input only pin3
symbol leftDrv = 4 '(leg 3) High = motor on
' (leg 1 Vdd, leg 8 = Vss, leg 2 = Serial In)
symbol spkr = 0 'extra symbol, speaker drive

' Variables used in program
symbol xCnt = b0
symbol rightDrvFlag = b1
symbol leftDrvFlag = b2
symbol objDetFlag = b3
symbol rightDrvTime = b4
symbol leftDrvTime = b5

init: ' Initialize chip so OK with low Vcc supply
disablebod
setfreq m4
' flash LED
high LED
pause 1000
low LED
pause 1000 'wait for Panic resets, etc...

' initialize variables
leftdrvTime = 120 ' Permits balancing forward motion
rightDrvTime = 100 ' allows motor speed balancing
low rightDrvFlag, leftDrvFlag, objDetFlag, xCnt ' initialize values


' Main driving loop avoids walls
main:

gosub driveforward
pause 10

goto main



' Move forward one time after the other - makes mouse wiggle
driveforward:
gosub objDetect 'makes 1/2 wiggle unless there is an object
' the other 1/2 wiggle even if there is a wall
high leftDrv
pause leftDrvTime
low rightDrv,leftDrv 'stop\
pause 10
return

' Driving commands (turns) stick in the appropriate spots
turnRight:
high rightDrv
pause rightDrvTime
low rightDrv,leftDrv 'stop
return

turnLeft:
high leftDrv
pause leftDrvTime
low rightDrv,leftDrv 'stop
return

' If an object is "sniffed out" then set objDetFlag high
objDetect:
pwmout pout, 22, 50 '25, 52 ' 26 usec period = 38.4 kHz
pause 3 ' Begins continuous output PWM

if pin3 = 0 then ' Object Detected
pause 3
pwmout pout, 0, 0 ' stop the continuous pulse output
else
' 1/2 wiggle (unless there's a wall)
high rightDrv
pause rightDrvTime
low rightDrv,leftDrv 'stop
pause 10
endif
pwmout pout, 0, 50 ' stop the continuous pulse output

return



MakeSound: ' fast-beep make a squeek...
setfreq m8 'kick into high-speed mode
for xCnt = 100 to 130
pulsout spkr, xCnt
next xCnt
low spkr
setfreq m4
return


' Chart of frequencies courtesy of PHAnderson...
'------------------------------------------------
' From IR_1.Bas
'
' copyright, Peter H Anderson, Baltimore, MD, May, '04

'
#rem ' PWMOut pout, Period, DutyCycles
PWMOut pout, 25, 52 ' 38.4 kHz
PWMOut pout, 24, 50 ' 40.0 kHz
PWMOut pout, 23, 48 ' 41.6 kHz
PWMOut pout, 22, 46 ' 43.5 kHz
PWMOut pout, 21, 44 ' 45.5 kHz
PWMOut pout, 20, 42 ' 47.6 kHz
PWMOut pout, 19, 40 ' 50.0 kHz
PWMOut pout, 18, 38 ' 52.6 kHz
PWMOut pout, 17, 36 ' 55.5 kHz
PWMOut pout, 16, 34 ' 58.8 kHz
#endrem

2.08.2008

MouseBot Is Quick! Powerful Motor Driver Transistors

Beefy Motor Driver Transistors - Makes MouseBot Move Quick. Like a Mouse!



Part 4 Wall Follower Mouse 'Bot Transformation

Hold on, last time we said we would add some gumption to our MouseBot. We will accomplish this feat while reducing the power disapated in those little innocent 3904's... Basically, this means we don't melt our Mouse's head...

From Mouse Bot Tra...

While the concept is covered in this schematic, the real-world shows that these motors are drawing a lot of power at startup, this overheats the 3904's, so far this means we've only been testing MouseBot... It's time for this robot to distribute the power to another transistor to stabilize the smaller transistors. This is going to allow MouseBot to do all sorts of things..

From Mouse Bot Tra...

MouseBot gets really real after you put in the TIP-29's (or whatever lives in your junkbox)... Now the mouse scoots so fast, it seems a little nervous, like it's biological counterpart...

For the issues and tricks, here's what I did:
  • Mount the Power Transistors right down at the motors, if you bend them like wings, you can connect to their bases and feed power directly from the on/off switch
  • With the batteries I'm using AA-1700 mah, you have to turn off brown out protection to allow the processor to go under 3 and 1/2 volts or so, you also need to keep the batteries fresh
  • The four battery clip is a little large and collides with the top of the back, shim it in the back so it leans forward, that works.
That's it!!

Have fun programming your MouseBot!!!

2.06.2008

MouseBot Electronic Motor Control

MouseBot Electronic Motor Control



Part 3 Wall Follower Mouse 'Bot Transformation



Let's put the ram in ramalamadingdong!

First Ya Need a Motor... Pretty much any-old hobby motor will work here. In Mousebot, we have not just one motor, but two... That means, of course, we can steer mousebot... That's how he works in the first place, using two motors, one that steers "into" the wall, and other that pulls mousebot forward into the open spaces...

We have our mousebot whiskers ready to go now (see blog) with a cool object avoidance system overseen by a picAxe m8 8-pin processor. By judicious re-use of pin0 for running the redLED in MouseBot's head and a piezo noise maker, we have two pins left over...

That means we could use one pin to turn on one motor and with two pins, this is most promising for MouseBot... Let me show you:

From Mouse Bot Tra...
This is electronic motor control in its most basic form. When the microcontroller output pins go high, they "turn on" the NPN transistors and large currents run through the motors. If the motors are working too hard, you just reduce the duty cycle, that is, you pulse the motors with a signal where you control the ratio of off/on time.

MouseBot's simple driver will not be able to back up, but, MouseBot can stop on a dime, and can turn on it's motors independently of each other, like this:

' System resources 08m pinouts and layouts
symbol LED = 0 '(leg 7) Serout/LED
symbol M1 = 1 '(leg 6)ADC1
symbol pout = 2 '(leg 5)ADC2,PWMout2
symbol IRin = 3 '(leg 4)
symbol M2 = 4 '(leg 3)ADC4
'(leg 1 Vdd, leg 8 = Vss, leg 2 = Serial In)
symbol xCnt = b0

'
high LED
pause 1000
Main:
low LED

pwmout pout, 22, 50 '25, 52 ' 26 usec period = 38.4 kHz
' for 40 kHz, use pwm IRsignal, 24, 50
' MAX Range about 4-5 ft 26, 50
' 3ft 27, 50
' 6" (closeup) 18, 40
' 2" (eXtreme closeup) 10, 40
Pause 3 ' Begins continuous output PWM


if pin3 = 0 then ' Object Detected
high LED
low M2
pause 1000
' go do things...
endif

gosub driveAround

pwm pout, 00, 00 ' turn off the PWM
Pause 100
GoTo Main

driveAround:
high M1,M2
pause 100
return

So the software controls the MouseBot's motors as it runs around... As shown in the test Run listing above. There are lot of things wrong with this piece of code, it makes no effort to make the motor run with any efficiency or multiprocess the motor and the picAxe simply by using an interrupt driven system. Those improvements will come later, the whole idea here was to add a picAxe to the Wall Following Mouse Robot. Since we have enough pins to do the object detection, it was decided to use the two extra pins to control MouseBot.

Let's add the transistors shown like in the conceptual schematic shown... Then the whole Mouse Bot project is done, though ol' Mousey will never go backwards. Most mice I've dealt with ran forwards anyway, of course that could be because a pack of humans with brooms and loud screaming voices were after them...

Finished!

From Mouse Bot Tra...
In an odd way, I'm kinda dissapointed because I've been "intending" to do this conversion for so long, now that its done I don't have much to blame myself for, so I'll have to take on another project, like making some sophisticated software for MouseBot, maybe with random number generators. Also, I can't wait to use the sensitivity controls, I love being able to shift the frequency from the IRLED and control how "far away" MouseBot stays from objects...

Closeup:
From Mouse Bot Tra...

Hardware Finished... Of course, the software needs fixin' I'll get to that later, I can usually cram a few hours of programming in more easily than a few hours with the hardware. And, software is really all that's left to extract the most fun from the MouseBot...

Mouse Bot Rules!

If you try this test, you will notice MouseBot gives up the ghost very quickly... This effect is caused by driving the 2N3904's too hard... Don't run it this way other than short tests, or with the body off the robot... You'll melt MouseBot's head!

But wait! All is not lost! We have the next (and hopefully, final) episode in the transformation of the wall following robotic mouse: Next Time... A non-melting drive system....

2.03.2008

MouseBot: How to Make an IR Object Detection System

MouseBot: How To - IR Object Detection System!



Part 2 Wall Follower Mouse 'Bot Transformation



The Nose Knows...

Last time we took the little mousebot down to it's skeleton, let's put something back. We want our mousebot to look around without actually touching things. It's a solid improvement to the wall follower, it's a good robotics first step and it involves something almost every roboticist has to face: Object Detection and Avoidance. We will use Infrared (IR) generators and detectors to give the wall following mouse a touchless interface to the wall.

Let's make an IR Object Detection system. While we intend to use the module in our little wall follower mouse upgrade, anyone can use it for any "bot." Basically, it's pretty simple if you have the right attitude about just how much functionality to expect from the microcontroller chip you use.

The little teeny 8-bit pic microcontroller in the version of the picAxe chip seemed a fun choice and could give us a whole load of ideas about how to make it even cooler...

Basic IR detection circuit:

Here's the diagram of the nose test circuit...



From Mouse Bot Tra...

Driving the IR LED is easy with most chips, AVR, Stamp module, everything you can imagine, but with the m8 picAxe, there's only one way to do it... While that way is pretty neat, you gotta dedicate the whole chip to giving our mousebot the nose to end all noses. That's just what we do in this project. Give the picAxe one job to do and expect it to do that job well...

This mouse's nose will have an m8 picAxe chip driving any one of a handful of IR 3-pin IR detector modules while supplying it's own 38 kHz signal to the IR detector... The issue is that when you drive the modulated IR LED you can't stop sending while you check the IR detector because you'd have to shut off the IR you are generating... The m8 picAxe has a pwmOUT command (in Basic) which switches on and continues to run while the picAxe goes on to other instructions...

You guessed it, we start up the IR LED, then let it run while the processor takes a peek at the IR Detector output... In our case, if the detector input goes low (meaning it picked up the reflection of an IR signal from the LED, the m8 responds. In this example, it simply turns on an LED, but in the mousebot, it could tell the other motor to run, so it would turn mouse bot away from the refected signal. Without the reflected signal bouncing off the wall, the mousebot motors flip around and the motor switches so the power is applied to the wheel until it turns again and again, wiggling its way along the wall, just like it did before we cannibalized it.
From Mouse Bot Tra...

After all that, we intend to get the little mouse bot running without touching the walls, but performing only the simplest function... Wall Following... Since we have a microprocessor running the nose, we might as well take advantage of this by adding some sophistcated features... Like variable sensitivity...

If you drop mousebot in the middle of a big room, he needs to be able to find a wall to follow, so, by using the picAxe, we detune the IR LED's output signal so it still stimulates the IR Detector, but has very little of the power... Thus we can use the sensitivity of the "nose" to determine how far away from the wall the mousebot will wiggle along at... Oh boy, now the little guy can use the smart nose to enhance it's capability and justify the four bucks spent on the picAxe...

We will still have motor control to deal with when we finish this project, but knowing where you are going and what you are looking at will go a long way to improving the Wall Following Mouse Robot...

And here is the code for the test circuit:

#rem
PWMOut pout, Period, DutyCycles
PWMOut 3, 25, 52 ' 38.4 kHz
PWMOut 3, 24, 50 ' 40.0 kHz
PWMOut 3, 23, 48 ' 41.6 kHz
PWMOut 3, 22, 46 ' 43.5 kHz
PWMOut 3, 21, 44 ' 45.5 kHz
PWMOut 3, 20, 42 ' 47.6 kHz
PWMOut 3, 19, 40 ' 50.0 kHz
PWMOut 3, 18, 38 ' 52.6 kHz
PWMOut 3, 17, 36 ' 55.5 kHz
PWMOut 3, 16, 34 ' 58.8 kHz
#endrem


' System resources 08m pinouts and layouts
symbol LED = 0 '(leg 7) Serout/LED
symbol io1 = 1 '(leg 6)ADC1
symbol pout = 2 '(leg 5)ADC2,PWMout2
symbol IRin = 3 '(leg 4)
symbol io4 = 4 '(leg 3)ADC4
'(leg 1 Vdd, leg 8 = Vss, leg 2 = Serial In)
symbol xCnt = b0

'
high LED
pause 1000
Main:
low LED

pwmout pout, 14, 40 '25, 52 ' 26 usec period = 38.4 kHz
' for 40 kHz, use pwm IRsignal, 24, 50
'
' MAX Range about 4-5 ft 26, 50
' 3ft 27, 50
' 6" (closeup) 18, 40
' 2" (eXtreme closeup) 10, 40
Pause 3 ' Begins continuous output PWM


if pin3 = 0 then
high LED
endif


pwm pout, 00, 00 ' turn off the PWM
Pause 100
GoTo Main


Invisible Whiskers


MouseBot is ready for it's "sniffer" or infrared eyes... First we tape down the pc board that will hold the IR LED's that will make the mousebot eyes...
From Mouse Bot Tra...


Now with everything in place, make a couple of marks where the eyes will be...
From Mouse Bot Tra...


From Mouse Bot Tra...

Now we have two eye-marks which we plan to drill out so the IR LEDs protrude from the mouse body... Kinda like little mouse eyeballs... But remember, these are not sensors, these are generators... It's the NOSE that counts, the IR Detector lets the Mouse "sniff" around basking in reflected IR from the eyes...

It's time to fire up the drill...
From Mouse Bot Tra...

Now this bot's got eyes...
From Mouse Bot Tra...

Almost time to solder, except we need to make a decision about just how much we want this version of mousebot to do... If we need rudimentary motor control, that means one thing, for a more exotic motor control, we'll use another picAxe, this one dedicated to moving the mouse's body around...

From Mouse Bot Tra...

Now the soldering is complete!

Oh boy, this means I'm ready to enclose our Infrared Object Detection system into the MouseBot body to make sure the experiment worked, remember IR Detector on the Inside and IR generator LED on the outside of the body?

So I crammed everything into the mouse body and Voila!


Next Step? Well, let's hookup some rudimentary Motor Control for the MouseBot so it can go run around the floor..

2.01.2008

Mouse Bot Transformation

Wall Follower Mouse 'Bot Transformation


Part I. Transformation Begins:


At last I've begun to transform the little wall follower mouse into something a little smarter... The mouse bot is pretty cute, and simple... The mouse itself is a BEAM robot, that is, it simply consists of a SPST switch with a long "whisker"... When you turn on the bot, immediately one of the motors starts to run...

You can see the whisker extending from the body of the BEAM bot in the picture:
From Mouse Bot Tra...

You can see the whisker at the top of the photo...

So the motor is on, the mouse turns "into" the whisker, then the whisker contacts the wall, the SPDT switch throws and Voila! We turn off the left motor and turn on the right motor which pulls the mouse away from the wall, then the whisker unbends, and the SPDT switch action, you guessed it: Fires up the left motor again.
From Mouse Bot Tra...

The result is the mouse runs along against any "wall" and follows the wall, wiggling from one side to the other thus simply pulling itself along this way... Until the Battery runs out... It's a C-Cell - - You're going to have a long wait with each motor pulling only about 50 ma with roughly a 50% duty cycle...


Let's Gut This Mouse!



Don't worry, it's not going to be as messy as your old biology class... (Nor as sickening.) We need to strip the mousebot down to its essentials and make sure everything is going to fit together the way we hope:

From Mouse Bot Tra...


The wall follower taken to it's skeletal self:




I made a bracket from some electrical interconnect tabs which are about an inch long, drilled and rounded on each end. These are easy to bend. So I can check to see how the proposed pcb will mount.



From Mouse Bot Tra...



Now I put the cover over it to guesstimate whether or not it will all fit together




A closer View:

From Mouse Bot Tra...

Whoo Hoo! It looks like everything will fit...

Now my hopes are high for this project!

It's time for the high tech stuff... We've stripped down our Wall Follower mouse robot and we are ready to add some fun stuff!

We start with the nose... See next post for object detection...