Experience in creating the first robot on Arduino (robot-"hunter")

Hello.

In this article I want to describe the process of assembling my first robot on arduino. The material will be useful to other beginners like me who want to make some kind of "self-running cart". The article is a description of the stages of working with my additions in various nuances. A link to the final code (probably not the most ideal one) is given at the end of the article.

Experience in creating the first robot on Arduino (robot-"hunter")

Whenever possible, I involved my son (8 years old) in the participation. What exactly worked with him and what did not - I allocated part of the article for this, perhaps it will be useful to someone.

General description of the robot

First, a few words about the robot itself (idea). I didn’t really want to collect something typical at the start. At the same time, the set of components was pretty standard - chassis, motors, ultrasonic sensor, line sensor, LEDs, buzzer. Initially, from this "soup set" a robot was invented that guards its territory. He rides on the intruder who crossed the circle line and then returns to the center. However, in this version, a drawn line was needed, plus extra mathematics in order to constantly stay in the circle.

Therefore, after some deliberation, I slightly changed the idea and decided to make a “hunter” robot. At the start, he turns around his axis, choosing a nearby target (person). If the "victim" is found, the "hunter" turns on the flasher and siren, and starts to go to her. When the person moves away/runs away, the robot chooses a new target and pursues it, and so on. Such a robot does not need a limited circle, and it can work in an open area.

As you can see, this is a lot like a catch-up game. Although in the end the robot did not turn out to be frisky enough, it honestly interacts with the people around it. Children especially like it (sometimes, however, it seems that they are about to trample it, as much as the heart skips a beat ...). I think this is a good solution to popularize technical design.

Robot Structure

So, we have decided on the idea, let's move on to layout. The list of elements is formed from what the robot should be able to do. Everything is quite obvious here, so let's immediately look at the numbering:

Experience in creating the first robot on Arduino (robot-"hunter")

The “brains” of the robot are the arduino uno board (1); Was in a set ordered from China. For our purposes, it is quite enough (we focus on the number of pins used). From the same set, we took a finished chassis (2), on which two drive wheels (3) and one rear (freely rotating) wheel (4) are attached. Also in the kit was a ready-made battery compartment (5). The robot has an ultrasonic sensor (HC-SR04) (6) in front, a motor driver (L298N) (7) in the back, an LED flasher (8) in the center, and a squeaker (9) a little to the side.

In the build phase we look at:

- to fit everything
- to be balanced
- to be rationally placed

In part, our Chinese colleagues have already done this for us. So, the heavy battery compartment is placed in the center, and the driving wheels are approximately below it. All other boards are lightweight, they can be placed on the periphery.

Nuances:

  1. There are many factory holes in the chassis from the kit, but I still haven’t figured out what logic is in them. The motors and the battery pack were fixed without any problems, then the “fitting” began with drilling new holes to secure this or that board.
  2. Brass racks and other fasteners from the store helped out a lot (sometimes I had to get out).
  3. I passed the tires from each board through the clamps (again I found it in the storerooms). Very comfortable, all the wires lie beautifully and do not hang out.

Separate blocks

Now I'll walk through blocks and I will tell you personally about each.

battery compartment

It is clear that the robot must have a good source of energy. The options may be different, I chose the option with 4 AA batteries. In total, they give about 5 V, and this voltage can be directly applied to the 5V pin of the arduino board (bypassing the stabilizer).

Of course, I had some caution, but this solution is quite efficient.

Since power is needed everywhere, for convenience, I made two connectors in the center of the robot: one “distributes” the ground (on the right), and the second - 5 V (on the left).

Experience in creating the first robot on Arduino (robot-"hunter")

Motors and driver

First, about the engine mounts. Mounting factory, but made with large tolerances. In other words, the engines can "wobble" a couple of millimeters left and right. For our task, this is not critical, but somewhere it can influence (the robot will start to lead away). Just in case, I set the engines strictly in parallel and fixed them with glue.

Experience in creating the first robot on Arduino (robot-"hunter")

To control the motors, as I wrote above, the L298N driver is used. According to the documentation, it has three pins for each motor: one for changing the speed and a couple of pins for the direction of rotation. There is one important point here. It turns out that if the supply voltage is 5 V, then the speed control simply does not work! That is, either it does not twist at all, or it twists to the maximum. Here is such a feature, because of which I "killed" a couple of evenings. In the end, I found a mention somewhere on one of the forums.

Generally speaking, I needed a low rotation speed when turning the robot - so that it had a margin of time to scan the space. But, since nothing came of this idea, I had to do it differently: a small turn - stop - turn - stop, etc. Again, not so elegant, but workable.

I’ll also add here that after each pursuit, the robot chooses a random direction for a new turn (clockwise or counterclockwise).

Ultrasonic sensor

Experience in creating the first robot on Arduino (robot-"hunter")

