Me465 Plate Angle Control Project
Me465 Plate Angle Control Project
ME 465
System Dynamics and Automatic Control.
Semester 432
by
No Name ID
1 Abdullah Saleh Nasser 381126354
2 Naif Almasaabi 381126404
Instructor
Introduction:
In this project, a control system will be build that includes the automatic
balancing of a patient transfer trolley with a feedback system, utilizing all
of the theoretical information obtained. An actuator (Servo Motor), an
angle sensor (MPU6050), an Arduino board, wiring, and the physical
model are all included in the system, the system operates by the sensor
detecting the angle disturbance which reference is 0, delivering the
feedback to the PID controller to implement the appropriate parameters,
and then sending the final values to the Servo motor to balance the system.
System Components:
1- Arduino board.
2- Servo Motor.
3- MPU 6050 Sensor
4- Breadboard
1-Arduino board
Arduino boards can take inputs - such as light from a sensor, a finger on a
button, or a Twitter message - and convert them to outputs - such as turning
on an LED, triggering a motor, or publishing anything online. By providing
a set of instructions to the board's microcontroller, you may tell it what to
do. [1]
Figure 1-Arduino board component
2- servo motor
3-sensor
Figure 3: MPU6050.
Figure 4:breadboard
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include <Servo.h>
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 mpu;
Servo myservo;
void setup() {
myservo.attach(servo_pin);
myservo.write(0);
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if
having compilation difficulties
#elif I2CDEV_IMPLEMENTATION ==
I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Serial.begin(115200);
while (!Serial); // wait for Leonardo enumeration, others continue
immediately
Serial.println(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize();
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
if (devStatus == 0) {
mpu.CalibrateAccel(6);
mpu.CalibrateGyro(6);
mpu.PrintActiveOffsets();
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
void loop() {
if (!dmpReady) return;
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
if (fifoCount < packetSize) {
}
else if ((mpuIntStatus & (0x01 <<
MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) {
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
} else if (mpuIntStatus & (0x01 <<
MPU6050_INTERRUPT_DMP_INT_BIT)) {
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print("YAW: ");
Serial.print(ypr[0] * 180 / M_PI);
Serial.print("\t");
Serial.print("PITCH:");
Serial.print(ypr[1] * 180 / M_PI);
Serial.print("\t");
Serial.print("ROLL: ");
Serial.println(ypr[2] * 180 / M_PI);
Mathematical model:
Sensor
Figure 6: Feedback controller loop using a PID controller
In the figure below is the free body diagram of the servo motor
Transfer Function:
∅(𝑠) 𝐾𝑡
=
𝑉(𝑠) (𝑅𝑎 + 𝑠𝐿𝑎 )𝐽𝑠 2 + 𝐾𝑏 𝐾𝑡 𝑠
If the team run the simulations of the system without using a PID
controller in matlab we will get the result shown in figure 8 below.
1.5
0.5
Imaginary Axis
-0.5
-1
-1.5
-2
-2.5
-4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5
Real Axis
Figure 9:Root locus
Bode Diagram
80
60
Magnitude (dB)
40
20
-20
-40
-90
Phase (deg)
-135
-180
-1 0 1 2
10 10 10 10
Frequency (rad/sec)
Figure 10: Bode diagram.
After applying the controller Kp=10 ,Ki=0 ,Kd=0
Figure 8 shows that the team worked without using a PID controller at
first, and it is clear that the system has a long rise time and a small steady
state error. By using the P from the PID controller, as shown in figure 11,
the system will be faster and have a lower steady state error than the case
without a PID controller.
Conclusion
The team desired to have a final model with better results and finish with
a complete model during this project, but due to MPU6050 library issues
that made the servo motor not move, the team was unable to achieve the
planned goals. That said however, working on this project and attempting
to build the control was a great experience, and the team wishes to have a
better experience in the upcoming projects.
Reference
https://www.theengineeringprojects.com/2018/06/introduction-to-
arduino-nano.html
https://arabic.alibaba.com/product-detail/GY-521-MPU-6050-MPU6050-
Module-62475468526.html
https://www.jsumo.com/sg90-micro-servo-motor
https://www.adafruit.com/product/64
https://www.sparkfun.com/products/11026