ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:
Go to gazebo_ros_create.h and add a new private variable: std::string robot_namespace_;
Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load
(I added it around line 56)
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) {
this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}
With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace
in order to add the robotNamespace
String on it:
this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}
Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel
, /odom
and /sensor_state
and change them to local names cmd_vel
, odom
and sensor_state
.
cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );
sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);
Finally, rosmake
the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)
Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.
Thanks!
Ana
2 | added robotNamespace to topic_namespace and erased slashes from topic names |
Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:
Go to gazebo_ros_create.h and add a new private variable: std::string robot_namespace_;
Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load
(I added it around line 56)
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) {
this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}
With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace
in order to add the robotNamespace
String on it:
this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}
Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel
, /odom
and /sensor_state
and change them to local names cmd_vel
, odom
and sensor_state
.. The lines should now look like this:
cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );
sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);
Finally, rosmake
the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)
Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.
Thanks!
Ana
3 | No.3 Revision |
Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:
Go to gazebo_ros_create.h and add a new private variable:
std::string robot_namespace_;
Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load
(I added it around line 56)
With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace
in order to add the robotNamespace
String on it:
Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel
, /odom
and /sensor_state
and change them to local names cmd_vel
, odom
and sensor_state
. The lines should now look like this:
Finally, rosmake
the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)
Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.
Thanks!
Ana
4 | No.4 Revision |
Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom topics. Here is what I did:
Go to gazebo_ros_create.h and add a new private variable:
std::string Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load
(I added it around line 56)
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) {
this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace
in order to add the robotNamespace
String on it:
this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel
, /odom
and /sensor_state
and change them to local names cmd_vel
, odom
and sensor_state
. The lines should now look like this:
cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this Finally, rosmake
the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)
Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.
Thanks!
Ana
5 | No.5 Revision |
Hi. I am also working with 2 Turtlebots in Gazebo (ROS Fuerte). I was able to separate both /cmd_vel and /odom /cmd_vel
and /odom
topics. Here is what I did:
Go to gazebo_ros_create.h and add a new private variable:
std::string robot_namespace_;
Go to gazebo_ros_create.cpp. Add the following lines in the function GazeboRosCreate::Load
(I added it around line 56)
this->robot_namespace_ = "";
if (_sdf->HasElement("robotNamespace")) {
this->robot_namespace_ = _sdf->GetElement("robotNamespace")->GetValueString() + "/";
}
With that line you are getting the namespace you assigned for the nodes (in my case turtle_1 and turtle_2). Modify the line corresponding to node_namespace
in order to add the robotNamespace
String on it:
this->node_namespace_ = "";
if (_sdf->HasElement("node_namespace")) {
this->node_namespace_ = this->robot_namespace_ + _sdf->GetElement("node_namespace")->GetValueString() + "/";
}
Now go down and find the lines in which you subscribe/advertise the topics /cmd_vel
, /odom
and /sensor_state
and change them to local names cmd_vel
, odom
and sensor_state
. The lines should now look like this:
cmd_vel_sub_ = rosnode_->subscribe("cmd_vel", 1, &GazeboRosCreate::OnCmdVel, this );
sensor_state_pub_ = rosnode_->advertise<turtlebot_node::TurtlebotSensorState>("sensor_state", 1);
odom_pub_ = rosnode_->advertise<nav_msgs::Odometry>("odom", 1);
joint_state_pub_ = rosnode_->advertise<sensor_msgs::JointState>("joint_states", 1);
Finally, rosmake
the package (make sure that you generate a new library, erase the ROS_NOBUILD if needed (otherwise the library won't be compiled and your changes won't be effective)
Hope it helps. If you found other way to work around this (other than editing the source code), please let me know.
Thanks!
Ana