mzos.cpp
Go to the documentation of this file.
00001 /*
00002  * mzos.cpp
00003  *
00004  *  Created on: Jun 25, 2014
00005  *      Author: Filip Mandic
00006  */
00007 
00008 /*********************************************************************
00009 * Software License Agreement (BSD License)
00010 *
00011 *  Copyright (c) 2014, LABUST, UNIZG-FER#include <sensor_msgs/Joy.h>
00012 *
00013 *  All rights reserved.
00014 *
00015 *  Redistribution and use in source and binary forms, with or without
00016 *  modification, are permitted provided that the following conditions
00017 *  are met:
00018 *
00019 *   * Redistributions of source code must retain the above copyright
00020 *     notice, this list of conditions and the following disclaimer.
00021 *   * Redistributions in binary form must reproduce the above
00022 *     copyright notice, this list of conditions and the following
00023 *     disclaimer in the documentation and/or other materials provided
00024 *     with the distribution.
00025 *   * Neither the name of the LABUST nor the names of its
00026 *     contributors may be used to endorse or promote products derived
00027 *     from this software without specific prior written permission.
00028 *
00029 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00030 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00031 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00032 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00033 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00034 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00035 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00036 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00037 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00038 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00039 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040 *  POSSIBILITY OF SUCH DAMAGE.
00041 *********************************************************************/
00042 
00043 //#ifndef EVENTEVALUATION_HPP_
00044 //#define EVENTEVALUATION_HPP_
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                          ***  Class functions
00061                          ****************************************************************/
00062 
00063                         DataManager();
00064 
00065                         void updateData(const auv_msgs::NavSts::ConstPtr& data);
00066 
00067                         /*********************************************************************
00068                          ***  Class variables
00069                          ********************************************************************/
00070 
00071                         //ros::Subscriber subExternalEvents;
00072                         //ros::Subscriber subStateHatAbs;
00073 
00074                         /* State Hat variables */
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                         /* Events data variables */
00079                         std::vector<double> eventsVar;
00080 
00081                         /* Mission specific variables */ // Svki specificni projekt ima klasu koja extenda DataManager klasu
00082                         std::vector<double> missionVar;
00083                 };
00084 
00085                 DataManager::DataManager(){
00086 
00087                         ros::NodeHandle nh;
00088                         //subExternalEvents= nh.subscribe<misc_msgs::ExternalEvent>("externalEvent",1, &EventEvaluation::onReceiveExternalEvent, this);
00089                         //subStateHatAbs= nh.subscribe<auv_msgs::NavSts>("stateHatAbs",1, &DataManager::onStateHat, this);
00090 
00091 
00092                         //externalEventContainer.resize(5); // 5 eksternih evenata
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                 /* Subscribers */
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                 /* Publishers */
00152                 pubEvent = nh.advertise<misc_msgs::ExternalEvent>("externalEvent",5);
00153                 pubDeltaPos = nh.advertise<auv_msgs::NED>("quad_delta_pos", 1);
00154                 //pubKFmode = nh.advertise<std_msgs::Bool>("quad_delta_pos_available",1);
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                         /* Publish controller mode*/
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             /* Publish controller mode*/
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                         /* Publish controller mode*/
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 


labust_mission
Author(s): Filip Mandic
autogenerated on Fri Aug 28 2015 11:23:04