ROS中调用动作服务器所使用的message名称问题

今天碰到个问题,在建立action client的时候,始终提示一个错误

程序(正确的):


#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的功能。

后来折腾了好久发现这个问题:

我上面的动作服务器用的消息是

control_msgs::GripperCommandActionGoal

后面的grigoal也使用的同样的消息类型,但是这样是不对的。goal是我们要发送的目标,格式应该是这个消息类型中包含的下一级的类型,即

control_msgs::GripperCommandGoal

这样加入的就是

grigoal.command.position = 0;

是添加上一级的消息然后加上grigoal.goal.command.position = 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值