====== Create a New AL ====== **Author:** Yu Hang He \\ **Email:** \\ **Date:** Last modified on <10/25/18> \\ **Keywords:** Hubo 2, PODO 3, Ubuntu, AL, QT GUI \\ ===== Motivation and Audience ===== The tutorial serves as a guide for creating a new AL in PODO system. The tutorial will cover how to create a new GUI in QT program, creating a new AL in PODO, and modifying AL DB file. Contact the author for necessary files. The steps for creating a new AL is as follows: *''Creating a main GUI'' *''Creating AL program'' *''Create basic program structure'' *''Add communication functions'' *''Implement GUI communication function'' *''Adding AL program to Daemon'' *''DB file modification'' Author of this tutorial assumes the reader has the following background and interests: * Familiar with programming process \\ * Interested in creating GUI with QT IDE \\ * Interested in working with Jaemi-Hubo and other Hubo robots \\ \\ The rest of this tutorial is presented as follows: * [[new_podo_al#create_gui_in_qt|Create GUI in QT]] * [[new_podo_al#create_new_al|Create New AL]] * [[new_podo_al#edit_gui_code|Edit GUI Code]] * [[new_podo_al#modify_db_file|Modify DB File]] ===== Create GUI in QT ===== This section will demonstrate how to create a GUI file for PODOGUI in QT Creator. *Open the PODOGUI and ALPrograms project in QT Creator. Both are located under src/ folder of repository. *Right click on PODOGUI project -> Add new -> QT -> Click Qt Designer Form Class. {{ :yuhang:hubo2:800px-screenshot_from_2018-06-29_13-39-20.png |}} *Choose a Form Template -> Dialog without Buttons. Set the class name to be related to the AL to be created. {{ :yuhang:hubo2:screenshot_from_2018-06-29_13-42-06.png |}} *Create one test button by dragging the Push Button on the left panel onto GUI. {{ :yuhang:hubo2:screenshot_from_2018-06-29_13-43-08.png |}} *Change text on the button by double clicking. *Right click on button -> go to slot -> clicked(). {{ :yuhang:hubo2:screenshot_from_2018-06-29_13-43-47.png |}} *This will create a function that is called every time the button is pressed. *Add header files at the top of GUI dialog.cpp file *''#include "CommonHeader.h"'' *''#include "BasicFiles/PODOALDialog.h"'' *Editing the GUI dialog.h file. Found under project PODOGUI/Headers. *''#include "CommonHeader.h"'' *Declaring private objects in the GUI dialog.h file, basic variables for communicating with Al *''private:'' *''LANDialog * lanData; ////Communication with Daemon''\\ *''int AlnumXXXX; //// Choose the name of AL you want to use or create''\\ *''int AlnumOmniWheel; //For example'' *''int AlnumWalkReady; //or this'' ===== Create New AL ===== This section will demonstrate how to create a new AL for PODO. *Within QT Creator, ''right click on ALPrograms -> project -> New Subproject.'' *In New Project window ''-> Application -> Select Qt Console Application.'' {{ :yuhang:hubo2:screenshot_from_2018-06-29_13-55-42.png |}} *Name the project similar to the GUI project name you created earlier. *Using Files Navigator, go to the file ''PODO/DRC_HUBO/PODO_DRC/src/ALPrograms/ALTutorial'' and Copy the BasicFiles folder into the folder of new AL that was created. *Open the ALTutorial/main.cpp and copy the content of Line 1::80 into main.cpp of the new AL. Overwrite the Existing content. *Right click on the new AL project created in ''QT -> Add Existing Directory''. In the new window ''click -> Browse -> Click on BasicFIles folder ''that was copied into the new AL project folder. {{ :yuhang:hubo2:screenshot_from_2018-06-29_14-15-46.png |}} *Trying building the project. Ignore the error for now. *Next, modify the project management file. QT's project management is implemented with an extension file called ''[project name].pro''. *Copy the content of the ALTutorial.pro file in ALTutorial project folder and overwrite the contents of [new AL name].pro. *Modify the .pro file by insert the following codes between CONFIG setting and QMAKE setting. *''CONFIG (debug, debug | release) {'' *''DESTDIR = ../PODO_PROC_Build'' *''} else {'' *''DESTDIR = ../PODO_PROC_Build'' *''}'' *Return to new AL/main.cpp and delete or comment out the FingerControl function on line 25. *''Important!''Modify line 38 with name of new AL. The name must be unique and matches the name that will be add to the DB file later. *''sprintf(__AL_NAME, "ALTutorial");'' *From line 64::70 delete or comment out the switch case TUTORIAL_FINGER_CONTROL. *Finally, imported the RBTaskThread and RBFlagThread functions from ALTutorial/main.cpp by copy and paste. *Before Rebuilding, open Projects tab and configure the build directory. *Right click on project -> Run qmake. *Right click on project again -> Rebuild. *Change enum TUTORIAL_COMMAND at the top of Main.cpp *Note: Always set NO_ACT at the beginning and set the initial value to 100. *The naming convention is to use AL name_COMMAND for command and AL name_function for function. {{ :yuhang:hubo2:screenshot_from_2018-07-02_13-38-00.png |}} *Change the enum name used in the switch-case statement in the main statement, just as you did in Enum. *It is more convenient and clear to use an enum than to declare a number like 999. {{ :yuhang:hubo2:screenshot_from_2018-07-02_13-37-48.png |}} ===== Edit GUI Code ===== *Copy the [AL]_COMMAND enum created in AL to the top of [GUI]dialog.cpp. *Assigning the value of AlnumXXXX (AL used or new AL created): *Inside the [AL]dialog.cpp UI constructor, after ui->setupUi(this); *AlnumXXXX = PODOALDialog :: GetALNumFromFileName ("ALFILENAME");Write the correct AL file name *For the new AL created, input the AL name you picked. {{ :yuhang:hubo2:screenshot_from_2018-07-02_14-29-08.png |}} *Use Qtimer if you want to display variables in the GUI. *Declare a Qtimer variable in [new AL]dialog.h: *under private: *''QTimer *displayTimer;'' *Inside the UI constructor: *''displayTimer = new QTimer(this);'' *''connect(displayTimer, SIGNAL(timeout()), this, SLOT(DisplayUpdate())); function inside SLOT() will be updated according to the interval set'' *''displayTimer->start(50); set the time interval (50 ms) for the function inside SLOT() to be updated Create a DisplayUpdate() function to update the variables on GUI.'' {{ :yuhang:hubo2:screenshot_from_2018-07-02_14-47-27.png |}} *Add the following code inside the event function that occurs when the button is clicked: *''USER_COMMAND cmd;'' *''cmd.COMMAND_DATA.USER_COMMAND = (Enter one of the variables declared in the enum);'' *''cmd.COMMAND_TARGET = (variable with name of AL to use ex) AlnumManualMove);'' *''pLAN-> SendCommand (cmd);'' *Edit GUIMainWindow.h *#include "your own gui header file" *Declare a Gui object *ex) TestDialog *dialogTest; {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-06-19.png |}} *Modify GUIMainWindow.cpp *''Declare [new AL]dialog object = new Classname(this);'' *''ui-> MAIN_TAB-> addTab ((Qwidget *) declared dialog, "TABNAME");'' {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-09-41.png |}} *Rebuild. ===== Modify DB File ===== *Download SQLiteStudio from its official download site. *Extract the compressed file and open sqlitestudio executable inside the folder. *The Core_config.db file we will modify is in the /exe folder within the PODO path *In SQLiteStudio, click on Database in upper left corner -> Add a Database. *Navigate to Core_config.db file and open the database. {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-45-15.png |}} *Under Core_Config -> Tables -> double click AL. {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-45-46.png |}} *Go to Data tab, click green plus button to create a new entry and enter new ALName, FileName, and PathName. *click green check button to commit the new changes. {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-46-11.png |}} *Double click on General table -> Data tab -> change the No. of PODO AL'. {{ :yuhang:hubo2:screenshot_from_2018-07-02_15-57-07.png |}} *Open PODO_DRC/share/Headers/RBSharedMemory.h and fix MAX_AL if necessary. ===== Final Words ===== For questions and comments, email