Ask Your Question
0

error while publishing trajectory_msgs/jointtrajectory msgs [closed]

asked 2016-12-31 10:35:54 -0500

dinesh gravatar image

updated 2016-12-31 12:42:25 -0500

When i set the position and velocities of the joints in the trajectory msgs i got an error: \

[state_publisher-2] process has died [pid 13362, exit code -11, cmd /home/rob/catkin_ws/devel/lib/r2d2/state_publisher __name:=state_publisher __log:=/home/rob/.ros/log/9980f352-cf74-11e6-8644-d4c9efe8bd37/state_publisher-2.log].
log file: /home/rob/.ros/log/9980f352-cf74-11e6-8644-d4c9efe8bd37/state_publisher-2*.log

My ros node to send geometry_msgs is:

 #include <string>
    #include <ros/ros.h>
    #include <sensor_msgs/JointState.h>
    #include <tf/transform_broadcaster.h>
    #include <trajectory_msgs/JointTrajectory.h>
    #include <vector>
    int main(int argc, char** argv) {
        ros::init(argc, argv, "state_publisher");
        ros::NodeHandle n;
        ros::Publisher joint_pub = n.advertise<trajectory_ms

gs::JointTrajectory>("set_joint_trajectory", 1);
   ros::Rate loop_rate(30);

   const double degree = M_PI/180;

   // robot state
   double tilt = 0, tinc = degree, swivel=0, angle=0, height=0, hinc=0.005;

   // message declarations
   trajectory_msgs::JointTrajectory joint_state;
   std::vector<trajectory_msgs::JointTrajectoryPoint> points_n(3);
   points_n[0].positions[0] = 1; points_n[0].velocities[0]=10;
   while (ros::ok()) {
       //update joint_state
       joint_state.header.stamp = ros::Time::now();
       joint_state.joint_names.resize(3);
       joint_state.points.resize(3);

       joint_state.joint_names[0] ="swivel";
       joint_state.points[0] = points_n[0];
       joint_state.joint_names[1] ="tilt";
       joint_state.points[1] = points_n[1];
       joint_state.joint_names[2] ="periscope";
       joint_state.points[2] = points_n[2];


       joint_pub.publish(joint_state);



       // This will adjust as needed per iteration
       loop_rate.sleep();
   }


   return 0;
   }

Here when i donot set the position and velocity value it runs without error and when i run rostopic echo /set_joint_trajectory i can clearly see the outputs as all the parameters of points is 0. I also tried below program but it published nothing:

  #include <string>
    #include <ros/ros.h>
    #include <sensor_msgs/JointState.h>
    #include <tf/transform_broadcaster.h>
    #include <trajectory_msgs/JointTrajectory.h>
    #include <vector>
    int main(int argc, char** argv) {
        ros::init(argc, argv, "state_publisher");
        ros::NodeHandle n;
        ros::Publisher joint_pub = n.advertise<trajectory_msgs::JointTrajectory>("set_joint_trajectory", 1);

        trajectory_msgs::JointTrajectory joint_state;

           joint_state.header.stamp = ros::Time::now();
           joint_state.header.frame_id = "camera_link";
           joint_state.joint_names.resize(3);
           joint_state.points.resize(3);

           joint_state.joint_names[0] ="swivel";
           joint_state.joint_names[1] ="tilt";
           joint_state.joint_names[2] ="periscope";

           size_t size = 2;
           for(size_t i=0;i<=size;i++) {
              trajectory_msgs::JointTrajectoryPoint points_n;
              int j = i%3;
              points_n.positions.push_back(j);
              points_n.positions.push_back(j+1);
              points_n.positions.push_back(j*2);
              joint_state.points.push_back(points_n);
              joint_state.points[i].time_from_start = ros::Duration(0.01);
           }
           joint_pub.publish(joint_state);
           ros::spinOnce();
       return 0;
   }
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by NEngelhard
close date 2017-01-01 12:43:03.548880

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-01 02:17:53 -0500

dinesh gravatar image

I was not setting the size of the points so i was getting problem here. To solve this problem i first allocated memory for the points also than it works fine.

trajectory_msgs::JointTrajectory joint_state;
std::vector<trajectory_msgs::JointTrajectoryPoint> points_n(3);
points_n[0].positions.resize(1);
points_n[0].velocities.resize(1);
...
edit flag offensive delete link more

Comments

Hello Dinesh, i am also facing the same issue more or less. Since, i am working on motion planning with Cartesian planner displayed in rviz the publishes the output on topic with sensor_msgs/JointState and i want to command the robot in Gazebo with arm controller, which subscribes to topic with trajectory_msgs/JointTrajectory. I have written the code but do not know where i am making mistakes. Can you please help me to figure it out the issue.

SunnyKatyara gravatar imageSunnyKatyara ( 2019-07-29 04:53:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-12-31 10:35:54 -0500

Seen: 187 times

Last updated: Jan 01 '17