Você está na página 1de 13

Software Documentation The desired system of the project is able to control the turbine speed via PC.

In order to develop the desired system of the project, the authors combined the use of Arduino IDE and Digia Qt. Arduino IDE used to develop the microcontroller program, while Digia Qt to develop the GUI (Graphical User Interface). 1. Arduino IDE The program codes developed here is the main part of the system. By using this development environment, the authors were able to drive the servo motor which will cause the valve opening of the turbine. Firstly, the authors include the servo library and create the servo object.
#include <Servo.h> Servo aratakusServo; //Include the Servo Library //Create a Servo Object

Next step is determining the servo pin and the initial servo angle.
int servoPin = 9; int i = 0; //Set the Servo Pin //Set initial angle

Thus, baudrate of the serial used is set and the new servo object is attached in the program.
Serial.begin(9600); aratakusServo.attach(servoPin); //Baudrate //"Attach" the Servo Object

Afterwards, the authors developed the main program of the system. The program codes below tells that if the serial is connected, then the system will read the sent serial data. The servo will also move to the initial angle i.
char w; while(Serial.available()>0) { w = Serial.read(); aratakusServo.write(i); delay(100);

There are 6 conditions provided by the programmer. Those 6 conditions are implemented as push buttons in the developed GUI. By those buttons, user is able to choose at which turbine speed the system will be operated and is able to stop the system by resetting the opening valve so that the speed goes into 0 again. Condition 1 is to reset the speed and stop the system.
/* ========= reset the speed ======== */ if (w == '0') { i = 0; aratakusServo.write(i); } /* ================================== */

Condition 2 is the first speed.


/* ============= Speed 1 ============ */ if (w == '1') { if(i == 0) i = i+36; else if(i == 36) i = i; else if(i == 72) i = i-36; else if(i == 108) i = i-72; else if(i == 144) i = i-108; else if(i == 180) i = i-144; aratakusServo.write(i); } /* ================================== */

Condition 3 is the second speed.


/* ============= Speed 2 ============ */ if(w=='2') { if(i == 0) i = i+72; else if(i == 36) i = i+36; else if(i == 72) i = i; else if(i == 108) i = i-36; else if(i == 144) i = i-72; else if(i == 180) i = i-108; aratakusServo.write(i); } /* ================================== */

Condition 4 is the third speed.


/* ============= Speed 3 ============ */ if(w=='3') { if(i == 0) i = i+108; else if(i == 36) i = i+72; else if(i == 72) i = i+36; else if(i == 108) i = i; else if(i == 144) i = i-36; else if(i == 180) i = i-72; aratakusServo.write(i); } /* ================================== */

Condition 5 is the fourth speed.


/* ============= Speed 4 ============ */ if(w=='4') { if(i == 0) i = i+144; else if(i == 36) i = i+108; else if(i == 72) i = i+72; else if(i == 108) i = i+36; else if(i == 144) i = i; else if(i == 180) i = i-36; aratakusServo.write(i); } /* ================================== */

Condition 6 is the fifth speed.


/* ============= Speed 5 ============ */ if(w=='5') { if(i == 0) i = i+180; else if(i == 36) i = i+144; else if(i == 72) i = i+108; else if(i == 108) i = i+72; else if(i == 144) i = i+36; else if(i == 180) i = i; aratakusServo.write(i); } /* ================================== */ }

2. Digia Qt The use of Digia Qt here is to develop the GUI application for turbine speed controller. There are 7 push buttons, a display, and a slider provided in this application. The display and the slider is not functioning due to the absence of the rotary encoder to be mounted on the turbine to measure the turbine speed, while the slider is to adjust the valve openings gradually. Those mentioned 7 push buttons comprised Power ON and Power OFF buttons, to build and break the serial connection between the GUI application and the Arduino microcontroller. To variate the speed, Speed 1, Speed 2, Speed 3, Speed 4, or Speed 5 button can be selected by the user.

Figure 3.6 :The initial GUI Steam Turbine Controller

Figure 3.7 : The serial port of GUI Steam Turbine Controller is connected

Figure 3.8 : The serial port of GUI Steam Turbine Controller is not connected

Figure 3.9 : The serial port of GUI Steam Turbine Controller is closed/powered OFF

Figure 3.10 : Appeared message box when the GUI Steam Turbine application is closed In developing the serial connection, the authors used the additional library of qtextserialport. Thus, the necessary functions were taken to the program codes. Here is the whole programming codes of the header file.
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QtAddOnSerialPort/serialport.h> #include <QMessageBox> // // // // // // enabling the QMAinWindow library enabling the library of qtextserialport enabling the QmessageBox library

