SimCore.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, LABUST, UNIZG-FER
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the LABUST nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *  Author: Dula Nad
00035  *  Created: 01.02.2013.
00036  *********************************************************************/
00037 #ifndef SIMCORE_HPP_
00038 #define SIMCORE_HPP_
00039 #include <labust/simulation/RBModel.hpp>
00040 //#include <labust/ros/SimSensors.hpp>
00041 #include <labust/tools/conversions.hpp>
00042 
00043 #include <auv_msgs/BodyForceReq.h>
00044 #include <geometry_msgs/WrenchStamped.h>
00045 #include <geometry_msgs/TwistStamped.h>
00046 #include <geometry_msgs/Vector3.h>
00047 #include <auv_msgs/NavSts.h>
00048 #include <nav_msgs/Odometry.h>
00049 #include <ros/ros.h>
00050 #include <tf/transform_broadcaster.h>
00051 #include <tf/transform_listener.h>
00052 
00053 #include <boost/thread.hpp>
00054 
00055 namespace labust
00056 {
00057         namespace simulation
00058         {
00065                 void configureModel(const ros::NodeHandle& nh, RBModel& model);
00066 
00075                 class SimCore
00076                 {
00077                 public:
00081                         SimCore();
00082 
00086                         void onInit();
00087 
00091                         void start();
00092 
00093 //                      /**
00094 //                       * Add a new sensor to the simulation.
00095 //                       */
00096 //                      inline void addSensor(SimSensorInterface::Ptr sensor)
00097 //                      {
00098 //                                      boost::mutex::scoped_lock l(sensor_mux);
00099 //                                      sensors.push_back(sensor);
00100 //                      }
00101 
00102                 private:
00106                         void modelReport();
00110                         void step();
00115                         template <class ROSMsg>
00116                         void onTau(const typename ROSMsg::ConstPtr& msg)
00117                         {
00118                                 boost::mutex::scoped_lock l(tau_mux);
00119                                 labust::tools::pointToVector(msg->wrench.force, tau);
00120                                 labust::tools::pointToVector(msg->wrench.torque, tau, 3);
00121 
00122                                 //Allocate
00123                                 vector tauAch(tau);
00124                                 model.allocator.allocate(tau,tauAch);
00125                                 tau = tauAch;
00126 
00127                                 //Publish allocated.
00128                                 typename ROSMsg::Ptr ach(new ROSMsg());
00129                                 labust::tools::vectorToPoint(tau,ach->wrench.force);
00130                                 labust::tools::vectorToPoint(tau,ach->wrench.torque,3);
00131                                 publish_windup(ach, model.allocator.getCoercion());
00132                                 publish_dispatch(ach);
00133                         }
00134 
00138                         template <class WindupType>
00139                         inline void publish_windup(auv_msgs::BodyForceReq::Ptr& tau, const WindupType& windup)
00140                         {
00141                                 labust::tools::vectorToPoint(windup,tau->disable_axis);
00142 
00143                                 tau->disable_axis.roll = windup(3);
00144                                 tau->disable_axis.pitch = windup(4);
00145                                 tau->disable_axis.yaw = windup(5);
00146                         }
00150                         template <class WindupType>
00151                         inline void publish_windup(geometry_msgs::WrenchStamped::Ptr& tau, const WindupType& windup){};
00152 
00156                         inline void publish_dispatch(auv_msgs::BodyForceReq::Ptr& tau)
00157                         {
00158                                 this->tauAch.publish(tau);
00159                         }
00163                         inline void publish_dispatch(geometry_msgs::WrenchStamped::Ptr& tau)
00164                         {
00165                                 this->tauAchWrench.publish(tau);
00166                         }
00167 
00173                         void allocate();
00174 
00178                         void onCurrents(const geometry_msgs::TwistStamped::ConstPtr& currents);
00179 
00183                         void publishNavSts();
00187                         void etaNuToNavSts(const vector& eta, const vector& nu, auv_msgs::NavSts& state);
00188 
00192                         void publishOdom();
00196                         void etaNuToOdom(const vector& eta, const vector& nu, nav_msgs::Odometry& state);
00197 
00201                         void publishWorld();
00205                         void publishSimBaseLink();
00206 
00210                         RBModel model;
00214                         tf::TransformBroadcaster broadcast;
00218                         ros::Subscriber tauIn, tauInWrench, currentsSub;
00222                         ros::Publisher tauAch, tauAchWrench, meas, measn, odom, odomn, acc;
00226                         vector tau;
00230                         boost::mutex tau_mux, model_mux, sensor_mux;
00234                         boost::thread runner;
00238 //                      std::vector<SimSensorInterface::Ptr> sensors;
00242                         ros::Rate rate;
00246                         int wrap;
00250                         bool enablePublishWorld;
00254                         bool enablePublishSimBaseLink;
00258                         double originLat, originLon;
00259                 };
00260         }
00261 }
00262 
00263 /* SIMCORE_HPP_ */
00264 #endif


labust_sim
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:33