Autonomous Barrel Collecting

We decided to tackle the Eco-Disaster Challenge autonomously using a Raspberry Pi camera and the OpenCV library for image processing. First we calibrate for the different colours the colour needs to recognise. Next, the script initialises the robot's control interface, stops the robot, and sets the operational mode.

Camera configuration is set up, including preview format and size.

Main Loop:

The main loop captures images from the camera and analyzes them to detect objects of interest based on calibrated colors.
It alternates between searching for red/yellow and green/blue objects.
It moves the robot towards the detected object and performs specific actions (like grabbing or placing) depending on the mode.

Movement Control:

move_towards: Moves the robot towards the detected object, adjusting its trajectory based on colour detection and distance.

Colour Detection:

The method begins by capturing an image from the camera using self.take_photo(picam).
The image is processed to detect the target colour using colour bounds specified during calibration.
OpenCV's inRange function is utilised to create a mask for isolating pixels within the specified colour bounds.
The contours of the detected colour regions are identified using cv2.findContours.

Object Alignment:

The method calculates the difference between the detected object's position and the centre of the image.
Based on this difference, the robot adjusts its trajectory to align with the object.
If the object is not detected or the contour area is too small, the robot may turn left to search for the object.

Distance Adjustment:

The method also considers the distance between the robot and the detected object.
It adjusts the robot's speed based on the distance to ensure smooth movement and prevent collisions.
If the object is too close or too far away, the robot may adjust its speed or direction accordingly.

Special Actions:

Depending on the operational mode and the type of detected object (e.g., barrel or placement area), the method may trigger specific actions such as grabbing or placing objects.
Special conditions are implemented to handle different scenarios, such as when the robot is close enough to perform the desired action or when it needs to maneuver around obstacles.

Error Handling:

Basic error handling is included to handle exceptions gracefully.

Cleanup:

Upon completion or interruption, the script performs cleanup tasks, such as closing OpenCV windows and shutting down the robot.

Tuning this code has been extremely challenging as we found it difficult to get the robot to turn in small enough increments. We also found that sometimes the robot would move towards the barrels at a snail’s pace, whereas other times it would overshoot, knocking the barrel over and sending it skidding across the kitchen floor! Sometimes it would get into a state where it tried to move forwards and backwards at the same time, causing it to just jitter on the spot, unable to do anything. Another problem was that it struggled with the colour recognition. For example, more often than not, the robot would drop the red barrels on top of the green barrels instead of in the yellow drop-off area. Another time, the robot tried to pick up a maroon coat instead of a red barrel!










Comments

Popular posts from this blog

The Beginnings of a Robot

Artistic Design