LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
-
date post
19-Dec-2015 -
Category
Documents
-
view
218 -
download
0
Transcript of LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
LEGO RoboticsLecture 1: Getting acquainted with
your robotic environment
Getting to know your Robotics Environment
• You will be using:– The parts in the kit
• build the bots
– Computer• write, compile and
debug programs
– The infrared (IR) tower• Communicate with the
brick
– The RCX brick• To power and control
you robot
Programming
• Open program called “Bricx Command Center”– Select “COM1,” click
“ok.” – Turn on the brick and
place the IR sensor side of it facing the IR tower
– Start a new file
• For a list of commands, either hit the “F9” key or select View templates from the menu bar
• The command list is very useful! Every command you might need is here.
• Now, we just have to learn how to use the commands!
Now some programming
• Write the following EXACTLY as it is written– Punctuation, upper/lower case, etc
task main(){
OnFwd(OUT_A);}
– You could also insert the command OnFwd() without typing by finding it in the templates menu and clicking on it
– What does this mean?? It will make more sense soon
Compiling (constructing)
• Many ways to compile: “F5” key, the compile menu, or this button
• If all is well, you will get no errors
• Errors appear here• Most common error is a “parse
error.” This means that you are not following the rules of the programming language
• There are many ways to upload: “F6,” the compile menu bar or this button (Brick must be on & facing tower).
Selects which program slot (1-5) the program downloads to
Hooking up motors
• Using a wire, connect a motor to the “A” connector of the RCX brick
• The “program” key on the brick will cycle through the choice of programs to run. Select the program slot that you downloaded to
• On the brick click “run.” • What happens???
Turn on two motors
• Write the following EXACTLY as it is written– Punctuation, upper/lower case, etc
task main(){
OnFwd(OUT_A+OUT_C);}
Or you could use OnFwd(OUT_AC);
– This time connect motors to A and C. Compile, – download and run like before. What happens?
Reverse motor direction
• 1) rotate connector orientation 180 degrees
• Or use– OnRev( ) command
in place on OnFwd( )
Motor: starting and stopping
Try this code:
Task main(){
OnFwd(OUT_A);
Off(OUT_A);
}
• Upload and run the program like before, correcting any errors.
Motor: starting and Stopping
• What happened? Run the program again and look carefully!
• Did the motor do what you thought it would do, or what you told it to do?
Ah, the computer is quick!• The brick executes commands pretty quickly, so you saw
the motor turn on for a very very short time and then turn off
• How can we tell the program to keep the motor on?– There are many ways to do this but lets try this command …
Wait ("time");
• Where “time” is a value in hundredths (.01) of a second• Example
– Wait(100) will pause for 1 second, or 100 hundredths of a second• Time=.01sec*100 =1sec “time is 100 .01 seconds”
– Wait(1500) will pause for 15 seconds, or1,500 hundredths of a second
• Time=.01sec*1500 seconds=15sec “time is 1500 .01 seconds”
• Now modify your program using the wait command in the appropriate place
• Make the motor turn on for 5sec, and then turn off.
• Did it work?
Task for the day:
• Build a robot– Your choice of how to build it– Focus on functionality and simplicity, not looks!
• From a starting point, program your robot to:– Drive forward and stop exactly 6 feet from the starting
point as quickly as possible– Pretend that there is a little LEGO man 6 feet away
and you want to really scare him, but not hit him.– You will compete with other teams for the closest
distance without hitting the man.• You may work on this with remaining time today
and the majority of next class
Turn in for class credit
Submit a copy of your program
• Plot the position, acceleration and velocity of the robot as a function of time.– Remember, position is how many feet the
robot travels in a certain time, velocity how many feet/sec the robot travels in a second and acceleration is the change in velocity (think back to physics class freshman year!)