首页 > 其他分享 >10.30

10.30

时间:2024-10-30 16:12:19浏览次数:4  
标签:node 10.30 actionlib server client action ros

actionlib_server_node.cpp
actionlib_client_node.cpp
ActionlibExMsg.action
#goal definition
int32 whole_distance
---
#result definition
bool is_finish
---
#feedback
int32 moving_meter
  <build_depend>message_generation</build_depend>
  <exec_depend>message_runtime</exec_depend>
  add_action_files(
    FILES
    ActionlibExMsg.action
    
  )
  generate_messages(
    DEPENDENCIES
    actionlib_msgs
  )
add_executable(actionlib_client_node src/actionlib_client_node.cpp)
add_dependencies(actionlib_client_node ${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS})
target_link_libraries(actionlib_client_node ${catkin_LIBRARIES})
add_executable(actionlib_server_node src/actionlib_server_node.cpp)
add_dependencies(actionlib_server_node ${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS})
target_link_libraries(actionlib_server_node ${catkin_LIBRARIES})

---------

#include <actionlib/client/simple_action_client.h>
#include <actionlib_example_pkg/ActionlibExMsgAction.h>

// Action完成后调用的回调函数
void doneCb(const actionlib::SimpleClientGoalState& state,
            const actionlib_example_pkg::ActionlibExMsgResultConstPtr& result)
{
    ROS_INFO("Task completed!");
    ros::shutdown();
}

// Action激活时调用的回调函数
void activeCb()
{
    ROS_INFO("Goal is active! The robot begins to move forward.");
}

// Action执行过程中接收反馈的回调函数
void feedbackCb(const actionlib_example_pkg::ActionlibExMsgFeedbackConstPtr& feedback)
{
    ROS_INFO("The robot has moved forward %d meters.", feedback->moving_meter);
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "actionlib_client_node");

    // 创建一个action的client,指定action名称为“moving_forward”
    actionlib::SimpleActionClient<actionlib_example_pkg::ActionlibExMsgAction> client("moving_forward", true);

    ROS_INFO("Waiting for action server to start");
    client.waitForServer(); // 等待服务器响应
    ROS_INFO("Action server started");

    // 创建一个目标:移动机器人前进10m
    actionlib_example_pkg::ActionlibExMsgGoal goal;
    goal.whole_distance = 10;

    // 把action的任务目标发送给服务器,绑定上面定义的各种回调函数
    client.sendGoal(goal, &doneCb, &activeCb, &feedbackCb);

    ros::spin();

    return 0;
}

-----------

#include <ros/ros.h>

#include <actionlib/server/simple_action_server.h>

#include <actionlib_example_pkg/ActionlibExMsgAction.h>

// 服务器接收任务目标后,调用该函数执行任务
void execute(const actionlib_example_pkg::ActionlibExMsgGoalConstPtr& goal,
             actionlib::SimpleActionServer<actionlib_example_pkg::ActionlibExMsgAction>* as) {
    ros::Rate r(0.5);
    actionlib_example_pkg::ActionlibExMsgFeedback feedback;

    ROS_INFO("Task: The robot moves forward %d meters.", goal->whole_distance);

    for(int i = 1; i <= goal->whole_distance; ++i) {
        feedback.moving_meter = i;
        as->publishFeedback(feedback); // 反馈任务执行的过程
        r.sleep();
    }

    ROS_INFO("Task completed!");
    as->setSucceeded();
}

int main(int argc, char** argv) {
    ros::init(argc, argv, "actionlib_server_node");
    ros::NodeHandle n;

    // 创建一个action的server,指定action名称为"moving_forward"
    actionlib::SimpleActionServer<actionlib_example_pkg::ActionlibExMsgAction> server(
        n, "moving_forward", boost::bind(&execute, _1, &server), false);

    // 服务器启动
    server.start();

    ros::spin();

    return 0;
}

