Upload files to 'Color_Sorting'
This commit is contained in:
parent
a376f256e6
commit
087e220e39
101
Color_Sorting/README.md
Normal file
101
Color_Sorting/README.md
Normal file
@ -0,0 +1,101 @@
|
||||
# EV3_Python Color sorting cubes
|
||||
|
||||
The following document describes a program written in Python for the Lego Mindstorm EV3.
|
||||
The purpose of the program is to let a robot sort cubes based on their color.
|
||||
|
||||
## Used Hardware
|
||||
<img align="right" src="LINK: Foto Roboter" width="150">
|
||||
The program was written for the LEGO EV3 Brick. It is the base of every Mindstorm EV3 robot. Additional for identification of a object / color a camera from an external company is used.
|
||||
The built / used robot has two motors, one on each side, with two wheels each connected via a caterpillar track.
|
||||
But the program should work with all robots that have one driven wheel per side.
|
||||
|
||||
#### Camera
|
||||
|
||||
The camera used for this program is the **Pixy2** for Lego Mindstorms. To work with the camera you have to teach them the object you want to sort. For this you need PixyMon on your PC. How to get PixyMon, teach an object and everything else you need to know is listed on the [PixyCam Website](https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:pixy_lego_quick_start).
|
||||
|
||||
* **Camera**: Connected to input port **1** `pixy2 = Pixy2(port=1, i2c_address=0x54)`
|
||||
|
||||
* Taught **Signature 1**: orange cube, leave in sorting area `sig_let = 1`
|
||||
* Taught **Signature 2**: green cube, sort out `sig_sort = 2`
|
||||
|
||||
The camera should be mounted on top of the robot, directed downwards for good results in detection.
|
||||
|
||||
#### Motors
|
||||
|
||||
The used robot drives forward when the wheels turn counter-clockwise. `polarity = 'inversed'` If you use a robot with a clockwise direction of rotation, you need to change the settings in the program. `polarity = 'normal'`
|
||||
* **Left** Motor: Connected to output-port **A**
|
||||
* **Right** Motor: Connected to output-port **D**
|
||||
|
||||
#### Sensors
|
||||
|
||||
To track the distance between the robot and the cube a LEGO Ultrasonic Sensor is used. To identify the outer line of the sorting area, one LEGO Color Sensor is used. For keeping track of the rotation on the back side of the robot a LEGO gyrosensor is mounted.
|
||||
* **Ultrasonic Sensor**: Connected to input-port **2**
|
||||
* **Color Sensor**: Connected to input-port **3**
|
||||
* **Gyrosensor**: Connected to input-port **4**
|
||||
|
||||
|
||||
#### Objects to sort
|
||||
<img align="right" src="LINK: Foto WÜrfel" width="150">
|
||||
The sorted objects are simple cubes made of paper. You can find the tutorial to fold the cube on [YouTube](https://youtu.be/VjooTcZRwTE?si=HaiStBDw1cQu3K7o). To ensure the ultrasonic sensor recognizes the cube it is 5.5 cm high and long. The two colors should be distinct from each other.
|
||||
|
||||
## Program
|
||||
The purpose of the program is to sort different objects. In detail this means that the robot should push all orange cubes out of the sorting area and leave all the green cubes inside.
|
||||
|
||||
Due to the fact that the robot gets a lot of inputs and does not need to check everything at the same time the program is divided into 5 states / classes. The robot will switch between the states when certain events happen. You can identify the current state by looking at the LEDs of the EV3-brick.
|
||||
* **Search**: Both LEDs are black
|
||||
* **Get**: Only left LED is green
|
||||
* **Sort**: Both LEDs are green
|
||||
* **Avoid**: Both LEDs are orange
|
||||
* **Edge**: Both LEDs are red
|
||||
|
||||
The different classes are explained in detail below.
|
||||
|
||||
### Class: Search
|
||||
The target of the class is to search for new cubes to sort. The robot spins around until one of five events cause a change.
|
||||
|
||||
**Robot drives over black line**: If the robot drives across the line it switches to the class "[Edge](#class-edge)".
|
||||
|
||||
**Robot has a cube in his arms**: When the Ultrasonic Sensor detects an object in front of him this means there is already a cube in his arms, and he switches to class "[Sort](#class-sort)".
|
||||
|
||||
**Camera detects orange cube**: If the camera finds an orange cube, it changes to the class "[Avoid](#class-avoid)".
|
||||
|
||||
**Camera detects green cube**: If the camera finds a green cube, it changes to the class "[Get](#class-get)".
|
||||
|
||||
**Robot spun without finding something**: When the robot has turned for 2 full rounds (720°) and has not detected one of the four things above it will drive a bit forward. If it reaches the line it changes to the class "[Edge](#class-edge)". Otherwise, it starts the class "[Search](#class-search)" again at the new spot.
|
||||
|
||||
### Class: Get
|
||||
The purpose of the class is to drive towards the green cube and "catch" it in its arms.
|
||||
To make that happen the class checks currently the position of the cube and corrects the driving direction if necessary. Due to that fact that there are several reasons why the camera does not consistently recognize the cube, the robot has a routine to find the cube again (driving backwards, turning left). If the routine does not work the program changes back to class "[Search](#class-search)".
|
||||
Otherwise, the ultrasonic sensor detects the cube in the arms, and the program changes to class"[Sort](#class-sort)", or the robot moves over the line, and it switches to class "[Edge](#class-edge)".
|
||||
|
||||
### Class: Sort
|
||||
The task of the class is to drive with the cube to the outline of the sorting area and avoid the orange cubes on the way.
|
||||
If the camera detects an orange cube the program switches to the class "[Avoid](#class-avoid)", whereas if it doesn't, the robot continues straight ahead until the outline is reached and the program changes to class "[Edge](#class-edge)".
|
||||
|
||||
### Class: Avoid
|
||||
The detected orange cube should be avoided by the robot. Therefore, the camera looks for the orange cube again and gets its position. If it is out of reach of the robot the drive path will not change but if the cube is on the way the robot corrects its driving direction. After that the program switches back to the class before. ("[Search](#class-search)" or "[Sort](#class-sort)")
|
||||
|
||||
### Class: Edge
|
||||
The robot has reached the outline. It drives backwards and turns to the right for 100°. Afterwards the program switches back to the class "[Search](#class-search)".
|
||||
|
||||
|
||||
## Problems and Improvements
|
||||
### Robot does not detect outer line
|
||||
During programming I got challenged by the problem, that the outer line is sometimes not detected. After trying different approaches to fix the bug I suspect that the processor of the EV3 is slowed down by the camera and for this reason does not detect the line when the sensor is above it.
|
||||
|
||||
Another reason can be that the line doesn't differ enough from the floor. Make sure that the given values making sense for your circumstances.
|
||||
|
||||
You can change all the input values such as the minimal line reflection and the driving rates in the program.
|
||||
|
||||
```
|
||||
# Defined inputs for the given experiment / enviroment
|
||||
fast = 30 # driving speed
|
||||
slow = 10 # searching speed
|
||||
line = 10 # min. reflection of outline
|
||||
```
|
||||
|
||||
### Camera does not detect cubes
|
||||
In the cases that the camera does not detect the cubes there are multiple reasons. Sometimes due to lightning changes the camera does not identify the different colors correct. You can go back to PixyMon and see if the cubes are even detected. If not you have to teach the object / cube to the camera again, preferably in the environment where the sorting happens. Also, there is a [section](https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:some_tips_on_generating_color_signatures_2) on the PixyCam Website about improving the detection accuracy you should read.
|
||||
|
||||
### Ultrasonic sensor does not detect cube
|
||||
The ultrasonic sensor should be mounted as near to the floor as possible to make sure the cube gets detected. You should build the arms in a way that they are not in the sensor's field of vision. But they should hold the cube as centered as possible in front of the robot. Make sure that you have followed all the construction advice.
|
Loading…
Reference in New Issue
Block a user