Blocking when building the client of action
** I want to build an action client, but I find that when the program runs to the statement of building the client, it doesn't continue to execute. I don't know what happened. The program does not report errors and can be compiled normally. The program is blocked here: "client (nh," actiontrajectorydemo ", true);"
This is my code:**
typedef actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction> Client;
int main(int argc, char *argv[])
{
ROS_INFO("action client...");
ros::init(argc,argv,"action_trajectory_client");
ros::NodeHandle nh;
std::cout << "ok-1" << std::endl;
Client client(nh,"action_trajectory_demo",true); //The program is blocked here!!!!
control_msgs::FollowJointTrajectoryGoal action_goal;
rosbag::Bag bag;
bag.open("trajectory.bag", rosbag::bagmode::Read);
rosbag::View view(bag, rosbag::TopicQuery("/robotic_arm_controller/follow_joint_trajectory/goal"));
foreach(rosbag::MessageInstance const m, view)
{
control_msgs::FollowJointTrajectoryActionGoal::ConstPtr s = m.instantiate<control_msgs::FollowJointTrajectoryActionGoal>();//control_msgs/FollowJointTrajectoryGoal
if (s != NULL) //std_msgs::Int32::ConstPtr
{
action_goal = s->goal;
//std::cout << action_goal.trajectory.joint_names[2] << std::endl;
std::cout << "send goal..." << std::endl;
client.sendGoal(action_goal,&done_cb,&active_cb,&feedback_cb);//向服务端发送goal
}else
{
std::cout << "null" << std::endl;
}
}
bag.close();
ros::spin();
return 0;
}
Asked by haoshuiwuxiang on 2022-07-28 10:22:17 UTC
Comments