PROGRAM "MINI-SUMO ROBOT. The final article on assembling a mini-sumo robot. The first part of the article "Chassis for a mini-sumo robot" described in detail how to make a robot chassis. In this article, we will analyze in detail the compilation of a program for a robot. Our robot ready. It has a chassis, the function of "brains" will be performed by a microcontroller, and communication with the outside world will be carried out by sensors. But, despite all this, it will still stand motionless on the table. And to prevent this from happening, it's time to breathe into our creation life, so to speak, to feel like a "creator" completely.The program that we will create will not only revive the robot, but also make it behave meaningfully and logically in the ring.


1. The basis of the program is the algorithm.

As before, we cannot do without a plan. In the previous article, our plan was the fundamental circuit diagram. In programming, a plan is called an algorithm. Some of you know what it is, someone just heard, but there are those who did not know and hear for the first time.

I will not use scientific terms, I will simply say that an Algorithm is a description of a sequence of certain actions. Our whole life is various actions; we walk, we talk, we move our arms and legs, we turn our heads. All this has its own meaning - an algorithm, a sequence that determines our behavior, and it can be compiled and described. For clarity, I will give an example from life. You brush your teeth every morning. Try to describe how you do it, how to write a program for yourself. Here's what happens: “We take a toothbrush. Squeeze out the paste. We brush our teeth with left-right movements. I rinse my mouth. My brush."

In principle, everything is correct, but we can perform this small program at lunchtime, in the evening, or after every meal. But we did not take into account important factors that can nullify all our efforts. Initially, we talked about the morning. This is an important factor, and if you do not take it into account, then you will have to brush your teeth while lying in bed and with your eyes closed. Therefore, any program must always have some kind of beginning and end with the possibility of repeating the cycle. The repeating cycle for a person is the next day, where it will be morning again, and teeth will need to be brushed again. Therefore, we add the following algorithm (sequence of actions) to our program.

"Wake up. Get out of bed...” If you stop creating the algorithm at this stage and go straight to brushing your teeth, the program will stall (hang). Why? Because we again did not take into account all the factors. You are standing in the middle of your bedroom and unable to execute the next command; “We take a toothbrush”, since the brush is in the bathroom, and you still need to get into it. Well, if you sleep in the bathroom, then no problem - the program will run! But in most cases, normal people sleep in another room. This approach is called logical, that is meaningful. All our actions must be reasonable and contain a certain meaning, otherwise the goal will not be achieved. So "Wake up. Get up. Go to the bathroom" would be the best option.

Let's get back to work. Now how do we plan the actions of the mini-sumo robot in the ring? We have rules where the goal is clearly marked - "Push the opponent out of the ring." But to achieve it, certain factors must be taken into account. The main factor is not to go beyond the circle itself, or to be more precise, not to go beyond the white border of the circle. Here's what we got:

Rice. 1 Algorithm of the robot's behavior in the ring.

In Figure 1 you see a block diagram. By all rights, this is how it is customary to compose algorithms. Clear and understandable.

The first block is "Start". From this moment, the program starts executing the actions of the robot after it is turned on. The first thing he will have to do is to find the enemy, the "Target Search" block. The next block of our scheme is in the form of a rhombus “Target found?”. This means that we will have a choice of actions to achieve a certain event. If the target is found (Yes), then we will continue the execution of the program and move on to the next part of the “Attack” program, but if the target is not found (No), then it is most logical to continue searching for it. The program will loop on this moment until the robot detects the enemy. When attacking, the robot moves forward towards the opponent, trying to push him out of the ring, at this moment the “Did you reach the edge of the ring?” proceeds to the next block "Drive back" and "Reversal". After the turn, the cycle of the main program is repeated, that is, it starts from the very beginning and the robot is again looking for the enemy. It was done so for a reason. If at the time of the attack, the enemy managed to escape from our robot, then we must return to his search without leaving the edge of the ring. Everything with theory. Let's move on to practice.

2. Rules for writing programs for Arduino.

Although I said that the theoretical part is over, but we should study the principle of constructing a program for Arduino microcontrollers, although these principles will be true for other MKs in the AVR family.

Rice. 2 Method of writing a program for Arduino.

This block diagram shows us clearly what important points, and in what order should be observed when writing a program.

At the very beginning of the program, if necessary, additional modules are connected. Then the global variables are declared. Next comes the controller initialization block. It defines the port assignments, whether it is an input or an output, and other settings. Additional auxiliary routines can also be called from this block. To be brief, at this point the program produces presets controller. This block is executed once when starting or rebooting the controller. Please note that the line "delay 5 seconds" has been added to the block. To general rules this does not apply to writing a program, but a mini-sumo robot is necessary. The rules say that after the referee's command, the robots must start moving after 5 seconds. This delay cannot be performed in the main loop of the program, as it will be constantly repeated, and the behavior of the robot will not change for the better.

In the block of the main cycle of the program, the main algorithm of the robot's behavior in the ring will be executed, which we have considered in Fig. 1. During the operation of the main loop, it will be possible to access subroutines. Programmers very often use subroutines to optimize and reduce code. For example, a program for moving forward or backward, it is more logical to single out in individual modules, and not included in the main body of the program. From this it will become huge, completely unreadable, and it will be very problematic to find an error or make a small change.

