'Author Bob Gross 'WARBOT97.BAS Code is for Counterfit Stamp or Stamp 1 'I used The Counterfit Stamp powered by a seperate 9V bat. 'The robot spins in place unless it sees the oppent. If it 'sees the oppent it goes after them. It will follow an oppent 'either to the left or to the right. If it looses sight of the 'oppent it begins searching again. The lift operates every so often. 'Instead of a wiring diagram the wiring is discribed '****** 'Pin designations '0 has power to the rest of robot on it via a relay '1 has power to the left drive motor, connected to always run either ' forward or reverse. via a relay '2 has power to the right drive motor, connected to always run either ' forward or reverse. via a relay '3 has power to the weapon, (lift) via a relay '4 not used '5 connected to the front left IR sensor output directly '6 connected to the front right IR sensor output directly '7 not used '****** 'Variable designations 'B2 the period of beacon on your robot in 10us increments 'B1 the IR sensor being currently read 'B5 the weapon timer/counter 'B3 holds the total pulse period 'B4 holds the negitive pulse period 'W4 holds the positive pulse period 'The Bits 0 though 3 are used to store if the sensors see something 'Storing a 0 means I don't see someting 'Storing a 1 means I see something 'Note that in the program Bits 0 and 1 are not used but could be used 'if one wanted to impiment a wander around while looking for oppent. 'Bit0 Front Left,Do I see a wall or object? (Bits 0 and 1 are not used but 'Bit1 Front Right, Do I see a wall or object?(could be used for wandering) 'Bit2 Front Left, Do I see another robot? 'Bit3 Front Right, Do I see another robot? '********* 'Set B2 to the period value for the beacon mounted on your robot. 'Note that an IR sensor could be set up to read this directly, but 'that is for another day. 'Note that the stamp reads in 10 uS increments so the formula is ' B2 = 100000/(beacon frequency) B2 = 143 '100 for 1KHz, 118 for 850Hz, 143 for 700Hz, 182 for 550Hz High 3 'Lower the lift (do first, prevents damage to my robot) Pause 5000 'Five second Start delay, change to whatever is needed High 0 'Turn on main 24V power Pause 100 'Allow 100 mS for main relay to close (I want every 'thing to settle.) Top: 'This is the start of the main control loop. For B1 = 5 to 6 'This next section is weapon control. It is software speed depentant. 'Becasue the software runs faster when it sees someone the weapon timing 'is correct only when it sees something. Only durring the time that it 'takes for B5 to count to 50 is the lift up (about 1 second), otherwise, 'from 51 to 250 (about 4 seconds) the lift is down. B5 = B5 + 1 'Increment the counter If B5 < 50 Then SkipLift 'don't lower the lift until 50 High 3 'Lower the lift If B5 < 250 Then SkipLift 'don't raise the lift until 250 Low 3 'Lift up B5 = 0 'reset the weapon timer SkipLift: 'B6 = B1 'Set B6 to the correct pin numbers before calling sub 'ReadPulseIn: 'This rutine first looks for valid pulse signal for measurement. 'First the negitive width is measured. Then if the negitive width 'was valid, it then measures the positive width. These are then 'added together to make an accurate period measurement. Note that 'if a pulse isn't there it will take about 0.6 seconds to read a pulse in. 'That is why the reading of the positive pulse width measurement ' is skipped if there isn't a negitive pulse. Pulsin B1, 0, B4 'Read the negitive pulse in If B4 < 30 Then SkipRPI 'If valid neg wasn't their then skip, else Pulsin B1, 1, W4 'Read the positive pulse width If B4 < 30 Then SkipRPI 'If valid pos wasn't their then skip, else W4 = W4 + B4 'Combine the negitive and positive widths GOTO PulseGood SkipRPI: 'Skip Read Pulse In W4 = 0 'Reset words if data isn't valid PulseGood: 'The data at this point is valid B3 = W4 'Need number in byte form to send out RS-232 '************* This next code is spcificic to the front left sensor 'This code could be done with less code, more effeciently If B1 <> 5 Then SkipFL 'Skip reading if not my sensor at Front Left If B3 > 80 Then StoreFL 'This tells me I see something. Bit0 = 0 'Store that I don't see a thing Bit2 = 0 Goto SkipFL: StoreFL: If B2 > B3 Then B2IsHigher 'To subtract B3 must be grater than B2 B3 = B3 - B2 'Look at the variance in data. If B3 <10 Then FLObject 'Closer than 10 counts = sees object else Bit0 = 0 'I don't see object Bit2 = 1 'but I see another robot B2IsHigher: B3 = B2 - B3 'Find out if data is valid If B3 <10 Then FLObject 'Closer than 10 counts = sees object Bit0 = 0 'I don't see object Bit2 = 1 'but I see another robot Goto SkipFL FLObject: 'The data is valid "Sees Object" Bit0 = 1 'Store that I see my own beacon Bit2 = 0 'I dont see some else SkipFL: '************ '********** This section is specific to the front right sensor *** 'This code could be done with less code, more effeciently If B1 <> 6 Then SkipFR 'This is my sensor looking at Front Right If B3 > 80 Then StoreFR 'This tells me I see it. Bit1 = 0 'If I don't see it, Store that I don't see a thing Bit3 = 0 Goto SkipFR: StoreFR: If B2 > B3 Then B2FRIsHigher ' B3 = B3 - B2 'Look at the variance in data. If B3 <15 Then FRObject 'Closer than 15 counts = sees object else Bit1 = 0 'I don't see object Bit3 = 1 'but I see another robot B2FRIsHigher: B3 = B2 - B3 'Find out if data is valid If B3 <15 Then FRObject 'Closer than 15 counts = sees object Bit1 = 0 'I don't see object Bit3 = 1 'but I see another robot Goto SkipFR FRObject: 'The data is valid "Sees Object" Bit1 = 1 'Store that I see my own beacon Bit3 = 0 'I dont see some else SkipFR: Next B1 '************ 'Make desisions based upon what I saw. This is the robots smarts. 'Only three rules. Pretty dumb robot... If Bit2 = 1 and Bit3 = 1 Then Forward If Bit2 = 1 and Bit3 = 0 Then LeftReverse 'Same as RightForward If Bit2 = 0 and Bit3 = 1 Then RightReverse RightReverse: Low 1 High 2 Goto State LeftReverse: Low 2 High 1 Goto State Forward: Low 1 Low 2 Goto State State: Goto Top 'Do it all again