00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ASCTEC_UAV_H
00029 #define ASCTEC_UAV_H
00030
00031 #include "HummingBirdUavComm.h"
00032 #include "HBstructs.h"
00033 #include <Uav.h>
00034
00035 namespace MipResources {
00037
00038
00039 class asctecUavOptions : public Options {
00040 public:
00041 StringOption *port_name;
00042 IntOption *max_input;
00043 IntOption *fdata_send_rate;
00044 IntOption *read_rate;
00045 IntOption *send_rate;
00046
00047 IntOption *ctrlin_send_rate;
00048 IntOption *ctrlfl_send_rate;
00049
00050 IntOption *h_sonar_rate;
00051 IntOption *h_sonar_p_gain;
00052 IntOption *h_sonar_i_gain;
00053 IntOption *h_sonar_d_gain;
00054 DecimalOption *height_ref;
00055
00056 StringOption *log_path;
00057 StringOption *log_name;
00058 BoolOption *make_log;
00059 BoolOption *use_ros;
00060 BoolOption *use_test;
00061
00062 StringOption *ros_gains_sender_name;
00063
00064 string getObjectName() const {
00065 return "asctecUavOptions";
00066 }
00067
00068 asctecUavOptions() {
00069 MIP_DEBUG(5,"asctec Options constructor");
00070
00071 port_name = createStringOption("asctecUavPortName" ,
00072 "Name of com port, default \"/dev/ttyUSB0\".",
00073 "/dev/ttyUSB0");
00074
00076 max_input = createIntOption("asctecUavMaxInput",
00077 "Maximum remote input in [-2047,+2047], default 500.",
00078 500);
00079
00080 fdata_send_rate = createIntOption("asctecUavFdataSendRate",
00081 "Rate of data transmission (1000/sendRate Hz) from quadrotor to pc, default 20.",20);
00082 read_rate = createIntOption("asctecUavReadRate",
00083 "Rate of data reading loop (1000/readRate Hz), default 20.",20);
00084 send_rate = createIntOption("asctecUavSendRate",
00085 "Rate of data sending to the quadrotor (1000/sendRate Hz), default 30.",30);
00086
00087 height_ref = createDecimalOption("asctecUavHReference",
00088 "Initial height reference for controller, default 1.5.",1.5);
00089
00090 h_sonar_rate = createIntOption("asctecUavhSonarRate",
00091 "Rate for sonar height controller (1000/rate Hz), default 40.", 40);
00092 h_sonar_p_gain = createIntOption("asctecUavhSonarPGain",
00093 "Proportional gain in pid height controller", 200);
00094 h_sonar_i_gain = createIntOption("asctecUavhSonarIGain",
00095 "Integral gain in pid height controller",0);
00096 h_sonar_d_gain = createIntOption("asctecUavhSonarDGain",
00097 "Derivative gain in pid height controller", 220);
00098
00099 log_path = createStringOption("asctecUavlogPath",
00100 "Path to save log. Default: current directory.", "./");
00101
00102 ros_gains_sender_name = createStringOption("hbGainsRosTopicName",
00103 "Name of ros topic for sending gains.", "quad_sendGains");
00104
00105 time_t rawtime;
00106 struct tm * timeinfo;
00107 char buffer [80];
00108 time ( &rawtime );
00109 timeinfo = localtime ( &rawtime );
00110 strftime(buffer,80,"%Y-%m-%d_%H-%M_HBdata",timeinfo);
00111
00112 log_name = createStringOption("asctecUavlogName",
00113 "Name for log file. Default: date_hour_HBdata.", buffer);
00114
00115 make_log = createBoolOption("asctecUavmakeLog",
00116 "Whether on not register log. Deafult: true.", false);
00117 use_ros = createBoolOption("asctecUavUseRos",
00118 "Whether on not use ROS. Deafult: false." , false);
00119 use_test = createBoolOption("asctecUavUseTest",
00120 "Whether on not use test version. Deafult: true.", false);
00121
00122 updateValues();
00123 }
00124 };
00125
00129 class asctecUavPar : public UavPar{
00130 private:
00131 public:
00132 };
00133
00137 class asctecUavVar : public UavVar{
00138 private:
00139 public:
00140 };
00141
00146 class asctecUav : public Uav{
00147 private:
00148 static const ResourcePlate _plate = UAV_HUBI_RES;
00149 HummingBirdUavComm* _com;
00150 asctecUavVar * _HBvar;
00151
00152 Thread _dataThread;
00153 Thread _ctrlThread;
00154
00155 EnhancedMutEx _comMutex;
00156 EnhancedMutEx _ctrlMutex;
00157
00158 Time mutexTimeoutWrite;
00159 Time mutexTimeoutRead;
00160
00161 asctecUavOptions options;
00162
00163 LABROB_CTRL_INPUT ctrl_input;
00164 bool ctrl_input_update;
00165
00166 static const Decimal angle2hubi;
00167 static const Decimal hubi2angle;
00168 static const Decimal hubi2angleVel;
00169
00170 static const int thrust2hubi = 4095;
00171 static const Decimal hubi2thrust;
00172 ofstream _logFile;
00173 int _numrow;
00174
00175 public:
00176 void dataLoop();
00177 void ctrlLoop();
00178
00180 asctecUav(int argc, const char** argv);
00181
00183 ~asctecUav();
00184
00186 ResourcePlate getPlate() const {
00187 return _plate;
00188 }
00189
00192 Position3D getPosition(Time& t) {
00193 t = _HBvar->time();
00194 return _HBvar->position();
00195 }
00196
00199 Orientation3D getAttitude(Time& t) {
00200 t = _HBvar->time();
00201 return _HBvar->attitude();
00202 }
00203
00205 HummingBirdUavComm* getCom() {
00206 return _com;
00207 }
00208
00213 bool setStatus(Orientation3D& pDes, Decimal& tDes);
00214
00218 bool setThrust(Decimal tDes);
00219
00224 bool setControllersGains(Decimal height_pid_des[3]);
00225
00229 bool setFiltersGains(Decimal sonar_h_filt_des[2]);
00230
00234 bool setYaw(Angle yaw){}
00235
00240 bool setPose(Pose3D& pDes, short ctrlIn);
00241
00245 bool setAttitude(Orientation3D& oDes);
00246
00249 bool setPosition( Position3D p,
00250 Velocity3D v = Velocity3D(0.0,0.0,0.0),
00251 Acceleration3D a = Acceleration3D(0.0,0.0,0.0));
00252
00254 bool setVelocity(Velocity3D p,Acceleration3D a){}
00255
00257 bool setAcceleration(Acceleration3D p){}
00258
00261 bool readPosition(){}
00262
00265 bool readVelocity(){};
00266
00269 bool readAttitude(){}
00270
00271 private:
00272
00273 pthread_t thread_data;
00274 pthread_attr_t thread_attr;
00275 pthread_mutex_t mutex_run;
00276
00277 pthread_mutex_t mutex_list;
00278
00279 pthread_t thread_data_write;
00280 pthread_attr_t thread_attr_write;
00281 pthread_mutex_t mutex_run_write;
00282
00283 int stack_size_max;
00284 int stack_size;
00285 bool run_write_loop;
00286 bool run_data_loop;
00287
00288 void stopLoop();
00289 };
00290 };
00291
00292 #endif // ASCTEC_UAV_H