3. Arduino IDE development tool.

Download from the website Arduino.ru latest version Arduino IDE. The program does not require any special installation, it is enough to unpack the contents of the archive into Right place. At the end of this article is the Ultrasonic rangefinder library file. It should be unpacked into the Libraries folder.

We launch the application. We check the correct installation of the library, go to the menu, "File" - "Examples". Almost at the very bottom, the Ultrasonic item should appear as in fig. 3.

Rice. 3 Verify that the Ultrasonic library is installed correctly.

If everything is fine, go to the "Service" - "Pay" item. We need to choose our board - Arduino Pro Mini 5v.

Rice. 4 controller board setup

The serial port must be selected the one that appears after Arduino connections to the computer. A little should be said about the Arduino Pro Mini. Unlike other controllers in the Arduino family, the Pro Mini does not have a built-in computer connection module. It comes separately as a board. USB adapter to UART(TTL) and is connected to the controller board using four wires.

Rice. 5 USB-UART (TTL) adapter.

On fig. 6 shows how to properly connect the controller and adapter.

Rice. 6. Connecting the controller to the USB-UART adapter.

Unlike the received connection of signal lines, instead of RX-TX and TX-RX, these lines need to be connected directly: RX-RX, TX-TX. The first time you connect the adapter to your computer, the device drivers will automatically start installing. You should wait for the installation to finish. Another feature of the controller is the lack of software Reset at the time of programming. This is of course a little inconvenient, but not enough to refuse the Pro Mini. It is enough to press the Reset button on the controller after the inscription "Compiling" changes to "Download", Fig. 7.

Rice. 7. Displaying information about the progress of programming MK.

4. We write the code.

In this chapter, I will not dwell on the description of commands, directives and operators. It is assumed that you already have some basic knowledge. Otherwise, you need to refer to the documentation on the official website or other sources on the network. We will write the program code clearly according to the plan or algorithm that we have compiled. I added code to certain blocks of the algorithm, which we will now consider in more detail in Fig. eight.

Rice. 8. Writing the initial block of the program.

The first block: the directive # connects the module control library to our project.

Second block: We declare variables and write initial values ​​equal to zero into them. Please note that we will not create names for the output ports of the MK. I intentionally left them in digital form so that you can easily refer to circuit diagram. In this block, we declare only three variables - these are the left and right sensors of the ring (_ and _), they will store the ADC values. As well as the distance variable of the ultrasonic rangefinder (_), it will record the distance in centimeters to the obstacle.

The line Ultrasonic ultrasonic (4, 2) is nothing more than a declaration of a variable for the ultrasonic rangefinder, taken from the example of the included library. In parentheses are the ports to which the sensor legs and are connected.

The third block: (), in it we configure all the inputs and outputs of the microcontroller. We will receive incoming signals on ports 15, 17, so we assign (Input) to them. We have four ports controlling the engines: 3.5 for the left engine and 6.9 for the right engine, we assign them as an output.

Why do we use two ports for one engine? Everything is simple; If voltage is applied to the motor contacts, it will begin to spin in one of the directions, say clockwise. But if you change the polarity, i.e. change the "plus" and "minus" - the motor shaft will spin in the other direction. We will use this property for full-fledged maneuvers.

5. The main loop loop.

In this cycle, the main program of the controller is executed. You can't get out of it completely or complete it. From it, only calls to external procedures, the so-called subroutines, are possible.

Consider the structure of our cycle based on the algorithm in Fig. 9

Rice. 9. Algorithm of the main loop Loop.

From the very beginning, we need to get the readings of all sensors, for this we call the subroutine:

void check_sensor() // Subroutine for checking sensors.

R_Sensor=analogRead(15); // read the right sensor readings

L_Sensor=analogRead(17); // read the readings of the left sensor

delay(10); //delay to finish ADC conversion

dist_cm = ultrasonic.Ranging(CM); // read the readings of the ultrasonic rangefinder

delay(10); // Delay to finish conversion

After receiving the data, we need to process it. First we must determine our location, whether we are in the ring or not. If we check the presence of an opponent within 40 cm in the ring. If there is no opponent, we are looking for him by turning to the left procedure:

void go_left() // search for a target or go left

analogWrite(5, 100); //LEFT MOTOR

analogWrite(6, 100); //RIGHT MOTOR

The value of the power of the motors is almost halved, if we spin too fast, we can slip through the detected target by inertia.

If the target is detected, we must attack it, moving forward at full speed.

void go_forward() //Attack - moving forward

analogWrite(3, 0); //LEFT MOTOR

If at the time of the attack we ran into the edge of the ring and found a white stripe, then we need to stop, back out, turn around and drive a little forward, then resume the search again. To do this, call the procedures in order:

go_stop(); // stop

delay(100); //wait 10ms

go_back(); // Move back

delay(1000); //1 second.

go_right(); //Turn right

delay(300); //300ms

go_forward(); //Move forward

delay(300); //300ms

