can call back based simple action client subscribe to other topics?
Is it possible for a call back based simple action client to subscribe to other topics?
I want the client to subscribe to /topicA that publishes sensor_msg::JointState and pass the name, velocity, position, effort to the server.
I tried the following: (partial code): no compilation error but I'm getting segmentation fault immediately when I run the client
//client side code
sensor_msgs::JointState j_msg; // global variable
void subCallback(const sensor_msgs::JointState::ConstPtr& msg){
ROS_INFO("joint_name: %f",msg->position);
j_msg.name.push_back(msg->name[0]);
j_msg.position.push_back(msg->position[0]);
j_msg.velocity.push_back(msg->velocity[0]);
j_msg.effort.push_back(msg->effort[0]);
}
int main(int argc, char ** argv){
ros::init(argc, argv, "action_client_node");
std::string topicName = "topicA";
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe(topicName,1000, subCallback);
std::string joint_name = j_msg.name[0];
float position = j_msg.position[0];
float velocity = j_msg.velocity[0];
float effort = j_msg.effort[0];
std::cout<<"joint_name: "<<joint_name<<std::endl;
std::cout<<"position: "<<position<<std::endl;
std::cout<<"velocity: "<<velocity<<std::endl;
std::cout<<"effort: "<<effort<<std::endl;
//============================================================================================
actionlib::SimpleActionClient<my_action::MyAction> ac_("my_action_server");
.....
goal.target.name.push_back(joint_name);
goal.target.position.push_back(position);
goal.target.velocity.push_back(velocity);
goal.target.effort.push_back(effort);
.....
}