Index: /trunk/lib/FlairSimulator/src/Plane.cpp
===================================================================
--- /trunk/lib/FlairSimulator/src/Plane.cpp	(revision 457)
+++ /trunk/lib/FlairSimulator/src/Plane.cpp	(revision 457)
@@ -0,0 +1,311 @@
+// %flair:license{
+// This file is part of the Flair framework distributed under the
+// CECILL-C License, Version 1.0.
+// %flair:license}
+//  created:    2021/12/22
+//  filename:   Plane.cpp
+//
+//  author:     Armando Alatorre Sevilla, Guillaume Sanahuja
+//              Copyright Heudiasyc UMR UTC/CNRS 7253
+//
+//  version:    $Id: $
+//
+//  purpose:    classe definissant un avion
+//
+/*********************************************************************/
+
+#include "Plane.h"
+#include <SimuBldc.h>
+#include <TabWidget.h>
+#include <Tab.h>
+#include <DoubleSpinBox.h>
+#include <SpinBox.h>
+#include <GroupBox.h>
+#include <math.h>
+#ifdef GL
+#include <ISceneManager.h>
+#include <IMeshManipulator.h>
+#include "Blade.h"
+#include "MeshSceneNode.h"
+#include "Gui.h"
+#include <Mutex.h>
+#endif
+
+#define K_MOT 0.4f    // blade animation
+#define G (float)9.81 // gravity ( N/(m/s²) )
+
+#ifdef GL
+using namespace irr::video;
+using namespace irr::scene;
+using namespace irr::core;
+#endif
+using namespace flair::core;
+using namespace flair::gui;
+using namespace flair::actuator;
+
+namespace flair {
+namespace simulator {
+
+Plane::Plane(std::string name, uint32_t modelId)
+    : Model(name,modelId) {
+  Tab *setup_tab = new Tab(GetTabWidget(), "model");
+  m = new DoubleSpinBox(setup_tab->NewRow(), "mass (kg):", 0, 20, 0.1);
+  
+  motorTimeout = new SpinBox(setup_tab->NewRow(), "motor timeout:","ms", 0, 1000, 100,100);
+  
+  motor = new SimuBldc(this, name, 1, modelId,0);
+  
+  SetIsReady(true);
+}
+
+Plane::~Plane() {
+  // les objets irrlicht seront automatiquement detruits (moteurs, helices,
+  // pales) par parenté
+}
+
+#ifdef GL
+
+void Plane::Draw(void) {
+  // create unite (1m=100cm) UAV; scale will be adapted according to arm_length
+  // parameter
+  // note that the frame used is irrlicht one:
+  // left handed, North East Up
+  const IGeometryCreator *geo;
+  geo = getGui()->getSceneManager()->getGeometryCreator();
+
+  // cylinders are aligned with y axis
+  IMesh *motor_mesh = geo->createCylinderMesh(7.5, 5, 16);
+  ITexture *texture = getGui()->getTexture("metal047.jpg");
+  MeshSceneNode *f_motor = new MeshSceneNode(this, motor_mesh, vector3df(150, 0, 20),
+                               vector3df(0, 0, -90), texture);
+  f_blade = new Blade(this, vector3df(155, 0,20), vector3df(90, 0, 90));
+  
+  IMesh *body_mesh = geo->createCylinderMesh(20, 150, 32,SColor(0, 255, 255, 255));
+  MeshSceneNode *body = new MeshSceneNode(this, body_mesh, vector3df(0, 0, 20),
+                             vector3df(0, 0, -90));
+  
+  IMesh *wing= geo->createCubeMesh (vector3df(35, 100, 2));
+  IMesh *aileron= geo->createCubeMesh (vector3df(10, 90, 2));
+  //origine de l'aile en son centre
+  MeshSceneNode *l_wing = new MeshSceneNode(this, wing, vector3df(75, -20-50, 20),
+                             vector3df(0, 0, 0));
+  MeshSceneNode *r_wing = new MeshSceneNode(this, wing, vector3df(75, 20+50, 20),
+                             vector3df(0, 0, 0));
+                             
+  l_aileron = new MeshSceneNode(this, aileron, vector3df(55, -20-50, 20),
+                             vector3df(0, 0, 0));
+                             
+  r_aileron = new MeshSceneNode(this, aileron, vector3df(55, 20+50, 20),
+                             vector3df(0, 0, 0));
+                               
+  motor_speed_mutex = new Mutex(this);
+  motor_speed = 0;
+  ExtraDraw();
+}
+
+void Plane::AnimateModel(void) {
+  motor_speed_mutex->GetMutex();
+  motor_speed=10;
+  f_blade->SetRotationSpeed(K_MOT *vector3df( 0,motor_speed,0));
+
+  motor_speed_mutex->ReleaseMutex();
+
+  // adapt UAV size
+  /*
+  if (arm_length->ValueChanged() == true) {
+    setScale(arm_length->Value());
+  }*/
+}
+
+size_t Plane::dbtSize(void) const {
+  return 6 * sizeof(float) + 1 * sizeof(float); // 6ddl+1moteur
+}
+
+void Plane::WritedbtBuf(
+    char *dbtbuf) { /*
+                       float *buf=(float*)dbtbuf;
+                       vector3df vect=getPosition();
+                       memcpy(buf,&vect.X,sizeof(float));
+                       buf++;
+                       memcpy(buf,&vect.Y,sizeof(float));
+                       buf++;
+                       memcpy(buf,&vect.Z,sizeof(float));
+                       buf++;
+                       vect=getRotation();
+                       memcpy(buf,&vect.X,sizeof(float));
+                       buf++;
+                       memcpy(buf,&vect.Y,sizeof(float));
+                       buf++;
+                       memcpy(buf,&vect.Z,sizeof(float));
+                       buf++;
+                       memcpy(buf,&motors,sizeof(rtsimu_motors));*/
+}
+
+void Plane::ReaddbtBuf(
+    char *dbtbuf) { /*
+                       float *buf=(float*)dbtbuf;
+                       vector3df vect;
+                       memcpy(&vect.X,buf,sizeof(float));
+                       buf++;
+                       memcpy(&vect.Y,buf,sizeof(float));
+                       buf++;
+                       memcpy(&vect.Z,buf,sizeof(float));
+                       buf++;
+                       setPosition(vect);
+                       memcpy(&vect.X,buf,sizeof(float));
+                       buf++;
+                       memcpy(&vect.Y,buf,sizeof(float));
+                       buf++;
+                       memcpy(&vect.Z,buf,sizeof(float));
+                       buf++;
+                       ((ISceneNode*)(this))->setRotation(vect);
+                       memcpy(&motors,buf,sizeof(rtsimu_motors));
+                       AnimateModele();*/
+}
+#endif // GL
+
+// states are computed on fixed frame NED
+// x north
+// y east
+// z down
+void Plane::CalcModel(void) {
+  
+  float u_roll, u_pitch, u_yaw, u_thrust;
+  Time motorTime;
+#ifdef GL
+  motor_speed_mutex->GetMutex();
+#endif // GL
+  motor->GetSpeeds(&motor_speed,&motorTime);
+  if((GetTime()-motorTime)/1000000>motorTimeout->Value()) {
+      if(motor_speed!=0) {
+         //Printf("timout\n");
+        motor_speed=0;
+      }
+  }
+#ifdef GL
+  motor_speed_mutex->ReleaseMutex();
+#endif // GL
+  
+ 
+  /*
+  ** ===================================================================
+  **    u roll: roll torque
+  **
+  ** ===================================================================
+  */
+  /*
+  u_roll = arm_length->Value() * k_mot->Value() *
+           (fl_speed * fl_speed + rl_speed * rl_speed - fr_speed * fr_speed -
+            rr_speed * rr_speed) *
+           sqrtf(2) / 2;
+
+  /// Classical Nonlinear model of a quadrotor ( This is the w_x angular speed
+  /// of the quadri in the body frame). It is a discrete integrator
+  state[0].W.x =
+      (dT() / j_roll->Value()) *
+          ((j_yaw->Value() - j_pitch->Value()) * state[-1].W.y * state[-1].W.z +
+           u_roll) +
+      state[-1].W.x;
+*/
+ 
+  /*
+  ** ===================================================================
+  **   u pitch : pitch torque
+  **
+  ** ===================================================================
+  */
+  /*
+  u_pitch = arm_length->Value() * k_mot->Value() *
+            (fl_speed * fl_speed + fr_speed * fr_speed - rl_speed * rl_speed -
+             rr_speed * rr_speed) *
+            sqrtf(2) / 2;
+
+  /// Classical Nonlinear model of a quadrotor ( This is the w_y angular speed
+  /// of the quadri in the body frame). It is a discrete integrator
+  state[0].W.y =
+      (dT() / j_pitch->Value()) *
+          ((j_roll->Value() - j_yaw->Value()) * state[-1].W.x * state[-1].W.z +
+           u_pitch) +
+      state[-1].W.y;
+*/
+  
+  /*
+  ** ===================================================================
+  **    u yaw : yaw torque
+  **
+  ** ===================================================================
+  */
+  /*
+  u_yaw = c_mot->Value() * (fl_speed * fl_speed + rr_speed * rr_speed -
+                            fr_speed * fr_speed - rl_speed * rl_speed);
+
+  /// Classical Nonlinear model of a quadrotor ( This is the w_z angular speed
+  /// of the quadri in the body frame). It is a discrete integrator
+  state[0].W.z = (dT() / j_yaw->Value()) * u_yaw + state[-1].W.z;
+*/
+ 
+  // compute quaternion from W
+  // Quaternion derivative: dQ = 0.5*(Q*Qw)
+  Quaternion dQ = state[-1].Quat.GetDerivative(state[0].W);
+
+  // Quaternion integration
+  state[0].Quat = state[-1].Quat + dQ * dT();
+  state[0].Quat.Normalize();
+
+  // Calculation of the thrust from the reference speed of motors
+  /*
+  u_thrust = k_mot->Value() * (fl_speed * fl_speed + fr_speed * fr_speed +
+                               rl_speed * rl_speed + rr_speed * rr_speed);
+  Vector3D<double> vect(0, 0, -u_thrust);
+  vect.Rotate(state[0].Quat);
+*/
+  /*
+      ** ===================================================================
+      **     x double integrator
+      **
+      ** ===================================================================
+      */
+   /*   
+  state[0].Pos.x =
+      (dT() * dT() / m->Value()) *
+          (vect.x - f_air_lat->Value() * (state[-1].Pos.x - state[-2].Pos.x) / dT()) +
+      2 * state[-1].Pos.x - state[-2].Pos.x;
+  state[0].Vel.x = (state[0].Pos.x - state[-1].Pos.x) / dT();
+ */
+  /*
+  ** ===================================================================
+  **     y double integrator
+  **
+  ** ===================================================================
+  */
+  /*
+  state[0].Pos.y =
+      (dT() * dT() / m->Value()) *
+          (vect.y -
+           f_air_lat->Value() * (state[-1].Pos.y - state[-2].Pos.y) / dT()) +
+      2 * state[-1].Pos.y - state[-2].Pos.y;
+  state[0].Vel.y = (state[0].Pos.y - state[-1].Pos.y) / dT();
+*/
+  /*
+  ** ===================================================================
+  **     z double integrator
+  **
+  ** ===================================================================
+  */
+  /*
+  state[0].Pos.z =
+      (dT() * dT() / m->Value()) *
+          (vect.z +
+           f_air_vert->Value() * (state[-1].Pos.z - state[-2].Pos.z) / dT() +
+           m->Value() * G) +
+      2 * state[-1].Pos.z - state[-2].Pos.z;
+  state[0].Vel.z = (state[0].Pos.z - state[-1].Pos.z) / dT();
+*/
+#ifndef GL
+  if (state[0].Pos.z < 0)
+    state[0].Pos.z = 0;
+#endif
+}
+
+} // end namespace simulator
+} // end namespace flair
Index: /trunk/lib/FlairSimulator/src/Plane.h
===================================================================
--- /trunk/lib/FlairSimulator/src/Plane.h	(revision 457)
+++ /trunk/lib/FlairSimulator/src/Plane.h	(revision 457)
@@ -0,0 +1,76 @@
+// %flair:license{
+// This file is part of the Flair framework distributed under the
+// CECILL-C License, Version 1.0.
+// %flair:license}
+//  created:    2021/12/22
+//  filename:   Plane.h
+//
+//  author:     Armando Alatorre Sevilla, Guillaume Sanahuja
+//              Copyright Heudiasyc UMR UTC/CNRS 7253
+//
+//  version:    $Id: $
+//
+//  purpose:    classe definissant un avion
+//
+/*********************************************************************/
+
+#ifndef PLANE_H
+#define PLANE_H
+
+#include <Model.h>
+
+namespace flair {
+namespace core {
+class Mutex;
+}
+namespace gui {
+class DoubleSpinBox;
+class SpinBox;
+}
+namespace actuator {
+class SimuBldc;
+}
+}
+
+#ifdef GL
+namespace irr {
+namespace scene {
+class IMesh;
+}
+}
+#endif
+
+namespace flair {
+namespace simulator {
+class Blade;
+class MeshSceneNode;
+
+class Plane : public Model {
+public:
+  Plane(std::string name, uint32_t modelId);
+  ~Plane();
+#ifdef GL
+  virtual void Draw(void);
+  virtual void ExtraDraw(void){}; 
+#endif
+
+private:
+  void CalcModel(void);
+#ifdef GL
+  void AnimateModel(void);
+  size_t dbtSize(void) const;
+  void WritedbtBuf(char *dbtbuf);
+  void ReaddbtBuf(char *dbtbuf);
+  core::Mutex *motor_speed_mutex;
+  Blade *f_blade;
+  MeshSceneNode *l_aileron,*r_aileron;
+#endif
+
+  actuator::SimuBldc *motor;
+  float motor_speed;
+  gui::DoubleSpinBox *m;
+  gui::SpinBox *motorTimeout;
+};
+} // end namespace simulator
+} // end namespace flair
+#endif // PLANE_H