void go_stop() //stop

analogWrite(5, 255); //LEFT MOTOR

analogWrite(9, 255); //RIGHT MOTOR

void go_back () //go back

analogWrite(3, 255); //LEFT MOTOR

analogWrite(6, 255); //RIGHT MOTOR

analogWrite(9, 0); //RIGHT MOTOR

void go_right () //search for a target or move to the right

analogWrite(3, 100); //LEFT MOTOR

analogWrite(5, 0); //LEFT MOTOR

analogWrite(6, 0); //RIGHT MOTOR

analogWrite(9, 100); //RIGHT MOTOR

void go_forward() //Attack forward movement

analogWrite(3, 0); //LEFT MOTOR

analogWrite(5, 255); //LEFT MOTOR

analogWrite(6, 0); //RIGHT MOTOR

analogWrite(9, 255); //RIGHT MOTOR

Time delays between procedures determine the duration of the engines in different directions of movement. If you increase or decrease it, you can achieve various angles turn or the distance that the robot will travel before the next command is executed.

The full sketch for download is at the end of the article.

The presented code, of course, is not final or the most the right option, each of you has the right to supplement or correct it according to your requirements, because the general essence of the article is to teach beginner roboticists to think logically and systematically, to correctly solve tasks using all available resources.

Archive 1

Archive 2 to the article "Program of the minisumo robot".

If YOU have any questions, write on the FORUM or in the Online chat on robotics, we will discuss them!

Attention! Full or partial copying of material without the permission of the administration is prohibited!

Hello! Would you like to assemble a robot that is not difficult to assemble? You've come to the right place! =) It is on our website that you can find detailed articles on step-by-step assembly of your first robot, as well as many other robots, and even for competitions.

We are very glad that our articles will help you, a beginner in robotics, to master this most interesting area and pump your skills in this direction. We also want to note that according to these articles, we, the developers of the SERVODROID website, conduct classes in free circles of robotics, and we really like to teach and tell everyone what BEAM robotics is.

Help our project! Register on our website and come to our Online chat or forum and share your crafts and your progress - after all, it is your activity that attracts more and more attention to robotics for beginners - they look at your success and want to become just as cool, and we really It's nice to see that everything works out for you. And if something doesn't work out - we will help;)

Sumo- one of the most exciting Lego Ev3 robot competition. In this competition, the robot must push the opponent's robot out of the circle without leaving the circle itself.

At the very beginning of the competition, the robots are placed in the center of the circle, after the stratum the programs are launched and the robots must wait 3 seconds, after which the robots must reach the border of the circle and only then they have the opportunity to attack the enemy. The portal contains schemes of robots for Lego sumo and assembly instructions

Let's describe Sumo algorithm and program for EV3 robot

1 Action.

The robot waits 3 seconds, we drive away from the center of the circle to the border, we go forward, we spin, we look for the enemy, we go to the enemy, if we drive from the border, then we drive back.

Set the wait to 3 seconds.

2 Action. We drive back to the border.


3 action. After the robot has driven to the border, it must move forward. Forward movement.

4 Action. We set up an infinite loop. The robot will attack the enemy until it is pushed out or until the competition time is over.

We put a rotation cycle with an ultrasonic sensor into it. (you can also use an infrared sensor)


5 Action. We go forward until the color sensor sees a black line, the border of the circle.

6. Action After seeing the border, we drive back.

Exercise.

Write the departure back yourself using lesson 1.

Hey Geektimes!

Introduction

We have long known that robots are our future. There are many branches of robotics. Military development, social, entertainment and just working robots.
But this time I want to tell on behalf of the College team at MIREA about the competitive component, but exactly about sumo robots.

A little about our team

We have been in existence since 2014. Winners and prize-winners of most competitions Robofinist, Robofest, the MIPT Spartakiad and smaller tournaments, and we are also the absolute champions of Russia for 2016-2017 in the mini-sumo nomination.

Who are these sumo robots anyway?

Initially, when we first learned about such competitions, sumo wrestlers were made mainly from Lego. But this is a pretty bad idea, more on that later.

On the this moment the right sumo wrestler is described very simply: a completely autonomous piece of iron on wheels, with brains and a pair of sensors, which knocks a similar piece of iron out of the ring.

There are 4 types:

1. Mega sumo wrestler
2. Mini sumo wrestler
3. Micro sumo wrestler
4. Nano sumo wrestler

Everyone is different not only externally, but also internally.

Mega - the largest and most dangerous robots. The maximum weight is up to 3 kg, the ability to put various "suckers", which is not allowed to do with other robots.

Mini - pleasant, small robots up to 500 grams 10 by 10 cm. Not difficult to solder, easy to set up and assemble. They are the most popular nomination in sumo.

Micro and nano - reduced mini copies. Micro 5x5x5, nano 2.5x2.5x2.5. Difficult to solder and pick up parts. More popular than mega sumo.

What are they made of?

Let's get back to Lego. Most likely, many of you have tried to do something with a programmable Lego constructor, or at least have seen how it is done. There is even a separate nomination for such robots 15 by 15, but it is terribly boring and suitable only for very beginners or small roboticists. Compared to homemade samples, this one loses in everything except the complexity of assembly.

