Suscribirse a: Enviar comentarios Atom. Visitas a este Blog. Buscar este blog. Entradas populares. Emocionante final de la competencia de robots sumo teleoperados desde Ushuaia Argentina y Rep.
Dominicana con un merecido triunfo para Ushua Robot Caminante con Lego WeDo 2. Use the following number: Send email to class. NXT Google search. Podcast tutorials. Robolab Handbook. Nxtasy forums. Designing Behaviors. Art Fundamentals of Interface Design Winter Course Overview. Course Information. Course Schedule. Subroutines simplify by hiding the details of sections of the program. Unfortunately, SubVIs are more difficult to create. Local subroutines. A local subroutine exists inside a program.
It is saved with that program and cant be used by other programs. In other programming languages this might be called a private subroutine. Local subroutines must be declared before they are called. Local subroutines are identified and called by number In the example below, it makes sense to talk about the programs subroutine 1. There are several rules that must be followed. The local subroutine must be defined before it is used.
The subroutine definition must end with a red light an END function. The example has one subroutine, which goes forward for red container seconds. Instead, create two subroutines: one subroutine to go forward for 5 seconds, and a second one to turn right. The idea is to build a subroutine for each robot function. When does it make sense to divide a task into two subroutines?
What happens if a motor is stopped and immediately started? Shared subroutines or VIs. In contrast to local subroutines, shared subroutines a. In fact, they arent even stored with the program. No program owns a shared subroutine. Instead, shared subroutines are stored in their own files. They often have the file extension. Here is an example:.
Use the pointer tool to select the code that will become the VI subroutine. Pointer Tool. Double click the Inventor icon and a new window will open. Drag a corner to expand the window. The three lines have become three terminals. The End and Begin terminals are ok. The numeric terminal needs to be edited to give users an idea what is expected. In this case, numeric is the number of seconds the robot will travel forward before stopping.
To change numeric to Seconds, use the text tool to select the numeric caption and enter Seconds. Open the icon editor by double clicking the icon in the top right corner. This version is used on Black and White printers. Set the default value of seconds. Scroll up and down, or type the default value. For this example, 5 seconds makes sense. Save the VI as a file. So where did the programming go? From the menu, select Windows, Show Diagram to see: Use the text tool to add comments.
This comment either credits brilliance or assigns blame. Other comments describe the VI and explain important ideas. Naming Subroutines.
Naming is very important. If done properly, it will help your kids tell at a glance where they are and what the program is up to. Choosing poor names makes programming much more difficult. Think of some of the basic motion functions that the FLL robot may need to do for the challenge: 1.
To name the examples above, I might use the following names: 1. As you can see, you have to be creative. But some naming consistency makes sense. Some poor examples might include: Fwd5sec when changing to 6 seconds, you dont want to have to change the name ; GoToTallTower too long, and probably cant re-use such a specific subroutine. GoStraight no sense of direction cant tell if the robot will move forward or backward.
This is about as easy to read as the program can be. Can you see the defference between this program and the versions above that perform the same routine? See the simplicity of the code? It is very easy to read. The complexity of the code is hidden well, but can be viewed easily if desired by opening the subVI commands. Saving your program Go ahead and save your program using the File Save menu option.
Topics learned in task 3: Congratulations! You have learned more about the following topics: Using a loop. Why use subroutines: 1. Most important reason: reduce a programs complexity 2. Create subroutines to hide information so you wont have to think about the details 3. Think about the subroutine when you are writing it, but use it later without knowing about its internal workings 4.
Avoiding duplicate code 5. Promotes code re-use 6. Isolates complex operations importance of names importance of hiding information difficulty with turn based on motor run time webs of wired functions are difficult to follow. Requirements In this lesson, we will use the rotation sensor to measure distance traveled more accurately.
This should result in a robot that gives a more repeatable performance run after run. Structure of programming You should now have a good idea of how to structure a program. We want to use well-named subroutines to create building blocks of code fragments that perform specific tasks. As you have probably noticed, locomotion using motor run time results in limited accuracy.
What we have to cover now is building some really useful routines. Turning motors on for a specific amount of time is of limited value in FLL. It will get the kids started but isnt going to help with most of the missions. Rotation sensor introduction Why use a rotation sensor? As you have probably noticed, positioning a robot based on motor run time leaves a lot to be desired. Any of the following can cause the robot to alter its path based on motor run time: Squeeze the Lego parts together.
Friction between the gears increases. Battery power fades with every robot run. The surface friction changed by warming up, cooling down, etc;. These uncontrollable issues make time a poor way for the kids to navigate their robot.
Think of giving a friend driving directions to Chicago. Would you say drive you car for 25, seconds, turn right for 10 seconds, then drive for seconds to a restaurant? They would not get near the restaurant that you had in mind! It probably would land them in a different city, and it is likely that after the first turn, they turned off the road and onto a farm!
A more accurate instruction set would be drive miles, then exit at the water tower. Turn right, and go 2. Your friend would most likely end up at the same place that you had planned on.
A rotation sensor can behave as an odometer for the Lego robot. It can measure the number of rotations that an axle turns. If the axle is somehow connected to a wheel, it will quite accurately measure distance traveled. Manually measuring distance with the RCX It makes a good demonstration to measure a distance with the robot using the rotation sensor. And, this method will be used often to measure distances. Why bother converting from inches to rotations and back many times?
Simply use the robot to take the measurements, then your kids will know exactly how far it must travel! Programming task 4: Rotation sensor Page Before we can use the robot to measure, the RCX computer needs to have the rotation sensor activated. Activating a robots rotation sensor To activate the rotation sensor on the robot, we must build a program that uses the rotation sensor. This can be a very simple program, such as one command to wait for the rotation sensor to reach a certain value.
Setting the port to 1 is not required, since it is the default value. The rotation counter counts 16 for each turn of the axle. Measuring by moving the robot Any sensor can have its current value displayed on the RCX window. After downloading a program containing a rotation sensor command, you are ready to begin measuring. Press the view button until the arrow is pointing to the sensor port that you want to monitor. For your robot, press view until the arrow pointing to port 1. Press View on the RCX until the arrow points to port 1.
Now you can measure distances using the robot as the measuring device. Give it a try! Press the RUN button on the robot to execute the program and activate the rotation sensor. As you move the robot around, does the RCX window display the rotation counter value? Programming with the rotation sensor Now lets turn our attention back to programming. Lets say that we hand-measured a distance of 50 that we would like the robot to move.
First, think about how to walk 50 feet. Here are the first few commands to walk 50 feet: 1. Set the zero mark at where you currently are standing. Point your legs in a certain direction. Set the power that you legs will use. Walk forward. Now the tricky part: what is the next command that you would give your legs?
If you think about it, the next command is WAIT. Wait seems like it would indicate stopping, but it does not. Wait means to continue doing whatever you are doing, until an event occurs. If your goal is to walk 50 feet, the event would be your eyes sensing that you have reached 50 feet. At that moment, you would issue a command to your legs to stop walking.
Here is a series of commands that might complete the above sequence for the Lego robot: 1. Reset the rotation sensor to zero 2. Set motor direction 3. Set motor power Programming task 4: Rotation sensor Page Resetting the rotation sensor When should the rotation sensor be reset? Again, think of driving directions to a distant place. Distances are usually given as measurements between fixed objects. The same idea works for the rotation sensor. It is highly recommended that the rotation sensor be reset to zero whenever the robot is in a known location on the board!
Using variables to expand the robots capabilities Variables are probably one of the most useful tools your kids can use to make useful functions. What if the mission requires that the robot travel 58 rotation counts? Or counts? This is where variables are useful. Set a variable x to the number of counts.
Rewrite the program to wait for x rotations. First, variables are known as containers. Containers can hold only hold 16 bit signed integers. That is, the numbers 0, 1, 2, 3, , and -1, -2, -3, , Here is a silly example that shows the use of the default container red. The red container is zeroed, then incremented until After a couple of minutes, it beeps. Container Fork. If the container is greater than follow the top wire, else the bottom wire. Not exactly worth the trouble, but it does show how to set and use a variable container.
Note: The modifiers to set a container value and get a container value are different. Turning using the rotation sensor The rotation sensor can also be used to make more accurate turns. Try making a RightTurnUsingRotation program that uses the rotation sensor instead of the timing commands to make a more accurate turn. If the rotation sensor is geared to the robots left-side tire, should the right-side tire turn? Can the right-side tire be locked, so it doesnt turn?
If only the left-side tire turns, does the robot turn as sharply? A RightTurnUsingRotation program might look like this:. Caveat of using rotation sensor Suppose your kids want their robot to travel until the rotation sensor reaches , but the robot hits a wall at What happens now? At first, you might think that the robot would pause at the wall for a few seconds and then proceed with its program.
How can your kids program so that the robot will not wait forever at an object if it reaches the object earlier than expected? Topics learned in task 4: Congratulations! You have learned more about the following topics: using a rotation sensor for measuring mileage during straight runs and turns add a rotation sensor to the robot Introduce containers variables. Requirements In this lesson we will program the robot to move forward until it reaches a black line.
The robot should then stop, and turn right. Light sensor The Mindstorms light sensor is programmed like the rotation sensor. You can view the value of the light sensor through the RCX window exactly as you did with the rotation sensor. The light sensor interprets the amount of light from a reading of zero black through white. Run a program containing a light sensor to activate this feature. Like this:.
Light sensor programming To use the light sensor in a program, we will follow the same technique that was used with the rotation sensor. In English: Move up to the black line and turn right.
In pseudocode: 1. WAIT until the light sensor reading is dark 5. Write a new program named Fwd2Line See if you can do this yourself from the above pseudocode. Programming task 5: Forward to a black line, stop, turn right Page The trick here is determining what the RCX will read as Dark. For example, the white reading is 50, and the dark reading is So youve reached the black line, now what? Turn Right, remember. Didnt we already do that? Open the your final version of the Lab 3 program.
Use the pointer tool to select the RightTurn icon. Copy it. Locate and select the Fwd2Line program window. Paste it. The RightTurn icon will be plopped somewhere in the window. If you used a local subroutine, instead of a subVI, more work is required. Again, open the final version of the Lab 3 program. Use the pointer tool to select all of the RightTurn subroutine.
It is best to drag a box around the entire subroutine to select it. Usually, the icons must be moved around so that they can be neatly selected. It may be easier to copy everything and delete what isnt needed after the paste. In any case, after selecting, copy it. Switch to the new programs window. A second copy and paste will be needed for the icons that call the local subroutine.
Then again, recoding a right turn is pretty easy. Maybe easy is better. It depends. Comments are always nice hint: judges love to see these and so will your kids as the program becomes more complex. The TurnRight90deg. Changing light conditions Lets say that your kids found that 40 is the value that they want the light sensor to read as Dark. If their program has several different light sensor commands in a program, they could hard-code 40 as the dark reading.
Hard coding means to enter a specific value into a command. If the kids take their robot to the competition and the ambient lights are much brighter, it could cause the light sensors to not see dark when they should, because the black line never reads below 62, for example. Can you think of a method to address this problem? Can you think of a second method? Remember, if you only think of one solution, you might end up using the worst possible solution.
If you start the program on a dark area, it behaves differently than if you start it on a light area. A second method is to use a container to store the light sensor threshold. If you want to sense dark as below 60, you can use the following command:. A fourth method watches values of the light sensor and waits for an out-of-range value. Of course this requires the hardcoding of the idea out-of-range. A fifth method saves the out-of-range threshold to a container.
And so on. Which is best? By the way, there are more possibilities. Where else could you store the threshold containers?
Is it possible to store thresholds without using containers? What if someone uses a flash to take a picture of a running robot? Additional notes Which commands are used most often? Motor n Forward. Some teams spend a lot of time with power settings, others just run the motors at the default full power. Which commands should be avoided? Task Split: The command works very well as the last set of commands, but as an intermediate step it can be difficult.
For example: a line following program can be run as two tasks: 1 if too white, power motor A. Great, it works. Now add it to code that follows a line until a rotation sensor is greater than How do you put the two together? If a rotation sensor task is added, it will serve to detect the rotation, but how do you stop the tasks running the motors? Stop Tasks does just that, including the task that was watching the rotation sensor.
Essentially, the program stops. There has to be a way to program around this, but until shown a working counter-example: task splits should be avoided. Why do sensors and containers need to be reset to zero? Just like the firmware, the values in containers dont disappear unless the battery power fails. There are containers for most sensors. While this is a problem that forces programmers to reset container values when programs first start, it can be useful.
Load this is another slot: Consider this program: A value saved into a container can be used by another program. Additional notes. Write a program so that programmers can copy command icons and paste them into their programs.
This program will not run, but that doesnt mean it isnt useful. Waiting for several sensors at the same time. Consider the following requirements: 1.
0コメント