geometry_msgs的ros message 类型赋值
test_custom_particles.cpp

// // Created by gary on 2019/8/27. // #include <ros/ros.h> #include <std_msgs/String.h> #include <geometry_msgs/PoseArray.h> #include <geometry_msgs/Pose.h> #include "amcl/amcl_particles.h" #include <stdlib.h> ros::NodeHandle *nh = 0; ros::ServiceClient test_custom_particles_; int main(int argc, char** argv) { ros::init(argc, argv, "test_custom_particles"); ros::NodeHandle nh_("~"); nh = &nh_; while(!ros::service::waitForService("/amcl/set_particles", ros::Duration(3.0))) { ROS_ERROR("The service of /amcl/set_particles is not available."); } test_custom_particles_ = nh->serviceClient<amcl::amcl_particles>("/amcl/set_particles", true); if(!test_custom_particles_) { ROS_ERROR("Could not initialize goal_reached_client service from %s",test_custom_particles_.getService().c_str()); //抛出错误,以及其他处理机制 return 0; } ROS_INFO("11111"); amcl::amcl_particles test_custorm_particle_srv; test_custorm_particle_srv.request.pose_array_msg.header.stamp = ros::Time::now();//-1意思为告诉用户到达零点失败 //test_custorm_particle_srv.request.pose_array_msg.poses = (geometry_msgs::Pose *)malloc(sizeof(geometry_msgs::Pose) * 1000); geometry_msgs::Pose le; for(int i = 0; i < 1000; i++) { le.position.x = 0; le.position.y = 0; le.position.z = 0; le.orientation.x = 0; le.orientation.y = 0; le.orientation.z = 0; le.orientation.w = 1; test_custorm_particle_srv.request.pose_array_msg.poses.push_back(le) ; } ROS_INFO("2222"); if(test_custom_particles_.call(test_custorm_particle_srv)) { if(test_custorm_particle_srv.response.success) { ROS_INFO("success."); } else { ROS_ERROR("failture."); } } ros::spin(); return 0; }
amcl_particles.srv

geometry_msgs/PoseArray pose_array_msg --- bool success
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】