First it low speed. Secondly, the size is huge. Thirdly, the low response speed of the sensors. And also the controller itself leaves much to be desired.

More about assembly and packaging

Sumo wrestlers who compete are doing on arduino. They use textolite boards, soldering sensors, a controller, a driver, etc. to it. There is also a wide selection of sensors for detecting an enemy, but it is worth using infrared or laser ones, because sonars are very slow and bulky. Of course, engines and wheels are needed for the robot to move around. You can put them in an unlimited number, but practice shows that the robot rides best on two wheels placed at the back. And, of course, the robot cannot live without a bucket and a hook. The bucket is just a case, a wrapper and protection for the board and elements. Most often steel or iron. The hooks are made from blades for stationery knives, but there are instances with a non-standard approach, for example, a sharpened wooden ruler or cotton wool, but this approach is of little use.

The most difficult thing (besides programming) is to design a robot.

First stage



This is what is called the very first stage - the placement of engines and sensors. You can also observe here two small sensors in front of the hook, so these are the line sensors.

They are used to detect a white line on the range to avoid accidental falls out of the ring, but are not a required component and are not actually used very often. high speeds often do not allow time to stop.

Second phase



And here the controller, driver, switches and battery connector are already applied.
All that remains is to print the trace and transfer it to a textolite board, and then work out the tracks.

Here's what it looks like on the finished board:

Finished board



Robot ready to run:

As you can see, there is nothing particularly complicated here. About the problems below.

Let's move on to programming

The easiest way is to use arduino or arduino-compatible controllers. Also, Arduino IDE to help us. By standard scheme the robot has 5 sensors. So the states can be

We exclude the situation when the side sensors see the enemy at the same time (because this cannot happen, and if it does, then there is a malfunction in one of the sensors), as well as the situation in which the side and two front sensors give 0 (i.e. . see), because this also cannot be, or the chance is too small.

To make it go to the enemy, we just need to install the pins, apply voltage to the motors and read the sensor readings:

Robot code

// Setting pins for sensors int pin_left=10; int pin_center_left=11; int pin_center_right=4; int pin_center=12; int pin_right=7; // Pins to motors int pin_motor_left_forward=9; int pin_motor_left_back=6; int pin_motor_right_forward=3; int pin_motor_right_back=5; // Variables for storing the result of polling sensors int cl,cc,cr,l,r; // Function for polling sensors void GLAZ() ( cl = digitalRead(pin_center_left); cc = digitalRead(pin_center); cr = digitalRead(pin_center_right); l = digitalRead(pin_left); r = digitalRead(pin_right); ) // Function movement, accepting speeds from 0 to 255 to feed each motor void MOVE(int a, int b) ( if(a<0) { digitalWrite(pin_motor_left_forward,LOW); analogWrite(pin_motor_left_back,0-a); } else { analogWrite(pin_motor_left_forward,a); digitalWrite(pin_motor_left_back,LOW); } if(b<0) { digitalWrite(pin_motor_right_forward,LOW); analogWrite(pin_motor_right_back,0-b); } else { digitalWrite(pin_motor_right_back,LOW); analogWrite(pin_motor_right_forward,b); } } void setup() { pinMode (pin_center,INPUT);//центральный pinMode (pin_right, INPUT);//правый датчик pinMode (pin_left,INPUT);//левый датчик pinMode (pin_center_right, INPUT);//передний правый датчик pinMode (pin_center_left,INPUT);//передний левый датчик pinMode (pin_line_left, INPUT); pinMode (pin_line_right, INPUT); pinMode (pin_start,INPUT);//старт pinMode (13,OUTPUT);//старт digitalWrite(13,HIGH); pinMode (pin_motor_left_back, OUTPUT);//мотор лево назад pinMode (pin_motor_right_forward, OUTPUT);//мотор право вперед pinMode (pin_motor_right_back, OUTPUT);//мотор правый назад pinMode (pin_motor_left_forward,OUTPUT);//мотор лево вперед // ожидание сигнала к началу схватки while(!digitalRead(pin_start))continue; MOVE(200,200); } void loop() { GLAZ(); if(l && r) { if((cl + cc + cr) < 2 || !cc){ MOVE(255,255); } if(cc) { if(!cl && cr) MOVE(0-180,180); if(cl && !cr) MOVE(180,0-180); } } else if(cc + cr + cl == 3) { if(!l && r) MOVE(0-200,200); if(!r && l) MOVE(200,0-200); } else if(cc) { if(!l && !cl && cr && r) MOVE(0-150,150); if(l && cl && !cr && !r) MOVE(150,0-150); } if(!digitalRead(pin_start))while(1){MOVE(0,0);} }


You just have to improve the code.

Important!
Sensors return 1 if they see nothing and 0 if there is an obstacle.

After downloading the code via usb, the robot is ready to compete.

Worth considering

First, there are the elements. The sensors we use (sharp 340) are quite rare or non-existent. Therefore, if possible, then you need to take a lot at once or find an analogue that is suitable in terms of parameters.

