How to change default joint_states topic in C++ script?

asked 2020-05-15 15:43:27 -0500

updated 2020-05-15 15:47:48 -0500

Hey. I am trying to get arm joint model group of my robotic arm using below 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 perhaps, my C++ code is set to use default /joint_states topic, which is mapped to /robot/joint_states in my case. So, my question is

How to change default joint_states topic in C++ script?

This can be done in Python via below code:

import rospy
from moveit_commander import MoveGroupCommander, roscpp_initialize
import moveit_commander

# remapped
joint_state_topic = ['joint_states:=/robot/joint_states']
moveit_commander.roscpp_initialize(joint_state_topic)
rospy.init_node('foo', anonymous=False)
roscpp_initialize(sys.argv)

I want C++ equivalent of above Python code. I would really appreciate someone's help on this. Thanks in advance !!

edit retag flag offensive close merge delete

Comments

Hi, did you solve this? I have the same problem.

Zenzu gravatar image Zenzu  ( 2021-04-17 16:06:08 -0500 )edit