0
$\begingroup$

Rosanswers logo

Dear all,

I am basically trying to subscribe to the rostopic which broadcast the sensor_msgs/JointState and then call the /joint_path_command service to move the ABB robot in robot studio simulation. Hence, Whenever there is new joint positions in that topic, I will call /joint_path_command to mvoe the robot accordingly.

I have managed to receive the joint states from the rostopic. However, I have encountered problem when trying to create industrial_msgs/CmdJointTrajectory message which is required for the /joint_path_command service.


void chatterCallback(const sensor_msgs::JointState::ConstPtr &msg)
{
  for(int i = 0; i<msg->position.size(); i++)
  {
    posi.push_back(msg->position.at(i));
  }

  for(int i = 0; i<msg->velocity.size(); i++)
  {
    velo.push_back(msg->velocity.at(i));
  }  

  for(int i = 0; i<6; i++)
  {
    acc.push_back(0.0);
  }

  for(int i = 0; i<msg->effort.size(); i++)
  {
    eff.push_back(msg->effort.at(i));
  }
  
  ros::NodeHandle n;
  ros::ServiceClient client = n.serviceClient<industrial_msgs::CmdJointTrajectory>("joint_path_command");
  industrial_msgs:CmdJointTrajectory srv;
  srv.request.trajectory.header = msg->header;
  srv.request.trajectory.joint_names = jointnames;
  srv.request.trajectory.points.positions = posi;
  srv.velocities = velo;
  srv.accelerations = acc;
  srv.effort = eff;

  //  srv.request.trajectory.points = srvvv;

  //  srv.time_from_start = ros::Time::now();

  if(client.call(srv))
  {
    ROS_INFO("hoolay");
  }
}

above is my program that tries to call the joint_path_command service with the information gathered from a sensor_msg/JointState msg.

Below is the compilation result

[100%] [100%] Built target add_two_ints_client
Built target add_two_ints_server
/home/colin/catkin_ws/src/armpost_listener/src/listen_armpost.cpp: In function 'void chatterCallback(const ConstPtr&)':
/home/colin/catkin_ws/src/armpost_listener/src/listen_armpost.cpp:66:33: error: 'trajectory_msgs::JointTrajectory_<std::allocator<void> >::_points_type' has no member named 'positions'
   
srv.request.trajectory.points.positions = posi;

                                 
/home/colin/catkin_ws/src/armpost_listener/src/listen_armpost.cpp:67:33: error: 'trajectory_msgs::JointTrajectory_<std::allocator<void> >::_points_type' has no member named 'velocities'

   srv.request.trajectory.points.velocities = velo;
                                 ^

/home/colin/catkin_ws/src/armpost_listener/src/listen_armpost.cpp:68:33: error: 'trajectory_msgs::JointTrajectory_<std::allocator<void> >::_points_type' has no member named 'accelerations'

   srv.request.trajectory.points.accelerations = acc;
                                 ^
/home/colin/catkin_ws/src/armpost_listener/src/listen_armpost.cpp:69:33: error: 'trajectory_msgs::JointTrajectory_<std::allocator<void> >::_points_type' has no member named 'effort'

   srv.request.trajectory.points.effort = eff;
                                 ^
make[2]: *** [armpost_listener/CMakeFiles/listen_armpost.dir/src/listen_armpost.cpp.o] Error 1

make[1]: *** [armpost_listener/CMakeFiles/listen_armpost.dir/all] Error 2

make: *** [all] Error 2

Invoking "make -j8 -l8" failed

As you can see, The compiler does not recognize the members of the points struct within trajectory/points (positions, velocities, effort, accelerations) of the industrial_msgs/CmdJointTrajectory when it is clearly stated in the rossrv show(shown below)

colin@Colin-GF:~$ rossrv show industrial_msgs/CmdJointTrajectory
trajectory_msgs/JointTrajectory trajectory
  std_msgs/Header header
    uint32 seq
    time stamp
    string frame_id
  string[] joint_names
  trajectory_msgs/JointTrajectoryPoint[] points
    float64[] positions
    float64[] velocities
    float64[] accelerations
    float64[] effort
    duration time_from_start
---
industrial_msgs/ServiceReturnCode code
  int8 SUCCESS=1
  int8 FAILURE=-1
  int8 val

Am I doing something wrong? Any help will be greatly appreciated!

Thank you!


Originally posted by ninanona on ROS Answers with karma: 7 on 2016-12-03

Post score: 0


Original comments

Comment by gvdhoorn on 2016-12-04:
Just curious: what are you trying to achieve exactly? The code you include above seems to be sending the robot back to where it already is (ie: setpoint == current_state).

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

points in srv.request.trajectory.points is an array as you correctly note in your question. Thus, you should access its elements in order to access their members (e.g. positions, velocities and accelerations). Instead of

srv.request.trajectory.points.positions

try

srv.request.trajectory.points[i].positions

where i is the joint you want to specify.

You might also benefit from this answer.


Originally posted by jsanch2s with karma: 136 on 2016-12-03

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by ninanona on 2016-12-04:
Thank you so much! I didn't realise the point array meant the trajectory points. It solved my problem!

$\endgroup$

Your Answer

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