QT_BEGIN_NAMESPACE_SERIALPORT class SerialPort; QT_END_NAMESPACE_SERIALPORT QT_USE_NAMESPACE_SERIALPORT namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void openSerialPort(); // // // void closeSerialPort(); // // // void writeData(const QByteArray &data); // // // SerialPort *serial; // private: Ui::MainWindow *ui; // signal slots of the buttons private slots: void readData(); void void void void void void void }; #endif // MAINWINDOW_H on_powerON_clicked(); on_powerOFF_clicked(); on_Speed1_clicked(); on_Speed2_clicked(); on_Speed3_clicked(); on_Speed4_clicked(); on_Speed5_clicked();

function obtained from qtextserialport to open the serial port function obtained from qtextserialport to close the serial port function obtained from qtextserialport to write data to the serial port serial pointer

As usual in the Qt GUI programming, the main program will always be the same. It will appear like beow programming codes. The meaning of the codes are just to execute the program in the main window.
#include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show();

return a.exec();

The main window holds the whole contents of the GUI application system. This provides the functions of GUI application initialization, serial connection, and the functions of existing buttons. Below is the whole programming codes of the main window file.
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); serial = new SerialPort(this); // main window in initialization ui->Speed1->setEnabled(false); ui->Speed2->setEnabled(false); ui->Speed3->setEnabled(false); ui->Speed4->setEnabled(false); ui->Speed5->setEnabled(false); ui->powerOFF->setEnabled(false); connect(serial, SIGNAL(readyRead()), this, SLOT(readData())); } MainWindow::~MainWindow() { delete ui; closeSerialPort(); } void MainWindow::openSerialPort() { serial->setPort("COM22"); if (serial->open(QIODevice::ReadWrite)) { if (serial->setRate(SerialPort::Rate9600) && serial->setDataBits(SerialPort::Data8) && serial->setParity(SerialPort::NoParity) && serial->setStopBits(SerialPort::OneStop) && serial->setFlowControl(SerialPort::NoFlowControl)) { QMessageBox::information(this, tr("Port is connected!"), tr("Berhasi, berhasil, berhasil, hore!")); } else { serial->close(); QMessageBox::critical(this, tr("Port disconnected"), tr("Wes gak connect maning, mas!")); } } else { QMessageBox::critical(this, tr("Port is not connected"), tr("Yaaaaa!! Schade. Ga konek, bro!")); } } void MainWindow::closeSerialPort()

{ serial->close(); QMessageBox::information(this, tr("Tschss!"), tr("See you next time, mein Bruder!")); } //! [6] void MainWindow::writeData(const QByteArray &data) { serial->write(data); } //! [6] //! [7] void MainWindow::readData() { QByteArray data = serial->readAll(); } void MainWindow::on_powerON_clicked() { openSerialPort(); ui->Speed1->setEnabled(true); ui->Speed2->setEnabled(true); ui->Speed3->setEnabled(true); ui->Speed4->setEnabled(true); ui->Speed5->setEnabled(true); ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false); } void MainWindow::on_powerOFF_clicked() { writeData("0"); ui->Speed1->setEnabled(false); ui->Speed2->setEnabled(false); ui->Speed3->setEnabled(false); ui->Speed4->setEnabled(false); ui->Speed5->setEnabled(false); ui->powerOFF->setEnabled(false); ui->powerON->setEnabled(true); closeSerialPort(); } void MainWindow::on_Speed1_clicked() { writeData("1"); ui->Speed2->setEnabled(true); ui->Speed3->setEnabled(true); ui->Speed4->setEnabled(true); ui->Speed5->setEnabled(true); ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false); } void MainWindow::on_Speed2_clicked() { writeData("2"); ui->Speed1->setEnabled(true); ui->Speed3->setEnabled(true); ui->Speed4->setEnabled(true); ui->Speed5->setEnabled(true);

ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false); } void MainWindow::on_Speed3_clicked() { writeData("3"); ui->Speed2->setEnabled(true); ui->Speed1->setEnabled(true); ui->Speed4->setEnabled(true); ui->Speed5->setEnabled(true); ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false); } void MainWindow::on_Speed4_clicked() { writeData("4"); ui->Speed2->setEnabled(true); ui->Speed3->setEnabled(true); ui->Speed1->setEnabled(true); ui->Speed5->setEnabled(true); ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false); } void MainWindow::on_Speed5_clicked() { writeData("5"); ui->Speed2->setEnabled(true); ui->Speed3->setEnabled(true); ui->Speed4->setEnabled(true); ui->Speed1->setEnabled(true); ui->powerOFF->setEnabled(true); ui->powerON->setEnabled(false);

System Flowchart

Você também pode gostar