Secondly, you can not cause any critical damage to the enemy robot or use, for example, magnets to pick up. This slightly limits us in the choice of means for the struggle.

Also, don't forget the wheels. Curves, thin and sliding will not work, you simply will not be able to maneuver and there will not be enough moment of force. Be sure to test the tires.

When working with engines, keep in mind that they will have to work under maximum load and they will burn quite often.

It also makes sense to make removable batteries, because. The robot is discharged quite quickly, and it takes a long time to charge.

List of necessary purchases:

1. Soldering iron, solder, flux (optional)
2. Textolite boards (to etch, you need to close all the tracks, then put it all in a solution of hydrogen peroxide + citric acid + salt for several hours, and then tear off the paper, for example, under which the tracks were hidden)
3. Sharp 340 sensors
4. Engines, choose to taste, the more rpm, the better.
It is worth choosing one of these: polulu. (added)
5. Batteries (I advise you to take lithium polymer) + charging station
6. Key (switch button, soldered to the board) and electrical elements (there is in the picture with a trace)
7. Driver
8. Controller, for starters, you can try Polulu A-Star 32u4 micro and upload the arduino bootloader there
9. Metal sheet for the body
10. Drill for holes in the board
11. Launcher and starter module
P.S. If I missed something - write, I will correct it.

Competition

The next competitions will be held in St. Petersburg, Robofinist, so now we are intensively preparing for them and if you want to take part, then you need to do everything clearly and quickly.

But these competitions are not the only ones, there are quite a lot of them in Russia, the largest ones are held in Moscow. About once a month or two, you can experience happiness and compete.

Such competitions abroad are not uncommon and we also want to get there. Here is an approximate map of competitions around the world:

We really hope that robot sumo will only develop in our country and we invite everyone to participate in the creation of our robot. It looks very epic when pieces fly off from some robot.

This is the end of our introductory article and we wish you all success in robotics, we will be glad to see you at the competitions!

1. General rules

1.1. The robot must push the opponent robot out of the black line (out of bounds).

1.2. After the start of the competition, the robots must move towards each other until the collision.

1.3. After the collision, the robots should try to make contact with each other.

1.4. During the competition, team members should not touch the robots.

1.5. Two autonomous robots are placed in the ring (round field). The robots are trying to push the opponent out of the ring.

1.6. The robot that wins the most rounds wins the match.

1.7. When playing "each with each", the best robot is considered to have won the most matches.

1.8. With a large number of participants, it is possible to organize the ranking according to the "Olympic system" (for departure).

2. Robot

2.1. Robots must be built using only LEGO Mindstorms parts.

2.2. During the whole round:

The size of the robot should not exceed 25x25x25cm.

The weight of the robot must not exceed 1kg.

2.3. A robot, in the opinion of the judges, that intentionally damages other robots, or otherwise damages the surface of the field, will be disqualified for the entire duration of the competition.

2.4. It is strictly forbidden to use in the design of the robot:

Adhesives.

2.5. Before the match, the robots are checked for dimensions and weight.

2.6. The robot may have a plurality of programs from which the operator may choose each round.

2.7. Between matches, it is allowed to change the design and programs of robots.

3. Field

3.1. White circle with a diameter of 1 m with a black border 5 cm thick.

3.2. In the circle, the starting zones of the robots are marked with red stripes.

3.3. The red dot marks the center of the circle.

3.4. The field is placed on a podium with a height of 16 mm.

4. Holding Competitions

4.1. Competitions consist of a series of matches. The match determines which of the two robots participating in it is the strongest. The match consists of 3 rounds of 30 seconds. The match is won by the robot that wins the most rounds. The judge may use an additional round to clarify disputed situations.

4.2. Rounds are held consecutively.

4.3. At the beginning of the round, robots are placed behind the red stripes (from the center of the ring) in their starting areas, all parts of the robot touching the field must be inside the starting area.

4.4. At the command of the referee, a signal is given to start the robots, while the operators of the robots must start the program on the robots and move away from the field by more than 1 meter within 5 seconds. In the same 5 seconds, the robots must travel in a straight line and collide with each other.

4.5. For beginners: After the collision, the robots cannot maneuver around the ring.

4.6. For the experienced: After the collision, the robots can maneuver around the ring as they please.

4.7. If the robots do not collide within 5 seconds after the start of the round, then the robot, due to which, in the opinion of the judge, there is no collision, is considered the loser of the round. If the robots are traveling in a straight line and do not have time to collide in 5 seconds, then the robot closest to its starting area is considered the loser of the round.

5. Winner Selection Rules

5.1. If the robot does not move without being in contact with another robot for more than 10 seconds, then it is considered the loser of the round.

5.2. When touching any part of the robot (even not attached to the robot) beyond the black border, the robot loses the round.

5.3. If at the end of the round no robot is pushed out of the circle, then the robot closest to the center of the circle is considered the winner of the round.

5.4. If the winner cannot be determined by the methods described above, the decision on victory or a replay is made by the judge of the competition.

6. Refereeing

6.1. The organizers reserve the right to make any changes to the competition rules if these changes do not give advantages to one of the teams.