Another piece of iron, where I had to look for a compromise solution. The ultrasonic sensor on real obstacles gives unstable numbers. Actually, it was expected. Ideally, it works somewhere in competitions where there are smooth, even and perpendicular surfaces, but if someone’s legs “flash” in front of it, then additional processing needs to be introduced.

As such processing, I put median filter for three counts. Based on tests on real children (during the tests, not a single child was injured!), It turned out to be quite enough to normalize the data. The physics here is simple: we have signals reflected from the right objects (giving the required distance) and reflected from more distant ones, such as walls. The second ones are random outliers in measurements like 45, 46, 230, 46, 46, 45, 45, 310, 46 ... It is their median filter that cuts off.

After all the processing, we get the distance to the nearest object. If it is less than a certain threshold value, then we turn on the alarm and drive straight to the “violator”.

Flasher and siren

Perhaps the simplest elements of all of the above. You can see them in the photos above. There is nothing to write about the iron here, so now let's move on to code.

Control Program

I don’t see the point in describing the code in detail, who needs it - the link is at the end of the article, everything is quite readable there. But the general structure would be nice to explain.

The first thing I had to think about was that a robot is a real-time device. More precisely, to remember, because before, and now I still do electronics. So, we immediately forget about the challenge delay (), which is very popular in example sketches, and which simply “freezes” the program for a specified period of time. Instead, as experienced people advise, we introduce timers for each block. The required interval has passed - they performed the action (increased the brightness of the LED, turned on the engine, and so on).

Timers can be linked. So, for example, the squeaker works synchronously with the flasher. This simplifies the program a bit.

Naturally, we break everything down into separate functions (flashing light, sound, turn, forward movement, and so on). If you don’t do this, then you won’t be able to figure out what comes from where and where.

The nuances of pedagogy

Everything that was described above, I did in my free time in the evenings. In a leisurely mode, I spent about three weeks on the robot. This could have ended, but I also promised to tell you about working with a child. What can be done at this age?

Work according to instructions

We first checked each detail separately - LEDs, tweeter, motors, sensors, etc. There are a large number of ready-made examples - some right in the development environment, others can be found on the Internet. This, of course, pleases. We take the code, connect the part, make sure that it works, then we already begin to change it to suit our task. Connections according to the scheme and under some of my control, the child makes himself. This is good. You also need to be able to work clearly according to the instructions.

Order of work ("from particular to general")

Here is a difficult point. You need to teach that a big project (“make a robot”) consists of small tasks (“connect a sensor”, “connect motors” ...), and those, in turn, consist of even smaller steps (“find a program”, “connect a board "," download firmware "...). By performing more or less understandable tasks of the lower level, we “close” the tasks of the middle level, and from them the overall result is already added. I explained, but I think the realization will not come soon. Somewhere around adolescence.

Installation

Drilling, threads, screws, nuts, soldering and the smell of rosin - where without it. The child received the basic skill “Working with a soldering iron” - he managed to solder several joints (I helped a little, I won’t hide it). Don't forget the safety explanation.

Computer work

I wrote the program for the robot, but I managed to achieve some passing results.

First: English. At school, it had just begun, so we “scrambled” to sort out what pishalka, migalka, yarkost and other transliteration are. At least they understood that. I deliberately did not use native English words, since we have not yet reached this level.

Second: effective work. Learned hot key combinations, how to quickly perform typical operations. Periodically, when we were writing the program, my son and I changed places, and I said what needed to be done (replacement, search, etc.). I had to repeat over and over again: “select with a double click”, “hold down Shift”, “hold down Ctrl” and so on. The learning process here is not fast, but I think the skills will gradually be deposited “in the subcortex”.

Hidden textYou can say that the above is almost obvious. But, honestly, this fall I had a chance to teach computer science in the 9th grade at one school. That's horrible. Students do not know such elementary things as Ctrl + Z, Ctrl + C and Ctrl + V, select text while holding Shift or double-click on a word, and so on. This is despite the fact that they were in their third year of studying computer science ... Draw your own conclusion.

Third: blind printing. I entrusted the comments in the code to the child to print (let him practice). Immediately put the right hands so that the fingers gradually remember the location of the keys.

As you can see, we are still just getting started. We will continue to hone our skills and knowledge, they will come in handy in life.

Speaking of perspective...

Further development

The robot is made, drives, blinks and squeaks. What now? Inspired by what we have achieved, we plan to refine it further. There is an idea to make a remote control - like a lunar rover. It would be interesting, sitting at a conventional remote control, to control the movement of a robot that travels in a completely different place. But that will be a different story...

And at the end, in fact, the heroes of this article (video by click):

Experience in creating the first robot on Arduino (robot-"hunter")

Thank you for attention!

Link to code

Source: habr.com

Add a comment