gazebosim / gz-sim

Open source robotics simulator. The latest version of Gazebo.
https://gazebosim.org
Apache License 2.0
621 stars 251 forks source link

Add robotNamespace to DetachableJoint plugin #2409

Open Janphr opened 1 month ago

Janphr commented 1 month ago

Problem description

Spawning multiple models with DetachableJoint plugin will result in only one shared detach topic. Consider using robotNamespace like here: https://github.com/gazebosim/gz-sim/blob/6af74459f4b0f5a2a33fa112e24ac50633a90d3b/src/systems/multicopter_motor_model/MulticopterMotorModel.cc#L376 for all plugins.

Implementation suggestion

https://github.com/gazebosim/gz-sim/blob/6af74459f4b0f5a2a33fa112e24ac50633a90d3b/src/systems/detachable_joint/DetachableJoint.cc#L98

    std::string robotNamespace = this->model.Name(_ecm);
    if (_sdf->HasElement("robotNamespace")) {
        robotNamespace = _sdf->Get<std::string>("robotNamespace");
    }

    // Setup detach topic
    std::vector<std::string> detachTopics;
    if (_sdf->HasElement("detach_topic")) {
        detachTopics.push_back(transport::TopicUtils::AsValidTopic(
            robotNamespace + "/" + _sdf->Get<std::string>("detach_topic")));
    } else {
        detachTopics.push_back("/model/" + this->model.Name(_ecm) +
                               "/detachable_joint/detach");
    }

same for attach and state

arjo129 commented 1 month ago

Distantly related: https://github.com/gazebosim/gz-sim/pull/1097

We should probably refactor this plugin a bit.