An open API service indexing awesome lists of open source software.

https://github.com/lubyruffy/balancerobot-raspberry-pi

Raspberry Pi Talking Balance Robot project c++ for Linux
https://github.com/lubyruffy/balancerobot-raspberry-pi

Last synced: 2 months ago
JSON representation

Raspberry Pi Talking Balance Robot project c++ for Linux

Awesome Lists containing this project

README

        

# BalanceRobot Raspberry Pi

Talking BalanceRobot Raspberry Pi written in c++ for Linux

Please install build-essential, alsa , qmake and espeak before compile.

sudo apt-get install build-essential

sudo apt-get install alsa

sudo apt-get install qt4-default

sudo apt-get install espeak

sudo apt-get install libasound2-dev

Building code:

cd BalanceRobotPi

qmake, make

in BalanceRobotPi/main.cpp, plaese change the mac address to your android phone mac address
std::string RfCommAndroidMac = "XX:XX:XX:XX:XX:XX";// change it with your phone mac

Remote module written in android studio java ,

for controlling robot via Rfcomm serial bluetooth connection.

Please first pair your android device with rapberry pi, and run remote android app on phone than keep it in listening mode.

After run raspberry pi code with sudo. The default start mode is off (m_IsRunning = false).

You can press start button from android app
to power dc motors
or set m_IsRunning variable to thing you want true or false for start option.

For autostart the app on raspberry boot please read below instructions.

The Balance Robot parts are:

18650 battery holder,

Raspberry Pi 3

2 x 12V 37mm 350 Rpm 30:1 DC GearMotor with Half Encoder

MPU6050 (6-axis motion-tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer) With MPU6050 , you can get stable angle when the Kalman filter is used. Place the sensor in the lower section, middle part of robot.
I put it in the middle of two dc motors. This prevents oscillations.

RPi Motor Driver Board for Raspberry (each channel supply 5a)

https://www.waveshare.com/wiki/RPi_Motor_Driver_Board

//physcal pins

#define PWMR1 31 IN1

#define PWMR2 33 IN2

#define PWML1 38 IN3

#define PWML2 40 IN4

#define PWMR 32 PWMR

#define PWML 37 PWML



//encoder define

#define SPD_INT_L 12 //interrupt R Phys:12 A

#define SPD_PUL_L 16 //Phys:16

#define SPD_INT_R 18 //interrupt L Phys:18 B

#define SPD_PUL_R 22 //Phys:22



Video:https://vimeo.com/243418683

https://www.youtube.com/watch?v=WB55xWTzZrw

AutoStart the app on boot:

I assume that your code and exec (bin) will be in /home/pi/BalanceRobotPi folder.

create a script start.sh on your home folder (home/pi)

place below code in it.

#!/bin/bash

sudo chown root.root /home/pi/BalanceRobotPi/BalanceRobot

sudo chmod 4755 /home/pi/BalanceRobotPi/BalanceRobot

cd /home/pi/BalanceRobotPi

./BalanceRobot

Open a sample unit file using the command as shown below:

sudo nano /lib/systemd/system/startrobot.service

Add in the following text :

[Unit]

Description=My Robot Service

After=multi-user.target



[Service]

Type=idle

ExecStart=/home/pi/start.sh



[Install]

WantedBy=multi-user.target



You should save and exit the nano editor.



The permission on the unit file needs to be set to 644 :

sudo chmod 644 /lib/systemd/system/startrobot.service



Configure systemd

Now the unit file has been defined we can tell systemd to start it during the boot sequence :

sudo systemctl daemon-reload

sudo systemctl enable startrobot.service

Reboot the Pi and your custom service should run:

sudo reboot



Calibrating your PID Controller

Set all PID constants to zero. This is as good a place to start as any… Slowly increase the P-constant value. While you are doing this, hold the robot to make sure it doesn’t fall over and smash into a million pieces! You should increase the P-constant until the robot responds quickly to any tilting, and then just makes the robot overshoot in the other direction. Now increase the I-constant. This component is a bit tricky to get right. You should keep this relatively low, as it can accumulate errors very quickly. In theory, the robot should be able to stabilise with only the P and I constants set, but will oscillate a lot and ultimately fall over. Raise the D-constant. The derivative components works against any motion, so it helps to dampen any oscillations and reduce overshooting.