6.2. Control and summing up is carried out by the panel of judges in accordance with the above rules.

6.3. Judges have full powers throughout all competitions; all participants must abide by their decisions.

6.4. If there are any objections regarding refereeing, the team has the right to verbally appeal the decision of the judges to the Organizing Committee no later than the end of the current round.

6.5. A replay can be held by the decision of the judges in the case when the robot was unable to finish the stage due to outside interference, or when the malfunction occurred due to the poor condition of the playing field, or due to an error made by the judging panel.

6.6. Team members and the leader must not interfere with the actions of the robot of their team or the robot of the opponent, either physically or from a distance. Interference leads to immediate disqualification.

6.7. The referee may end the match at his own discretion if the robot is unable to continue moving within 10 seconds.

12.2. The design of the robot for the competition "Sumo".

Basic robot behavior in "Sumo" very similar to the behavior of a robot in "Kegelring". The robot also needs to find an object inside the field and push it out of the circle. The differences, as usual, lie in the details: now this object, in turn, is looking for our robot and is also eager to push it out as soon as possible.

Nevertheless, let's focus on our goal: one of the sensors capable of detecting objects at a distance (infrared or ultrasonic) will still help us look for an opponent, and we will timely determine the black border of the field using a color sensor. Therefore, to create and debug the sumo robot program, we suggest you use the same robot that we prepared for Lesson #11 - Kegelring.

In order to protect the sensor located in front from interaction with an opponent, we will build a bumper and fix it on our robot. Below are detailed building instructions for both home and educational Lego mindstorms EV3. Feel free to experiment and come up with your own design.

Lego Mindstorms EV3 Home

Lego Mindstorms EV3 Education

We fix the resulting element on the front beam of our robot.

Lego Mindstorms EV3 Home

Lego Mindstorms EV3 Education

Our training robot is ready. Let's start creating a sumo robot program. It's great if you have the opportunity to debug the program using another robot! If not, then it's okay: you can use as an opponent, for example, a radio-controlled car model or the same skittles from Kegelring.

12.3. Creation of a program for the competition "Sumo".

The first thought that comes to mind is to use the program to "Kegelring" with some cosmetic changes. Indeed, the robot behavior algorithms in "Kegelring" and in "Sumo" very similar. They implement the search for an object and pushing it out of the field. You can download a program to the sumo wrestler for "Kegelring", but such a sumo wrestler will not work very efficiently. However, the knowledge gained in the previous lesson will be useful to us now.

It's time to upload our project to the programming environment "lessons-2", create a new program in it lesson-12 and connect the robot to the programming environment.

The behavioral model of a sumo wrestler can be divided into two parts: search for an opponent and opponent's attack. Let's start with the implementation of the first part - search for an opponent.

Let's describe in detail the sequence of actions of our robot when an opponent is detected on the field:

  1. rotate around its axis until the sensor located in front detects an opponent;
  2. stop in front of an opponent.

This sequence of actions completely repeats the robot's search algorithm for skittles in "Kegelring", but since the distance between the robots in "Sumo" can exceed the distance from the robot to the pin, then we need to choose a different threshold value for the sensor used.

Set up opponents on the field opposite each other, as shown in the figure below.

This position practically corresponds to the maximum distance between the robots from each other during the competition, so the current reading of the sensor that measures the distance to the opponent can be taken as a threshold value. Important: since the threshold value will be large enough, it is necessary that outside the field at a distance of about 1 m. during the operation of the robot there are also no foreign objects that can interfere with the search.

On the "Hardware page", located in the lower right corner of the programming environment, select the tab "Port view" (Fig. 1, 2 pos. 1) and take the reading of the sensor that determines the distance to the opponent by setting the appropriate display mode of the readings.

In our case, the ultrasonic sensor is in the mode "Distance in centimeters" shows value - 56.1 (Fig. 1 pos. 2) 57 .

Rice. one

Infrared sensor in mode "Approximation" shows value - 68 (Fig. 2 pos. 2). For the threshold value we take the number - 70 .

Rice. 2

By analogy with "Kegelring" we can program the robot to find an opponent, only to distance ourselves a little from the previous lesson, we change the direction of rotation of the robot to the opposite:

ultrasonic sensor

  1. "Green Palette" "Turn on" "B" set equal to -30 , power value for the port "C" set equal to 30 (Fig. 3 pos.1).
  2. To search for an opponent, use the program block in the mode "Ultrasonic sensor - Comparison - Distance in centimeters" 57 (Fig. 3 pos. 2).
  3. turn off the motors (Fig. 3 pos. 3).

Rice. 3

infrared sensor

  1. In order to make the robot rotate around its axis, we use the program block "Independent Motor Control" "Green Palette", Set the block operation mode "Turn on", power value for the port "B" set equal to -30 , power value for the port "C" set equal to 30 (Fig. 4 pos. 1).
  2. To search for an opponent, we use the program block "Waiting" "Orange Palette" in mode "Infrared Sensor - Comparison - Approximation", with the threshold value of the sensor operation equal to 70 (Fig. 4 pos. 2).
  3. After the robot is opposite the opponent, using the program block "Independent Motor Control" "Green Palette" turn off the motors (Fig. 4 pos. 3).

