Hi @lguyot
Thank you very much for the great answers! I have looked through the files you referred to, but I will probably have to admit that it is beyond me to fully understand the OpenSim muscle implementation for now.
However, regarding the “gazebo/default/visual” topic, I see now that it is actually there, but for some reason isn’t responding as when run in Gazebo directly. I guess that means that I was looking for the issue in the wrong place. Thanks for pointing it out!
Indeed, if I could only get the visual topic to respond to my messages in NRP, then my problems would be solved.
I have made some tests and found that the message gets published alright. I can listen to the visual topic which shows the intended message, but for some reason NRP does not want to update the visuals.
The message is exactly the same in Gazebo and NRP and looks as follow (publisher is initiated with topic name: “/gazebo/default/visual” but appears to convert it to “~/visual” automatically):
{
"op":"publish","topic":"~/visual", "msg": {
"name": "my_muscles::m_agonist_link", "material": {
"ambient": {"r": 0.0, "g": 0.0, "b": 1.0, "a": 0.5},
"diffuse": {"r": 0.0, "g": 0.0, "b": 1.0, "a": 0.5}
},
"parent_name": "my_muscles",
"parent_id": 9,
"scale": {
"x": 0.043648510166301314, "y": 0.043648510166301314, "z": 0.42702979667397373
}
}
}
Despite this message being successfully published on the visual topic, the visual in question neither scales nor changes color as it is supposed to, and is doing when I run the same code in Gazebo.
Can you think of any potential reason for this?
My function for generating the visual message looks like this, in case it helps:
gazebo::msgs::Visual JWelnerMuscle::GetVisMsg( physics::LinkPtr link_,\
gazebo::common::Color newColor,\
ignition::math::Vector3d scale_) {
sdf::ElementPtr linkSDF = link_->GetSDF();
sdf::ElementPtr visualSDF = linkSDF->GetElement("visual");
std::string visual_name_ = visualSDF->Get<std::string>("name");
gazebo::msgs::Visual visualMsg = link_->GetVisualMessage(visual_name_);
gazebo::msgs::Vector3d* scale_factor = new gazebo::msgs::Vector3d{gazebo::msgs::Convert(scale_)};
visualMsg.set_name(link_->GetScopedName());
visualMsg.set_parent_id(link_->GetParentId());
visualMsg.set_parent_name(link_->GetParent()->GetScopedName());
visualMsg.set_allocated_scale(scale_factor);
// Set material
if ((!visualMsg.has_material()) || visualMsg.mutable_material() == NULL) {
gazebo::msgs::Material *materialMsg = new gazebo::msgs::Material;
visualMsg.set_allocated_material(materialMsg);
}
// Set color
gazebo::msgs::Color *colorMsg = new gazebo::msgs::Color(gazebo::msgs::Convert(newColor));
gazebo::msgs::Color *diffuseMsg = new gazebo::msgs::Color(*colorMsg);
gazebo::msgs::Material *materialMsg = visualMsg.mutable_material();
if (materialMsg->has_ambient())
{
materialMsg->clear_ambient();
}
materialMsg->set_allocated_ambient(colorMsg);
if (materialMsg->has_diffuse())
{
materialMsg->clear_diffuse();
}
materialMsg->set_allocated_diffuse(diffuseMsg);
return visualMsg;
}
Node is initiated with:
node_ = gazebo::transport::NodePtr(new gazebo::transport::Node());
node_->Init(this->world->GetName());
pub_visual_ = node_->Advertise<gazebo::msgs::Visual>("/gazebo/default/visual");
And the visualMsg is published with
pub_visual_->Publish( visualMsg );
Does any of this employ functions or name conventions that might change between native Gazebo an NRP? Currently I am at a loss…
Thanks a lot