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;
}
View Code
复制代码

amcl_particles.srv

geometry_msgs/PoseArray pose_array_msg
---
bool success
View Code

 

posted on   gary_123  阅读(1119)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 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】

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示