Less Is More 08M2 Robot

#1
Hello All,
I built a robot using the 08M2 chip. I have a write up on it on this website: [URL="http://letsmakerobots.com/node/8408"/URL]
It ran ok with the original code but I wanted to update it. Here is the updated code:
'****************************
Code:
'Robot#2_R1.bas
'Picaxe 08M2 MicroProcessor
'I/O Pins
'Servo = Output 0
'IR Sensor = ADC Input 1
'Motor Control = Output 2,4
'Motor Forward = high 2: low 4
'Motor Reverse = high 4: low 2
'Motor Stop = low 2: low 4
'Servo 80 = Rotate Left
'Servo 175 = Center
'Servo 250 = Rotate Right
'*****************************

'** Directives
#picaxe 08m2        '08m2 Chip
#com 3            'Com Port

init:
servo 0,175            'Center Servo
pause 100

main:
low 2: low 4        'Motor Stop
pause 150
gosub ir
high 2: low 4          'Motor Forward
do
    readadc 1, b3
    pause 50
    high 2: low 4     'Motor Forward
    pause 200
        if b3 > 90 then
        exit
        endif
loop
goto main

'-----------------------------------------------
ir:
servopos 0,80     'Look Left -60 deg
pause 250
readadc 1, b0     'Read IR store at b0
pause 50
servopos 0,175    'Look Straight Ahead 0 deg
pause 250
readadc 1, b1     'Read IR store at b1
pause 50
servopos 0,250    'Look Right +60 deg
pause 250
readadc 1, b2     'Read IR store at b2
pause 50
servopos 0,175    'Servo = Center
pause 250
if b0 => b2 then
    goto LTurn 
    else
    goto RTurn 
endif
return    
        
LTurn:
servopos 0,250
pause 250
high 4: low 2     'Motor Reverse
pause 750
servopos 0,175    'Servo = Center
pause 250
high 2: low 4     'Motor Forward
pause 500
return        

NoTurn:
servopos 0,175    'Servo = Center
pause 250
high 2: low 4     'Motor Forward
pause 500
return    

RTurn:
servopos 0,80
pause 250
high 4: low 2     'Motor Reverse
pause 750
servopos 0,175    'Servo = Center
pause 250
high 2: low 4     'Motor Forward
pause 500
return
If you look at the IR: code there are 3 storage locations. I am looking at b0 & b2 to compare readings. I would like to look at b0, b1, b2 to select the best path to take. I am having trouble writing anything that will work. Anyone have any suggestions how to accomplish this?

Thanks for any help!

-Gary
 
Last edited:

erco

Senior Member
#2
Nice bot, Gary! Looks like you're upgrading your 2009 08M robot to an 08M2 chip. Sweet, I also enjoy getting as much as possible from these little 08M2s. If you still have input pin C.3 vacant, you could add an IR receiver so you can control it with a Sony TV remote.

Are you sure that's your latest code? I'm trying to run it in my head. Your subroutine "NoTurn" (which drives straight ahead) is never called.

The short MAIN loop in your code above reads

Code:
main:
low 2: low 4        'Motor Stop
pause 150
gosub ir               [COLOR="#FF0000"]' this calls your scan routine[/COLOR]
high 2: low 4          'Motor Forward
do
    readadc 1, b3
    pause 50
    high 2: low 4     'Motor Forward
    pause 200
        if b3 > 90 then
        exit
        endif
loop
goto main
But since the bot in your LMR video doesn't scan via subroutine "ir" on powerup, I suspect that's not the actual code in the bot. Perhaps "ir" is actually called immediately after your do loop, which drives forward until it senses an obstacle then stops.

WRT using all 3 distance variables, it seems like you are using them already in various parts of your program. You drive forward until the sensor reading is above 90, then stop to look left and right, backing up to get away from the obstacle and turn toward the more open direction. Sound logic.

But if you get stuck in a "box canyon" where both left and right measurements are less than your forward measurement (likely under 90 from your code) then you could back straight out. Simple enough to add those IF checks inside your ir subroutine.

Great work, keep us posted. Nice to see some active robot projects! I'm also busy building Picaxe bots now but I'm not free to share, they are proprietary contract work.

Here's one of my previous 08M2 tricycle bots doing figure 8's.

 
#3
Thanks for the comments Mr. erco!
This is the program loaded onto the 08m2. I have played with it from time to time since 2009. I put in the NoTurn routine but could not figure out how to call it to make it work. I am still trying different code and reading the manual. I actually have a IR sensor made up for tv remote control. I will add it and see if I can get that to work.

I like your Trike! Neat little bot.
Again thanks for your help.
Regards,
-Gary
 
#4
Erco... I took your advice and added the IR receiver for an extra remote control. All my IO is now used. The code has been re-written for the IR. All that is needed is the universal tv remote. See if I can find one this weekend. Here is a new photo of the robot.
DSCN1468.JPG
 

erco

Senior Member
#5
Excellent. Is that mast just to hold up your IR receiver? If so, you may not need it, as IR signals are ridiculously strong and reflect off walls and ceilings. OK to mount the the receiver right on the breadboard pointing upwards.

It's a good feeling using up all the I/O pins, huh? You're aware you can further use the serial programming pins ? :)

Serial input C.5 can be connected to an active high front bump switch. Serial output C.0 can be used as an output, I like to drive a beeper or even another servo.

Keep at it! :)
 
Top