Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <labust_mission/labustMission.hpp>
00049 #include <sensor_msgs/Joy.h>
00050
00051
00052 namespace labust {
00053 namespace data {
00054
00055 class DataManager{
00056
00057 public:
00058
00059
00060
00061
00062
00063 DataManager();
00064
00065 void updateData(const auv_msgs::NavSts::ConstPtr& data);
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 enum {u=0, v, w, r, x, y, z, psi, x_var, y_var, z_var, psi_var, alt, stateHatNum};
00076 std::vector<double> stateHatVar;
00077
00078
00079 std::vector<double> eventsVar;
00080
00081
00082 std::vector<double> missionVar;
00083 };
00084
00085 DataManager::DataManager(){
00086
00087 ros::NodeHandle nh;
00088
00089
00090
00091
00092
00093 stateHatVar.resize(stateHatNum);
00094 }
00095
00096 void DataManager::updateData(const auv_msgs::NavSts::ConstPtr& data){
00097
00098 stateHatVar[u] = data->body_velocity.x;
00099 stateHatVar[v] = data->body_velocity.y;
00100 stateHatVar[w] = data->body_velocity.z;
00101 stateHatVar[r] = data->orientation_rate.yaw;
00102
00103 stateHatVar[x] = data->position.north;
00104 stateHatVar[y] = data->position.east;
00105 stateHatVar[z] = data->position.depth;
00106 stateHatVar[psi] = data->orientation.yaw;
00107
00108 stateHatVar[x_var] = data->position_variance.north;
00109 stateHatVar[y_var] = data->position_variance.east;
00110 stateHatVar[z_var] = data->position_variance.depth;
00111 stateHatVar[psi_var] = data->orientation_variance.yaw;
00112
00113 stateHatVar[alt] = data->altitude;
00114
00115 }
00116 }
00117 }
00118
00119
00120 class CKT : public labust::data::DataManager{
00121
00122 public:
00123
00124 ros::Subscriber subStateHatAbs, subRequestLawn, subMissionOffset, subJoy;
00125 ros::Publisher pubEvent;
00126
00127 ros::Timer timer;
00128
00129 bool requestTurn;
00130
00131 double course;
00132
00133
00134
00135 auv_msgs::NED offset;
00136
00137
00138
00139 double startLawnX, startLawnY;
00140
00141
00142 CKT():startLawnX(0.0),startLawnY(0.0), requestTurn(false), course(0){
00143
00144 ros::NodeHandle nh;
00145
00146
00147 subStateHatAbs = nh.subscribe<auv_msgs::NavSts>("stateHatAbsSlow",1, &CKT::onStateHat, this);
00148
00149
00150 subJoy = nh.subscribe<sensor_msgs::Joy>("joy", 1, &CKT::onJoy,this);
00151
00152
00153
00154
00155 pubEvent = nh.advertise<misc_msgs::ExternalEvent>("externalEvent",1);
00156
00157
00158
00159
00160 }
00161
00162 void onStateHat(const auv_msgs::NavSts::ConstPtr& data){
00163
00164 updateData(data);
00165
00166 ros::NodeHandle nh;
00167
00168 misc_msgs::ExternalEvent sendEvent;
00169
00170
00171 if(requestTurn == true){
00172
00173
00174
00175
00176 timer = nh.createTimer(ros::Duration(0.5), &CKT::onTimeout, this, true);
00177 requestTurn = false;
00178
00179 ROS_ERROR("KURS: %f", course*180/M_PI);
00180 }
00181
00182
00183
00184 }
00185
00186
00187 void onTimeout(const ros::TimerEvent& timer){
00188
00189
00190
00191
00192 misc_msgs::ExternalEvent sendEvent;
00193
00194 sendEvent.id = 2;
00195 sendEvent.value = 0;
00196 pubEvent.publish(sendEvent);
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 }
00209
00210
00211 void onJoy(const sensor_msgs::Joy::ConstPtr& data){
00212
00213 misc_msgs::ExternalEvent sendEvent;
00214 if(data->buttons[2]){
00215
00216 ROS_ERROR("lijevo");
00217
00218 course -= M_PI/2;
00219
00220 if(course>M_PI){
00221 course -= 2*M_PI;
00222 }else if(course<-M_PI){
00223 course += 2*M_PI;
00224 }
00225
00226
00227 sendEvent.id = 5;
00228 sendEvent.value = course;
00229 pubEvent.publish(sendEvent);
00230
00231 requestTurn = true;
00232 } else if(data->buttons[3]){
00233
00234 ROS_ERROR("desno");
00235
00236 course += M_PI/2;
00237
00238 if(course>M_PI){
00239 course -= 2*M_PI;
00240 }else if(course<-M_PI){
00241 course += 2*M_PI;
00242 }
00243
00244
00245 sendEvent.id = 5;
00246 sendEvent.value = course;
00247 pubEvent.publish(sendEvent);
00248 requestTurn = true;
00249
00250 }
00251
00252 if(requestTurn){
00253 sendEvent.id = 2;
00254 sendEvent.value = 1;
00255 pubEvent.publish(sendEvent);
00256 }
00257 }
00258
00259
00260 };
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 int main(int argc, char** argv){
00272
00273 ros::init(argc, argv, "LOD");
00274 ros::NodeHandle nh;
00275
00276 CKT courseKeepingTurns;
00277
00278
00279 ros::spin();
00280 return 0;
00281 }
00282
00283
00284
00285
00286
00287
00288