' some crude autonomous vehicle software ' 'hardware is picaxe 18A 'L293D motor driver connected to outputs 0,1, and 2,3 '2 mini robot motors connect to the L293D and are attached to wheels via 'a gearbox to provide necessary higher torque (at the expense of speed) ' 'An LED is between pins 4 and 5 for simple signalling ' 'this program lets the robot wander toward light sensed by 2 LDRs ' slight improvements over initial photovore efforts, it works by: ' ' - measuring left and right ambient light values ' - if difference is above a threshold, turn toward the light a bit ' - else go straight a bit ' - instead of in-place turn (one wheel fwd, other backwd), use single motor to maintain forward motion ' - loop to measuring light values... (loops several times per sec) 'define pinouts symbol motor1A=0 'left motor symbol motor1B=1 symbol motor2A=3 'right motor symbol motor2B=2 symbol LDR1=1 symbol LDR2=2 symbol LED1A=4 'LED across these pins for now symbol LED1B=5 'define variables symbol commandb=b0 symbol tmp1b=b1 symbol execloop=b2 'execution loop counter symbol tmpb1=b3 symbol randomw=w2 symbol randomb=b4 symbol tmpb2=b6 symbol tmpb3=b7 symbol diff=b8 'define constants symbol leddly=250 symbol motorFwdOnDly=200 'delay while motors are on symbol motorTurnOnDly=200 'delay while motors are on symbol motorPWMloop=1 'numer of loops for crude motor PWM symbol mindiff=3 'minimum difference in light values required to change direction symbol actionDly=200 'delay between actions init: gosub m1m2off gosub flashled 'let user know we're alive pause 6000 randomw=4098 pause actionDly 'wait a bit gosub flashled 'indicate command start: readadc LDR1, tmpb2 'get light vals readadc LDR2, tmpb3 if tmpb2>tmpb3 then 'figure out which one is greater diff=tmpb2-tmpb3 tmpb1=0 else diff=tmpb3-tmpb2 tmpb1=1 endif ' pause actionDly 'wait a bit ' gosub flashled 'indicate command if diff>mindiff then 'if diff is above a threshold, then turn ' on tmpb1 gosub m1m2rt, m1m2lt on tmpb1 gosub m2fwd, m1fwd pause motorTurnOnDly 'wait a bit gosub m1m2off else 'else go straight gosub m1m2fwd pause motorFwdOnDly 'wait a bit gosub m1m2off endif goto start m1fwd: high motor1A low motor1B return m1rev: low motor1A high motor1B return m2fwd: high motor2A low motor2B return m2rev: low motor2A high motor2B return m1m2fwd: high motor1A low motor1B high motor2A low motor2B return m1m2rev: low motor1A high motor1B low motor2A high motor2B return m1m2lt: high motor1A low motor1B low motor2A high motor2B return m1m2rt: low motor1A high motor1B high motor2A low motor2B return m1m2off: low motor1A low motor1B low motor2A low motor2B return led1on: high LED1A low LED1B return led1off: low LED1A low LED1B return flashled: for tmp1b=0 to commandb gosub led1on pause leddly gosub led1off pause leddly next tmp1b return