Build a robot that works all the time, detecting if there are objects in front of it and dodging them to follow its path.
You will need the following parts to assemble the robot:
Image: Component parts
Separate all parts to assemble the robot
You must place the axle on the wheel pressing until it stops,
(the axes have a notch that you must match in the plastic part)
Then adjust the screws starting with the one with the notch, in this way the wheel will remain fixed.
In the motor enclosure you will find two patterns to connect building modules. For this configuration we will use the one under the wheel.
Place one of the basic modules with the conical side (where the screw goes) looking at the wheel and in this configuration we will use it rotated 22.5 ° counterclockwise to the floor plane, so that the motors remain vertical.
Now you must use 1 screw to secure the building module and the wheel, there is a hole where you can guide it to the piece. Then adjust it to become fixed.
Place the omnidirectional wheel coupling on the vertical rail.
At the same time you can combine it with other modules to adjust it to other types of projects … In this first guide we will use the simplest method to start.
Image: Distance sensor
Image: Robot assembled
Congratulations !, you have finished the assembly of the dodger configuration.
Now let’s program it…
To begin, we will use the MARK Robots extension for the mBlock software.
If you have not installed it yet, you can watch the following video:
It’s time to program the object dodger.
To program, we must think about how to give orders for the robot and we must think about how it can behave in different situations.
Our goal will be to make the robot move constantly and change direction when it finds an object at a distance of 20 cm, to start with.
Then we can deduce that it is an action that is going to repeat infinitely, measuring distances less than 20 cm all the time in front of the sensor. The robot will be in constant motion using 2 motors and if the value of the sensor is less than 20 cm then it will rotate to avoid the obstacle.
This already gives us a good idea of how to assemble the code:
We will start with the MARK block. We will use it at the beginning of each robot.
You can find it on the label.
Robots – MARK Extension – MARK
Enables communication with the Arduino board and ensures that the outputs and inputs correspond to the MARK Shield.
Now … we mentioned that our robot would infinitely repeat an action.
For this we will use the “forever” block of the “Control” palette (you can find it in the left part of the mBlock).
Control – Forever
It is a container where we will place a sequence of blocks, and once they reach their end, will be repeated “forever”.
As our actions depend on whether the distance sensor registers measurements greater or less than 20 cm, we will start programming it with the conditional “If – Then – Else”
You will find it on the label
Control – “If – Then – Else”
The block will verify if a condition is true or false, and then continue with the orders depending on these two situations.
Several blocks have the following symbol.
This means that it expect us to enter an operation.
You can find them in the “operators” section with blocks that have the same shape.
In our case we need a sensor measurement that is smaller than a fixed distance, therefore our block will be the following:
Operators – Less than
Our objective is to verify if the distance sensor finds measurements less than 20 cm, then, after “less than” we enter 20 in the text field (the sensor is configured to measure centimeters by default).
To the left of the “less than” we need the measurement of the distance sensor, for this we will use the block “distance” and you can place it in the space of the operator “less than”.
Robots – MARK Extension – Distance
The blocks are joined from the left, not from where you clicked, in case it is difficult for you to place the block in your container.
Now we will tell the robot what to do in each situation:
If there is nothing less than 20 cm, then the robot should move forward.
For this we will use the “start moving” block.
Robots – MARK Extension – Start moving
The block moves both motors backwards or forwards, using the speed that we enter.
The speed is a value from 0 to 255.
We will start by saying that the robot moves forward, at a speed of 100.
If the sensor finds something less than 20 cm, the robot should turn and then resume the march.
So first we will tell you to turn, for that we will use the block “start turning”.
Robots – MARK Extension – Start turning
The block makes the wheels move in synchrony to make a turn, we can define where it will be: left “or” right “. Finally we must tell what speed we want to turn, to start use 90.
Let’s try the robot …
You must connect to MARK using the USB port.
Now in the software we must tell the program what board and communication port we are using on the computer.
In the boards menu / select Arduino UNO.
Now in connect / serial port, select the port that appears there.
(Usually you will see only 1, if it is the only device you have connected to the computer).
COM + “port number”
It only remains to press “upload Arduino” and wait for the software confirmation.
Now disconnect the USB cable and turn on the robot with the power button.
What can you see?
Analyze how it works?
Let’s think how to improve MARK’s behavior …
The robot does not always start the same way, and we are always measuring a distance of <20 cm. When turning, that distance in front of an object will change, so the robot starts to march again. That is why we need to keep turning until the distance is a little bit bigger and make sure that we will not return to a situation of <20 cm right away.
We could also do that once the object is detected, before turning, the robot backs up a bit to avoid hitting the object (in the design of your robots, you will notice that depending on how you assemble them, the behaviors will be different)
We will make the changes based on the observations of step 09.
We will use “start moving” to tell the robot to move “back” at 100 speed.
Then we will use what we learned and we will give the action a waiting time of 0.2 seconds, so we will make sure that it will travel some distance.
You will find the “Wait” block on the label:
Control – “Wait”
Finally we will use the block “Wait until” on the label:
Control – “Wait until”
Unlike “wait seconds”, this block will wait until a condition is achieved. In our case we want you to wait until the distance sensor registers a safe measure to advance. Let’s try with “greater than” 40 cm …
Operators – Greater than
Use at the other end of the operator, we will continue to use the same distance sensor measurements.
It’s ready…. let’s test the robot …
You must connect to MARK using the USB port and press the “upload to Arduino” button again.