Introduction: Autonomous Soccer Playing Robot

This is an autonomous soccer playing robot using a webcam, 12V motors and controlled by a combination of a raspberry pi 3 and an arduino uno. OpenCv runs on the webcam and shows dedicated object tracking and colour differentiation to track balls and shoot goals.

Step 1: Concept

The concept for this project is to create an autonomous soccer playing robot (as in requires no human controller input). The robot searches for a coloured ball using the webcam (green in the code given but can be anything as long as it is not common in the environment the robot is in). It tries to centre and move to the ball itself, capturing it via a LDR enabled trapping arm. This robot then searches for the goal (another colour that can be specified) and kicks towards the goal (via a solenoid).

The project is inspired by work done Saymowan (https://www.instructables.com/id/The-RROP-RaspRobot-OpenCV-Project/) so please refer to this instructable for more background information on the technology used.

A raspberry pi running an OpenCv python program takes in information from the webcam and acts as the brains of the robot. An arduino is used to control the DC motors, kicking solenoid and trapping servo.

The python code runs OpenCv (open source computer vision software) to transform a normal webcam image into a black and white image highlighting the location of a certain colour (blue or green in this case). If the ball is not visible the robot rotates in either direction until it finds it again. The area and x position of this transformed image is calculated (centre of the object) and used to determine how close the robot is to the ball. If it is too far away (or to the left or the right) then the robot moves towards (or rotates) to try and centre the ball. When the ball gets close enough it casts a shadow on the LDR (LED normally shines on it) which in turn causes the trapping arm to come down (controlled entirely by the Arduino). This sends a signal back to the raspberry pi which transitions the robot into goal finding mode (looking for a blue object). The robot then moves with the ball until the blue object is a certain size (is changeable) and centred, then the raspberry pi sends a signal to the Arduino that the soccerbot should kick. The Arduino then raises the catching arm, actuates the 5V relay which causes the solenoid to fire, kicking the ball to the goal (hopefully). The loop then continues indefinitely (or until the battery dies).

Step 2: Bill of Materials

Controller (Raspberry Pi and Arduino)

1 x Raspberry Pi 3 Model B - Quad Core 1GB RAM WiFi Bluetooth

1 x Arduino Uno (Used High Quality UNO R3 ATmega328P CH340G Mini USB Board for Compatible-Arduino)

Robot Vision

1 x Logitech C270h 720p Video 3MP Video Call Camera Built-in Microphone HD Webcam (or similar)

Movement

2 x High Torque Turbo Worm Gear Box Geared Electric Drive Motor for DIY 12V 154rpm

2 x RC Model Airplane 45mm 1.77 in. R/C Hobby Wheels Tires (2pcs) WH749

2 x DC 6-30V 12V 24V MAX Motor PWM Speed Controller With Didital Display & Switch AU

2 x 5V Microswitch

6 x 5V Relay

Ball Trapping and Shooting

1 x White 5V LED

1 x Light Dependent Resistor (LDR)

1 x Servo

1 x Solenoid Valve

Misc

1 x 12V Battery

y X Arduino type jumper connections

1 x Voltage regulator (12V to 5V)

Step 3: Wiring Diagram

Refer above for the wiring diagram.

Step 4: Code

Refer following GitHub link for code for both raspberry pi and Arduino:

https://github.com/Beefstyles/Soccerbot

The python code is run on the raspberry pi (can alter to run on start-up or connect via wifi and start manually as required - i.e sudo python SB_GoalSeeker.py). Required to run as an administrator to access the GPIO pins. The python code in the Github links includes opportunity

Arduino code can be loaded as normal.

The brains of the robot run on the raspberry pi via the python script (using a separate thread for the camera viewing and the main action loop) and sends high and low voltages back and forward to the Arduino which in turn controls the motors. It was done this way as the Arduino is better at controlling servos and 5V relays (also have experience in doing this).

First Time Author Contest 2018

Participated in the
First Time Author Contest 2018

Arduino Contest 2017

Participated in the
Arduino Contest 2017

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017