diff --git a/ambf_framework/afFramework.cpp b/ambf_framework/afFramework.cpp index e4ed17ec4..05a5a2dbc 100644 --- a/ambf_framework/afFramework.cpp +++ b/ambf_framework/afFramework.cpp @@ -82,6 +82,7 @@ int afCamera::s_windowIdx = 0; bool afComm::s_globalOverride = false; int afComm::s_maxFreq = 1000; int afComm::s_minFreq = 50; +string afComm::s_global_namespace_prefix = ""; btGhostPairCallback* afGhostObject::m_bulletGhostPairCallback = nullptr; //------------------------------------------------------------------------------ @@ -628,6 +629,18 @@ void afComm::overrideMinPublishingFrequency(int freq) } +/// +/// \brief afComm::setGlobalNamespacePrefix +/// \param a_global_namespace_prefix +/// +void afComm::setGlobalNamespacePrefix(string a_global_namespace_prefix){ + s_global_namespace_prefix = a_global_namespace_prefix; + if (!s_global_namespace_prefix.empty()){ + cerr << " INFO! FORCE PREPENDING GLOBAL NAMESPACE PREFIX \"" << s_global_namespace_prefix << "\" \n" ; + } +} + + /// /// \brief afCartesianController::afCartesianController @@ -898,15 +911,15 @@ string afIdentification::getTypeAsStr(){ string afIdentification::getName(){return m_name;} -string afIdentification::getNamespace(){return m_namespace;} +string afIdentification::getNamespace(){return afComm::getGlobalNamespacePrefix() + m_namespace;} -string afIdentification::getQualifiedName(){return m_namespace + m_name;} +string afIdentification::getQualifiedName(){return getNamespace() + m_name;} void afIdentification::setName(string a_name){m_name = a_name;} void afIdentification::setNamespace(string a_namespace){m_namespace = a_namespace; } -string afIdentification::getQualifiedIdentifier(){return m_namespace + m_identifier;} +string afIdentification::getQualifiedIdentifier(){return getNamespace() + m_identifier;} /// @@ -3829,10 +3842,10 @@ bool afJoint::createFromAttribs(afJointAttributes *a_attribs) m_damping = attribs.m_damping; // Initialize damping to 0 // First we should search in the local Model space and if we don't find the body. - // On then we find the world space + // Only then we find the world space - string body1Name = m_namespace + m_parentName; - string body2Name = m_namespace + m_childName; + string body1Name = getNamespace() + m_parentName; + string body2Name = getNamespace() + m_childName; m_afParentBody = m_modelPtr->getRigidBody(body1Name, true); m_afChildBody = m_modelPtr->getRigidBody(body2Name, true); @@ -5645,7 +5658,7 @@ void afModelManager::addChildsSceneObjectsToWorld(afBaseObjectPtr a_object) /// \brief afWorld::afWorld /// \param a_global_namespace /// -afWorld::afWorld(string a_global_namespace): afIdentification(afType::WORLD), afModelManager(this){ +afWorld::afWorld(): afIdentification(afType::WORLD), afModelManager(this){ m_maxIterations = 10; // reset simulation time @@ -5714,7 +5727,6 @@ afWorld::afWorld(string a_global_namespace): afIdentification(afType::WORLD), af m_pickColor.setOrangeTomato(); m_pickColor.setTransparencyLevel(0.3); m_namespace = ""; - setGlobalNamespace(a_global_namespace); } afWorld::~afWorld() @@ -5822,30 +5834,6 @@ bool afWorld::loadCommunicationPlugin(afWorldPtr a_worldPtr, afWorldAttribsPtr a } -/// -/// \brief afWorld::getFullyQualifiedName -/// \param a_name -/// \return -/// -string afWorld::resolveGlobalNamespace(string a_name){ - string fully_qualified_name = getGlobalNamespace() + a_name; - fully_qualified_name = afUtils::removeAdjacentBackSlashes(fully_qualified_name); - return fully_qualified_name; -} - - -/// -/// \brief afWorld::setGlobalNamespace -/// \param a_global_namespace -/// -void afWorld::setGlobalNamespace(string a_global_namespace){ - m_global_namespace = a_global_namespace; - if (!m_global_namespace.empty()){ - cerr << " INFO! FORCE PREPENDING GLOBAL NAMESPACE \"" << m_global_namespace << "\" \n" ; - } -} - - /// /// \brief afWorld::resetCameras /// diff --git a/ambf_framework/afFramework.h b/ambf_framework/afFramework.h index 780ddb5ae..e87bc89d5 100644 --- a/ambf_framework/afFramework.h +++ b/ambf_framework/afFramework.h @@ -280,6 +280,10 @@ class afComm{ // Override the Min Freq static void overrideMinPublishingFrequency(int freq); + static string getGlobalNamespacePrefix(){return s_global_namespace_prefix;} + + static void setGlobalNamespacePrefix(string a_namespace_prefix); + private: // Min publishing frequency uint m_minPubFreq=50; @@ -294,6 +298,8 @@ class afComm{ static int s_maxFreq; static int s_minFreq; + static string s_global_namespace_prefix; + double m_timeStamp = 0.0; }; @@ -2105,7 +2111,7 @@ class afWorld: public afIdentification, public afComm, public afModelManager{ friend class afModel; public: - afWorld(string a_global_namespace); + afWorld(); virtual ~afWorld(); @@ -2206,12 +2212,6 @@ class afWorld: public afIdentification, public afComm, public afModelManager{ // defined in the bodies void buildCollisionGroups(); - string resolveGlobalNamespace(string a_name); - - string getGlobalNamespace(){return m_global_namespace;} - - void setGlobalNamespace(string a_namespace); - bool pickBody(const cVector3d& rayFromWorld, const cVector3d& rayToWorld); bool movePickedBody(const cVector3d& rayFromWorld, const cVector3d& rayToWorld); @@ -2340,10 +2340,6 @@ class afWorld: public afIdentification, public afComm, public afModelManager{ protected: - // If this string is set, it will force itself to preeced all nampespaces - // regardless of whether any namespace starts with a '/' or not. - string m_global_namespace; - // Current time of simulation. double m_simulationTime; diff --git a/ambf_ros_modules/ambf_server/include/ambf_server/RosComBase.h b/ambf_ros_modules/ambf_server/include/ambf_server/RosComBase.h index 3f2aac2fc..994990725 100644 --- a/ambf_ros_modules/ambf_server/include/ambf_server/RosComBase.h +++ b/ambf_ros_modules/ambf_server/include/ambf_server/RosComBase.h @@ -64,7 +64,7 @@ class afROSNode{ if (s_initialized == false){ int argc = 0; char **argv = 0; - ros::init(argc, argv, "ambf_comm_node"); + ros::init(argc, argv, "ambf_comm_node", ros::init_options::AnonymousName); s_nodePtr = new ros::NodeHandle; s_initialized = true; std::cerr << "INFO! INITIALIZING ROS NODE HANDLE\n"; diff --git a/ambf_simulator/src/ambf_simulator.cpp b/ambf_simulator/src/ambf_simulator.cpp index 1448149c8..d90e007ed 100644 --- a/ambf_simulator/src/ambf_simulator.cpp +++ b/ambf_simulator/src/ambf_simulator.cpp @@ -98,7 +98,7 @@ struct CommandLineOptions{ // Control whether to run headless or not bool showGUI; // // Override the default world namespace - std::string prepend_namespace; + std::string namespace_prefix; // The running speed of the simulation. 1.0 indicates a stepping of one second. double simulation_speed; @@ -247,7 +247,7 @@ int main(int argc, char* argv[]) ("override_max_comm_freq", p_opt::value(), "Override the maximum publishing frequency for all afObjects (default: 1000 Hz)") ("override_min_comm_freq", p_opt::value(), "Override the minimum publishing frequency for all afObjects (default: 50 Hz)") ("show_gui,g", p_opt::value()->default_value(true), "Show GUI") - ("ns", p_opt::value()->default_value(""), "Override the default (or specified in ADF) world namespace") + ("ns", p_opt::value()->default_value(""), "Global namespace prefix for ROS Communication") ("sim_speed_factor,s", p_opt::value()->default_value(1.0), "Override the speed of \"NON REAL-TIME\" simulation by a specified factor (Default 1.0)") ("plugins,", p_opt::value()->default_value(""), "Simulator plugins to load, .e.g. " "--plugins , loads plugin1 and plugin2 simualtor plugin") @@ -272,7 +272,7 @@ int main(int argc, char* argv[]) g_cmdOpts.useFixedHtxTimeStep = var_map["fixed_htx_timestep"].as(); g_cmdOpts.enableForceFeedback = var_map["enableforces"].as(); g_cmdOpts.showGUI = var_map["show_gui"].as(); - g_cmdOpts.prepend_namespace = var_map["ns"].as(); + g_cmdOpts.namespace_prefix = var_map["ns"].as(); g_cmdOpts.simulation_speed = var_map["sim_speed_factor"].as(); g_cmdOpts.simulator_plugins = var_map["plugins"].as(); @@ -340,7 +340,7 @@ int main(int argc, char* argv[]) glfwSetErrorCallback(errorCallback); // set OpenGL version - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); // set active stereo mode @@ -354,6 +354,8 @@ int main(int argc, char* argv[]) } } + cerr << "GLFW VERSION: " << glfwGetVersionString() << endl; + //----------------------------------------------------------------------- // 3D - SCENEGRAPH @@ -395,7 +397,8 @@ int main(int argc, char* argv[]) g_adfLoaderPtr->loadTeleRoboticUnitsAttribs(launchAttribs.m_inputDevicesFilepath.c_str(), &tuAttribs, devIndexes); // create a dynamic world. - g_afWorld = new afWorld(g_cmdOpts.prepend_namespace); + afComm::setGlobalNamespacePrefix(g_cmdOpts.namespace_prefix); + g_afWorld = new afWorld(); g_afWorld->m_physicsFrequency = g_cmdOpts.phxFrequency; g_afWorld->m_hapticsFrequency = g_cmdOpts.htxFrequency; g_afWorld->m_updateCounterLimit = g_cmdOpts.phxFrequency * 2;