Beruflich Dokumente
Kultur Dokumente
Introduction
1.1 Overview
The platform will not remain stable itself. Our job will be to balance the
platform using distance sensors and to maintain it horizontal. At first, we have
decided to just balance the robot on its two wheels. If the platform inclines then
microcontroller (in this case it is Arduino) will send signals to motors such that
motors would move forward or backward depending on the inclination direction
and extent. So, if the platform tilts forward then motors will run forward and
vice-versa to keep the platform horizontal. A PID-controller is able to control
the pendulum angle, since it is a SISO - Single Input Single-Output system. If
the robot should be able to be controlled in regard to position, x, as well as the
angle, it is a MIMO Multiple-Input Multiple-Output system and one PID-
controller is not enough. Controlling multiple states is conveniently made
through a state space controller.
For this we will need to code the Arduino in order to perform job according to
this. The open source community is full of instructions and code snippets, many
making use of the open source micro controller Arduino for control algorithms.
1
Figure 1.1 Self Balancing Robot
A robot that is capable of balancing upright on its two wheels is known as a two
wheeled balancing robot. The following figure contains the physical view for
the robot designed as part of this project. The process of balancing is typically
referred to as stability control. The two wheels are situated below the base and
allow the robot chassis to maintain an upright position by moving in the
direction of tilt, either forward or backward, in an attempt to keep the centre of
the mass above the wheel axles. The wheels also provide the locomotion thus
allowing the robot to transverse across various terrains and environments.
This type of robot provides a challenging problem and has resulted in many
useful and interesting designs being developed. One such two wheeled robot
that has become a commercial success is the Segway by Segway Inc. The
immediate impact has been within the personal transportation area where an
alternative to cumbersome wheelchairs is now available. Segway proves a
comfortable mobility opportunity for the elderly or people with disability thus
improving their individual sense of independence at the same time.
2
Figure 1.2 Views of the
two wheeled balancing robots
3
Figure 1.4 Inverted pendulum parameters
The following equations will provide a reliable and accurate model for
developing and implementing a suitable non-linear control system for the two
wheeled balancing robots.
Angular acceleration
Horizontal acceleration
4
Chapter 2
Discussion
2.1 Model definition
The physical problem of the balancing robot is well described by the widely
analysed inverted pendulum. It is commonly modelled as a rigid rod fastened by
a frictionless joint to a rigid cart moving in one direction. The simplification
that the wheel base can be seen as a cart sliding on a frictionless surface was
made.
Figure 2.1: The 3 degrees of freedom of the system (source: Anderson, 2003)
The robot has the ability to rotate around the z-axis (pitch) by an angle θp with a
corresponding angular velocity ωp. The linear movement of the robot is
characterized by the position xRM and the velocity vRM. Furthermore, the robot
can rotate about the vertical axis (yaw) by an angle δ with a corresponding
angular velocity δ ̇.
5
The control system of the robot would be based on two state controls
implemented through software: one controlling the stability around the lateral
axis (pitch) and a second one about the vertical axis (yaw). Both state controls’
outputs would then be combined and the robot’s motion would be controlled by
applying torques CL and CR to the corresponding wheels. Equations R1 and R2
can be used to calculate the individual torques required for the robot’s motion.
……. 1
……. 2
Since calculating the pitch angle θp accurately is crucial for the self-balancing
apparatus, a few methods were considered in order to measure the pitch angle
and its rate of change.
A method that is very popular with hobbyists is to use two infra-red sensors
(as a future scope) placed on either side of the robot. The control algorithm uses
the sensors to measure the distance to the ground on either side of the robot. By
comparing the values from the two sides, it is able to determine the pitch angle
accurately.
6
This method uses very little hardware and requires a very simple control
algorithm.
However, when the robot is on the move, the horizontal acceleration would be
added to the accelerometer readings. Due to this, the pitch angle can no longer
be determined accurately. Hence this method, used alone, will not be ideal.
Accelero
Gyroscope
-meter
Calculate
Pitch
Angle
Control
Algorithm
PID
Controller
Motor
The MPU6050 is also equipped with three rate gyroscopes. A rate gyroscope
measures the angular velocity and the signal can be integrated numerically (by
7
using a simplified Runga-Kutta method) as in equation (4) to obtain the pitch
angle.
θp (i) = θp (i-1) + 1 ⁄ 6 (vali-3 + 2 vali-2 + 2 vali-1 + vali) ……. 4
Accelero
Gyroscope
-meter
Calculate
Pitch
Angle
Control
Algorithm
PID
Controller
Motor
8
Chapter 3
Demonstration
3.1 Hardware
Why Arduino?
The Arduino software is easy-to-use for beginners, yet flexible enough for
advanced users. It runs on Mac, Windows, and Linux. Teachers and students
use it to build low cost scientific instruments, to prove chemistry and physics
principles, or to get started with programming and robotics. Designers and
9
architects build interactive prototypes, musicians and artists use it for
installations and to experiment with new musical instruments.
Microcontroller: ATmega328
Operating Voltage: 5V
Input Voltage (recommended): 7-12V
Input Voltage (limits): 6-20V
Digital I/O Pins: 14 (of which 6 provide PWM output)
Analog Input Pins: 6
DC Current per I/O Pin: 40 mA
DC Current for 3.3V Pin: 50 mA
Flash Memory: 32 KB of which 0.5 KB used by bootloader
SRAM: 2 KB (ATmega328)
EEPROM: 1 KB (ATmega328)
Clock Speed: 16 MHz
10
Figure 3.1 Arduino UNO
11
such as pressure sensors, on its auxiliary I 2C port. The MPU-60X0 is footprint
compatible with the MPU-30X0 family.
The L293 and L293D are quadruple high-current half-H drivers. These devices
are designed to drive a wide array of inductive loads such as relays, solenoids,
DC and bipolar stepping motors, as well as other high-current and high-voltage
loads. All inputs are TTL compatible and tolerant up to 7 V.
3.1.4 Motor
14
3.1.5 Construction of physical demonstrator
The demonstrator was designed both physically and in CAD. The used CAD
program is Circuit labs.
The battery is the component with the greatest value of density. The placement
of the battery at the top is to make sure that the centre of mass is located above
the pivot point. All the other components are placed close to each other to avoid
interference that comes with longer wires.
MPU6050
Arduino Uno
Encoder A Motor A
Motor Driver
L293D
Encoder B Motor B
3.1.6 Software
15
Figure 3.9. Simplified schematics of the software chain used for the validation
process
Software/editor used for the writing the program code is Arduino IDE v1.8.8
can be installed on Windows, Linux, Mac platform.
16
Chapter 4
Initialising
4.1 Connections
Making the connections for this Arduino based Self balancing Robot is pretty
simple. We just have to interface the MPU6050 with Arduino and connect the
motors though the Motor driver module. The whole set-up is powered by the
7.4V li-ion battery. The circuit diagram for the same is shown Figure 4.1.
The Arduino and the L298N Motor driver module is directly powered through
the Vin pin and the 12V terminal respectively. The on-board regulator on the
Arduino board will convert the input 7.4V to 5V and the ATmega IC and
MPU6050 will be powered by it. The DC motors can run from voltage 5V to
12V. But we will be connecting the 7.4V positive wire from battery to 12V
input terminal of motor driver module. This will make the motors operate with
7.4V.
17
Figure 4.1: Figure showing the connections
4.2 Programming
#include <PID_v1.h>
#include <LMotorController.h>
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#define MIN_ABS_SPEED 20
MPU6050 mpu;
18
// MPU control/status vars
bool dmpReady = false;
uint8_t mpuIntStatus;
uint8_t devStatus;
uint16_t packetSize;
uint16_t fifoCount;
uint8_t fifoBuffer[64];
Quaternion q;
VectorFloat gravity;
float ypr[3];
//PID
double originalSetpoint = 173;
double setpoint = originalSetpoint;
double movingAngleOffset = 0.1;
double input, output;
volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has
gone high
void dmpDataReady()
{
mpuInterrupt = true;
}
19
void setup()
{
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
mpu.initialize();
devStatus = mpu.dmpInitialize();
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788);
if (devStatus == 0)
{
mpu.setDMPEnabled(true);
dmpReady = true;
packetSize = mpu.dmpGetFIFOPacketSize();
pid.SetMode(AUTOMATIC);
pid.SetSampleTime(10);
pid.SetOutputLimits(-255, 255);
}
else
{
20
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
void loop()
{
if (!dmpReady) return;
pid.Compute();
motorController.move(output, MIN_ABS_SPEED);
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
}
else if (mpuIntStatus & 0x02)
{
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
22
Giving look towards how the PID controller works in a closed-loop system
using the system variable. ‘e’ represents the system error due to both system
noise and measurement noise, the difference between the desired output value
and the actual output produced. This error signal is given to the PID controller,
and the controller determines both the derivative and the integral of this error.
The input to the plant should be the summation of derivative constant multiplied
by derivative error, proportional constant times the proportional error and
integral times the integral error. When control signal (u) will sent to the plant as
the only input, and the output (y) is obtained according to the given input. The
new output (y) is then given back and subtracted to the desired reference to find
error signal (e) again and the loop continues. The PID takes this error and
calculates its control constants.
23
Chapter 5
Discussion and conclusions
5.1 Discussion
The results of the validation process show that the model is currently not precise
enough to be implemented with LQR-control. The purpose of the validation was
that its results could serve as an indication of what in the model causes the error.
Since the discrepancy between the model and the demonstrator was concluded
to be large regarding the settling time, no unequivocal conclusion of what
causes the error was drawn. The cause of the large error most likely lies within
some of the assumptions made in the development of the model as listed below:
The assumption that the robot only moves in one direction of freedom is
considered to be realistic since it was seen in the demonstrator that the robot
only moves as mentioned. The simplification that the robot consists of a cart
and pendulum was made from it being a common assumption in similar
projects. In these projects the reliability of that assumption has not been
discussed, and that has been perceived as the simplification being reasonable.
Although the assumption of what part of the model the components belong to is
difficult to determine. The idea was that the components belonging to the
24
pendulum should all follow the movement of the pendulum and the components
related to the cart was rigid relative to the pendulum.
The lacking speed of the motor is a problem. Though the demonstrator archived
to balance with a PID-control it could not handle bigger impulses than shown in
the results. For future work, a faster motor is recommended.
The 1:52 gear head supplied with the right drive motor stripped the teeth off a
cog within a very short period of operation. Unfortunately, the item was
25
supplied from the USA which delayed the assembly stage for some time. It is
unclear at this time if the gear head and motor combination is suitable for the
loads and weight of the derived robot. Difficulty was also experienced in
acquiring critical components such as the 7805 and 7812 voltage regulators.
These remained on back order for six weeks before they were eventually
received.
The shape, size and layout of the robot proved the most advantageous aspects of
the robot’s design. The cylinder shape proved ideal for manoeuvring on the
spot. This was evident during assembly and performance maintenance activities
on the robot as turning it on the spot allowed easy access from the one location.
The child like size made the robot easy to move, handle and to access each of
the layers. The platform layout allowed grouping of systems and PCB’s without
overcrowding thus sampling the maintenance and fault-finding procedures.
There were no disadvantages discovered with the design of the robot. The
battery posed a potential disadvantage from its inherent weight of 7 Kg. This
accounts for a significant portion of the total weight as well as the space
required to store it within the robot’s chassis. The impact from the battery may
have been reduced by selecting a smaller physical size and rated battery but
then the capability and operability would be adversely affected. There is also a
potential that the motor and gear head combination may have been underrated
for the specific task.
26
5.1.3 System Performance and Results
The actual performance of the hardware aspects of the robot cannot be fully
guaranteed without completion of the microcontrollers programming. It is
anticipated that the manufactured robot would have been fully capable in
achieving stability, locomotion and interaction streaming. No actual
performance results are available at this time.
At the beginning of the project, the expectations were quite substantial. The
goal was to develop a robot that was so robust that it could recover from
significant and deliberately induced tilt. As problems and difficulties started to
become evident in the programming, the expectations reduced to simply
providing a robot that could maintain stability. Incompletion of the program has
proved devastating as hence the results are not reflective of the expectations.
5.2 Conclusions
Modelling based on the inverted pendulum shows that the system is unstable
without a controller. A simple PID-controller can be implemented, but only to
control the angle deviation, ψ.
Since the demonstrator can receive angular data and position data, it is possible
to get data for all the states that are required for a state space controller.
The results of the validation process demonstrate that the model is not reliable.
That conclusion was made because of the big difference in settling time of the
impulses between the physical demonstrator and the corresponding simulation.
Reasons why the model in not reliable was discussed, where it was
recommended that the friction of the system should be investigated more
closely.
All required hardware for a robot controlled via LQR is mounted on the
demonstrator, so if the errors in the model are handled, the demonstrator is fully
prepared for implementation. Though, if the demonstrator is supposed to handle
impulses bigger than 8°, faster motors are recommended.
27
Chapter 6
Future Scope
6.1 Recommendations
Improvements to the current version of the robot can easily be achieved through
the microcontrollers programming. This would provide the fundamental
benefits faster control responses, effective and efficient computations and
improved overall system performance. Completing the software implementation
of the interaction system would allow the operator to have video and audio
streaming capabilities, locomotion control and microcontroller reprogramming
capability. Although the hardware would not require any significant change, the
completion of visual basic programs would complete the process.
The used motors, DC motor have a rated speed of 120 rpm, it was determined
that it was too slow if the robot is going to handle impulses of greater
magnitude than 8°. Eventually, when an LQR-controller is implemented, the
robot should also be able to control steps. If the demonstrator cannot handle
small impulses it would probably not be able to handle steps either. Therefore,
the recommendation is to acquire faster motors.
The friction in the system needs to be investigated and added to the model.
When the model works properly the demonstrator is ready to implement the
theoretically derived LQR-control. With LQR the system will become faster
and can handle both disturbances as impulses and steps. It is also possible to
change the reference of the position that enables navigation of the robot.
Low noise reference voltage circuit board can be used to regulate the conversion
by providing an accurate voltage reference to the microcontroller. It will reduce
the unstable reference voltage and noise in data conversion process.
28
DC motor with encoder is recommended as encoder generally has higher torque
and speed specification compared to dc gear motor. The encoder can be used to
gain feedback for determining and control the motor speed very accurately.
In addition, the width of the wheel can be increased to increase its moment of
inertia and grip on the surface. However, for future work with modifications and
recommendations discussed above, better balancing performance can be
expected.
29
Reference
AMCI Tech Tutorials. 2015. Stepper vs. Servo. Available at: http://www.amci.com/tutorials/
tutorials-stepper-vs-servo.asp. [Accessed 13 May 2015].
Faragher, Ramsey. 2012. Understanding the Basis of the Kalman Filter Via a Simple and
Intuitive Derivation. IEEE signal processing magazine.
Glad, Torkel. Ljung, Lennart. 2006. Reglerteknik - Grundläggande teori. 4th edn.
Studentlitteratur.
InvenSense Inc. 2013. MPU-9150 Product Specification. Sunnyvale, USA. Revision 4.3.
Available at: http://www.invensense.com/mems/gyro/documents/PSMPU-9150A-00v43.pdf.
[Accessed 22 April 2015]
Johansson, Hans. Lindahl, Per-Erik. Meyer, Robert. Grimheden, Martin. Sandqvist, William.
Paulsson, Magareta. 2013. Elektroteknik. KTH
Velleman. 2013. Motor and power shield for Arduino. Gavere, Belgium. Available at:
http://www.velleman.co.uk/manuals/vma03.pdf [Acessed 29 Mars 2015]
Jin, D. 2015. Development of a Stable Control System for a Segway. Available at:
http://www.raysforexcellence.se/wp-content/uploads/2013/01/Dennis-Jin-Developmentof-a-
stable-control-system-for-a-segway.pdf. [Accessed 02 May 2015]
30