publish fails to send message
Hi!
i'm writing a simple c++ code where i publish an message of type trajectory_msgs::JointTrajector. When i execute the code, everything works well except the moment of publishing the message. So what i understood is that my publisher.publish(msg); is having problem, is this my problem or is this type of message impossible to send?
heres my code:
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "trajectory_msgs/JointTrajectory.h"
#include "trajectory_msgs/JointTrajectoryPoint.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "trajectory_test_node");
ros::NodeHandle nh;
ros::Publisher r_arm_comand_publisher = nh.advertise<trajectory_msgs::JointTrajectory>("/signbot/r_arm_controller/command", 1000);
/// Create a JointTrajectory with all positions set to zero, and command the arm.
if(ros::ok())
{
// Create a message to send.
trajectory_msgs::JointTrajectory msg;
// Fill the names of the joints to be controlled.
msg.joint_names.clear();
msg.joint_names.push_back("r_shoulder_joint");
msg.joint_names.push_back("r_top_arm_joint");
msg.joint_names.push_back("r_elbow_joint");
msg.joint_names.push_back("r_wrist_joint");
// Create one point in the trajectory.
msg.points.resize(1);
// Resize the vector to the same length as the joint names.
// Values are initialized to 0.
msg.points[0].positions.resize(msg.joint_names.size(), 0.0);
// How long to take getting to the point (floating point seconds).
msg.points[0].time_from_start = ros::Duration(0.0001);
ROS_INFO_STREAM ("Sending command:\n" << msg);
r_arm_comand_publisher.publish(msg);
}
return 0;
}
Hope you can help :-)