Problem with MicroBot

m_pratley

New Member
Dear Forum,

I have pruchase the microBot and am have trouble get it correctly working. I have connected a servo, two IR sensors, a SRF004, a speaker and a DC fan controlled by a TIP transister. I have upgrade to an 18X.

My problem is that I set the speed using a modified example program, and when I stop the motors, they keep going! A simplified version of the program can be found below:

'Setup Pins
' out pins 7 - 4 used by motors

symbol pout_servo = 0
symbol pout_speaker = 1
symbol pout_fan = 2
symbol pout_srfTrig = 3

symbol pin_ir1 = 1 'ADC10
symbol pin_ir2 = 2 'ADC10
symbol pin_srfEcho = 7

'Setup Varibles
symbol wrd_range = w1
symbol bte_speedL = b5
symbol bte_speedR = b6

lblBegin:
‘ motor controller start-up pause
pause 100
lblLoop:
servo pout_servo,150
'Set Normal Speed
let bte_speedL=165
let bte_speedR=190
gosub fnSetSpeed
'Stop the buggy
gosub fnStop
'Get the range from SRF004
gosub fnGetRange
'Take avioding action if object nearby
if wrd_range < 20 then lblObjectNear
goto lblLoop

lblObjectNear:
goto lblLoop 'Exit loop for this test
gosub fnStop
servo pout_servo,100
let bte_speedL = 90 ‘ set slow speed
let bte_speedR = 90 ‘ set slow speed
gosub fnSetSpeed ' set the speed
gosub fnBack
pause 3000 ‘ wait 3 seconds
servo pout_servo,200
gosub fnLeft
pause 2000 ‘ wait 2 seconds
gosub fnStop
servo pout_servo,150
pause 1000
goto lblLoop ‘ loop

fnGetRange:
pulsout pout_srfTrig,2 ‘ produce 20uS trigger pulse
pulsin pin_srfEcho,1,wrd_range ‘ measures the range in 10uS steps
pause 10 ‘ SRF004 mandatory recharge period
‘ now convert range to cm (divide by 6.2)
‘ multiply by 10 then divide by 62
let wrd_range = wrd_range * 10 / 62
return

fnSetSpeed:
'Set the pins, then pulse to set speed
gosub fnStop
gosub fnSetL
pulsout 6,bte_speedL
pause 10
gosub fnStop
gosub fnSetR
pulsout 4,bte_speedR
pause 10
gosub fnStop
return

fnFoward:
low 6
low 4
high 7
high 5
return
fnBack:
low 7
low 5
high 6
high 4
return
fnLeft:
low 6
low 5
high 7
high 4
return
fnRight:
low 7
low 4
high 6
high 5
return
fnStop:
low 7
low 6
low 5
low 4
return
fnSetL:
low 7
high 5
high 4
return
fnSetR:
low 5
high 7
high 6
return

The program should never move the wheels, but the wheels do move, so what is going wrong?
Can anyone help?

Thanks in advance
 

BeanieBots

Moderator
I've only had a very quick browse through your code but to me it looks like the problem is in the section fnSetSpeed:
You call the routine to make it stop but then call the routine to set the speed. Hence, it never stops.
Break the code down into small chunks for testing and put in some debug to see what is comming back from the ultrasonic sensors.
 

m_pratley

New Member
Thanks for the reply,

I didn't quite unstand how the speed works. When I stop the buggy and then set the speed what should happen?
When I'm going fowards and then set the speed then reverse what should happen?
Do I need to stop the buggy before altering the speed?
Does the fact I use the command high and low to alter the state of the output pins compared to useing the command let pins=x, doe it make a differance? (I need the other output pins to work in isolation, i.e. move the servo and change dirrection)

Thanks in advance,

Martin
 

BeanieBots

Moderator
You need to 'walk' through the code and see for yourself what happens at each point. If your code jumps to or calls a routine that sets the motor outputs to make it move, then it will move. It really is that simple.
Using High/Low X is fine and in general is my prefered method because I find it easier to understand and follow what is going on.
Using Let pins =X can be used to control individual pins without effecting others by using a technique called masking. Stick to using high/low for now and explore masking later.
 

Rickharris

Senior Member
Why not start with a simple approach and build it up - that way you increase your knowlwdge and skill at the same time.

Start by turning on the outputs that drive the motors, you will then know which they are and what their effect is.

Then you can easily get the bot to move around.

Then move on to the sensors so you can avoid objects.

After that you can get fancy and start controlling speed etc.

A simple High pin
and see what happens will tell you a lot.
 
Top