Go to the documentation of this file.00001 #pragma once
00002
00022 #ifndef __CONTROLNODE_H
00023 #define __CONTROLNODE_H
00024
00025 #include "ros/ros.h"
00026 #include "geometry_msgs/Twist.h"
00027 #include "uga_tum_ardrone/filter_state.h"
00028 #include "std_msgs/String.h"
00029 #include <dynamic_reconfigure/server.h>
00030 #include "uga_tum_ardrone/AutopilotParamsConfig.h"
00031 #include "DroneController.h"
00032 #include "std_msgs/Empty.h"
00033 #include "std_srvs/Empty.h"
00034
00035 #include "uga_tum_ardrone/SetReference.h"
00036 #include "uga_tum_ardrone/SetMaxControl.h"
00037 #include "uga_tum_ardrone/SetInitialReachDistance.h"
00038 #include "uga_tum_ardrone/SetStayWithinDistance.h"
00039 #include "uga_tum_ardrone/SetStayTime.h"
00040 #include "std_srvs/Empty.h"
00041 #include <fstream>
00042
00043 class DroneKalmanFilter;
00044 class MapView;
00045 class PTAMWrapper;
00046 class KIProcedure;
00047
00048
00049 struct ControlNode
00050 {
00051 private:
00052 ros::Subscriber dronepose_sub;
00053 ros::Publisher vel_pub;
00054 ros::Subscriber uga_tum_ardrone_sub;
00055 ros::Publisher uga_tum_ardrone_pub;
00056 ros::Publisher takeoff_pub;
00057 ros::Publisher land_pub;
00058 ros::Publisher toggleState_pub;
00059
00060 ros::NodeHandle nh_;
00061 static pthread_mutex_t uga_tum_ardrone_CS;
00062
00063
00064 int minPublishFreq;
00065 std::string control_channel;
00066 std::string dronepose_channel;
00067 std::string command_channel;
00068 std::string packagePath;
00069 std::string land_channel;
00070 std::string takeoff_channel;
00071 std::string toggleState_channel;
00072
00073
00074 ros::ServiceServer setReference_;
00075 ros::ServiceServer setMaxControl_;
00076 ros::ServiceServer setInitialReachDistance_;
00077 ros::ServiceServer setStayWithinDistance_;
00078 ros::ServiceServer setStayTime_;
00079 ros::ServiceServer startControl_;
00080 ros::ServiceServer stopControl_;
00081 ros::ServiceServer clearCommands_;
00082 ros::ServiceServer hover_;
00083 ros::ServiceServer lockScaleFP_;
00084
00085 bool setReference(uga_tum_ardrone::SetReference::Request&, uga_tum_ardrone::SetReference::Response&);
00086 bool setMaxControl(uga_tum_ardrone::SetMaxControl::Request&, uga_tum_ardrone::SetMaxControl::Response&);
00087 bool setInitialReachDistance(uga_tum_ardrone::SetInitialReachDistance::Request&, uga_tum_ardrone::SetInitialReachDistance::Response&);
00088 bool setStayWithinDistance(uga_tum_ardrone::SetStayWithinDistance::Request&, uga_tum_ardrone::SetStayWithinDistance::Response&);
00089 bool setStayTime(uga_tum_ardrone::SetStayTime::Request&, uga_tum_ardrone::SetStayTime::Response&);
00090 bool start(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
00091 bool stop(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
00092 bool clear(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
00093 bool hover(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
00094 bool lockScaleFP(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
00095
00096
00097 std::deque<std::string> commandQueue;
00098 static pthread_mutex_t commandQueue_CS;
00099
00100
00101
00102 KIProcedure* currentKI;
00103
00104
00105 DronePosition parameter_referenceZero;
00106 double parameter_StayTime;
00107 double parameter_MaxControl;
00108 double parameter_InitialReachDist;
00109 double parameter_StayWithinDist;
00110
00111
00112 void startControl();
00113 void stopControl();
00114 void clearCommands();
00115 void updateControl(const uga_tum_ardrone::filter_stateConstPtr statePtr);
00116
00117 void popNextCommand(const uga_tum_ardrone::filter_stateConstPtr statePtr);
00118 void reSendInfo();
00119 char buf[500];
00120 ControlCommand lastSentControl;
00121 public:
00122 ControlNode();
00123 ~ControlNode();
00124
00125
00126
00127 void droneposeCb(const uga_tum_ardrone::filter_stateConstPtr statePtr);
00128 void comCb(const std_msgs::StringConstPtr str);
00129 void dynConfCb(uga_tum_ardrone::AutopilotParamsConfig &config, uint32_t level);
00130
00131
00132 void Loop();
00133
00134
00135
00136 void publishCommand(std::string c);
00137
00138
00139 void sendControlToDrone(ControlCommand cmd);
00140 void sendLand();
00141 void sendTakeoff();
00142 void sendToggleState();
00143
00144
00145 DroneController controller;
00146 ControlCommand hoverCommand;
00147
00148
00149 std::ofstream* logfileControl;
00150 static pthread_mutex_t logControl_CS;
00151 long currentLogID;
00152 long startedLogClock;
00153 void toogleLogging();
00154
00155
00156 long lastControlSentMS;
00157 bool isControlling;
00158 };
00159 #endif