Now we know how to control DC commutator motors. It’s time to start assembling our robot car, which will be our first
mobile robot. We already have all the control electronics, a power source, motors and wheels. What’s missing? We have 2 motors and 2 wheels, so we shall need a third support. For this purpose, we will use a ball like this one, which will allow the
robot to move and turn about the axis which passes through the wheels. We need a frame, which we shall assemble from familiar components. We will use some new details to mount the ball bearing and the motors. Besides, we will need to power our device. In the experiments with motors, we were powering the controller from
the computer. Here we will be using the same battery compartment, which powers the motors. We have 4 batteries of 1.2 V each, but 4.8 V will not be enough for Arduino. Therefore, we shall need a voltage up-converter. Let’s see in detail how our power will be organized. Wires come from the battery compartment to the voltage up-converter. Wires also go through the same terminal block and then directly
to the Motor Shield. In other words, 4.8 V is applied to the motors without any
conversion. From the converter’s output, the wires go to the Vin controller
and the ground. With the help of a trimming resistor, we will apply from 7 to 9 V there, which is permissible for the controller. Let’s set suitable voltage for our controller. [NO SOUND] [NO SOUND] I have set the voltage of approximately 9 V, which is more than enough for the Iskra. In the end, we get this beautiful device. Before we teach it to move, let’s see how our previous Motor Shield test sketch works with it. [NO SOUND] I have connected the power supply with a simple wire, since we don’t have a separate switch yet. [SIGNAL] We can hear the motor accelerating. The voltage is not yet enough. [NOISE] Let me say a couple more words about the assembly. I have deliberately decided to not direct your attention to the
assembly of the robot, for you can experiment as you want with it. Let me remind you that our task is to make the robot move along a
straight line. It can turn into a race along the line, if the speed becomes important for us. Things influencing the robot’s dynamics will be playing a central role then: say, wheelbase width, ground clearance height, center of gravity position of the battery compartment, etc. However, now it’s not that important for us, since we only need a test robot car, which will be able to move. Let’s finally get down to programming the robot’s movements and see what new things we have in the program. First, we have added a macrodefinition for the pins of the second motor –
“enable input”. Naturally, we have set them as outputs and started both motors. By the way, if you upload this code and the robot doesn’t move forward, don’t worry, as this all depends on how you connected the motors. You can either switch the wires in the terminal blocks or switch high to low. We are starting both motors at their maximum speed. Then we create a 1.5-second delay to see what’s happening and next we change the direction to “full astern”. Next comes a delay again, after which we start one motor in the “full ahead”
direction And the other one in the “full astern” direction so that the robot would
rotate. Afterwards, we are performing the same actions, but vice versa, so that the
robot would rotate in the opposite
direction. By the way, you can turn the robot in different ways - turning about the robot’s axis is not the only way. You can follow a curve when both wheels are turning forward: one should turn slowly and the other one fast. [NOISE] [NOISE] You must have already noticed that the robot doesn’t always follow a straight line and it turns at different spots, meaning that its turning angle is always different. This is natural, and without feedback, i.e without monitoring how the wheel actually turns, we won’t be able to follow a perfectly straight line. Even identical motors of the same manufacturer can differ a little bit from each other, and we come across this quite often. Think about it: would we want to add new lines to our code every time we need to change some of our parameters, be it the speed or the direction of motor rotation? I don’t think so. That’s why we need to create a definite function to control
our motors. Let’s call it “drive”. We will be communicating two parameters to it: the speed of the left and the right wheels. We can also set their direction simultaneously by changing the
sign of these parameters. Thus, if we set the -100 value, for instance, The wheel will be turning backwards with the speed of 100. Then we need to make sure that the motors operate with correct values, because the “drive” function can be called with an automatically calculated parameter, so we will need to ensure that it falls in the permissible range from -255 to 255. Otherwise, the “right” analog will react in a way that we can’t
predict. Next, we need to determine whether the parameter comes
with a plus or a minus sign. Thus, if it’s a plus sign, we will be rotating the motor
forward, and backward if it’s a minus sign. We need to do the same for the right motor, and then set the speed for both of them. Furthermore, the “right” and “left” parameters need to be absolute,
meaning that we shall go for
their absolute values. Now we can simply call this function by setting the speed for the right and the left wheels. Let’s conduct a small experiment by turning both wheels forward at their
maximum speed, and then backward at a different speed for both. By the way, we can’t say for sure if 80 will be enough to set the motor
in motion. But let’s see. Now let’s turn the motors in the opposite direction at different
speeds. We need to make sure that this works though. [NOISE] In fact, all the three actions are performed. Naturally, 80 is not enough to turn the left wheel backward, but that’s not a problem. Let’s do a mini-summary of what we have achieved here And look at our main circuit. We have new executors here: the collector and the DC motor together with the gear reducer and the wheel. The wheel is controlled not just by the signal sent from Arduino, but through an agent, which in our case is the motor driver. We control the motor driver by sending basic digital and analog signals, which make the wheels turn. We took two motors with wheels and built a robot car, which is a more complex executor. In spite of its complexity, it’s still controlled with the help
of the same micro circuit. We have also created the “drive” function, thanks to which we don’t have to think anymore about the combination of signals coming
to both motors - we simply need to set the speed for the right and the left wheels. We also tested how our robot car moves in different directions, and no feedback was needed for this. We just had a set of commands to make the robot car move in
different directions.