Let's Make Robots!

My Senior Project

Explore

I make nice robot to play with.  Too bad he's retarded...:(

Comment viewing options

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

could you look over this code?

symbol dangerlevel = 140
symbol turn = 300
symbol servo_turn = 700
'new symbols
symbol scenter = 150 'adjust to set servo center
symbol sright = 100 'adjust to set servo right
symbol sleft = 200 'adjust to set servo left
symbol lmbp = 4 'left motor back pin
symbol lmfp = 5 'left motor forward pin
symbol rmbp = 6 'right motor back pin
symbol rmfp = 7 'right motor forward pin
symbol ir_sensor = 1 'analog input pin
symbol sensor_servo = 0 'ir_sensor servo pin
symbol dist_front = b1
symbol dist_left = b2
symbol dist_right = b3

main:
   readadc ir_sensor, dist_front
   if dist_front < dangerlevel then
      gosub nodanger
   else
      gosub whichway
   end if
goto main

nodanger:
   'changed to increase readability
   'low 4 : high 5 : low 6 : high 7
   gosub leftmotorforward
   gosub rightmotorforward
return

whichway:
   gosub totalhalt
   gosub lturn
   'pause servo_turn
   'readadc 1, b1
   gosub totalhalt
   gosub rturn
   'pause servo_turn
   'readadc 1, b2
   gosub totalhalt
   if dist_left > dist_right then
      gosub body_lturn
   else
      gosub body_rturn
   end if
return

body_lturn:
    'high 4 : low 5 : low 6 : high 7
   gosub leftmotorbackward
   gosub rightmotorforward
   pause turn
   gosub totalhalt
return

body_rturn:
    'low 4 : high 5 : high 6 : low 7
   gosub leftmotorforward
   gosub rightmotorbackward
   pause turn
   gosub totalhalt
return

rturn:
   servo sensor_servo, sright
   pause servo_turn
   readadc ir_sensor, dist_right
return

lturn:
   servo sensor_servo, sleft
   pause servo_turn
   readadc ir_sensor, dist_left
return

totalhalt:
   'changed to help readability
   'low 4 : high 5 : low 6 : high 7 'this will make the motors go forward
   gosub leftmotorstop
   gosub rightmotorstop
   servo sensor_servo, scenter
   wait 1
return

leftmotorforward:
   low lmbp
   high lmfp
return

leftmotorbackward:
   high lmbp
   low lmfp
return

leftmotorstop:
   high lmbp
   high lmfp
return

rightmotorforward:
   low rmbp
   high rmfp
return

rightmotorbackward:
   high rmbp
   low rmfp
return

rightmotorstop:
   high rmbp
   high rmfp
return

I now have to wonder if your totalhalt subroutine was not the problem. What I wrote up has more code, but, does the same as your code.

Ok. First off thanks for the help, the motors are running fine now, but I am having some troubles with the code.  First thing, when moving during 'no danger' he only scoots forward an inch or so.  How can I tell him to go further?  Also, for some reason when deciding 'Which way is better' he acts rather sporadic and only seems to notice the 'wall' once, then proceeds to charge it at an inch a minute.

post your code, if you would like some of the people here to look it over.

ya actually this is a better idea 

Re-write the whole program all by yourself, know what each line means and does, check the sensor's sensiblity by using only the sensor program and change your dangerlevel according to your sensor's sensibility. check if all solders are done properly any loose solders will result in such "sporadic" movements 

All the best 

I know I have correctly soldered for that was my first problem with the motors, and I have a solid dangerlevel for my system.  I have been running through the code so much I can no longer make him run a straight line... so here it is

symbol dangerlevel = 140

symbol turn = 300

symbol servo_turn = 700

 

main:

readadc 1, b1

if b1 < dangerlevel then 

gosub nodanger

else

gosub whichway

end if

goto main

 

nodanger:

low 4 : high 5 : low 6 : high 7

return

 

whichway:

gosub totalhalt

 

gosub lturn

pause servo_turn

readadc 1, b1

gosub totalhalt

 

gosub rturn

pause servo_turn

readadc 1, b2

gosub totalhalt

 

if b1>b2 then

gosub body_lturn

else

gosub body_rturn

end if

return

 

body_lturn:

high 4 : low 5 : low 6 : high 7

pause turn : gosub totalhalt

return

 

body_rturn:

low 4 : high 5 : high 6 : low 7

pause turn : gosub totalhalt

return

 

rturn:

servo 0, 100

return

 

lturn:

servo 0, 200

return

 

totalhalt:

low 4 : high 5 : low 6 : high 7

servo 0, 150

wait 1

return

 

since you are having problems with your wheels/motors, try just

 low 4 : high 5 : low 6 : high 7 

and see if the wheels move, if they do move then try changing the value of dangerlevel to a small one like 100

you can check to make sure that you are getting signals to and from where they should be going. Also, make sure you are getting 5 volts to the PICAXE.

First, check the PICAXE pins to make sure you are getting a HIGH where you think you should be getting a HIGH. Follow that to the motor driver chip, L293D I believe. See that you are getting HIGHs and LOWs where they are needed. See that you are getting HIGHs and LOWs on the outputs to the motors.

Make sure that your L293D is plugged in in the correct orientation.

The wires are fine, soldering and everything, the camera works simply put, the wheels are UNRESPONSIVE!  The code I am using is the one form 'My First Robot'.  I just do not know...