'bob gross 'Q-basic program 'This program reads/talks to the PIC through RS-232. 'This version can be very useful for debugging as all sensors 'output are displayed. The software sends out the sensor 'number that one wants to read. GoSubs are not used for clarity. 'The PIC returns the period of the frequency that it senses. 'This data is returned in the number of 10 micro second intervals. 'This inteval can be used directly or can be used to calculate 'the frequecny of the beacon that is detected. 'It also returns the duty cycle of the sampled sensor. This duty 'cycle measurement is accurate with random data. As such it can be used 'to accuratly determine the probability of a beacon's presence. 'Because a beacon normally transmits with a 50 % duty cycle multipling 'the dutycycle by 2 yields the probability that a beacon is present. 'Any duty cycle that is less than 40 % (80 % probablity)is typically 'not stable enough'to accurately determine the frequency measued. 'Never the less when another beacon is some distance away the jitter 'may yield only a few percent duty cycle. This method allows one 'to "see" the greatest distance. When one gets closer then the 'frequency can be determined. Another advantage of this duty cycle 'measurement is that if it reads much over 60% (120% probability) 'then it is likely that there is more than one robot close by. CLOSE #1 CLS OPEN "COM1:2400,N,8,1,CD0,CS0,DS0,OP0" FOR RANDOM AS #1 LOCATE 1, 1 PRINT "Be sure to turn on the pic and connect the RS-232 cable" PRINT "before you start this program. If you haven't done this" PRINT "please exit and then restart this program." LOCATE 6, 6 PRINT "BaudRate = 2400" LOCATE 22, 26 PRINT "Press Q to quit program." AGAIN1: Start = TIMER DataToSend = 1 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod1 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle1 = ASC(INPUT$(1, #1)) 'Read DutyCycle. DataToSend = 2 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod2 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle2 = ASC(INPUT$(1, #1)) 'Read DutyCycle. DataToSend = 3 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod3 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle3 = ASC(INPUT$(1, #1)) 'Read DutyCycle. DataToSend = 4 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod4 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle4 = ASC(INPUT$(1, #1)) 'Read DutyCycle. DataToSend = 5 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod5 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle5 = ASC(INPUT$(1, #1)) 'Read DutyCycle. DataToSend = 6 PRINT #1, DataToSend 'Send via RS-232 command to read sensor. ThePeriod6 = ASC(INPUT$(1, #1)) 'Read period. Period in 10 uS increments. TheDutyCycle6 = ASC(INPUT$(1, #1)) 'Read DutyCycle. Done = TIMER LOCATE 8 PRINT USING " Time to read all sensors = ##.### Seconds"; (Done - Start) PRINT PRINT " Sensor 1 Sensor 2 Sensor 3 Sensor 4 Sensor 5 Sensor 6" PRINT " Prd Dty Prd Dty Prd Dty Prd Dty Prd Dty Prd Dty" PRINT " mS % mS % mS % mS % mS % mS %" PRINT USING " ##.## ### ##.## ### ##.## ### ##.## ### ##.## ### ##.## ###"; (ThePeriod1 / 100); TheDutyCycle1; (ThePeriod2 / 100); TheDutyCycle2; (ThePeriod3 / 100); TheDutyCycle3; (ThePeriod4 / 100); TheDutyCycle4; (ThePeriod5 / 100); TheDutyC ycle5; (ThePeriod6 / 100); TheDutyCycle6 'This next section calculates the frequency from the period. 'Note that the special case when their is no period (i.e. 0) is handled. 'It also calculates the probability from the duty cycle. IF ThePeriod1 <> 0 THEN TheFreq1 = 1 / (ThePeriod1 * .00001) ELSE TheFreq1 = 0 TheProbability1 = TheDutyCycle1 * 2 IF ThePeriod2 <> 0 THEN TheFreq2 = 1 / (ThePeriod2 * .00001) ELSE TheFreq2 = 0 TheProbability2 = TheDutyCycle2 * 2 IF ThePeriod3 <> 0 THEN TheFreq3 = 1 / (ThePeriod3 * .00001) ELSE TheFreq3 = 0 TheProbability3 = TheDutyCycle3 * 2 IF ThePeriod4 <> 0 THEN TheFreq4 = 1 / (ThePeriod4 * .00001) ELSE TheFreq4 = 0 TheProbability4 = TheDutyCycle4 * 2 IF ThePeriod5 <> 0 THEN TheFreq5 = 1 / (ThePeriod5 * .00001) ELSE TheFreq5 = 0 TheProbability5 = TheDutyCycle5 * 2 IF ThePeriod6 <> 0 THEN TheFreq6 = 1 / (ThePeriod6 * .00001) ELSE TheFreq6 = 0 TheProbability6 = TheDutyCycle6 * 2 PRINT PRINT " Frq Prb Frq Prb Frq Prb Frq Prb Frq Prb Frq Prb" PRINT " Hz % Hz % Hz % Hz % Hz % Hz %" PRINT USING " #### ### #### ### #### ### #### ### #### ### #### ###"; TheFreq1; TheProbability1; TheFreq2; TheProbability2; TheFreq3; TheProbability3; TheFreq4; TheProbability4; TheFreq5; TheProbability5; TheFreq6; TheProbability6 TheCharacter$ = INKEY$ 'Brings in a key if pressed. IF TheCharacter$ = "q" THEN TheCharacter$ = "Q" 'Makes a small "q" a capital "Q". IF TheCharacter$ = "Q" THEN CLOSE #1: END 'If Q was pressed quit. GOTO AGAIN1