Publishing Joint trajectory for robotic arm
I have been working on simple publisher for joint trajectory before moving to joint trajectory action client. However on running the node i get an error saying:
malloc(): memory corruption: 0x0000000000c28eb0 *** Aborted (core dumped)
I tried finding a solution online but nothing seems to be of any help. I would appreciate if you could help me with the same.
Following is the code:
#include <ros/ros.h>
#include <trajectory_msgs/JointTrajectory.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "path_plan");
ros::NodeHandle node;
ROS_INFO("path_plan node started");
ros::Publisher pub = node.advertise<trajectory_msgs::JointTrajectory>("/cyton_joint_trajectory_action_controller/command", 1000);
ros::Rate rate(10);
rate.sleep();
while (ros::ok())
{
trajectory_msgs::JointTrajectory traj;
traj.joint_names.push_back("shoulder_roll_joint");
traj.joint_names.push_back("shoulder_pitch_joint");
traj.joint_names.push_back("elbow_roll_joint");
traj.joint_names.push_back("elbow_pitch_joint");
traj.joint_names.push_back("elbow_yaw_joint");
traj.joint_names.push_back("wrist_pitch_joint");
traj.joint_names.push_back("wrist_roll_joint");
traj.joint_names.push_back("gripper_joint");
// trajectory_msgs::JointTrajectoryPoint points;
traj.points.resize(2);
int ind = 0;
traj.points[ind].positions.resize(8);
traj.points[ind].positions[0] = 0.0;
traj.points[ind].positions[1] = 0.0;
traj.points[ind].positions[2] = 0.0;
traj.points[ind].positions[3] = 0.0;
traj.points[ind].positions[4] = 0.0;
traj.points[ind].positions[5] = 0.0;
traj.points[ind].positions[6] = 0.0;
traj.points[ind].positions[7] = 0.7;
// Velocities
traj.points[ind].velocities.resize(8);
for (size_t j = 0; j < 8; ++j)
{
traj.points[ind].velocities[j] = 0.0;
}
// To be reached 1 second after starting along the traj
traj.points[ind].time_from_start = ros::Duration(1.0);
// Second trajectory point
// Positions
ind += 1;
traj.points[ind].positions.resize(7);
traj.points[ind].positions[0] = -0.3;
traj.points[ind].positions[1] = 0.2;
traj.points[ind].positions[2] = -0.1;
traj.points[ind].positions[3] = -1.2;
traj.points[ind].positions[4] = 1.5;
traj.points[ind].positions[5] = -0.3;
traj.points[ind].positions[6] = 0.5;
traj.points[ind].positions[7] = -0.7;
// Velocities
traj.points[ind].velocities.resize(8);
for (size_t j = 0; j < 8; ++j)
{
traj.points[ind].velocities[j] = 0.0;
}
// To be reached 2 seconds after starting along the traj
traj.points[ind].time_from_start = ros::Duration(2.0);
traj.header.stamp = ros::Time::now() + ros::Duration();
pub.publish(traj);
rate.sleep();
}
return 0;
}
Thanks!