Let's Make Robots!

Is this program correct??

My robot is only moving forward with this program. am usinf a SHARP IR 2Y0A21.. when i place my hands in front of it,it stops and then starts moving forward and wont turn to any side. this is my program..-

Symbol danger = 160

symbol turn = 200

symbol servo_turn = 700

main: readadc 0, b1 if b1 < danger then gosub nodprob else gosub whichway end if

goto main

noprob: high 5 : high 6 : low 4 : low 7 gosub whichway return

whichway: wait 1

gosub lturn

pause

robo_turn

readadc 0, b1

wait 1

gosub rturn

pause robo_turn

readadc 0, b2

gosub stopinst

if b1gosub robo_rturn

else

gosub robo_lturn

end if

return pause turn:

gosub stopinst

robo_lturn:high 6 : low 5 : low 7 : high 4

pause turn:gosub stopinst

return

robo_rturn:high 5:low 6:high 7:low 4

pause turn:gosub stopinst

return

rturn:

servo 0, 100

return

lturn:

servo 0, 200

return

stopinst:

low 4 : low 5 : low 6 : low 7

servo 0,150

wait 1

return

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

am using  4 AA batteries. 
is it gud.??

 

As long as there charged your great

is 900mAh battery gud for robots..?

your using 4 aa right

symbol servo_turn = 700

is this correct??

main:

servo 0,100

pause servo_turn

readadc 0, b2

 

debug

goto main

 

; Operate a servo sweep back and forth.

 

symbol pulse_pin = B.1

symbol val = b1

 

init: servo pulse_pin,75  ;initialize servo

 

main: 

 

   for val = 75 to 224 

    servo pulse_pin, val

    pause 20

   next val

 

   for val = 224 to 75 step -1

    servo pulse_pin, val

    pause 20

   next val

 

goto main   ;loop back to start

 

above is picaxe code example, good luck

sorry i didnt understand this code.

main:	servo B.1, 150		; Set the servo to its starting position
	pause 500		; Stay at the start position for a while

	for b0 = 80 to 200	; Move the servo from position 80 to 200
	  servopos B.1, b0	;   Set the new position
	  pause 20		;   Wait a while
	next b0			; Continue until at position desired

	goto main		; Repeat from start position

This is from picaxe site you will need to play with values and if you get it working play with valuses add stuff to make it
behave see if you can change its values

Paul in picaxe speak 150 is center servo, 75  is one end of travel and 225 is other end of travel another example to try it right out of picaxe pdf manual 3 page 19

init: servo b1,75 ‘ start servo on 1
main: servopos 1,75 ‘ move servo to one end
pause 2000 ‘ wait 2 seconds
servopos 1,150 ‘ move servo to centre
pause 2000 ‘ wait 2 seconds
servopos 1,225 ‘ move servo to other end
pause 2000 ‘ wait 2 seconds
goto main ‘ loop back to start

Both of the above work on tonights 14m2 just make sure your picking right pin, this one has pauses we can squeeze a ping or sharp into I think good luck :D

I googled "picaxe for loop" and arrived at this:

http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/for/