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

Keep namespace relative if base_prefix is empty string #40

Open
wants to merge 1 commit into
base: indigo
Choose a base branch
from
Open
Changes from all 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
14 changes: 8 additions & 6 deletions kobuki_gazebo_plugins/src/gazebo_ros_kobuki_loads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ void GazeboRosKobuki::setupRosApi(std::string& model_name)
{
std::string base_prefix;
gazebo_ros_->node()->param("base_prefix", base_prefix, std::string("mobile_base"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the default value std::string("mobile_base") has to be dropped. Otherwise you won't be able to set the base_prefix to be an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the parameter server has the empty string as the value of "base_prefix", then ros::NodeHandle::param() will use it and not the default. The API description of param() claims that the default value is only used if the parameter value cannot be retrieved.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right in case of the ROS parameter server, but this is not the case here. The parameter here comes from Gazebo and is set here: https://github.com/yujinrobot/kobuki_desktop/blob/indigo/kobuki_gazebo/launch/includes/robot.launch.xml#L9

If I provide an empty string, I believe the parameter is considered not set and the default is selected. At least this happend when I tried it. How did you make it work?

if (base_prefix.length() > 0)
base_prefix += "/";

// Public topics

Expand All @@ -325,32 +327,32 @@ void GazeboRosKobuki::setupRosApi(std::string& model_name)

// Private Topics
// motor power
std::string motor_power_topic = base_prefix + "/commands/motor_power";
std::string motor_power_topic = base_prefix + "commands/motor_power";
motor_power_sub_ = gazebo_ros_->node()->subscribe(motor_power_topic, 10, &GazeboRosKobuki::motorPowerCB, this);
ROS_INFO("%s: Try to subscribe to %s!", gazebo_ros_->info(), motor_power_topic.c_str());


std::string odom_reset_topic = base_prefix + "/commands/reset_odometry";
std::string odom_reset_topic = base_prefix + "commands/reset_odometry";
odom_reset_sub_ = gazebo_ros_->node()->subscribe(odom_reset_topic, 10, &GazeboRosKobuki::resetOdomCB, this);
ROS_INFO("%s: Try to subscribe to %s!", gazebo_ros_->info(), odom_reset_topic.c_str());

// cmd_vel
std::string cmd_vel = base_prefix + "/commands/velocity";
std::string cmd_vel = base_prefix + "commands/velocity";
cmd_vel_sub_ = gazebo_ros_->node()->subscribe(cmd_vel, 100, &GazeboRosKobuki::cmdVelCB, this);
ROS_INFO("%s: Try to subscribe to %s!", gazebo_ros_->info(), motor_power_topic.c_str());

// cliff
std::string cliff_topic = base_prefix + "/events/cliff";
std::string cliff_topic = base_prefix + "events/cliff";
cliff_event_pub_ = gazebo_ros_->node()->advertise<kobuki_msgs::CliffEvent>(cliff_topic, 1);
ROS_INFO("%s: Advertise Cliff[%s]!", gazebo_ros_->info(), cliff_topic.c_str());

// bumper
std::string bumper_topic = base_prefix + "/events/bumper";
std::string bumper_topic = base_prefix + "events/bumper";
bumper_event_pub_ = gazebo_ros_->node()->advertise<kobuki_msgs::BumperEvent>(bumper_topic, 1);
ROS_INFO("%s: Advertise Bumper[%s]!", gazebo_ros_->info(), bumper_topic.c_str());

// IMU
std::string imu_topic = base_prefix + "/sensors/imu_data";
std::string imu_topic = base_prefix + "sensors/imu_data";
imu_pub_ = gazebo_ros_->node()->advertise<sensor_msgs::Imu>(imu_topic, 1);
ROS_INFO("%s: Advertise IMU[%s]!", gazebo_ros_->info(), imu_topic.c_str());
}
Expand Down