| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
Introduction to the Calculator Robot
The CodeWe will step through the code bit-by-bit:0->S 191->I 135->F 64->G 132->RHere what we do is set up a few variable names with pre-defined meanings. For example, we assign the number that makes the robot stop to S, the number that makes the robot move forward to F etc. See the manual for details about the other numbers. The "Lbl" simply marks a label in the program that can be jumped to using the "Goto" command. The next statements clear the screen and recalls Pic1. Pic1 is a picture of the radar screen (above). Now we set the robot to move forward, but remember you must set the type of movement then tell the robot to execute the move command. F is set to forward, and G to go. The Asm(prgmSRBTEST) calls the program that interfaces with the robot hardware. 7 While Ans>6 getKey->K I:Asm(prgmSRBTEST) If Ans=4:Goto F If Ans=5:Goto L If Ans=6:Goto R If K=45:Goto X EndThe "7" confuses a lot of people - basically, when you execute anything, the result of the calculation is stored in Ans (the answer variable). So, that 7 effectively puts 7 into Ans, which allows the While statement to run. The while statement simply reads from the inputs and tests whether both switches were triggered, the left switch was triggered, the right switch was triggered or whether the user hit the Clear button to exit. These three "routines" load the correct picture up for the radar (see screenshots), then load a value into X that corresponds with the action the robot should take. If the robot bumps into something full on, we want to stop, so load S (Stop) into X. If the robot hits something on its left, make a full left turn (134). If the roobt hits something on its right, make a full right turn (133). After we have loaded the action to do into X we jump to Z. Lbl Z S:Asm(prgmSRBTEST) R:Asm(prgmSRBTEST) G:Asm(prgmSRBTEST) For(Y,1,15):End X:Asm(prgmSRBTEST) G:Asm(prgmSRBTEST) S:Asm(prgmSRBTEST) If X!=S:Goto AHere we stop the robot, reverse for a little while. Then we run out X command, stop and (if the command wasn't to stop) start running again. Lbl X S:Asm(prgmSRBTEST) ClrDrawStop the robot, and get rid of the radar screen!
Submitted: 04/11/2000 Article content copyright © James Matthews, 2000.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -