今天碰到个问题,在创建action client的时候,始终提示一个错误node
程序(正确的):服务器
#include <ros/ros.h> #include <actionlib/client/simple_action_client.h> #include <control_msgs/GripperCommandAction.h> #include <control_msgs/GripperCommandActionGoal.h> /*move_base_msgs::MoveBaseAction move_base在world中的目标 */ //typedef actionlib::SimpleActionClient<control_msgs::GripperCommandActionGoal> MoveBaseClient; int main(int argc, char** argv) { ros::init(argc, argv, "send_goals_node"); /* // create the action client // true causes the client to spin its own thread //don't need ros::spin() 建立action客户端,参数1:action名,参数2:true,不须要手动调用ros::spin(),会在它的线程中自动调用。 */ actionlib::SimpleActionClient<control_msgs::GripperCommandAction> ac("/movo/right_gripper_controller/gripper_cmd", true); // Wait 60 seconds for the action server to become available ROS_INFO("Waiting for the gripper action server"); ac.waitForServer(ros::Duration(60)); ROS_INFO("Connected to move base server"); // Send a goal to move_base1 //目标的属性设置 control_msgs::GripperCommandGoal grigoal; grigoal.command.position = 0; ROS_INFO("Sending goal"); ac.sendGoal(grigoal); // Wait for the action to return ac.waitForResult(); if (ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED) ROS_INFO("You have reached the goal!"); else ROS_INFO("The base failed for some reason"); return 0; }
针对这句话:线程
ac.sendGoal(grigoal)一直说没有这个sendGoal的功能。code
后来折腾了很久发现这个问题:server
我上面的动做服务器用的消息是ip
control_msgs::GripperCommandActionGoal
后面的grigoal也使用的一样的消息类型,可是这样是不对的。goal是咱们要发送的目标,格式应该是这个消息类型中包含的下一级的类型,即get
control_msgs::GripperCommandGoal
这样加入的就是cmd
grigoal.command.position = 0;
而不是添加上一级的消息而后加上grigoal.goal.command.position = 0;it