Robotics StackExchange | Archived questions

Segmentation fault (core dumped)

Hello ROS developers, I hope you are doing well.

I am trying to control individual joints of the Jaco Gen3 arm using a joystick that is mounted on a mobile robot. When the joystick's button 4 is pressed and axes 0 is handled, joint 1 should move. The same goes for joints 2,3 and 4. To move joints 5,6, and 7, the user will press buttons 5 and axis, 1,2, and 3. However, when I execute the following code, a segmentation fault error appears on the terminal. What could be the issue? Do you have any suggestions on how to fix it? Many thanks for your time in advance.

Following is the output of echoing jointstates topic. There are 10 joints in total. rostopic echo /mygen3/jointstates -n1 header: seq: 126031 stamp: secs: 2520 nsecs: 642000000 frameid: '' name: [gen3fingerjoint, gen3joint1, gen3joint2, gen3joint3, gen3joint4, gen3joint5, gen3joint6, gen3joint7, leftwheeljoint, rightwheeljoint] position: [0.011156074937225036, -0.006339358974963183, -0.0006194217005415226, 0.01151412114599104, 0.001642073905800956, 0.0028907791152485984, -0.002714561066495591, -0.005637248997325095, -1.5671764377613515, -1.5676743570935656]

Here is the code that i have written so far. By the way, I am on ROS melodic.

#include "ros/ros.h" #include #include #include #include "ros/time.h"

double posJ0; double posJ1; double posJ2; double posJ3; double posJ4; double posJ5; double posJ6; double posJ7; double posJ8; double posJ9;

double joyValJ1=0; double joyValJ2=0; double joyValJ3=0; double joyValJ4=0; double joyValJ5=0; double joyValJ6=0; double joyValJ7=0;

int setValeurPoint(trajectorymsgs::JointTrajectory* trajectoire,int postab, double val){ trajectoire->points[0].positions[pos_tab] = val; return 0; }

void joyCallback(const sensor_msgs::Joy::ConstPtr& joy)

{

if (joy->buttons[4]){ joyValJ1=joy->axes[0]; joyValJ2=joy->axes[1]; joyValJ3=joy->axes[2]; joyValJ4=joy->axes[3]; } else{ joyValJ1=0; joyValJ2=0; joyValJ3=0; joyValJ4=0; } if (joy->buttons[5]){ joyValJ5=joy->axes[0]; joyValJ6=joy->axes[1]; joyValJ7=joy->axes[2]; } else{ joyValJ5=0; joyValJ6=0; joyValJ7=0; } } void jointCallback(const sensor_msgs::JointState::ConstPtr& joint) {

// ROS_INFO("in callback");
         posJ0=joint->position[0];
             posJ1=joint->position[1];
             posJ2=joint->position[2];
             posJ3=joint->position[3];
             posJ4=joint->position[4];
             posJ5=joint->position[5];
             posJ6=joint->position[6];
             posJ7=joint->position[7];
             posJ8=joint->position[8];
             posJ9=joint->position[9];

}

int main(int argc, char** argv) { ros::init(argc, argv, "joyjointscontrolsim"); ros::NodeHandle n; ros::Publisher armpub; ros::Subscriber joysub = n.subscribe<sensormsgs::Joy>("/joy", 10, &joyCallback); ros::Subscriber jointsub = n.subscribe<sensormsgs::JointState>("/mygen3/jointstates", 10, &jointCallback); armpub = n.advertise<trajectorymsgs::JointTrajectory>("/mygen3/gen3gen3jointtrajectorycontroller/command",100); ros::Rate looprate(10);

 trajectory_msgs::JointTrajectory traj;
 traj.header.frame_id = "gen3_base_link";
 traj.joint_names.resize(10);
 traj.points.resize(1);
 traj.joint_names[0] ="gen3_finger_joint";
 traj.joint_names[1] ="gen3_joint_1";
 traj.joint_names[2] ="gen3_joint_2";
 traj.joint_names[3] ="gen3_joint_3";
 traj.joint_names[4] ="gen3_joint_4";
 traj.joint_names[5] ="gen3_joint_5";
 traj.joint_names[6] ="gen3_joint_6";
 traj.joint_names[7] ="gen3_joint_7";
 traj.joint_names[8] ="left_wheel_joint";
 traj.joint_names[9] ="right_wheel_joint,";
 while(ros::ok()) {

     traj.header.stamp = ros::Time::now();
     setValeurPoint(&traj,0,posJ0);
     setValeurPoint(&traj,1,posJ1+joyValJ1);
     setValeurPoint(&traj,2,posJ2+joyValJ2);
     setValeurPoint(&traj,3,posJ3+joyValJ3);
     setValeurPoint(&traj,4,posJ4+joyValJ4);
     setValeurPoint(&traj,5,posJ5+joyValJ5);
     setValeurPoint(&traj,6,posJ6+joyValJ6);
      setValeurPoint(&traj,7,posJ7+joyValJ7);
     setValeurPoint(&traj,8,posJ8);
      setValeurPoint(&traj,9,posJ9);

     traj.points[0].time_from_start = ros::Duration(1);
     arm_pub.publish(traj);
     ros::spinOnce();
     loop_rate.sleep();
 }

 return 0;

}

Asked by faraziii on 2021-07-08 04:54:57 UTC

Comments

Answers