Touch sensors
Today we decided to dive into the touch sensor. The first thing we had the boys do was to add the touch sensor to their robot. In no time at all, they had the sensor mounted to the front of the robot.The Challenge
The challenge today was to get the robot to touch three boxes set up like the diagram below.Using the sensor attached to the front they first drove forward until they touched the first box. At first, they had a problem where the robot continued to push after it had touched the box. After a little sleuthing, the boys realized that they did not stop the robot from moving forward as soon as it touched, but had some other commands in between. They added a stop as soon as it touched and it was no longer pushing against the box.
After playing with the rotations needed and the movement required to get the robot where it needed to be, the boys finally succeeded in getting it to touch each box successfully.
Improvements
After we got the bot to touch each box successfully, we took a minute to look at the code we had written to see if there were any improvements we could make to it.The original code looked something like this:
Drive forward until touch
Stop
Say "Object detected"
Back up 4 rotations
Turn 2 rotations
Drive forward until touch
Stop
Say "Object detected"
Back up 2 rotations
Turn 1 rotation
Drive forward until touch
Stop
Say "Object detected"
Back up 2 rotations
The boys noticed that the blue sections were repeated exactly, and that the red section was almost the same. We ended up creating a "MyBlock" called 3-block-challenge that looked like this:
Drive forward until touch
Stop
Say "Object detected"
Back up 2 rotations
So then, our code looked something like this:
3-block-challenge
Back up 2 rotations
Turn 2 rotations
3-block-challenge
Turn 1 rotation
3-block-challenge
Introducing the 3-block-challenge MyBlock made the code much easier to understand and easier to modify. The MyBlock can be saved as a separate program that can be included into any program they create in the future as well.
Next Meeting
We will not be meeting again until the 27th of April because of vacations and Easter.At the next meeting we are going to introduce a little finesse with the touch sensor. It has the ability to sense when it is simply bumped. We will set up a stack of blocks that will be easy to knock over if it is pushed too hard, and the boys will have to use the bump sensor to get the robot to touch the blocks without knocking them over.
Then, if there is time, we will see if they can get the robot to do something when the touch sensor is released.
No comments:
Post a Comment