AI Bi-Xin WANG Bin WANG Qing-Ling
Abstract To enable real-time flight visualization for junior operators,this paper designs a quadrotor flight system via computer simulation.The aircraft’s three-dimensional model and the flight scene are generated using open graphics library(OpenGL).Attitude angle of the model are calculated using the mathematical model of the quadrotor.The flight system provides an intuitive way to describe the flight according to real-time data input from the controller.
Key words flight system,quadrotor,three-dimensional modeling,OpenGL
UAV(Unmanned Aerial Vehicle)is the unmanned aircraft based on the radio remote control equipment and the program control device,its development are rapidly in recent years both in military and civilian fields.Among them,the quadrotor aircraft has become a hot research topic both domestic and abroad in the field of UAV by its simple structure,flexible control,high mobility and other characteristics.Quadrotor UAV has been widely used in land surveying and mapping,environmental monitoring,water monitoring,aerial photography and pesticide spraying[1].With the growth of the demand of UAV,the ability and quality of the UAV operator has become a key point.In the real flight training process,not only the weather and the site constrains,there are still exist the wrong operation of equipment and personnel security risks.Flight simulation system,as an important equipment through the operator training,can break the restrictions from weather,field and greatly reduces the training cost.
Currently,there are various types of quadrotor simulator on the UAV market,compare with them,this design has two outstanding advantages:different from the normal simulator,it faces on more practical and specific product of company,the modeling and experimental results are more appropriate;this simulator has universal interface,which can be applied to other products and possess low-cost test results.This paper aims to solve two problems:first,converting the control quantities of Futaba to attitude angels on quadrotor model;second,displaying a three-dimensional model on the screen and its attitude changes according to real-time attitude angels.
The first problem can be solved by establishing mathematical model of quadrotor,the mathematical model converts the pitch,roll,yaw control quantity to the pitch angle,roll angle,yaw angle.In this way,the hardware input the control quantity,the upper computer program can calculate out the attitude angle.A great mount of contributions have involved in this problem[2?7].This section presents a simplified mathematical model of attitude angels.Dynamic equation of attitude motion of quadrotor can be written as:
p,q,ris the rotate angle,?,θ,ψis attitude angle,Jris rotor moment of inertia,lis the distance between body and rotor,?iis the rotation speed of motor(i=1,2,3,4),?r= ?1
??2+?3??4,CTis lift coefficient,CQis torque constant determined by air density,rotor size and the pitch of the rotor,IX,IY,IZis the corresponding moment of inertia of three axesXb,Yb,Zbin body coordinate systemOb?XbYbZb.Considering the change of roll angle and pitch angle is relatively small during flying,suppose
Fig.1 Simulation results of angle model
Suppose motor speeds satisfy ?1= ?2= ?3= ?4= ?0,when quadrotor is hovering,and the yaw direction does not deflect when the quadrotor is pitching,andaθ1=
aθ5=the simplified mathematical model from Pitch control quantityuθto pitch angleθis shown below:
The form of the corresponding state space matrix is:
The roll angle model can be got from the symmetric structure of the body:
Likewise,suppose the pitch and roll direction does not deflect when the quadrotor is yawing.In the form of a state space matrix,simplified mathematical model from Yaw control quantityuψto pitch angleψ
Fig.2 Simulation results of yaw model
This design uses OpenGL and AutoDesk 3DS Max.OpenGL is an open graphics software based on C++programming package,which provides a powerful and convenient access to the underlying graphics library,it defines a cross language,cross platform programming interface specifications that can be used for 3D images[12].OpenGL can render complex graphics and control so as to achieve the effect of operation simulation.However,OpenGL uses the vertices to draw the 3D graph which combines triangle,quadrilateral,or polygon.Which means it uses the function to achieve the input and integration of the vertex coordinates to build a polyhedron.So it is difficult for the OpenGL to establish a specific complex aircraft model without the advanced three-dimensional modeling commands while it is difficult to find the specific coordinates of each vertex in the model.
3DS Max is a very sophisticated computer 3D animation,model and rendering software,is widely used in building modeling and animation production.3DS Max software provides part of the model,you can use their tools to draw more realistic model[8,10?11].3DS Max can be used to build a complex aircraft model in a short time,but it lacks of interactive capabilities which cannot achieve real-time control.
Through the use of the advantages of the professional modeling software 3DS Max,a more complex model is quickly established,and the OpenGL programming interface is used to protract the model in real time and control it interactively[13,15].In this paper,OpenGL and 3DS Max are effectively combined.Firstly,build the model in 3DS Max,generate OBJ file,and then read in the OpenGL drawing environment,at last achieve the desired threedimensional effect.The following figure is the aircraft model created in 3DS Max:
Fig.3 3D model of aircraft produced by 3DS Max
Obj file is a data output type of 3D animation software named Maya developed by Alias/Wavefront company.It defines the geometry of the object and some other properties[9].It is suitable for the application to read because of its simple file structure.This paper uses the glm function library,which contains a glm.h header files and a glm.cpp source file.It defines the definition of various data types in the glm.h file.The glm.cpp file has an important function glmReadOBJ,which is used to read the Obj file.
The procedure of reading the Obj file is divided into the following steps: firstly,define a GLMmodel object g_model which used to receive the Obj file,and then use the function glmReadOBJ to read the Obj fileit returns a pointer to a GLMmodel type,and then use the function glmUnitize normalize model into the(-0.5,-0.5,-0.5)-(0.5,0.5,0.5)box,the maximum size of the model is 1,Center is located at the origin(0.0,0.0,0.0),then use function glm Facet Normals and glmVertex Normals to generate surface normal vectors and point normal vectors.The fianl step is to display the model and the position of the model is at ObjPosition,which is(0,1-2).Because of Obj itself contains the texture,and the display function glmDraw determines the explicit mode,so here it is not required to explicitly specify the texture.The key code is as follows:
theApp.pmodel=glmReadOBJ(“ fl y_model.obj”);
if(!theApp.pmodel)exit(0);
glmUnitize(theApp.pmodel);
glmFacetNormals(theApp.pmodel);
glmVertexNormals(theApp.pmodel,90.0);
glmDraw(theApp.pmodel,
GLM_SMOOTH|GLM_MATERIAL);
Add a grid and Pitch angle,roll angle,yaw angle of real time data to an explicit interface,the interface is shown as below:
Fig.4 Visual interface by Visual Studio 2008
This design uses the T14SG remote control of Japanese Futaba company,the wireless receiver uses the R7008SB type receiver[14].Key devices are shown below.T14SG uses the 2.4GHz two-way communication system “FASSTest”,can receive and confirm the data returned from the receiver by the transmitter.At most 14 channels can be used for telemetry functions of the“14CH FASSTest mode” and the reaction rate is a priority of the “14CH FASSTest model”.R7008SB has the output interface for the S.BUS/S.BUS2 system(up to 14 channels and use with T14SG),as well as the output of the previous common system interface(at most 8 channels).
Fig.5 Futaba 14SG remote controller and R7008SB receiver
The remote control input quantity passed through the receiver and the transcoding board to computer,then using the four rotor UAV model to calculate out the yaw,pitch and roll angle.The key code is shown as follows:
for(int i=0;i { temp=0.0; for(int j=0;j { Temp+=Kalman C[i][j]*XRoll smcl[j]; } temp+=(Kalman D[i][0]*rollau1smc+Kalman D[i][1]*rollau2_smc+Kalman D[i][2]*rollau3smc); Y_Roll smc[i]=temp; } The last step is to rotate the aircraft model relative to the Y axis,X axis,Z axis on the user screen.There is an important function glRotated in Glm.cpp file,which is used to rotate the model.The glRotated function is def i ned as follows: void WINAPI glRotated( GLdouble angle,//The angle of rotation,in//degrees GLdouble x,//The x coordinate of a //vector GLdouble y,//The y coordinate of a //vector GLdouble z//The z coordinate of a //vector ); Therefore,set the x,z parameters to 0.0y to 1.0 then the control quantity is the yaw angle,Similarly,set the y,z parameters to 0.0x to 1.0 then the control quantity is the pitch angle,set the x,y parameters to 0.0z to 1.0 then the control quantity is the roll angle.The key code is as follows: glRotated(threeD yawangle,0.0,1.0,0.0);//yaw glRotated(theApp.debugdata pitch*180/3.1415926,1.0,0.0,0.0);//pitch glRotated(theApp.debugdata roll*180/3.1415926,0.0,0.0,1.0);//roll When there are real-time remote control input data,the interface is as follows: Fig.6 Visual interface in real time operation Fig.7 Program flow Main program flow is shown as below:render the canvas,read obj file,display the text,then the initialization ends.The user can set the PID parameters at the interface,click OK to start training,system modeling and attitude angle displaying the corresponding angles on the UAV model.Program ends when the exists button is down. In this paper,a flight system has been established to simulate the controlling of a quadrotor.The design calculated the attitude angels in the software,used 3DS Max to create a model,which greatly reduced the difficulty of establishing a complex model by OpenGL,and displayed real-time flight scene on the screen.2.4 Work flow of the Simulator
3 Conclusion