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 #include <labust_mission/labustMission.hpp>
00046 #include <sensor_msgs/Joy.h>
00048
00049 namespace labust {
00050 namespace data {
00051
00052 class DataManager{
00053
00054 public:
00055
00056
00057
00058
00059
00060 DataManager();
00061
00062 void updateData(const auv_msgs::NavSts::ConstPtr& data);
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 enum {u=0, v, w, r, x, y, z, psi, x_var, y_var, z_var, psi_var, alt, stateHatNum};
00073 std::vector<double> stateHatVar;
00074
00075
00076 std::vector<double> eventsVar;
00077
00078
00079 std::vector<double> missionVar;
00080 };
00081
00082 DataManager::DataManager(){
00083
00084 ros::NodeHandle nh;
00085
00086
00087
00088
00089
00090 stateHatVar.resize(stateHatNum);
00091 }
00092
00093 void DataManager::updateData(const auv_msgs::NavSts::ConstPtr& data){
00094
00095 stateHatVar[u] = data->body_velocity.x;
00096 stateHatVar[v] = data->body_velocity.y;
00097 stateHatVar[w] = data->body_velocity.z;
00098 stateHatVar[r] = data->orientation_rate.yaw;
00099
00100 stateHatVar[x] = data->position.north;
00101 stateHatVar[y] = data->position.east;
00102 stateHatVar[z] = data->position.depth;
00103 stateHatVar[psi] = data->orientation.yaw;
00104
00105 stateHatVar[x_var] = data->position_variance.north;
00106 stateHatVar[y_var] = data->position_variance.east;
00107 stateHatVar[z_var] = data->position_variance.depth;
00108 stateHatVar[psi_var] = data->orientation_variance.yaw;
00109
00110 stateHatVar[alt] = data->altitude;
00111
00112 }
00113 }
00114 }
00115
00116
00117
00118 class LOD : public labust::data::DataManager{
00119
00120 public:
00121
00122 ros::Subscriber subStateHatAbs, subRequestLawn, subMissionOffset, subJoy;
00123 ros::Publisher pubEvent;
00124
00125 ros::Timer timer;
00126
00127 bool requestLawnFlag;
00128
00129 int counter;
00130
00131 auv_msgs::NED offset;
00132
00133
00134
00135 double startLawnX, startLawnY;
00136
00137
00138 LOD():startLawnX(0.0),startLawnY(0.0), requestLawnFlag(false), counter(0){
00139
00140 ros::NodeHandle nh;
00141
00142
00143 subStateHatAbs = nh.subscribe<auv_msgs::NavSts>("stateHatAbs",5, &LOD::onStateHat, this);
00144 subRequestLawn = nh.subscribe<std_msgs::Bool>("requestLawn",1, &LOD::onRequestLawn, this);
00145 subMissionOffset = nh.subscribe<auv_msgs::NED>("missionOffset",1, &LOD::onMissionOffset, this);
00146 subJoy = nh.subscribe<sensor_msgs::Joy>("joy", 1, &LOD::onJoy,this);
00147
00148
00149
00150
00151 pubEvent = nh.advertise<misc_msgs::ExternalEvent>("externalEvent",3);
00152
00153
00154
00155
00156 }
00157
00158 void onStateHat(const auv_msgs::NavSts::ConstPtr& data){
00159
00160 updateData(data);
00161
00162 ros::NodeHandle nh;
00163 if(requestLawnFlag == true){
00164 timer = nh.createTimer(ros::Duration(2.0), &LOD::onTimeout, this, true);
00165 requestLawnFlag = false;
00166 }
00167
00168 }
00169
00170 void onTimeout(const ros::TimerEvent& timer){
00171
00172
00173
00174
00175 misc_msgs::ExternalEvent sendEvent;
00176
00177 sendEvent.id = 1;
00178 sendEvent.value = 0;
00179 pubEvent.publish(sendEvent);
00180
00181
00182 }
00183
00184 void onRequestLawn(const std_msgs::Bool::ConstPtr& req){
00185
00186 if(req->data){
00187
00188
00189 misc_msgs::ExternalEvent sendEvent;
00190 sendEvent.id = 2;
00191 sendEvent.value = startLawnX = stateHatVar[x] + offset.north;
00192 pubEvent.publish(sendEvent);
00193
00194 sendEvent.id = 3;
00195 sendEvent.value = startLawnY = stateHatVar[y] + offset.east;
00196 pubEvent.publish(sendEvent);
00197
00198 sendEvent.id = 1;
00199 sendEvent.value = 1;
00200 pubEvent.publish(sendEvent);
00201
00202 requestLawnFlag = true;
00203 }
00204 }
00205
00206 void onMissionOffset(const auv_msgs::NED::ConstPtr& data){
00207
00208 offset.north = data->north;
00209 offset.east = data->east;
00210 }
00211
00212 void onJoy(const sensor_msgs::Joy::ConstPtr& data){
00213
00214
00215
00216 if(data->buttons[1]){
00217
00218 ROS_ERROR("pritisak");
00219
00220 misc_msgs::ExternalEvent sendEvent;
00221 sendEvent.id = 2;
00222 sendEvent.value = startLawnX = stateHatVar[x] + offset.north;
00223 pubEvent.publish(sendEvent);
00224
00225 sendEvent.id = 3;
00226 sendEvent.value = startLawnY = stateHatVar[y] + offset.east;
00227 pubEvent.publish(sendEvent);
00228
00229 sendEvent.id = 1;
00230 sendEvent.value = 1;
00231 pubEvent.publish(sendEvent);
00232
00233 requestLawnFlag = true;
00234 }
00235 }
00236
00237
00238 };
00239
00240
00241 int main(int argc, char** argv){
00242
00243 ros::init(argc, argv, "LOD");
00244 ros::NodeHandle nh;
00245
00246 LOD lawnmowerOnDemand;
00247
00248
00249 ros::spin();
00250 return 0;
00251 }
00252
00253
00254