标签:node,10.30,actionlib,server,client,action,ros
From: https://www.cnblogs.com/lgqlht/p/18516013

相关文章

  • 闲话 10.30
    别样的丁真让我讲T2,所以提前写点东西出来。诗人小G首先根据题意,比较好写的是\(\mathcal{O(n^2)}\)的转移:\[f_i=\min_{j=0}^{i-1}\f_{j}+abs(sum_i-sum_j-L-1)^p\]其中\(sum\)为句子长度的前缀和。发现可优化的点是后面一坨柿子,我们把它记为\(G_{i,j}=abs(sum_i-sum_j-......
  • 10.30 索引,外键
    索引一、索引的介绍1、什么是索引?(1)定义:索引是一种数据结构一个索引在存储的表中的数据结构;(2)索引是在表的字段上创建的(3)索引包含了一列值,这个值保存在一个数据结构中2、索引作用?(1)保证数据记录的唯一性(2)实现表与表之间的参照性(3)减少排序和分组的时间(例如在使用orderby,gr......
  • A-10.30.0.21-核心-主
    SHDXYQB4-108-C-04_C-05-CSW-RGS6250-M1-01U40#showrunBuildingconfiguration...Currentconfiguration:11428bytesversion11.0(5)B9P120hostnameSHDXYQB4-108-C-04_C-05-CSW-RGS6250-M1-01U40privilegeexecalllevel1showrunning-configprivilegeexecalllev......
  • A-10.30.0.23-接入-主
    SHDXYQB4-108-C-04_C-05-ASW-RGS6250-M1-01U37#showrun Buildingconfiguration...Currentconfiguration:15621bytesversion11.0(5)B9P120hostnameSHDXYQB4-108-C-04_C-05-ASW-RGS6250-M1-01U37privilegeexecalllevel1showrunning-configprivilegeexeclevel......
  • A-10.30.0.24-接入-备
    SHDXYQB4-108-C-04_C-05-ASW-RGS6250-M2-01U37#showrunBuildingconfiguration...Currentconfiguration:15059bytesversion11.0(5)B9P120hostnameSHDXYQB4-108-C-04_C-05-ASW-RGS6250-M2-01U37privilegeexecalllevel1showrunning-configprivilegeexeclevel1......
  • D平台接入B10.30.0.48_2024.03.05
     YDSJYC2-105-A-01-ASW-RGS6520-M1-01U26#showrunYDSJYC2-105-A-01-ASW-RGS6520-M1-01U26#showrunning-configBuildingconfiguration...Currentconfiguration:15429bytesversion11.0(5)B9P120hostnameYDSJYC2-105-A-01-ASW-RGS6520-M1-01U26privilegeexecalll......
  • D平台接入A10.30.0.47_2024.03.05
     YDSJYC2-105-A-02-ASW-RGS6520-M2-01U26#showrunYDSJYC2-105-A-02-ASW-RGS6520-M2-01U26#showrunning-configBuildingconfiguration...Currentconfiguration:14428bytesversion11.0(5)B9P120hostnameYDSJYC2-105-A-02-ASW-RGS6520-M2-01U26!load-balance-profil......
  • 10.30
    今天实现了对于学生个人信息添加的基本功能,我使用的是springboot实现后端的代码,通过springboot加mybatis实现接口类的实现。POJO包定义类变量以及返回值变量1、PersonInformation.javapackagecom.example.pojo;importlombok.AllArgsConstructor;importlombok.Data;im......
  • 10.30
    今日学习内容<%--CreatedbyIntelliJIDEA.TochangethistemplateuseFile|Settings|FileTemplates.--%><%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head><title>Title</ti......
  • 10.30
    MySQL的数据类型有大概可以分为5种,分别是整数类型、浮点数类型和定点数类型、日期和时间类型、字符串类型、二进制类型等。注意:整数类型和浮点数类型可以统称为数值数据类型。1)数值类型整数类型包括TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT,浮点数类型包括FLOAT和DOUB......