Baking robot move on bumper hit?

sciguy77

Member
My robot consists of 2 motots, 2 bumper switches, a picaxe axe023, and a power source. It's working well, however it only backs up and turns when the bumper switch is released. This presents a problem, when the robot his a wall it does not back up and turn unless the switch is released. How would I fix this?

Here's my code:

Code:
symbol fw = 20
symbol bc = 200

do
if pin3 = 1 then
low 1
high 0
low 4
high 2
pause 1000
high 1
low 0
low 1
high 0
pause 500
else
high 1
low 0
high 4
low 2
endif
loop
 

lanternfish

Senior Member
My robot consists of 2 motots, 2 bumper switches, a picaxe axe023, and a power source. It's working well, however it only backs up and turns when the bumper switch is released. This presents a problem, when the robot his a wall it does not back up and turn unless the switch is released. How would I fix this?
Hi.

You will be asked to comment your code lines to describe what each line does so that we can better help you with the problem.

Have you thought of making the robot reverse a small distance once it strikes an object?

cheers
 
Last edited:

lanternfish

Senior Member
Some changes to your program

Code:
low 1
high 0
low 4
high 2
can be replaced by

Code:
outpins = %00010101
And what does this do?

Code:
high 1
low 0
low 1
high 0
as it only seems to toggle (twice) outputs 0 and 1

Code:
high 1
low 0
high 4
low 2
can be replaced by

Code:
outpins = %00010010
cheers
 

sciguy77

Member
The new code
Code:
symbol fw = 20
symbol bc = 200

do
if pin3 = 1 then
outpins = %00010101
pause 1000
high 1
low 0
low 1
high 0
pause 500
else
outpins = %00010010
endif
loop
now does nothing. The robot is nonresponsive. How can I fix this and make it so that the robot backs up when the bumper switch is pressed, not released?
 

lanternfish

Senior Member
The new code
Code:
symbol fw = 20
symbol bc = 200

do
if pin3 = 1 then
outpins = %00010101
pause 1000
high 1
low 0
low 1
high 0
pause 500
else
outpins = %00010010
endif
loop
now does nothing. The robot is nonresponsive. How can I fix this and make it so that the robot backs up when the bumper switch is pressed, not released?
sorry, replace outpins with pins

try this

Code:
symbol forw = 130
symbol back = 65
symbol aoff = 0
symbol arev = 1
symbol afwd = 2
symbol boff = 0
symbol brev = 4
symbol bfwd = 8			
symbol rlft = 129			; rotate left
symbol rrht = 66			; rotate right


main:

	pins = forw

bumper:

	if pin3 = 1 then
		pins = 0
		pause 1000
		pins = back
		pause 1000
		pins = rrht
		goto bumper
	else
		pause 1000
		goto main
	endif
 
Last edited:

sciguy77

Member
Hmm. Still nothing. No response. I checked the batteries and they're fine. Must be a problem with the code, though no errors were produced.
 

BeanieBots

Moderator
As suggested by Lanternfish, comment every line of your code.
Simply by doing that, you will probably solve the problem yourself as well as letting everyone else know what your code is doing.

However, for now, it is probably a good idea to stick with using high/low rather than pins=... as you may find it easier to understand.

Once you have clearly stated what action "high 1" does and what makes "pin3=1" plus all your other lines, it will become obvious what you need to do.

Try it.
If you still cannot get it to work, post again with your commented code.
 

hippy

Ex-Staff (retired)
Is it forward when pin3=1 ? If so, the code which operates when pin3=0 runs very quickly ( no substantial pauses ) so is it backing up only slightly then moving forwards ?

Plus, check you have the appropriate pull-up or pull-down resistor on the switch input.

The code does one thing when no contact, and another when there is contact with nothing to stop it looping, so it shouldn't need the contact switch to be released before backing up.
 

sciguy77

Member
Ok, here's my commented code. I need to figure out how to make it be able to execute the on hit code when the bumper switch is hit, not released.

Code:
symbol fw = 20
symbol bc = 200

do
if pin3 = 1 then 'if the bumper switch is hit. For some reason only works when released.
low 1
high 0
low 4
high 2 'Backs up motors
pause 1000 'Pauses for 1 second
high 1
low 0
low 1
high 0 '1 motor on, other off.
pause 500 'pause for 1/2 second
else
high 1
low 0
high 4
low 2 'move both motors forward
endif
loop
 

lanternfish

Senior Member
Are the bumper switches a microswitch? And are they a double throw type? And if so, are they wired correctly? If they are double throw, try swapping the wire from/to pin 3 to the other (spare) terminal on the microswitch(es)

cheers
 
Last edited:

BeanieBots

Moderator
I was hoping for more detailed comments.
Let's take this line.

if pin3 = 1 then 'if the bumper switch is hit. For some reason only works when released.

The reason you are struggling is because that line tells me (and therefore you) very little about what is going on.

An obvious question has to be, is "1" the value when pushed or released?
If you make full use of 'symbol' and comments, your own code will answer your questions.

Symbol Pushed=??
Symbol Bumper= pin3

If Bumper = Pushed then....

Either you have your bumper switch logic the wrong way around, or your motor direction control the wrong way around.
Do some simple checks using debug or sertxd and confirm if a PUSHED bumper is "1" or "0".
 

hippy

Ex-Staff (retired)
Re-reading the original post I still suspect its a hardware issue because the behaviour described is 'impossible'.

It is claimed, "the robot his a wall it does not back up and turn unless the switch is released". The code can be executing in either one or two paths dependant on pin3 level, forward when open, backwards when closed. When the switch closes we can accept the PICAXE does not back-up as it should, but opening the switch would then put it into the forward code again, not causing it to back up.

What is happening with the input pin needs to be examined.
 

Dippy

Moderator
Post a schematic (circuit diagram) of your switch arrangement and motor drive.
Show us how they connect to your PICAXE.

Post it exactly. Then check your actual circuit.
The logic is really easy and it's pointless wrestling with code if your hardware is dodgy.
 

Technical

Technical Support
Staff member
Re-reading the original post I still suspect its a hardware issue because the behaviour described is 'impossible'.
Impossible if the input jumper for the switches is in the correct left hand position.

However if the jumper is in the right hand incorrect possition, quite possible - the switch takes the serial input high, the chip resets and stays reset until the switch is released...

Sci guy - see page 3...
http://www.rev-ed.co.uk/docs/axe023.pdf
 
Top