00001 /* 00002 * Copyright (c) 2013 Tallinn University of Technology. 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 * Yuri Gavshin 00010 */ 00011 00012 #ifndef SIMULATEDDEVICE_H_ 00013 #define SIMULATEDDEVICE_H_ 00014 00015 #include <libxml++/libxml++.h> 00016 #include <iostream> 00017 #include <cstdlib> 00018 #include <list> 00019 #include <boost/smart_ptr/shared_ptr.hpp> 00020 00021 struct ROSInterfaceInfo; 00022 struct SimulatedIAUV; 00023 struct ROSInterface; 00024 struct ConfigFile; 00025 struct Vehicle; 00026 struct SceneBuilder; 00027 struct BulletPhysics; 00028 struct ViewBuilder; 00029 00030 namespace uwsim 00031 { 00032 struct SimulatedDevice; 00033 //Base class for device's XML configuration 00034 class SimulatedDeviceConfig 00035 { 00036 //device/rosinterface type identifier for both "XML config" and a "factory" 00037 std::string type; 00038 00039 public: 00040 typedef boost::shared_ptr<SimulatedDeviceConfig> Ptr; 00041 //common XML properties: 00042 std::string name; 00043 std::string getType() 00044 { 00045 return type; 00046 } 00047 00048 SimulatedDeviceConfig(std::string type); 00049 virtual ~SimulatedDeviceConfig() 00050 { 00051 } 00052 ; 00053 }; 00054 00055 //Base class for device/rosinterface "factory" 00056 class SimulatedDeviceFactory 00057 { 00058 //device/rosinterface type identifier for both "XML config" and a "factory" 00059 std::string type; 00060 public: 00061 typedef boost::shared_ptr<SimulatedDeviceFactory> Ptr; 00062 std::string getType() 00063 { 00064 return type; 00065 } 00066 SimulatedDeviceFactory(std::string type); 00067 00068 //DRIVER: parses XML and returns "XML config", executed first 00069 virtual SimulatedDeviceConfig::Ptr processConfig(const xmlpp::Node* node, ConfigFile * config) = 0; 00070 //DRIVER: checks parsed XML configurations and sets SimulatedAUV's data, executed second 00071 //Executed multiple times (to allow dependent devices work independent from order of ), until all factories return true 00072 //normally, configuration should occur only on iteration 0 00073 virtual bool applyConfig(SimulatedIAUV * auv, Vehicle &vehicleChars, SceneBuilder *oscene, size_t iteration) = 0; 00074 //ROSINTERFACE: returns configured ROSInterfaces, executed third 00075 virtual std::vector<boost::shared_ptr<ROSInterface> > getInterface( 00076 ROSInterfaceInfo & rosInterface, std::vector<boost::shared_ptr<SimulatedIAUV> > & iauvFile) = 0; 00077 00078 virtual ~SimulatedDeviceFactory() 00079 { 00080 } 00081 ; 00082 }; 00083 00084 //Base class for a simulated device 00085 class SimulatedDevice 00086 { 00087 std::string type; //driver/rosinterface type 00088 public: 00089 std::string name; //common property 00090 std::string getType() 00091 { 00092 return type; 00093 } 00094 typedef boost::shared_ptr<SimulatedDevice> Ptr; 00095 SimulatedDevice(SimulatedDeviceConfig * cfg); 00096 virtual void applyPhysics(BulletPhysics * bulletPhysics) 00097 { 00098 } 00099 virtual void setViewBuilder(ViewBuilder * viewBuilder) 00100 { 00101 } 00102 00103 virtual ~SimulatedDevice() 00104 { 00105 } 00106 }; 00107 } 00108 ; 00109 00110 #endif /* SIMULATEDDEVICES_H_ */