Teaching Your Robot to Bullfight...
There are several ways we could solve this Challenge. Let us think about two of them.
Plan One: We could send our Robot in to the Bullfighting Arena, and then use the same approach we used in SUMO; click here. This is a good plan, but since we already have notes about this, we will not say anything more about that here. If you want to use a SUMO approach to solve Bullfighting, you will get help by clicking here.
Plan Two: We could use LEGO's Ultrasonic (Sonar) Sensor. So far we have not had detailed notes about the use of this sensor. Sonar seems a good approach for Bullfighting. Let us look at Plan Two in detail.
Putting Plan Two Into Action.
First, we want to get our Robot to go forwards from the small blue starting square into the big blue bullfighting arena.
The NXT-G code below will help our robot do this.
The ultrasonic sensor is mounted about 5 centimetres (approximately 2 inches) above the floor, and this seems to work nicely.
To allow our robot to use the ultrasonic sensor, we
The control panel for the ultrasonic sensor is set up so that it will go to the top line of the switch (see below) when it sees something less than 40 centimetres in front of it. 40 centimetres is about 16 inches, which is roughly about three-quarters of the width of the bull fighting arena.
What do we want our robot to do when it sees a "Bull"?
Let us tell our robot to charge the Bull, pushing it out of the arena!
The command above will cause our robot to charge the Bull at 90% power. Good! Now let us put a loop around the switch so we can download the code to our robot, and test it.
Play this video to see what happens: (To play a video, click on the webcams above - the larger webcam produces a larger but slower downloading video; the smaller webcam produces a smaller but faster loading video).
The robot goes from the starting square in to the arena, and then stops! It can not see the Bull, which is out to one side. We need to tell the robot to turn until it sees the Bull.
To get our robot to turn, we can add some commands in the bottom line of the switch, as shown below.
The commands above will cause motor A to run backwards at a speed of 20%.
The commands above will cause motor C to run forwards at 20%. These additional commands will cause our robot to spin on the spot, looking for a Bull, as shown in the video below.
Does our robot do what we wanted?
Unfortunately our Robot charged straight over the edge of the bullfighting ring before it had a chance to turn. Not good!
In the diagram above, the light sensor has just left the bullfighting ring (see the blue arrow). We need to be able to instruct our Robot to stop charging forward when our Robot’s light sensor sees the white surrounds of the blue bullfighting ring. How do we instruct our Robot to go backwards in the direction of the orange arrow, back towards the safety of the centre of the ring?
Our Plan: Add a light switch. When the robot's light sensor sees dark blue, we still want the robot to charge forward. However when the light sensor sees white, we want it to go backwards.
A loop has been placed around the "charge forward" command. This will only allow the robot to charge forward as long as it is on the blue arena. Note that in the code above, the robot will only charge forward until it finds a light value that is greater than 46. How did we get the value of 46?
Telling motors A and C to go backwards one rotation will do, as a first guess. What happens when we download this code to our robot, and run it? Click on a video below to find out.
This video (taken before we used a light sensor) reveals another problem that we did not think about. Our robot can be caught between two Bulls, unable to turn. To make sure this can not occur, we can add a small extra turn after the robot returns to the centre of the arena.
In the code above, motor A is stopped after the robot returns to the centre of the arena.
In the code above, motor C is turned 90 degrees, (just a quarter of a turn). This should be just enough to get our robot out of the trap we saw in the previous video.
Download this code into your robot, and see if your robot now behaves as you would prefer.
Finally! Our Robot pushes the bulls out of the arena, without leaving the arena. Is this the best way to program a robot to push all the Bulls out of the ring? Are there better programs, better plans, that you could use when dealing with these Bulls? Are we pushing them out as quickly as possible? Have a think about all these, and have a talk to your teacher or mentor about the possibilities...
An Alternative Approach
A slightly different approach would be to use no switches, only loops. The program below has been tested, and works well. You may like to see if you can get it working (but there won't be any help this time!)
Enjoy...
Tutorial 54 - LEGO NXT MindStorms NXT-G - Robot Bullfighter Help - www.DrGraeme.net - copyright Dr. Graeme Faulkner