Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixing the namespacing for the sonar plugin #76

Open
wants to merge 3 commits into
base: kinetic-devel
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions hector_gazebo_plugins/src/gazebo_ros_sonar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <gazebo/gazebo_config.h>

#include <boost/algorithm/string.hpp>

namespace gazebo {

GazeboRosSonar::GazeboRosSonar()
Expand Down Expand Up @@ -84,8 +86,22 @@ void GazeboRosSonar::Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf)
frame_id_ = "/sonar_link";

// load parameters
if (_sdf->HasElement("robotNamespace"))
namespace_ = _sdf->GetElement("robotNamespace")->GetValue()->GetAsString();
if (_sdf->HasElement("useNamespaceFromScopedName")){
if (_sdf->GetElement("useNamespaceFromScopedName")){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an and &&. Otherwise, the option existing but set to false would not initialize the namespace at all.
Also, I'm pretty sure you also have to extract the value using GetValue()->GetAsBool().

And please follow the code style of the project, e.g., brackets {} on new lines, no spaces between function names and parameters etc.

std::vector<std::string> values;
std::string scopedName = _sensor->ScopedName();
boost::replace_all ( scopedName, "::", ",");
boost::split ( values, scopedName, boost::is_any_of (","));
if ( values.size()<2){
namespace_ = "";
} else {
namespace_ = values[1];
}
}
}else if (_sdf->HasElement("robotNamespace")){
namespace_ = _sdf->GetElement("robotNamespace")->GetValue()->GetAsString();
}


if (_sdf->HasElement("frameId"))
frame_id_ = _sdf->GetElement("frameId")->GetValue()->GetAsString();
Expand Down