The motion of a robot inside a field with obstacles¶
Line follower¶
To solve the problem of robot motion inside a field with obstacles, two different philosophies can be followed. The first is to trace a predefined path to avoid obstacles, in case you know beforehand the object to avoid, the second is to probe the surrounding space through appropriate sensors and to define the better path that allows the robot to avoid the obstacles. These two different philosophies lead to two different methodologies:
Line follower
Interpolated curves.
But why should a robot follow a line? Surely because in this way it could be made to move with a certain security within a space, without having to resort to other engineering concepts
Some examples from the real world of robots that work by exploiting this solution:
Restaurants
Industrial world
World health care
Preparing For This Tutorial:¶
Preparing For This Tutorial:
Instruments
Computers.
LEGO® Mindstorms EV3 Education Kit.
LEGO® Mindstorms EV3 Home Edition software and Python.
A white sheet on which a path is prepared using, for example, 2 and 5 cm black insulation tapes. Remember that the more tight the curves, the more complex it will be to program the robot and find suitable algorithms for tracking the line.
Time constraints: - 12 hrs
Exercise¶
Theory¶
Part 1¶
If we know that the robot is positioned on a white area, and must arrive on the black and stop the algorithm could be of this type:
#(the initial values will be high -> the robot is on the white)
Part 2¶
Try to chase the line!
Question:
If we start from the hypothesis that the robot is above the black line, what is the desired value, what the robot would like to measure continuously (with the sensor light) during its operation?
If the robot is precisely located with the sensor above the line, and at some point the value of reflected light detected by the sensor increases, which way do I bend the robot to correct the position and return to black? Right or left?
The solution that we propose is to choose as desired value 50% of white and 50% of black (typical ideal situation with white = 100 and black = 0 among which we average obtaining the value 50), with the sensor positioned on the right end of the belt, This solution is called ON-OFF because the robot either turns to the right or left, always with the same curvature parameters.There are no other possibilities!
Part 3¶
Improve the control algorithm! Can the robot avoid (or decrease) oscillation? What is due, and why does the robot behave in this way?
If the brightness of the right sensor is reduced, reduce the speed of the right motor proportionally, if the brightness of the left sensor is increased, increase proportionally the speed of the left motor, if the brightness is equal, proceed with the same speed of the two motors. Another way to control the movement of the robot is to introduce a control on the system that assesses the error compared to the optimum trajectory. The error indicated with E is nothing more than the difference between the value acquired by the sensor and the desired value (average between white and black). The correction of the robot (i.e. how much steer should be proportional to this error where Kp represents the coefficient of proportionality and is to be found empirically. To find the best value it is worth to initially set 1, and then proceed to modify about 0.2 the constant, until you get to the value that convinces them the most.
Part 4¶
Move an object within a security area or warehouse (as if you were to program an industrial robot) in the shortest time possible.
Short help on programming
Commands/functions needed for the exercise
Commands necessary to move
#!/usr/bin/env python3
from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C
tank_pair=MoveTank(OUTPUT_B,OUTPUT_C)
tank_pair.on(velocity_left,velocity_right)
tank_pair.off()
ms= MoveSteering(OUTPUT_B, OUTPUT_C)
ms.on(steering=0, speed=50)
ms.off()
MoveSteering functions control two motors based on a steering value and a speed value The steering value controls the path of the robot and can be any value between -100 and +100.
-100 means turn left on the spot
-50 means turn left with the left wheel not turning
0 means go straight
+50 means turn right with the right wheel not turning
+100 means turn right on the spot
The speed value refers to the speed of the faster wheel. The speed of the slower wheel is automatically calculated based on the steering and speed values.
Import necessary library and create a new instance of the class and assigns this object to the local variable color from ev3dev2.sensor.lego import ColorSensor
color = ColorSensor()
Read the value from color sensor
reflected_light_intensity
Reflected light intensity as an integer percentage 0-100. Light on the sensor is red.
ambient_light_intensity
Returns an integer in the range 0-100 that represents the ambient light intensity. Light on the sensor is dimly lit blue.
color
Color detected by the sensor, represented by an integer:
0: No color 1: Black 2: Blue 3: Green 4: Yellow 5: Red 6: White 7: Brown