ForceSensor.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2013 University of Jaume-I.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the GNU Public License v3.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.gnu.org/licenses/gpl.html
00007  * 
00008  * Contributors:
00009  *     Mario Prats
00010  *     Javier Perez
00011  */
00012 
00013 #ifndef FORCESENSOR_H_
00014 #define FORCESENSOR_H_
00015 #include "SimulatedDevice.h"
00016 using namespace uwsim;
00017 
00018 class ForceSensor_Config : public SimulatedDeviceConfig
00019 {
00020 public:
00021   //XML members
00022   std::string target;
00023   double offsetp[3];
00024   double offsetr[3];
00025   //constructor
00026   ForceSensor_Config(std::string type_) :
00027       SimulatedDeviceConfig(type_)
00028   {
00029   }
00030 };
00031 
00032 //Driver/ROSInterface factory class
00033 class ForceSensor_Factory : public SimulatedDeviceFactory
00034 {
00035 public:
00036   //this is the only place the device/interface type is set
00037   ForceSensor_Factory(std::string type_ = "ForceSensor") :
00038       SimulatedDeviceFactory(type_)
00039   {
00040   }
00041   ;
00042 
00043   SimulatedDeviceConfig::Ptr processConfig(const xmlpp::Node* node, ConfigFile * config);
00044   bool applyConfig(SimulatedIAUV * auv, Vehicle &vehicleChars, SceneBuilder *sceneBuilder, size_t iteration);
00045   std::vector<boost::shared_ptr<ROSInterface> > getInterface(ROSInterfaceInfo & rosInterface,
00046                                                              std::vector<boost::shared_ptr<SimulatedIAUV> > & iauvFile);
00047 };
00048 
00049 //can be a sparate header file for actual implementation classes...
00050 
00051 #include "ConfigXMLParser.h"
00052 #include "ROSInterface.h"
00053 #include <ros/ros.h>
00054 #include <geometry_msgs/WrenchStamped.h>
00055 #include "BulletPhysics.h"
00056 
00057 //Driver class
00058 static void forceSensorPreTickCallback(btDynamicsWorld *world, btScalar timeStep);
00059 static void forceSensorPostTickCallback(btDynamicsWorld *world, btScalar timeStep);
00060 
00061 
00062 class ForceSensor : public SimulatedDevice
00063 {
00064   void applyPhysics(BulletPhysics * bulletPhysics);
00065   btVector3 linInitial, linFinal;
00066   btVector3 angInitial, angFinal;
00067   double lastTimeStep;
00068 public:
00069   BulletPhysics * physics;
00070   btRigidBody * copy, * btTarget;  //Rigid object copy with physical reaction
00071   osg::ref_ptr<osg::Node> target;
00072   double offsetp[3];
00073   osg::Matrixd offset; //We only need rotation as traslation goes to bullet directly
00074 
00075   ForceSensor(ForceSensor_Config * cfg, osg::ref_ptr<osg::Node> target);
00076   void physicsInternalPreProcessCallback(btScalar timeStep);
00077   void physicsInternalPostProcessCallback(btScalar timeStep);
00078   void getForceTorque(double force[3], double torque[3]);
00079 };
00080 
00081 
00082 
00083 //ROS publishers and subscribers work exactly as before, no subclassing is needed
00084 class ForceSensor_ROSPublisher : public ROSPublisherInterface
00085 {
00086   //this is just an example, use a pointer to SimulatedIAUV, if only ROSInterface is implemented
00087   //pointer to a device
00088   ForceSensor * dev;
00089   ros::WallTime last;
00090 public:
00091   ForceSensor_ROSPublisher(ForceSensor *dev, std::string topic, int rate) :
00092       ROSPublisherInterface(topic, rate), dev(dev)
00093   {
00094     last = ros::WallTime::now();
00095   }
00096 
00097   void createPublisher(ros::NodeHandle &nh);
00098   void publish();
00099 
00100   ~ForceSensor_ROSPublisher()
00101   {
00102   }
00103 };
00104 
00105 #endif


uwsim
Author(s): Mario Prats
autogenerated on Mon Oct 6 2014 08:24:07