banner I have been a Lego League coach since 2007. This year, I wanted to document the season to give rookie coaches a resource to help them through to competition. The process can be intense, but it can also be a lot of fun for you and your team.

I hope to cover enough through my posts, but if I leave anything out, please feel free to leave a comment, or contact me.
Oct
31st

Go Until…

Author: fllCoach | Files under Programming

In my Motor Tip #1 post, I talked about moving the robot with a duration. But because the robot can turn or move in slightly different amounts in each run, using only durations can’t ensure your robot will be where you think it is when it’s done executing its commands. In my Achieving Mission Consistency post, I mentioned using landmarks on the board to know where you are. That would imply that you have to be able to stop your robot when you get to a landmark.

When I wrote my first program to stop at a landmark, a black line, my instinct as a software developer was to use a motor block within a loop with an end condition on the loop. It would seem to make sense to do a small movement and repeat that until you get to the black line (or other landmark). The program looked like this:

But because of the way the robot executes the motor block, the robot moves 5 degrees, stops, moves 5 degrees stops, etc, until it reaches the black line. This produces a really choppy movement.

When I first programmed the robot this way, the choppy movement surprised me. But it makes sense if you think about it. The brick will execute a command block in its entirety, then move on to the next one. If you tell it to move only 5 degrees, the motor has to stop after 5 degrees to ensure it executed the command correctly.

What you want to do instead is use a motor block set at a duration of unlimited and add a Wait Until block to stop the motor. This is a little counter-intuitive at first (at least for me) because you wouldn’t expect a duration of unlimited to ever stop. But remember, the brick executes a command block until it is done. With an unlimited duration, it will start the motor and move on to the next command block. If the next block is a Wait Until block, the motor will keep going until the condition of the Wait Until block is met.

But there is one more block you need to add. When the brick finds that the Wait Until condition is met, it simply turns off the motor. It does not put on the brake. That means that the robot will keep going forward for another second or so before it finally stops. This gives the impression that your Wait Until condition didn’t work. When I first did this, it drove me crazy because I thought the light sensor I was using to find a black line wasn’t working correctly.

Put a motor stop block after the Wait Until block and that will put the brake on the motor. Then your robot will then behave the way you expect it to. So here is what the program will look like:


Motor Unlimited


Light Sensor Detects Black


Motor Stop

You can take this a step further and create a MyBlock with these three blocks and re-use them as necessary.


2 Trackback(s)

  1. Nov 2, 2010: Following a Line | Lego League Coaching
  2. Nov 26, 2010: Motor Tip #2 | Lego League Coaching

Post a Comment