source: flair-src/trunk/demos/Skeletons/CustomTorques/src/MyApp.cpp @ 122

Last change on this file since 122 was 122, checked in by Sanahuja Guillaume, 5 years ago

modifs uav vrpn i686

File size: 2.7 KB
Line 
1//  created:    2015/10/29
2//  filename:   Uav.cpp
3//
4//  author:     Guillaume Sanahuja
5//              Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7//  version:    $Id: $
8//
9//  purpose:    skeleton to use UavStateMachine with custom torques only
10//
11//
12/*********************************************************************/
13
14//include files, add yours
15#include "MyApp.h"
16#include <GridLayout.h>
17#include <PushButton.h>
18#include <MetaDualShock3.h>
19#include <FrameworkManager.h>
20
21//namespaces, add others if necessary (filter, sensor, actuator)
22using namespace std;
23using namespace flair::core;
24using namespace flair::gui;
25using namespace flair::meta;
26using namespace flair::sensor;
27
28MyApp::MyApp(TargetController *controller): UavStateMachine(controller), behaviourMode(BehaviourMode_t::Default) {
29    start_CustomTorques=new PushButton(GetButtonsLayout()->NewRow(),"start CustomTorques");
30    stop_CustomTorques=new PushButton(GetButtonsLayout()->NewRow(),"stop CustomTorques");
31}
32
33MyApp::~MyApp() {
34}
35
36//this method is called by UavStateMachine::Run (main loop) when TorqueMode is Custom
37void MyApp::ComputeCustomTorques(Euler &torques) {
38    //compute the torques, with your own control laws
39
40    //torques.roll=;
41    //torques.pitch=;
42    //torques.yaw=;
43}
44
45void MyApp::SignalEvent(Event_t event) {
46    UavStateMachine::SignalEvent(event);
47    switch(event) {
48    case Event_t::TakingOff:
49        //always take off in default mode
50        behaviourMode=BehaviourMode_t::Default;
51        break;
52    case Event_t::EnteringFailSafeMode:
53        //return to default mode
54        Thread::Info("CustomTorques: stop\n");
55        behaviourMode=BehaviourMode_t::Default;
56        break;
57    }
58}
59
60void MyApp::ExtraCheckPushButton(void) {
61    if(start_CustomTorques->Clicked() && (behaviourMode!=BehaviourMode_t::CustomTorques)) {
62        StartCustomTorques();
63    }
64
65    if(stop_CustomTorques->Clicked() && (behaviourMode==BehaviourMode_t::CustomTorques)) {
66        StopCustomTorques();
67    }
68}
69
70void MyApp::ExtraCheckJoystick(void) {
71    //R1
72    if(GetJoystick()->IsButtonPressed(9) && (behaviourMode!=BehaviourMode_t::CustomTorques)) {
73        StartCustomTorques();
74    }
75
76    //stop is not managed here, it is done in UavStateMachine with cross button
77    //pushing cross button will enter fail safe mode and signal the EnteringFailSafeMode event
78}
79
80void MyApp::StartCustomTorques(void) {
81    //ask UavStateMachine to enter in custom torques
82    if (SetTorqueMode(TorqueMode_t::Custom)) {
83        Thread::Info("CustomTorques: start\n");
84    } else {
85        Thread::Warn("CustomTorques: could not start\n");
86        return;
87    }
88
89    behaviourMode=BehaviourMode_t::CustomTorques;
90}
91
92void MyApp::StopCustomTorques(void) {
93    //just ask to enter fail safe mode
94    EnterFailSafeMode();
95}
Note: See TracBrowser for help on using the repository browser.