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
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