Upload
paul-parrish
View
217
Download
2
Embed Size (px)
Citation preview
CSC 110 -Intro. to Computing
Lecture 16:
Robotran
Announcements
Homework #4 handed out todayDue next Monday at 5PMQuiz #4 will be in 1 week
Service learning logs due todayE-mail me logs written since last deadlineThese are not graded, you get full credit given
for logs showing you visited a site
Robotran
Robotran language is very similar to PalgoBut Robotran can program Lego robots
We will (briefly) discuss some of these differencesPlaying with the robots is more fun then
listening to mePlease ask questions – it is more important you
understand this material
Robotran Programs
All Robotran programs have a name I am not sure why and what the name is does
not make a difference Names do make it easier to tell programs apart
Begin each file with:program ProgramName
After the name we begin a normal Palgo-like program
Variables in Robotran
Create a variable using var commandOptionally provide variable’s initial valuevar anglevar nameAndInitialValue = 20
Assign value to variable using letVariable must have been created beforelet angle = 54let valueUp = valueUp + 1let dist = 45 * angle - valueUp
Special Variables
randomValue is a whole number from 0 – 99,
but this value changes each timelet d = random / 100
S1 (left bumper), S2 (right bumper)Contains 1 if bumper was hit, 0 otherwiseif S1 == 1 thenlet f = S2 * 50 + 10
Loops
Robotran’s loops are identical to Palgorepeat x timesrepeat 5 times -or- repeat var times
while testwhile S1 != 0 -or- while true
for var = y to zfor i = 1 to 4 -or- for j = 0 to random
If-then-else is also identical to Palgo
Moving The Robot
To have the robot go forwardgo forward (goes forward until stopped)go forward 1 secondgo forward 87239239 inches
To have the robot go in reverse:go backward (moves until stopped)go backward 12 inchesgo backward 10 seconds
Other options
Stop the robotstop
Tell the robot to make a noisebeep
Stop performing the last line if you hit somethingcontinue until bump
Turning the Robot
Turning for some amount of timemotor A go forward 10 secondsmotor B go forward 1 second
Turn to the right (left is similar)turn rightturn right 45 degreesturn sharp left makes a tighter turn
Drawing with Robotran
Like Palgo, we can draw with RobotranLess colors and options then Palgo, but more
satisfying To have the robot start drawing
pen down To have the robot stop drawing
pen up
Your Turn
Now even I’m tired of me speaking. Time to play with the robots!
Ideas for projects for the lecture: Write the digits 0 – 9 Write the letters in someone’s name Draw a flower Write a program to make robot send an SOS when it
gets bumped Write program to have robot get around an obstacle
For Next Lecture
Start reading Robotran handout E-mail me your new service learning logs Get ready for homework #4
So ask me any Palgo questions you still have