I didn't have the object avoiding abilities of my robot programmed with GCB. It wasn't big or clever but thought I'd share. It's so easy to tweak what it does when it senses an object.
The only features of the code are hpwm for motor speed and the servo command which is 50hz interrupt and is turned off when using the hso4 ultrasonic then back on. Incase you want to make one. https://youtu.be/VDr_0NmGu84
I zipped the code but can't find the attatch file option so sorry long code post.
;usonservorobot#chip 18F25k22,16#option explicit;#include<glcd.h>#include<srf04.h>#config osc=int,WDT=OFF;#define servo_pin portb.0 ; Servo signal On PIN 21#define lmotordira portb.2 ;h-bridge motor pins#define lmotordirb portb.1#define rmotordira portb.3#define rmotordirb portb.4#define US1Ping PORTb.5#define US1Echo PORTb.5;dirlmotordiraout:dirlmotordirbout:dirrmotordiraout:dirrmotordirbout:dirservo_pinoutdirportc.2out;pwmoutpin;dimrangeasworddimrturncountasbyte:rturncount=0dimlturncountasbyte:lturncount=0dimlast_turnasByte:last_turn=0dimtmpasbytedimsaferangeasword:saferange=40dimradardirasbyte:radardir=1dimservopositionasbyte:servoposition=150;----pointradarahead;;setupservointerrupt50Hzoninterrupttimer1overflowCallservoinittimer1(OSC,PS1_2)Starttimer1;wait50ms;-----------------------START------------------main:HPWM1,1,224motors_forwarddoget_rangerotate_radar;;----setsaferangefordifferentdirectionsifservoposition>130andservoposition<170thensaferange=40;frontelsesaferange=46;leftandrightendif;loopuntilrange<saferange;---testforobstacles;;objectdetectedmotors_stopreverseifservoposition>=160then;---objectleftturnrightgotomainendif;ifservoposition<=140then;---objectrightturnleftgotomainendif;aheadblocked;----objectaheadsorandomtestturnleftorrighttmp=Randomiftmp<128thenservoposition=130;pointradarfarrightwait22msget_rangeifrange>saferangethen;----rightisclearturnrightelseturnleftendifgotomainelseservoposition=170;----pointradarfarleftwait22msget_rangeifrange>saferangethen;----leftisclearturnleftelseturnrightendifgotomainendif;gotomain;----------endofmainprogram;...................Subroutines...................................subturnrighttmp=servoposition+30dountil(servoposition=tmp)or(servoposition>210)do:scanrotateright:loopuntilrange>saferange;----spinclockwiseuntilnoobjectaheadservoposition=servoposition+10wait22msloopradardir=1:servoposition=150;----pointradaraheadwait22msreverseendsub;......................................................subturnlefttmp=servoposition-30dountil(servoposition=tmp)or(servoposition<90)do:scanrotateleft:loopuntilrange>saferange;----spinanti-clockwiseuntilnoobjectaheadservoposition=servoposition-10wait22msloopreverse;radardir=0:servoposition=150;----pointradaraheadwait22msendsubsubscanrotateleftget_rangeHPWM1,1,255rotate_anticlockwisewait14msmotors_stopmotors_offendsubsubscanrotaterightget_rangeHPWM1,1,255rotate_clockwisewait14msmotors_stopmotors_offendsubsubreverseHPWM1,1,255motors_reversewait30msmotors_stopmotors_offendsubsubrotate_anticlockwisesetlmotordiraoff;leftmotorforwardsetlmotordirbonsetrmotordiraon;rightmotorbackwardsetrmotordirboffendsubsubrotate_clockwisesetlmotordiraon;leftmotorbackwardsetlmotordirboffsetrmotordiraoff;rightmotorforwardsetrmotordirbonendsubsubmotors_forwardsetlmotordiraon;leftmotorforwardsetlmotordirboffsetrmotordiraon;rightmotorforwardsetrmotordirboffendsubsubmotors_offsetlmotordiraoff;leftmotoroffsetlmotordirboffsetrmotordiraoff;rightmotoroffsetrmotordirboffendsubsubmotors_reversesetlmotordiraoff;leftmotorbackwardsetlmotordirbonsetrmotordiraoff;rightmotorbackwardsetrmotordirbonendsubsubmotors_stopsetlmotordiraon;shortleftmotorsetlmotordirbonsetrmotordiraon;shortrightmotorsetrmotordirbonwait5msendsubsubrotate_radar;ifradardir=1thenservoposition=servoposition+10ifservoposition=210thenradardir=0endifelseservoposition=servoposition-10ifservoposition=90thenradardir=1endifendifwait20msendsubsubget_range;ussensorrange=0dountilrange>0intoffrange=USDistance(1)intonwait10msloopendsub;;;;;;;;subservo;servointerruptsettimer1,25535pulseoutServo_Pin,servoposition10usendsub
formatting disappeared.
Last edit: Anobium 2017-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I didn't have the object avoiding abilities of my robot programmed with GCB. It wasn't big or clever but thought I'd share. It's so easy to tweak what it does when it senses an object.
The only features of the code are hpwm for motor speed and the servo command which is 50hz interrupt and is turned off when using the hso4 ultrasonic then back on. Incase you want to make one.
https://youtu.be/VDr_0NmGu84
I zipped the code but can't find the attatch file option so sorry long code post.
formatting disappeared.
Last edit: Anobium 2017-06-15
A few code twiddles and it got better but no where finished yet. leds later,more fun. https://youtu.be/Bs6rR2-KpAE