Scorpion Balance Board

by Scorpion_Balance in Circuits > Electronics

202 Views, 1 Favorites, 0 Comments

Scorpion Balance Board

WhatsApp Image 2023-06-04 at 00.15.18.jpeg
PrototypeScorpion.jpeg

The scorpion balance board is a project who's aim is to use different mechanical, electronic and programming components in order to create a movable machine that can keep a ball on the board without letting it fall off. This kind of solution can be applied in several sectors in real life such as helping people with Parkinson's disease or even waiters.

The logic behind the implementation consists of using a camera to track the position of the ball on the board and adjust it's position if it's going out of the acceptable range. This adjustment is done with the help of a PID system.

Supplies

This is a vast project that requires different supplies. Find below a list of required items.

  • 1 x Raspberry-pi 3
  • 1 x Raspberrypi-Camera
  •  1 x Tarja uSD de 16G
  •  1 x alimentador de Raspberry
  •  1 x junta de Cardan de 6mm
  •  1 x pack de bateries de NiMH de 12V 3000mAh
  •  1 x Carregador bateries NiMH
  •  2 x Reguladors LM2596 (2,5A)
  •  1 x Driver L298H
  •  1 x Arduino nano
  •  1 x cable miniUSB-USBA
  •  2 x servomotors 20kg SF3218MG
  •  1 x cable extensió Raspberrypi-Camera de 1m

Video

Scorpion Balance board

This is the final implementation of this project.

Preliminary Design

WhatsApp Image 2023-03-23 at 16.38.11.jpeg
WhatsApp Image 2023-03-23 at 16.37.13.jpeg
WhatsApp Image 2023-03-23 at 16.36.25.jpeg
electronics2.png
electronics1.png

The preliminary design is an important stage that will allow you to move forward with a clear set of steps.

Mechanics:

  • 3D designs of the required components of the project which includes:
  • Plate/board of 25 cm x 25 cm
  • Bottom movable part
  • Plate arms
  • Consider where all the components will be placed (Battery, Microprocessor, camera etc ..)

Electronics:

  • Design the electric schema for the project
  • Crash test

Programming:

  • Install the correct version of Raspberry Pi considering the use of the camera. In this case Raspberry Pi Legacy OS is the most effective.
  • Install all the required dependencies (https://raspberrypi-guide.github.io/programming/install-opencv)
  • sudo apt-get update && sudo apt-get upgrade
  • sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libfontconfig1-dev libcairo2-dev libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran libhdf5-dev libhdf5-serial-dev libhdf5-103 python3-pyqt5 python3-dev -y
  • sudo apt-get install python-opencv
  • sudo apt install python3-gpiozero
  • Crash test connectivity of camera
  • Crash test connectivity with servo motor

Implementation Plan

weights2.png
weights3.png

Power of the motors  


First, we calculate the forces from the structure that we have for later to be able to choose the motors that we will need. We can see that the weight that we are going to support are 0,22125Kg. 

W=3,54⋅0,25⋅0,25=0,22125Kg


The decision to choose the correct DC motors was backed by a crash test with 5kg on top of a makeshift support made of carton, as shown in the attached image.

Development and analysis


In this part we analysis the possible problems and the possible solutions that we can find. 

The material we must connect are: 

Camera Raspberry Pi: This component is used to scan the table to know where the ball is in every moment. 

Raspberry Pi 3: Controls the two axis that move the table and process the image. 

Arduino Nano: Controls the two wheels. 

H-bridge: Drive to control the motors dc. 

Servomotors: Move the arms from the table in axis X and axis Y. 

Motor DC: Move the wheels. 

Joystick: Allows to send the signal to move the scorpion where we want it. 

Schema


In the attached scheme we can see a simple electric scheme to know how we will connect all the components. 

That we can see in the “photo x” there are three different colors of lines: 

When the line is purple, it means that the communication is by Bluetooth.  

When the line is orange, it means that the communication is by serial port.  

When the line is blue, it means that are connected.  

Downloads

Electrical Development

electrical1.png
electrical2.png

In this section we explain the electric schemes with more details. 

We have a 12V battery with two regulators. One regulator is configurate with 7,2V to power the servomotors and the other regulator is configurate with 5V to power the Raspberry.   

On the Raspberry Pi we connect the camera and the two servos. For the camera is connected in a special connector that there is for the camera, and the motors are connected in pin 77 and 75 as shown in the attached image 1.


The Raspberry sends to Arduino the value from the joystick and then the Arduino process this information and do the movement to the wheels. 

The pins D2, D3 and D5 are the pins to control one wheel that are connected to the H-Bridge. The D4, D6 and D7 are the pins to control the other wheel and are connected to the H-Bridge too. 

The H-bridge is power with 12V and is used to drive a load, such a as a DC motor, in both directions and it controls the flow of current to a load. 

Software Development

Balance_board.png

The software and control part of this project was divided in different sections that finally interconnect to create one entry point.  

The main objective was to be able to capture the position of the ball with a camera and adjust the servos to return it to the default position, hence balancing.  

The second part was to move the base of the project which is on wheels using a joystick. 

The software is implemented in Python and Arduino’s C++. 

Image processing 


The image capture was done using a RasberryPi camera v3, set to 30 frame per second attached to RasberryPi. The objective is to identify the ball on each frame and update it’s position. There were multiple attempts to do this using high level python libraries, but this proved to be a hindrance in terms of the processing speed.  

As a solution the obtained frame is immediately converted to HSV (Hue Saturation Value). With the frame in this format we can calibrate it to only identify objects of a certain color. In this case the color of the ball is green therefore anything that is not in the acceptable range of green is a null pixel.  

The HSV technique has solved two problems.The first one being noise due to multiple objects in the field of view of the camera including natural light. The second one , this technicle is enough to identify what kind of ball the program is looking for. 

PID control (Proportional Integral Derivative) 


Once the position of the ball is known, we can apply the control to adjust. There are two PID controls for this project, one for the servo handling the x axis and another one for the servo handling the y axis.  

Each time the position of the ball is captured , using the PID class, the servo values are calculated according to the difference between the current position and the default. As of now there is still room to properly fine tune the parameters of the PID. 

Base movement 


As an additional functionality of the project, the base to which the balance board is attached, should be able to move on command using a joystick/controller. 

To implement this, an arduino was used which allowed direct accces to the wheel motors. The Arduino program receives commands from the RasberryPi using a python program which captures the code of the pressed button on the controller. 

Depending on the number sent to the arduino, a movement function will be triggered. 

The controller has to be wireless since the whole project is mobile. This requires capacity to auto connect the controller without a GUI. For this project, this connection was implemented as a service which tries to connect to a specific controller with bluetooth. It can wait until the device is available and stop waiting when the device is connected. 

Services 


Given that the project will be mobile and without a GUI, it is crucial that all software components operate independently. In order to achieve this the software parts were divided in different services that launch when the microprocessor is turned on.  

According to the attached image, there are three main services that operate in parallel.

They are separate to avoid dependecy which inevitablely more time than not blocks when one is not working. 

  • Camera service: This is the service that handles image capture and pid control. It’s always on as long as the microprocessor is turned on. 
  • Joystick service: This is the service that manages the autoconnection to the controller. It should be in standby until a controller is connected. 
  • Events service: This service is dedicated to sending commands of the controller from RasberryPi to Arduino through a USB channel.