Rice. four

At the stage of debugging this algorithm, you will have to select the values "Power" motors "B" and "C" as well as the threshold value of the sensor, to achieve accurate detection from your robot and stop directly in front of the opponent. Only after that it will be possible to proceed to the software implementation of the attack algorithm.

If the search for an opponent in "Sumo" very similar to the search for skittles in "Kegelring", then pushing the opponent has an important difference! Starting an attack, the first thing to do is to rush straight at the maximum power of the motors towards the detected opponent, checking the detection of the ring border with a color sensor. But our opponent can also move! Therefore, it is quite possible that the opponent will step aside from under the direction of our attack. In this case, our robot, having missed, will move towards the border of the ring, losing the opponent and precious time.

Therefore, we need to analyze both sensors during a straight forward movement and stop the attack if the robot will lose an opponent OR the robot will reach the border of the ring. Therefore, we need to stop using the program block "Waiting" "Orange Palette" and independently in a cycle to receive and process the readings of two sensors.

Let's proceed to the phased implementation of the algorithm opponent's attacks: for this we will create a temporary program in the project lesson-12-1 and start filling it with program blocks.

  1. Let's take a program block "Cycle" "Orange Palette".
  2. Inside the block "Cycle" put a program block "Independent Motor Control" "Green Palette" "Turn on" (Fig. 5 pos. 1), motor power "B" and "C" set to the maximum value - 100 (Fig. 5 pos. 2).

Rice. 5

  1. Behind the block "Independent motor control" place the program block . Set the block operation mode to "Comparison - Reflected Light Intensity" (Fig. 6)

Rice. 6

In this mode, the program block "Color sensor" "Yellow palette" visually very similar to the software block "Waiting" "Orange Palette" in mode "Color Sensor - Comparison - Reflected Light Intensity". But unlike the block "Expectation", this program block does not wait for the condition specified by the parameters "Comparison type" (Fig. 7 pos. 1) and "Threshold value" (Fig. 7 pos. 2), and immediately gives a boolean value ( "True" or "Lie") in the output parameter and the measured value in the output parameter "Lighting" (Fig. 7 pos. 4).

Options "Comparison type" and "Threshold" on the Rice. 7 pos. 12 "Comparison result" (Fig. 7 pos. 3) gave a boolean value "True" when the color sensor crosses the black border of the ring.

Rice. 7

  1. In case of using an ultrasonic sensor behind the unit "Color Sensor" install the software block "Ultrasonic sensor" "Yellow palette". Set the block operation mode to "Comparison - Distance in centimeters" (Fig. 8 pos. 1). Parameter "Type of comparison" (Fig. 8 pos. 2), parameter "Threshold value" (Fig. 8 pos. 3) set in such a way that the output parameter "Comparison result" (Fig. 8 pos. 4) gave a boolean value "True"

Rice. eight

In case of using an infrared sensor behind the unit "Color Sensor" install the software block "Infrared sensor" "Yellow palette". Set the block operation mode to "Comparison - Approximation" (Fig. 9 pos. 1). Parameter "Type of comparison" (Fig. 9 pos. 2), parameter "Threshold value" (Fig. 9 pos. 3) set in such a way that the output parameter "Comparison result" (Fig. 9 pos. 4) gave a boolean value "True" in case of loss of sight by the robot of the opponent.

Rice. 9

Let's once again analyze the intermediate code of our attack algorithm: we turned on the motors to maximum power and move forward, constantly polling the sensors in a cycle. If our robot crosses the black line of the ring border, then the value of the output parameter "Comparison Result" "Color Sensor" will take on the meaning "True". If our robot loses an opponent, then the value of the output parameter "Comparison Result" the sensor tracking the opponent will also take on the value "True". In any of these cases, we should stop the attack by ending our cycle. The program block will help us with this. Let's get acquainted with this block in more detail: program block "Logic Operations" designed to perform operations on logical data (Fig. 10).

Rice. ten

Selected program block mode "Logical operations" "Red palette" defines one of four operations on boolean data: "AND (AND)", "OR (OR)", "XOR" and "Exception (NOT)". D va input parameters "a" and "b"(for operation "Exception (NOT)"- one input parameter "a") pass input values ​​to the program block, and the resulting value is produced by the output parameter "Result". If you have not previously encountered logical operations, you can familiarize yourself with the basic knowledge in the attached help under the spoiler.

Boolean operations

Logical operations are performed only on logical values ​​(data), which is also a logical value. A boolean value can be in one of two states: "True" or "Lie". Logical operations are very often written in tabular form as: "input parameter 1" - "input parameter 2" = "result". Logic operations implemented by the program block "Logical operations" "Red palette" in tabular form can be written as follows:

Logical operation "AND (AND)"

The result of a logical operation "AND (AND)" there will be a value "True" "True" "Lie".

"a" operation "b" result
"Lie" "AND (AND)" "Lie" = "Lie"
"Lie" "AND (AND)" "True" = "Lie"
"True" "AND (AND)" "Lie" = "Lie"
"True" "AND (AND)" "True" = "True"

