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.

Bull fight where to go 1 Lego NXT MindStorms tutorial

The NXT-G code below will help our robot do this.

  Robot Bullfighter Lego NXT NXT-G free tutorial 2

 Robot Bullfighter Lego NXT NXT-G free tutorial 3

We can download this code into our robot, and check that the robot does what we want it to do. Click on the webcam images below to see what happened to my robot; (big webcam image = big video, slower download; small webcam image = small video, faster download).

 

 Next, how can our Robot find a Bull by using a LEGO Ultrasonic Sensor?

Hint: When adding an ultrasonic sensor to your robot, it is a good idea not to mount the sensor too close to the floor, as the ultrasonic sensor can sometimes mistake the floor itself for a Bull. I chose to build Clarebot (you can get building instructions by clicking here). You can see where I mounted the ultrasonic sensor in the photograph below (if you have a big screen you can click on the photograph for a bigger image).

ClareBot bullfighting robot Lego NXT mindStorms free tutorial

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 will need to add a switch that recognises the ultrasonic sensor.

Robot Bullfighter Lego NXT NXT-G free tutorial 4

I have plugged my LEGO Ultrasonic (Sonar) Sensor into computer brick slot 4. If your ultrasonic sensor is plugged in to another slot, you will need to change this program.

Robot Bullfighter Lego NXT NXT-G free tutorial 5

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!

Robot Bullfighter Lego NXT NXT-G free tutorial 6

Robot Bullfighter Lego NXT NXT-G free tutorial 7

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.

Robot Bullfighter Lego NXT NXT-G free tutorial 8

Robot Bullfighter Lego NXT NXT-G free tutorial 9

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.

Robot Bullfighter Lego NXT NXT-G free tutorial 10

 

The commands above will cause motor A to run backwards at a speed of 20%.

Robot Bullfighter Lego NXT NXT-G free tutorial 12

 

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.

I have plugged my LEGO Light Sensor into computer brick slot 1. If your light sensor is plugged in to another slot, you will need to change this program.

 

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?

To calculate this, we need to get the blue and white light sensor values.

Robot Bullfighter Lego NXT NXT-G free tutorial 22

If you can't remember how to read your light sensor values click here (but think "white and blue" instead of the "silver and black" used in the video). When I measured blue and white on my arena, I obtained 54 for the white, 37 for the blue (your values will be different because the light in your room will be different from the light in my room).

Switch value = (blue value + white value)/2

= (54+37)/2

= 45.5

So, either 45 or 46 would be equally good light switch values to keep our robot inside the arena. I chose 46, as we saw above.

Next we need to tell our robot to go backwards, away from the edge of the arena, so that it does not accidentally stray "out of bounds" again.

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!)

Robot Bullfighter Lego NXT-G program free tutorial

Enjoy...

Tutorial 54 - LEGO NXT MindStorms NXT-G - Robot Bullfighter Help - www.DrGraeme.net - copyright Dr. Graeme Faulkner