Segmentation fault (core dumped)

asked 2021-07-08 05:00:13 -0500

faraziii gravatar image

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 joint_states topic. There are 10 joints in total. rostopic echo /my_gen3/joint_states -n1 header: seq: 126031 stamp: secs: 2520 nsecs: 642000000 frame_id: '' name: [gen3_finger_joint, gen3_joint_1, gen3_joint_2, gen3_joint_3, gen3_joint_4, gen3_joint_5, gen3_joint_6, gen3_joint_7, left_wheel_joint, right_wheel_joint] 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 <trajectory_msgs jointtrajectory.h=""> #include <sensor_msgs joy.h=""> #include <sensor_msgs jointstate.h=""> #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(trajectory_msgs::JointTrajectory* trajectoire,int pos_tab, 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, "joy_joints_control_sim"); ros::NodeHandle n; ros::Publisher arm_pub; ros::Subscriber joy_sub = n.subscribe<sensor_msgs::joy>("/joy", 10, &joyCallback); ros::Subscriber joint_sub = n.subscribe<sensor_msgs::jointstate>("/my_gen3/joint_states", 10, &jointCallback); arm_pub = n.advertise<trajectory_msgs::jointtrajectory>("/my_gen3/gen3_gen3_joint_trajectory_controller/command",100); ros::Rate loop_rate(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 ...
(more)
edit retag flag offensive close merge delete