Logical operation "OR (OR)"

The result of a logical operation "OR (OR)" there will be a value "Lie" only if both input values ​​are equal "Lie", in all other cases the value of the operation is "True".

"a" operation "b" result
"Lie" "OR (OR)" "Lie" = "Lie"
"Lie" "OR (OR)" "True" = "True"
"True" "OR (OR)" "Lie" = "True"
"True" "OR (OR)" "True" = "True"

Logical operation "XOR"

The result of a logical operation "XOR" there will be a value "True" only if one of the input values ​​is equal "True", in all other cases the value of the operation is "Lie".

"a" operation "b" result
"Lie" "XOR" "Lie" = "Lie"
"Lie" "XOR" "True" = "True"
"True" "XOR" "Lie" = "True"
"True" "XOR" "True" = "Lie"

Logical operation "Exception (NOT)"

Boolean operation "Exception (NOT)" applies to only one input value. The result of a logical operation "Exception (NOT)" above the input value is the opposite value.

  1. Behind the programming block "Ultrasonic sensor" or "Infrared sensor" put a program block "Logical operations" "Red palette".
  • output parameter "Comparison Result" program block "Color sensor" (Fig. 11, 12 pos. 1) "a" program block "Logic Operations" (Fig. 11, 12 pos. 4).
  • output parameter "Comparison Result" program block "Ultrasonic (infrared) sensor" (Fig. 11, 12 pos. 2) connect with input parameter "b" program block "Logic Operations" (Fig. 11, 12 pos. 5).
  • Program block operation mode "Logic Operations" set in "OR (OR)" (Fig. 11, 12 pos. 3). In this case, the result of the logical operation will take the value "True", only if one of the conditions is met: the color sensor has crossed the black line, the robot has lost its opponent.
  • By setting the program block mode "Cycle" into meaning "Boolean value" (Fig. 11, 12 pos. 7), output parameter "Result" program block "Logical operations" (Fig. 11, 12 pos. 6) connect with input parameter "Until the truth is" program block "Cycle" (Fig. 11, 12 pos. 8). These settings will complete the cycle when "True" the result of a logical operation.

Rice. eleven


Rice. 12

Let's test the resulting attack algorithm! To do this, we will place our robot inside the ring, on the contrary, we will install a motionless opponent and launch the attack program for execution. Our robot must confidently push the opponent out of the ring and stop above the black border of the field. Happened? So our sumoist correctly controls the border of the ring.

Let's conduct the second experiment: we will again install a motionless opponent in front of the robot and launch the attack program. When our robot rushes to the opponent and gets close enough, we will sharply remove the opponent to the side. Our robot must, having lost an opponent, stop.

To summarize: we have implemented an opponent search algorithm and successfully tested it, and the attack algorithm has also been tested.

The completed program of the sumo wrestler must sequentially search for an opponent in an endless loop, and then attack the opponent. It would be possible to combine both parts of our program, if not for one small addition. If our robot stopped above the border of the ring, then before starting the search, the robot should, having driven back a little, return inside the ring. We will supplement our attack program with the following code: outside the attack loop, we will use the program block " Switch "Orange Palette". Block operation mode "Switch" set in "Color Sensor - Comparison - Reflected Light Intensity". Options "Comparison type" and "Threshold" set in the same way as previously used in the program block "Color sensor" "Yellow palette". Therefore, if our robot stopped above the black line, then the execution will be transferred to the upper container of the program block "Switch". It is in the upper container that we place the program block "Steering" "Green Palette", with parameter settings that cause the robot to move back one revolution of the motors. To the bottom container of the program block "Switch" place a program block that turns off the motors (Fig. 13). Having re-tested the attack algorithm, we will make sure that after the sumo robot pushed the opponent out of the ring, he returned a little back.

Rice. 13

Now you can complete the development of the program for the sumo robot. Inside the infinite loop, we sequentially nest the program for searching for an opponent, and then the program for attacking an opponent. Try to do this work yourself without peeking into the solution.

Conclusion:

The program that we discussed with you in this lesson implements only one direct force algorithm for the behavior of a sumo robot. It implies that in a direct power confrontation, the robot must certainly defeat its opponent. But our training robot, of course, is nothing like a muscular sumo wrestler. In order to confidently perform in this competition, it is necessary to pay the closest attention, first of all, to the design of the robot, to create a solid, protected platform, to increase traction with the surface of the ring with the help of additional driving wheels or tracks. Popular video hosting Youtube.com on request "sumo lego robots" you can find many videos from real robot competitions, from which you will certainly draw interesting ideas for yourself to implement in your own designs.

The main goal of this lesson is to show you a method for continuously processing readings from a pair of sensors using a practical example. Can our program be improved? Undoubtedly! For example, using the program block "Random value" "Red Palette", change the algorithm for finding an opponent in such a way as to set a random rotation of the robot to the left or right, thereby disorienting the opponent. Try to build this additional code into our program yourself. Think also about what changes you need to make to the program, in the case of a competition on a black ring with a white border. You may have your own improvement ideas: share them in the comments to the lesson!