Index: trunk/include/FlairMeta/HdsX8.h
===================================================================
--- trunk/include/FlairMeta/HdsX8.h	(revision 9)
+++ trunk/include/FlairMeta/HdsX8.h	(revision 13)
@@ -16,21 +16,19 @@
 #include "Uav.h"
 
-namespace flair
-{
-namespace meta
-{
-    /*! \class HdsX8
-    *
-    * \brief Class defining an ardrone2 uav
-    */
-    class HdsX8 : public Uav {
-        public:
-            HdsX8(core::FrameworkManager* parent,std::string uav_name,filter::UavMultiplex *multiplex=NULL);
-            ~HdsX8();
-            void StartSensors(void);
+namespace flair {
+namespace meta {
+/*! \class HdsX8
+*
+* \brief Class defining an ardrone2 uav
+*/
+class HdsX8 : public Uav {
+public:
+  HdsX8(core::FrameworkManager *parent, std::string uav_name,
+        filter::UavMultiplex *multiplex = NULL);
+  ~HdsX8();
+  void StartSensors(void);
 
-        private:
-
-    };
+private:
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/MetaDualShock3.h
===================================================================
--- trunk/include/FlairMeta/MetaDualShock3.h	(revision 9)
+++ trunk/include/FlairMeta/MetaDualShock3.h	(revision 13)
@@ -17,11 +17,11 @@
 
 namespace flair {
-    namespace core {
-        class AhrsData;
-        class Quaternion;
-    }
-    namespace filter {
-        class Ahrs;
-    }
+namespace core {
+class AhrsData;
+class Quaternion;
+}
+namespace filter {
+class Ahrs;
+}
 }
 
@@ -31,40 +31,42 @@
 namespace meta {
 
-    /*! \class MetaDualShock3
-    *
-    * \brief Classe intégrant la manette MetaDualShock3
-    */
-    class MetaDualShock3 : public sensor::TargetEthController {
-        friend class ::MetaDualShock3_impl;
+/*! \class MetaDualShock3
+*
+* \brief Classe intégrant la manette MetaDualShock3
+*/
+class MetaDualShock3 : public sensor::TargetEthController {
+  friend class ::MetaDualShock3_impl;
 
-        public:
-            MetaDualShock3(core::FrameworkManager* parent,std::string name,uint16_t port,uint8_t priority);
-            ~MetaDualShock3();
-            core::AhrsData* GetReferenceOrientation(void) const;
-            float ZRef(void) const;
-            float DzRef(void) const;
-            void SetYawRef(float value);
-            /*!
-            * \brief Set yaw reference
-            *
-            * Yaw part of the output quaternion is obtained by integrating the wz desired angular speed.\n
-            * This method reset the yaw.
-            *
-            * \param value value, only the yaw part of the quaternion is used
-            */
-            void SetYawRef(core::Quaternion const &value);
-            void SetZRef(float value);
-            float RollTrim(void) const;
-            float PitchTrim(void) const;
-            void ErrorNotify(void);
-            void Rumble(uint8_t left_force,uint8_t left_timeout=20,uint8_t right_force=0,uint8_t right_timeout=0);
-            void SetLedON(unsigned int ledId);
-            void SetLedOFF(unsigned int ledId);
-            void FlashLed(unsigned int ledId,uint8_t on_timeout,uint8_t off_timeout);
+public:
+  MetaDualShock3(core::FrameworkManager *parent, std::string name,
+                 uint16_t port, uint8_t priority);
+  ~MetaDualShock3();
+  core::AhrsData *GetReferenceOrientation(void) const;
+  float ZRef(void) const;
+  float DzRef(void) const;
+  void SetYawRef(float value);
+  /*!
+  * \brief Set yaw reference
+  *
+  * Yaw part of the output quaternion is obtained by integrating the wz desired
+  *angular speed.\n
+  * This method reset the yaw.
+  *
+  * \param value value, only the yaw part of the quaternion is used
+  */
+  void SetYawRef(core::Quaternion const &value);
+  void SetZRef(float value);
+  float RollTrim(void) const;
+  float PitchTrim(void) const;
+  void ErrorNotify(void);
+  void Rumble(uint8_t left_force, uint8_t left_timeout = 20,
+              uint8_t right_force = 0, uint8_t right_timeout = 0);
+  void SetLedON(unsigned int ledId);
+  void SetLedOFF(unsigned int ledId);
+  void FlashLed(unsigned int ledId, uint8_t on_timeout, uint8_t off_timeout);
 
-        private:
-            class MetaDualShock3_impl* pimpl_;
-
-    };
+private:
+  class MetaDualShock3_impl *pimpl_;
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/MetaUsRangeFinder.h
===================================================================
--- trunk/include/FlairMeta/MetaUsRangeFinder.h	(revision 9)
+++ trunk/include/FlairMeta/MetaUsRangeFinder.h	(revision 13)
@@ -17,43 +17,41 @@
 
 namespace flair {
-    namespace filter {
-        class ButterworthLowPass;
-        class EulerDerivative;
-    }
-    namespace sensor {
-        class UsRangeFinder;
-    }
-    namespace gui {
-        class DataPlot1D;
-    }
+namespace filter {
+class ButterworthLowPass;
+class EulerDerivative;
+}
+namespace sensor {
+class UsRangeFinder;
+}
+namespace gui {
+class DataPlot1D;
+}
 }
 
-namespace flair
-{
-namespace meta
-{
-    /*! \class MetaUsRangeFinder
-    *
-    * \brief Classe haut niveau pour capteur à ultra son
-    *
-    * Contient une dérivée d'euler et un passe bas.
-    * Cette classe est adaptée pour un capteur d'altitude.
-    */
-    class MetaUsRangeFinder: public core::Object {
-        public:
-            MetaUsRangeFinder(sensor::UsRangeFinder* us);
-            ~MetaUsRangeFinder();
-            void UseDefaultPlot(void);
-            float z(void) const;
-            float Vz(void) const;
-            gui::DataPlot1D *GetZPlot();
-            gui::DataPlot1D *GetVzPlot();
+namespace flair {
+namespace meta {
+/*! \class MetaUsRangeFinder
+*
+* \brief Classe haut niveau pour capteur à ultra son
+*
+* Contient une dérivée d'euler et un passe bas.
+* Cette classe est adaptée pour un capteur d'altitude.
+*/
+class MetaUsRangeFinder : public core::Object {
+public:
+  MetaUsRangeFinder(sensor::UsRangeFinder *us);
+  ~MetaUsRangeFinder();
+  void UseDefaultPlot(void);
+  float z(void) const;
+  float Vz(void) const;
+  gui::DataPlot1D *GetZPlot();
+  gui::DataPlot1D *GetVzPlot();
 
-        private:
-            sensor::UsRangeFinder* us;
-            filter::ButterworthLowPass *pbas_z,*pbas_vz;
-            filter::EulerDerivative *vz_euler;
-            gui::DataPlot1D* vz_plot;
-    };
+private:
+  sensor::UsRangeFinder *us;
+  filter::ButterworthLowPass *pbas_z, *pbas_vz;
+  filter::EulerDerivative *vz_euler;
+  gui::DataPlot1D *vz_plot;
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/MetaVrpnObject.h
===================================================================
--- trunk/include/FlairMeta/MetaVrpnObject.h	(revision 9)
+++ trunk/include/FlairMeta/MetaVrpnObject.h	(revision 13)
@@ -17,60 +17,53 @@
 #include "io_data.h"
 
-namespace flair
-{
-    namespace core
-    {
-        class Vector3D;
-        class FloatType;
-    }
-    namespace gui
-    {
-        class DataPlot1D;
-        class DataPlot2D;
-        class Tab;
-    }
-    namespace filter
-    {
-        class EulerDerivative;
-        class LowPassFilter;
-    }
-    namespace sensor
-    {
-        class VrpnClient;
-    }
+namespace flair {
+namespace core {
+class Vector3D;
+class FloatType;
+}
+namespace gui {
+class DataPlot1D;
+class DataPlot2D;
+class Tab;
+}
+namespace filter {
+class EulerDerivative;
+class LowPassFilter;
+}
+namespace sensor {
+class VrpnClient;
+}
 }
 
-namespace flair
-{
-namespace meta
-{
+namespace flair {
+namespace meta {
 
-    /*! \class MetaVrpnObject
-    *
-    * \brief Classe haut niveau intégrant un objet VRPN
-    *
-    * Contient un objet VRPN et une dérivée, d'euler.
-    */
-    class MetaVrpnObject: public sensor::VrpnObject {
-        public:
-            MetaVrpnObject(const sensor::VrpnClient *parent,std::string name);
-            MetaVrpnObject(const sensor::VrpnClient *parent,std::string name,uint8_t id);
-            ~MetaVrpnObject();
-            gui::DataPlot1D* VxPlot(void) const;//1,0
-            gui::DataPlot1D* VyPlot(void) const;//1,1
-            gui::DataPlot1D* VzPlot(void) const;//1,2
-            gui::DataPlot2D* XyPlot(void) const;
-            void GetSpeed(core::Vector3D &speed) const;
+/*! \class MetaVrpnObject
+*
+* \brief Classe haut niveau intégrant un objet VRPN
+*
+* Contient un objet VRPN et une dérivée, d'euler.
+*/
+class MetaVrpnObject : public sensor::VrpnObject {
+public:
+  MetaVrpnObject(const sensor::VrpnClient *parent, std::string name);
+  MetaVrpnObject(const sensor::VrpnClient *parent, std::string name,
+                 uint8_t id);
+  ~MetaVrpnObject();
+  gui::DataPlot1D *VxPlot(void) const; // 1,0
+  gui::DataPlot1D *VyPlot(void) const; // 1,1
+  gui::DataPlot1D *VzPlot(void) const; // 1,2
+  gui::DataPlot2D *XyPlot(void) const;
+  void GetSpeed(core::Vector3D &speed) const;
 
-        private:
-            void ConstructorCommon(const sensor::VrpnClient *parent,std::string name);
-            filter::LowPassFilter *pbas;
-            filter::EulerDerivative *euler;
-            gui::DataPlot2D *xy_plot;
-            gui::DataPlot1D *vx_opti_plot,*vy_opti_plot,*vz_opti_plot;
-            gui::Tab* plot_tab;
-            core::FloatType elementDataType;
-
-    };
+private:
+  void ConstructorCommon(const sensor::VrpnClient *parent, std::string name);
+  filter::LowPassFilter *pbas;
+  filter::EulerDerivative *euler;
+  gui::DataPlot2D *xy_plot;
+  gui::DataPlot1D *vx_opti_plot, *vy_opti_plot, *vz_opti_plot;
+  gui::Tab *plot_tab;
+  core::FloatType elementDataType;
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/SimuX4.h
===================================================================
--- trunk/include/FlairMeta/SimuX4.h	(revision 9)
+++ trunk/include/FlairMeta/SimuX4.h	(revision 13)
@@ -16,21 +16,20 @@
 #include "Uav.h"
 
-namespace flair
-{
-namespace meta
-{
-    /*! \class SimuX4
-    *
-    * \brief Class defining a simultation x4 uav
-    */
-    class SimuX4 : public Uav {
-        public:
-            //simu_id: 0 if simulating only one UAV
-            //>0 otherwise
-            SimuX4(core::FrameworkManager* parent,std::string uav_name,int simu_id=0,filter::UavMultiplex *multiplex=NULL);
-            ~SimuX4();
-            void StartSensors(void);
-            void SetupVRPNAutoIP(std::string name);
-    };
+namespace flair {
+namespace meta {
+/*! \class SimuX4
+*
+* \brief Class defining a simultation x4 uav
+*/
+class SimuX4 : public Uav {
+public:
+  // simu_id: 0 if simulating only one UAV
+  //>0 otherwise
+  SimuX4(core::FrameworkManager *parent, std::string uav_name, int simu_id = 0,
+         filter::UavMultiplex *multiplex = NULL);
+  ~SimuX4();
+  void StartSensors(void);
+  void SetupVRPNAutoIP(std::string name);
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/SimuX8.h
===================================================================
--- trunk/include/FlairMeta/SimuX8.h	(revision 9)
+++ trunk/include/FlairMeta/SimuX8.h	(revision 13)
@@ -16,21 +16,20 @@
 #include "Uav.h"
 
-namespace flair
-{
-namespace meta
-{
-    /*! \class SimuX8
-    *
-    * \brief Class defining a simultation x8 uav
-    */
-    class SimuX8 : public Uav {
-        public:
-            //simu_id: 0 if simulating only one UAV
-            //>0 otherwise
-            SimuX8(core::FrameworkManager* parent,std::string uav_name,int simu_id=0,filter::UavMultiplex *multiplex=NULL);
-            ~SimuX8();
-            void StartSensors(void);
-            void SetupVRPNAutoIP(std::string name);
-    };
+namespace flair {
+namespace meta {
+/*! \class SimuX8
+*
+* \brief Class defining a simultation x8 uav
+*/
+class SimuX8 : public Uav {
+public:
+  // simu_id: 0 if simulating only one UAV
+  //>0 otherwise
+  SimuX8(core::FrameworkManager *parent, std::string uav_name, int simu_id = 0,
+         filter::UavMultiplex *multiplex = NULL);
+  ~SimuX8();
+  void StartSensors(void);
+  void SetupVRPNAutoIP(std::string name);
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/Uav.h
===================================================================
--- trunk/include/FlairMeta/Uav.h	(revision 9)
+++ trunk/include/FlairMeta/Uav.h	(revision 13)
@@ -17,84 +17,86 @@
 
 namespace flair {
-    namespace core {
-        class FrameworkManager;
-    }
-    namespace filter {
-        class Ahrs;
-        class UavMultiplex;
-    }
-    namespace actuator {
-        class Bldc;
-    }
-    namespace sensor {
-        class UsRangeFinder;
-        class BatteryMonitor;
-        class VrpnClient;
-        class Imu;
-        class Camera;
-    }
+namespace core {
+class FrameworkManager;
+}
+namespace filter {
+class Ahrs;
+class UavMultiplex;
+}
+namespace actuator {
+class Bldc;
+}
+namespace sensor {
+class UsRangeFinder;
+class BatteryMonitor;
+class VrpnClient;
+class Imu;
+class Camera;
+}
 }
 
 namespace flair {
 namespace meta {
-    class MetaUsRangeFinder;
-    class MetaVrpnObject;
+class MetaUsRangeFinder;
+class MetaVrpnObject;
 
-    /*! \class Uav
-    *
-    * \brief Base class to construct sensors/actuators depending on uav type
-    */
-    class Uav: public core::Object {
-        public:
-        /*
-            typedef enum {
-                None,
-                Auto,//rt serial if hds x4 ou x8, auto ip sinon
-                AutoIP,
-                UserDefinedIP,
-                AutoSerialPort,
-                } VRPNType_t;
+/*! \class Uav
+*
+* \brief Base class to construct sensors/actuators depending on uav type
 */
-            //uav_name: for optitrack
-            Uav(core::FrameworkManager* parent,std::string name,filter::UavMultiplex *multiplex=NULL);
-            ~Uav();
-            void SetupVRPN(std::string optitrack_address,std::string name);
-            //vrpn serial: broken, need to add serial port in uav specific code
-            //void SetupVRPNSerial(core::SerialPort *vrpn_port,std::string name,int VRPNSerialObjectId);
-            virtual void SetupVRPNAutoIP(std::string name);
+class Uav : public core::Object {
+public:
+  /*
+      typedef enum {
+          None,
+          Auto,//rt serial if hds x4 ou x8, auto ip sinon
+          AutoIP,
+          UserDefinedIP,
+          AutoSerialPort,
+          } VRPNType_t;
+*/
+  // uav_name: for optitrack
+  Uav(core::FrameworkManager *parent, std::string name,
+      filter::UavMultiplex *multiplex = NULL);
+  ~Uav();
+  void SetupVRPN(std::string optitrack_address, std::string name);
+  // vrpn serial: broken, need to add serial port in uav specific code
+  // void SetupVRPNSerial(core::SerialPort *vrpn_port,std::string name,int
+  // VRPNSerialObjectId);
+  virtual void SetupVRPNAutoIP(std::string name);
 
-            virtual void StartSensors(void);
-            void UseDefaultPlot(void);
-            actuator::Bldc* GetBldc(void) const;
-            filter::UavMultiplex* GetUavMultiplex(void) const;
-            sensor::Imu* GetImu(void) const;
-            filter::Ahrs* GetAhrs(void) const;
-            MetaUsRangeFinder* GetMetaUsRangeFinder(void) const;
-            sensor::UsRangeFinder* GetUsRangeFinder(void) const;
-            sensor::BatteryMonitor* GetBatteryMonitor(void) const;
-            sensor::VrpnClient* GetVrpnClient(void) const;
-            meta::MetaVrpnObject* GetVrpnObject(void) const;
-            sensor::Camera* GetVerticalCamera(void) const;
+  virtual void StartSensors(void);
+  void UseDefaultPlot(void);
+  actuator::Bldc *GetBldc(void) const;
+  filter::UavMultiplex *GetUavMultiplex(void) const;
+  sensor::Imu *GetImu(void) const;
+  filter::Ahrs *GetAhrs(void) const;
+  MetaUsRangeFinder *GetMetaUsRangeFinder(void) const;
+  sensor::UsRangeFinder *GetUsRangeFinder(void) const;
+  sensor::BatteryMonitor *GetBatteryMonitor(void) const;
+  sensor::VrpnClient *GetVrpnClient(void) const;
+  meta::MetaVrpnObject *GetVrpnObject(void) const;
+  sensor::Camera *GetVerticalCamera(void) const;
 
-        protected:
-            void SetBldc(const actuator::Bldc *bldc);
-            void SetMultiplex(const filter::UavMultiplex *multiplex);
-            void SetAhrs(const filter::Ahrs *ahrs);
-            void SetUsRangeFinder(const sensor::UsRangeFinder *us);
-            void SetBatteryMonitor(const sensor::BatteryMonitor *battery);
-            void SetVerticalCamera(const sensor::Camera *verticalCamera);
+protected:
+  void SetBldc(const actuator::Bldc *bldc);
+  void SetMultiplex(const filter::UavMultiplex *multiplex);
+  void SetAhrs(const filter::Ahrs *ahrs);
+  void SetUsRangeFinder(const sensor::UsRangeFinder *us);
+  void SetBatteryMonitor(const sensor::BatteryMonitor *battery);
+  void SetVerticalCamera(const sensor::Camera *verticalCamera);
 
-        private:
-            sensor::Imu* imu;
-            filter::Ahrs* ahrs;
-            actuator::Bldc* bldc;
-            filter::UavMultiplex *multiplex;
-            sensor::UsRangeFinder* us;
-            MetaUsRangeFinder* meta_us;
-            sensor::VrpnClient *vrpnclient;
-            MetaVrpnObject* uav_vrpn;
-            sensor::BatteryMonitor* battery;
-            sensor::Camera* verticalCamera;
-    };
+private:
+  sensor::Imu *imu;
+  filter::Ahrs *ahrs;
+  actuator::Bldc *bldc;
+  filter::UavMultiplex *multiplex;
+  sensor::UsRangeFinder *us;
+  MetaUsRangeFinder *meta_us;
+  sensor::VrpnClient *vrpnclient;
+  MetaVrpnObject *uav_vrpn;
+  sensor::BatteryMonitor *battery;
+  sensor::Camera *verticalCamera;
+};
 } // end namespace meta
 } // end namespace flair
Index: trunk/include/FlairMeta/UavFactory.h
===================================================================
--- trunk/include/FlairMeta/UavFactory.h	(revision 9)
+++ trunk/include/FlairMeta/UavFactory.h	(revision 13)
@@ -21,5 +21,7 @@
 #include <Uav.h>
 
-flair::meta::Uav* CreateUav(flair::core::FrameworkManager* parent,std::string uav_name,std::string uav_type,flair::filter::UavMultiplex *multiplex=NULL);
+flair::meta::Uav *CreateUav(flair::core::FrameworkManager *parent,
+                            std::string uav_name, std::string uav_type,
+                            flair::filter::UavMultiplex *multiplex = NULL);
 
 #endif // UAVFACTORY
Index: trunk/include/FlairMeta/UavStateMachine.h
===================================================================
--- trunk/include/FlairMeta/UavStateMachine.h	(revision 9)
+++ trunk/include/FlairMeta/UavStateMachine.h	(revision 13)
@@ -26,281 +26,275 @@
 
 namespace flair {
-    namespace core {
-        class FrameworkManager;
-        class AhrsData;
-        class io_data;
-    }
-    namespace gui {
-        class PushButton;
-        class GridLayout;
-        class Tab;
-        class DoubleSpinBox;
-    }
-    namespace filter {
-        class ControlLaw;
-        class NestedSat;
-        class Pid;
-        class PidThrust;
-        class TrajectoryGenerator1D;
-    }
-    namespace sensor {
-        class TargetController;
-    }
-    namespace meta {
-        class MetaDualShock3;
-        class Uav;
-    }
-}
-
-namespace flair { namespace meta {
-
- /*! \class UavStateMachine
+namespace core {
+class FrameworkManager;
+class AhrsData;
+class io_data;
+}
+namespace gui {
+class PushButton;
+class GridLayout;
+class Tab;
+class DoubleSpinBox;
+}
+namespace filter {
+class ControlLaw;
+class NestedSat;
+class Pid;
+class PidThrust;
+class TrajectoryGenerator1D;
+}
+namespace sensor {
+class TargetController;
+}
+namespace meta {
+class MetaDualShock3;
+class Uav;
+}
+}
+
+namespace flair {
+namespace meta {
+
+/*! \class UavStateMachine
 *
 * \brief State machine for UAV
 *
-* thread synchronized with ahrs, unless a period is set with SetPeriodUS or SetPeriodMS
+* thread synchronized with ahrs, unless a period is set with SetPeriodUS or
+*SetPeriodMS
 */
 
-class UavStateMachine : public core::Thread
-{
-    protected:
-        enum class AltitudeMode_t {
-            Manual,
-            Custom
-        };
-        const AltitudeMode_t &GetAltitudeMode(void) const {
-            return altitudeMode;
-        }
-        bool SetAltitudeMode(const AltitudeMode_t &altitudeMode);
-
-        //uses TrajectoryGenerator1D *altitudeTrajectory to go to desiredAltitude
-        //available in mode AltitudeMode_t::Manual
-        //return true if goto is possible
-        bool GotoAltitude(float desiredAltitude);
-
-        enum class OrientationMode_t {
-            Manual,
-            Custom
-        };
-        const OrientationMode_t &GetOrientationMode(void) const {
-            return orientationMode;
-        }
-        bool SetOrientationMode(const OrientationMode_t &orientationMode);
-
-        enum class ThrustMode_t {
-            Default,
-            Custom
-        };
-        const ThrustMode_t &GetThrustMode() const {
-            return thrustMode;
-        }
-        bool SetThrustMode(const ThrustMode_t &thrustMode);
-
-        enum class TorqueMode_t {
-            Default,
-            Custom
-        };
-        const TorqueMode_t &GetTorqueMode(void) const {
-            return torqueMode;
-        }
-        bool SetTorqueMode(const TorqueMode_t &torqueMode);
-
-        enum class Event_t {
-            EnteringFailSafeMode,
-            EnteringControlLoop,
-            StartLanding,
-            FinishLanding,
-            Stopped,
-            TakingOff,
-            EmergencyStop,
-            Stabilized, //as soon as uav is 3cm far from the ground
-            ZTrajectoryFinished,
-        };
-
-        UavStateMachine(meta::Uav* uav,uint16_t ds3Port=20000);
-        ~UavStateMachine();
-
-        const core::Quaternion &GetCurrentQuaternion(void) const;
-
-        const core::Vector3D &GetCurrentAngularSpeed(void) const;
-
-        const meta::Uav *GetUav(void) const;
-
-        void Land(void);
-        void TakeOff(void);
-        void EmergencyStop(void);
-        //! Used to signal an event
-        /*!
-            \param event the event which occured
-        */
-        virtual void SignalEvent(Event_t event);
-
-        virtual const core::AhrsData *GetOrientation(void) const;
-        const core::AhrsData *GetDefaultOrientation(void) const;
-
-        virtual void AltitudeValues(float &z,float &dz) const;//in uav coordinate!
-        void EnterFailSafeMode(void);
-        bool ExitFailSafeMode(void);
-        void FailSafeAltitudeValues(float &z,float &dz) const;//in uav coordinate!
-
-        gui::GridLayout *GetButtonsLayout(void) const;
-        virtual void ExtraSecurityCheck(void){};
-        virtual void ExtraCheckJoystick(void){};
-        virtual void ExtraCheckPushButton(void){};
-
-        void GetDefaultReferenceAltitude(float &refAltitude, float &refVerticalVelocity);
-        virtual void GetReferenceAltitude(float &refAltitude, float &refVerticalVelocity);
-        //float GetDefaultThrustOffset(void);
-        const core::AhrsData *GetDefaultReferenceOrientation(void) const;
-        virtual const core::AhrsData *GetReferenceOrientation(void);
-
-        /*!
-        * \brief Compute Custom Torques
-        *
-        * Reimplement this method to use TorqueMode_t::Custom. \n
-        * This method is called internally by UavStateMachine, do not call it by yourself. \n
-        * See GetTorques if you need torques values.
-        *
-        * \param torques custom torques
-        */
-        virtual void ComputeCustomTorques(core::Euler &torques);
-
-        /*!
-        * \brief Compute Default Torques
-        *
-        * This method is called internally by UavStateMachine when using TorqueMode_t::Default. \n
-        * Torques are only computed once by loop, other calls to this method will use previously computed torques.
-        *
-        * \param torques default torques
-        */
-        void ComputeDefaultTorques(core::Euler &torques);
-
-        /*!
-        * \brief Get Torques
-        *
-        * \return torques current torques
-        */
-        //const core::Euler &GetTorques() const;
-
-        /*!
-        * \brief Compute Custom Thrust
-        *
-        * Reimplement this method to use ThrustMode_t::Custom. \n
-        * This method is called internally by UavStateMachine, do not call it by yourself. \n
-        * See GetThrust if you need thrust value.
-        *
-        * \return custom Thrust
-        */
-        virtual float ComputeCustomThrust(void);
-
-        /*!
-        * \brief Compute Default Thrust
-        *
-        * This method is called internally by UavStateMachine when using ThrustMode_t::Default. \n
-        * Thrust is only computed once by loop, other calls to this method will use previously computed thrust.
-        *
-        * \return default thrust
-        */
-        float ComputeDefaultThrust(void);
-
-        /*!
-        * \brief Get Thrust
-        *
-        * \return current thrust
-        */
-        //float GetThrust() const;
-
-        /*!
-        * \brief Add an IODevice to the control law logs
-        *
-        * The IODevice will be automatically logged among the Uz logs,
-        * if logging is enabled (see IODevice::SetDataToLog, FrameworkManager::StartLog
-        * and FrameworkManager::AddDeviceToLog). \n
-        *
-        * \param device IODevice to log
-        */
-        void AddDeviceToControlLawLog(const core::IODevice* device);
-
-        /*!
-        * \brief Add an io_data to the control law logs
-        *
-        * The io_data will be automatically logged among the Uz logs,
-        * if logging is enabled (see IODevice::SetDataToLog, FrameworkManager::StartLog
-        * and FrameworkManager::AddDeviceToLog). \n
-        *
-        * \param data io_data to log
-        */
-        void AddDataToControlLawLog(const core::io_data* data);
-
-        const sensor::TargetController *GetJoystick(void) const;
-
-        gui::Tab *setupLawTab,*graphLawTab;
-
-    private:
-        /*!
-        \enum AltitudeState_t
-        \brief States of the altitude state machine
-        */
-        enum class AltitudeState_t {
-            Stopped,        /*!< the uav motors are stopped */
-            TakingOff,      /*!< take off initiated. Motors accelerate progressively until the UAV lift up */
-            Stabilized,     /*!< the uav is actively maintaining its altitude */
-            StartLanding,   /*!< landing initiated. Altitude is required to reach the landing altitude (0 by default) */
-            FinishLanding   /*!< motors are gradually stopped */
-        };
-        AltitudeState_t altitudeState;
-        void ProcessAltitudeFiniteStateMachine();
-        void ComputeReferenceAltitude(float &refAltitude, float &refVerticalVelocity);
-
-
-        float groundAltitude; // effective altitude when the uav leaves the ground
-        float currentAltitude,currentVerticalSpeed;
-
-        bool failSafeMode;
-        void SecurityCheck(void);
-        void MandatorySecurityCheck(void);
-        void CheckJoystick();
-        void GenericCheckJoystick();
-        void CheckPushButton(void);
-        void GenericCheckPushButton(void);
-        void Run(void);
-        void StopMotors(void);
-
-        meta::Uav *uav;
-
-        core::Quaternion currentQuaternion;
-        core::Vector3D currentAngularSpeed;
-
-        const core::AhrsData *ComputeReferenceOrientation(void);
-
-        void ComputeOrientation(void);
-        void ComputeAltitude(void);
-
-        void ComputeTorques(void);
-        core::Euler currentTorques,savedDefaultTorques;
-        bool needToComputeDefaultTorques;
-
-        void ComputeThrust(void);
-        float currentThrust,savedDefaultThrust;
-        bool needToComputeDefaultThrust;
-
-        gui::PushButton *button_kill,*button_take_off,*button_land,*button_start_log,*button_stop_log;
-        gui::GridLayout *buttonslayout;
-        gui::DoubleSpinBox *desiredTakeoffAltitude,*desiredLandingAltitude;
-        AltitudeMode_t altitudeMode;
-        OrientationMode_t orientationMode;
-        ThrustMode_t thrustMode;
-        TorqueMode_t torqueMode;
-        bool flagBatteryLow;
-        bool flagConnectionLost;
-        bool flagZTrajectoryFinished;
-        filter::NestedSat *uRoll,*uPitch;
-        filter::Pid *uYaw;
-        filter::PidThrust *uZ;
-
-        MetaDualShock3 *joy;
-        filter::TrajectoryGenerator1D *altitudeTrajectory;
+class UavStateMachine : public core::Thread {
+protected:
+  enum class AltitudeMode_t { Manual, Custom };
+  const AltitudeMode_t &GetAltitudeMode(void) const { return altitudeMode; }
+  bool SetAltitudeMode(const AltitudeMode_t &altitudeMode);
+
+  // uses TrajectoryGenerator1D *altitudeTrajectory to go to desiredAltitude
+  // available in mode AltitudeMode_t::Manual
+  // return true if goto is possible
+  bool GotoAltitude(float desiredAltitude);
+
+  enum class OrientationMode_t { Manual, Custom };
+  const OrientationMode_t &GetOrientationMode(void) const {
+    return orientationMode;
+  }
+  bool SetOrientationMode(const OrientationMode_t &orientationMode);
+
+  enum class ThrustMode_t { Default, Custom };
+  const ThrustMode_t &GetThrustMode() const { return thrustMode; }
+  bool SetThrustMode(const ThrustMode_t &thrustMode);
+
+  enum class TorqueMode_t { Default, Custom };
+  const TorqueMode_t &GetTorqueMode(void) const { return torqueMode; }
+  bool SetTorqueMode(const TorqueMode_t &torqueMode);
+
+  enum class Event_t {
+    EnteringFailSafeMode,
+    EnteringControlLoop,
+    StartLanding,
+    FinishLanding,
+    Stopped,
+    TakingOff,
+    EmergencyStop,
+    Stabilized, // as soon as uav is 3cm far from the ground
+    ZTrajectoryFinished,
+  };
+
+  UavStateMachine(meta::Uav *uav, uint16_t ds3Port = 20000);
+  ~UavStateMachine();
+
+  const core::Quaternion &GetCurrentQuaternion(void) const;
+
+  const core::Vector3D &GetCurrentAngularSpeed(void) const;
+
+  const meta::Uav *GetUav(void) const;
+
+  void Land(void);
+  void TakeOff(void);
+  void EmergencyStop(void);
+  //! Used to signal an event
+  /*!
+      \param event the event which occured
+  */
+  virtual void SignalEvent(Event_t event);
+
+  virtual const core::AhrsData *GetOrientation(void) const;
+  const core::AhrsData *GetDefaultOrientation(void) const;
+
+  virtual void AltitudeValues(float &z, float &dz) const; // in uav coordinate!
+  void EnterFailSafeMode(void);
+  bool ExitFailSafeMode(void);
+  void FailSafeAltitudeValues(float &z, float &dz) const; // in uav coordinate!
+
+  gui::GridLayout *GetButtonsLayout(void) const;
+  virtual void ExtraSecurityCheck(void){};
+  virtual void ExtraCheckJoystick(void){};
+  virtual void ExtraCheckPushButton(void){};
+
+  void GetDefaultReferenceAltitude(float &refAltitude,
+                                   float &refVerticalVelocity);
+  virtual void GetReferenceAltitude(float &refAltitude,
+                                    float &refVerticalVelocity);
+  // float GetDefaultThrustOffset(void);
+  const core::AhrsData *GetDefaultReferenceOrientation(void) const;
+  virtual const core::AhrsData *GetReferenceOrientation(void);
+
+  /*!
+  * \brief Compute Custom Torques
+  *
+  * Reimplement this method to use TorqueMode_t::Custom. \n
+  * This method is called internally by UavStateMachine, do not call it by
+  *yourself. \n
+  * See GetTorques if you need torques values.
+  *
+  * \param torques custom torques
+  */
+  virtual void ComputeCustomTorques(core::Euler &torques);
+
+  /*!
+  * \brief Compute Default Torques
+  *
+  * This method is called internally by UavStateMachine when using
+  *TorqueMode_t::Default. \n
+  * Torques are only computed once by loop, other calls to this method will use
+  *previously computed torques.
+  *
+  * \param torques default torques
+  */
+  void ComputeDefaultTorques(core::Euler &torques);
+
+  /*!
+  * \brief Get Torques
+  *
+  * \return torques current torques
+  */
+  // const core::Euler &GetTorques() const;
+
+  /*!
+  * \brief Compute Custom Thrust
+  *
+  * Reimplement this method to use ThrustMode_t::Custom. \n
+  * This method is called internally by UavStateMachine, do not call it by
+  *yourself. \n
+  * See GetThrust if you need thrust value.
+  *
+  * \return custom Thrust
+  */
+  virtual float ComputeCustomThrust(void);
+
+  /*!
+  * \brief Compute Default Thrust
+  *
+  * This method is called internally by UavStateMachine when using
+  *ThrustMode_t::Default. \n
+  * Thrust is only computed once by loop, other calls to this method will use
+  *previously computed thrust.
+  *
+  * \return default thrust
+  */
+  float ComputeDefaultThrust(void);
+
+  /*!
+  * \brief Get Thrust
+  *
+  * \return current thrust
+  */
+  // float GetThrust() const;
+
+  /*!
+  * \brief Add an IODevice to the control law logs
+  *
+  * The IODevice will be automatically logged among the Uz logs,
+  * if logging is enabled (see IODevice::SetDataToLog,
+  *FrameworkManager::StartLog
+  * and FrameworkManager::AddDeviceToLog). \n
+  *
+  * \param device IODevice to log
+  */
+  void AddDeviceToControlLawLog(const core::IODevice *device);
+
+  /*!
+  * \brief Add an io_data to the control law logs
+  *
+  * The io_data will be automatically logged among the Uz logs,
+  * if logging is enabled (see IODevice::SetDataToLog,
+  *FrameworkManager::StartLog
+  * and FrameworkManager::AddDeviceToLog). \n
+  *
+  * \param data io_data to log
+  */
+  void AddDataToControlLawLog(const core::io_data *data);
+
+  const sensor::TargetController *GetJoystick(void) const;
+
+  gui::Tab *setupLawTab, *graphLawTab;
+
+private:
+  /*!
+  \enum AltitudeState_t
+  \brief States of the altitude state machine
+  */
+  enum class AltitudeState_t {
+    Stopped,      /*!< the uav motors are stopped */
+    TakingOff,    /*!< take off initiated. Motors accelerate progressively until
+                     the UAV lift up */
+    Stabilized,   /*!< the uav is actively maintaining its altitude */
+    StartLanding, /*!< landing initiated. Altitude is required to reach the
+                     landing altitude (0 by default) */
+    FinishLanding /*!< motors are gradually stopped */
+  };
+  AltitudeState_t altitudeState;
+  void ProcessAltitudeFiniteStateMachine();
+  void ComputeReferenceAltitude(float &refAltitude, float &refVerticalVelocity);
+
+  float groundAltitude; // effective altitude when the uav leaves the ground
+  float currentAltitude, currentVerticalSpeed;
+
+  bool failSafeMode;
+  void SecurityCheck(void);
+  void MandatorySecurityCheck(void);
+  void CheckJoystick();
+  void GenericCheckJoystick();
+  void CheckPushButton(void);
+  void GenericCheckPushButton(void);
+  void Run(void);
+  void StopMotors(void);
+
+  meta::Uav *uav;
+
+  core::Quaternion currentQuaternion;
+  core::Vector3D currentAngularSpeed;
+
+  const core::AhrsData *ComputeReferenceOrientation(void);
+
+  void ComputeOrientation(void);
+  void ComputeAltitude(void);
+
+  void ComputeTorques(void);
+  core::Euler currentTorques, savedDefaultTorques;
+  bool needToComputeDefaultTorques;
+
+  void ComputeThrust(void);
+  float currentThrust, savedDefaultThrust;
+  bool needToComputeDefaultThrust;
+
+  gui::PushButton *button_kill, *button_take_off, *button_land,
+      *button_start_log, *button_stop_log;
+  gui::GridLayout *buttonslayout;
+  gui::DoubleSpinBox *desiredTakeoffAltitude, *desiredLandingAltitude;
+  AltitudeMode_t altitudeMode;
+  OrientationMode_t orientationMode;
+  ThrustMode_t thrustMode;
+  TorqueMode_t torqueMode;
+  bool flagBatteryLow;
+  bool flagConnectionLost;
+  bool flagZTrajectoryFinished;
+  filter::NestedSat *uRoll, *uPitch;
+  filter::Pid *uYaw;
+  filter::PidThrust *uZ;
+
+  MetaDualShock3 *joy;
+  filter::TrajectoryGenerator1D *altitudeTrajectory;
 };
-
 };
 };
Index: trunk/include/FlairMeta/XAir.h
===================================================================
--- trunk/include/FlairMeta/XAir.h	(revision 9)
+++ trunk/include/FlairMeta/XAir.h	(revision 13)
@@ -16,21 +16,19 @@
 #include "Uav.h"
 
-namespace flair
-{
-namespace meta
-{
-    /*! \class XAir
-    *
-    * \brief Class defining an ardrone2 uav
-    */
-    class XAir : public Uav {
-        public:
-            XAir(core::FrameworkManager* parent,std::string uav_name,filter::UavMultiplex *multiplex=NULL);
-            ~XAir();
-            void StartSensors(void);
+namespace flair {
+namespace meta {
+/*! \class XAir
+*
+* \brief Class defining an ardrone2 uav
+*/
+class XAir : public Uav {
+public:
+  XAir(core::FrameworkManager *parent, std::string uav_name,
+       filter::UavMultiplex *multiplex = NULL);
+  ~XAir();
+  void StartSensors(void);
 
-        private:
-
-    };
+private:
+};
 } // end namespace meta
 } // end namespace flair
