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 #include <labust_mission/labustMission.hpp>
00048 #include <sensor_msgs/Joy.h>
00049 #include <geometry_msgs/PoseStamped.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 MZOS : public labust::data::DataManager{
00121
00122 public:
00123
00124 ros::Subscriber subStateHatAbs, subRelativeDistance, subTargetPos, subAgvPos;
00125 ros::Publisher pubEvent, pubKFmode, pubDeltaPos;
00126
00127 ros::Timer timer;
00128
00129 auv_msgs::NED offset;
00130
00131
00132
00133 double deltaXposTarget, deltaYposTarget, targetXpos, targetYpos, agvXpos, agvYpos;
00134
00135 enum {initial = 0, coarseApproach, fineApproach, Tugging};
00136
00137 int missionState;
00138
00139
00140 MZOS():deltaXposTarget(0.0),deltaYposTarget(0.0), targetXpos(0.0), targetYpos(0.0), agvXpos(0.0), agvYpos(0.0),
00141 missionState(0){
00142
00143 ros::NodeHandle nh;
00144
00145
00146 subStateHatAbs = nh.subscribe<auv_msgs::NavSts>("stateHatAbsSlow",1, &MZOS::onStateHat, this);
00147 subRelativeDistance = nh.subscribe<geometry_msgs::PoseStamped>("target_pose", 1, &MZOS::onRelativeDistance, this);
00148 subTargetPos = nh.subscribe<auv_msgs::NED>("target_pos", 1, &MZOS::onTargetPos, this);
00149 subAgvPos = nh.subscribe<auv_msgs::NED>("agv_pos", 1, &MZOS::onAgvPos, this);
00150
00151
00152 pubEvent = nh.advertise<misc_msgs::ExternalEvent>("externalEvent",5);
00153 pubDeltaPos = nh.advertise<auv_msgs::NED>("quad_delta_pos", 1);
00154
00155 pubKFmode = nh.advertise<std_msgs::Bool>("KFmode",1);
00156
00157 }
00158
00159 void onStateHat(const auv_msgs::NavSts::ConstPtr& data){
00160
00161 }
00162
00163 void onTargetPos(const auv_msgs::NED::ConstPtr& msg){
00164
00165 targetXpos = msg->north;
00166 targetYpos = msg->east;
00167
00168 if(missionState == initial){
00169
00170 misc_msgs::ExternalEvent sendEvent;
00171
00172 sendEvent.id = 1;
00173 sendEvent.value = targetXpos;
00174 pubEvent.publish(sendEvent);
00175
00176 sendEvent.id = 2;
00177 sendEvent.value = targetYpos;
00178 pubEvent.publish(sendEvent);
00179
00180
00181 std_msgs::Bool KFdeltaMode;
00182 KFdeltaMode.data = false;
00183 pubKFmode.publish(KFdeltaMode);
00184
00185 sendEvent.id = 5;
00186 sendEvent.value = 1;
00187 pubEvent.publish(sendEvent);
00188
00189 missionState = coarseApproach;
00190
00191 }
00192 }
00193
00194 void onRelativeDistance(const geometry_msgs::PoseStamped::ConstPtr& msg){
00195
00196 deltaXposTarget = -msg->pose.position.x;
00197 deltaYposTarget = -msg->pose.position.y;
00198
00199
00200 if(missionState == coarseApproach){
00201
00202 misc_msgs::ExternalEvent sendEvent;
00203
00204 sendEvent.id = 1;
00205 sendEvent.value = deltaXposTarget;
00206 pubEvent.publish(sendEvent);
00207
00208 sendEvent.id = 2;
00209 sendEvent.value = deltaYposTarget;
00210 pubEvent.publish(sendEvent);
00211
00212 sendEvent.id = 5;
00213 sendEvent.value = 2;
00214 pubEvent.publish(sendEvent);
00215
00216
00217 std_msgs::Bool KFdeltaMode;
00218 KFdeltaMode.data = true;
00219 pubKFmode.publish(KFdeltaMode);
00220
00221 missionState = fineApproach;
00222 }
00223 }
00224
00225 void onAgvPos(const auv_msgs::NED::ConstPtr& msg){
00226
00227 agvXpos = msg->north;
00228 agvYpos = msg->east;
00229
00230 if(missionState == fineApproach){
00231
00232 misc_msgs::ExternalEvent sendEvent;
00233
00234 sendEvent.id = 3;
00235 sendEvent.value = agvXpos;
00236 pubEvent.publish(sendEvent);
00237
00238 sendEvent.id = 4;
00239 sendEvent.value = agvYpos;
00240 pubEvent.publish(sendEvent);
00241
00242 sendEvent.id = 5;
00243 sendEvent.value = 3;
00244 pubEvent.publish(sendEvent);
00245
00246
00247 std_msgs::Bool KFdeltaMode;
00248 KFdeltaMode.data = false;
00249 pubKFmode.publish(KFdeltaMode);
00250
00251 missionState = Tugging;
00252 }
00253 }
00254
00255 void onLostContact(const std_msgs::Bool::ConstPtr& data){
00256
00257 }
00258
00259 };
00260
00261
00262 int main(int argc, char** argv){
00263
00264 ros::init(argc, argv, "mzos_mission");
00265 ros::NodeHandle nh;
00266
00267 MZOS mzos;
00268
00269 ros::spin();
00270 return 0;
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283