Help programming first bot?

sciguy77

Member
Hi,

I'm done building my 1st robot, which consists of an axe023 board, two bumper switches, and two motors. However, I'm rather short on time and know nothing of Basic or the picaxe programming editor. Could someone give me a hand in writing the code for my robot? I'm trying to make it do something like this:

motor 1 & 2 drive forward
if bumper 1 or 2 pressed
motor 1 & 2 drive in reverse
motor 1 & 2 pause
motor 1 drive forward
loop

I've been reading the manuals, but I'm still not completely sure how to do this.

Thanks.
 

Rickharris

Senior Member
Hi,

I'm done building my 1st robot, which consists of an axe023 board, two bumper switches, and two motors. However, I'm rather short on time and know nothing of Basic or the picaxe programming editor. Could someone give me a hand in writing the code for my robot? I'm trying to make it do something like this:

motor 1 & 2 drive forward
if bumper 1 or 2 pressed
motor 1 & 2 drive in reverse
motor 1 & 2 pause
motor 1 drive forward
loop

I've been reading the manuals, but I'm still not completely sure how to do this.

Thanks.
Somewhere in these posts I give an outline programm to control a simple robot - you could start with that - try a search on my name to find it - It was quite recent.

To specifically write any code should anyone be happy to do that they will need a lot more information about what you have done - i.e. what picaxe, what input/output is connected to what?

What do you expect the bot to do. help us to help you.

Oh by the way, even with limited time the experience of learning to do the hard bit is ll part of the journey.

Is this a school project?

You need to get a grasp of the following commands at least

high
Low
Gosub and labels
Pause/wait
If then
for next.

With these you would be able programme your robot to do simple routines or tasks.
 

sciguy77

Member
Thanks for the response. This isn't a school project, but the reason I'm pressed for time as I'm only hours away from a competition deadline. I have experience programming with Python and ActionScript 3.0, but I haven't programmed hardware in a long time (last time I did I actually failed miserably).

I have no problem learning Basic, on the contrary I look forward to adding it to my coding toolbox, I'm just racing against the clock right now.

I'm not sure as to which post you're referring to, unfortunately I'm using the 08 not the 08M, so I hear things are a bit different.

I apologize if I was unclear as to what I wanted the robot to do. Here are the specifics,

I'm using an axe023 motor driver board which contains a 08 picaxe microcontroller and a L239D motor driver. I have it hooked up to two Omeron bumper switches which are done through the 4 pins farthest from the programming audio jack (pins 3, 5, 7, & 8 I believe). There are two geared motors hooked up through pins 0, 1, 2, & 4 on the axe023 board.

With this robot I hope to achieve simple navigation and collision avoidance with the bumper switches. The idea is to have the robot roam through a room and be able to bump into an object, go in reverse, then turn right or left and keep going.
 

adub

New Member
Code:
#picaxe 08
'robot consists of an axe023 board, two bumper switches, and two motors.
do
   ' assumes active high. If it just goes backward and spins use 0 instead of 1.
	if pin3 = 1 then
		gosub goBackward
		pause 1000
		gosub spinRight '(or left...your choice.)
		pause 500
	else
		gosub goForward
	endif
loop

'Spinning could be backward. 
'Depends on how the motors are hooked up.
'The two motors will turn in opposite directions and turn like a tank.
'Got the info on which pins to go high or low with from the datasheet.
spinRight:
	high 0: low 1 ' motor A
	low 2: high 4 ' motor B
return

spinLeft:
	high 2: low 4 ' motor B
	low 0: high 1 ' motor A
return

goForward: 'both motors on forward.
	high 0: low 1 ' motor A
	high 2: low 4 ' motor B
return

goBackward: 'both motors on forward.
	low 0: high 1 ' motor A
	low 2: high 4 ' motor B
return
 
Last edited:

sciguy77

Member
My bot seems to have some kind of trouble going in reverse, I tested it with an external power source, and the motors are fine.
 

adub

New Member
Yeah. Try "gosub goBackwards". Same with goForward...try "gosub goForward". And spinRight should be...you guessed it... "gosub spinRight". I typed the program in less time than it took to write this message.

It won't spin correctly either. Looks like I cut and pasted the wrong second lines into the wrong subroutine. Need to switch spin right's second line with spin left's second line. Give it a try.

All errors added at no extra charge as a training exercise for you. Aren't I thoughtful? ;)
 
Last edited:

Rickharris

Senior Member
This is very simple and not optimised so I hope you can understand how it works because you may need to play with it. It will work on an 08
Code:
'Assumes pin0 = left forward
'pin 1 = left back
'pin 2= right forward
'pin 4 = right back
'pin 3- bump switch input.

start:
high 0
high  2  ' move forward
check:
if pin3=1 then turn  'checks if you touch anything assumed input is high when touched.
goto check

turn:
low  0
low  2 ; stop

high 2  'drive left motor forward
high 4 ' drive right motor back this makes robot turn
wait 2   this number controls how far it turns.
low 2
low 4

goto start  'move forward again
this is a simmple approach to what I think you want to do - You may need to play with the pin number or your motor connections as well as the wait delay to control how far the robot turns.

have fun
 

westaust55

Moderator
For an example of basic code have a look at the rev Ed Exemplar Buggy project.

With the Program Editor running and a program window open,
From the toolbar select: Help / Picaxe Catalogue.

A small window will pop up. At the bottom right of that window is a button labelled "Exemplar Projects".

Click that button and you see a list of projects. Select the project "buggy.pdf"
 
Top