0
$\begingroup$

I am working with a robotic arm in simulation. I am using ros-noetic, gazebo and moveit for this purpose. I am using /robot_namespace as robot namespace, because of which robot joints data are being published on /robot_namespace/joint_states topic, in place of /joint_states.

I am trying to run below c++ code:

#include <ros/ros.h>
#include <moveit/move_group_interface/move_group_interface.h>

class MyRobot{
    public:
        explicit MyRobot(ros::NodeHandle nh);
        ~MyRobot();
    private:
        ros::NodeHandle nh_;
        const std::string ARM_PLANNING_GROUP = "arm_manipulator";
        moveit::planning_interface::MoveGroupInterface arm_move_group;
        const robot_state::JointModelGroup *arm_joint_model_group;
};   
MyRobot::MyRobot(ros::NodeHandle nh)
  : nh_(nh),
    arm_move_group(ARM_PLANNING_GROUP){
      arm_joint_model_group = arm_move_group.getCurrentState()->getJointModelGroup(ARM_PLANNING_GROUP);
    }
MyRobot::~MyRobot(){}
int main(int argc, char **argv){
  ros::init(argc, argv, "test");
  ros::NodeHandle nh;
  ros::AsyncSpinner spinner(1);
  spinner.start();
  MyRobot myRobot(nh);
  return 0;
}

but getting below error:

[ INFO] [1589572504.193567368, 922.494000000]: Didn't received robot state (joint angles) with recent timestamp within 1 seconds.Check clock synchronization if your are running ROS across multiple machines!
[ERROR] [1589572504.193719017, 922.494000000]: Failed to fetch current robot state

After doing some research, I found that arm_move_group uses default /joint_states topic, which is mapped to /robot_namespace/joint_states in my case via <remap from="joint_states" to="/robot_namespace/joint_states"/>

I have already tried some of the solution available online:

  1. Passing joint_states:=/robot_namespace/joint_states as argument to move_group node inside move_group.launch file.

    <node name="move_group" args="joint_states:=/robot_namespace/joint_states $(arg command_args)" ...>

  2. Passing <param name="use_sim_time" value="true"/> to move_group, robot_state_publisher and rviz nodes.

But none of the solutions seem to be working in my case.

I would really appreciate some help with this.

Thanks.

$\endgroup$
5
  • $\begingroup$ It looks like there is a joint_state_topic ros param in github.com/… that you could change. Also instead of remap from="joint_states" try remap from="/joint_states" with the leading slash. $\endgroup$ Commented Jan 12 at 15:13
  • $\begingroup$ How should I change joint_state_topic ? Via launch file(like in move_group.launch) or directly in c++ code? And regarding adding leading slash in from="joint_states", I will do that. Thanks for pointing it out. $\endgroup$ Commented Jan 12 at 17:30
  • $\begingroup$ I think only a moveit test (moveit_cpp) is setting the joint state topic to "/joint_states" instead of "joint_states" (the default according to github.com/ros-planning/moveit/blob/…). If you have the default then the answer below robotics.stackexchange.com/a/107574/884 applies and my suggested remap won't work. Alternatively setting joint_state_topic param in the launch file should work (though it's hard to say exactly where you set it to be in the right ns). $\endgroup$ Commented Jan 14 at 17:10
  • $\begingroup$ remap from="/joint_states" is not working either. $\endgroup$ Commented Jan 15 at 10:55
  • $\begingroup$ Ok try roslaunch some_package_name move_group.launch __ns:=/robot_namespace $\endgroup$ Commented Jan 15 at 19:51

1 Answer 1

0
$\begingroup$

I found that arm_move_group uses default /joint_states topic

A more accurate statement is that arm_move_group uses the joint_states topic (with no slash) in the current namespace of your MyRobot node.

I think the cleanest way to fix this problem is to execute your MyRobot node in the correct namespace. If using a launch file, you do this with the ns= attribute of the <node> or <group> tag.

$\endgroup$
3
  • $\begingroup$ Can you please elaborate this a bit more like where should I put ns="" ? $\endgroup$ Commented Jan 15 at 11:14
  • $\begingroup$ There is good documentation for the launch file syntax: wiki.ros.org/roslaunch/XML Click the link for <node>. $\endgroup$
    – Mike973
    Commented Jan 15 at 14:13
  • $\begingroup$ What I meant was "execute your MyRobot node in the correct namespace" Can you please elaborate this a bit more? $\endgroup$ Commented Jan 15 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.