beacon.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <geometry_msgs/Pose.h>
11 #include <mrpt/obs/CObservationBeaconRanges.h>
12 #include <mrpt/ros1bridge/pose.h>
13 #include <mrpt/ros1bridge/time.h>
14 #include <mrpt_msgs/ObservationRangeBeacon.h>
16 
19 
20 using namespace mrpt::obs;
21 
23  const mrpt_msgs::ObservationRangeBeacon& _msg,
24  const mrpt::poses::CPose3D& _pose, CObservationBeaconRanges& _obj)
25 {
26  _obj.timestamp = mrpt::ros1bridge::fromROS(_msg.header.stamp);
27  mrpt::poses::CPose3D cpose_obj;
28 
29  _obj.stdError = _msg.sensor_std_range;
30  _obj.sensorLabel = _msg.header.frame_id;
31  _obj.maxSensorDistance = _msg.max_sensor_distance;
32  _obj.minSensorDistance = _msg.min_sensor_distance;
33 
34  if (_pose.empty())
35  {
36  cpose_obj = mrpt::ros1bridge::fromROS(_msg.sensor_pose_on_robot);
37  _obj.setSensorPose(cpose_obj);
38  }
39  else
40  {
41  _obj.setSensorPose(_pose);
42  }
43 
44  ASSERT_(_msg.sensed_data.size() >= 1);
45  const size_t N = _msg.sensed_data.size();
46 
47  _obj.sensedData.resize(N);
48 
49  for (std::size_t i_mrpt = 0; i_mrpt < N; i_mrpt++)
50  {
51  _obj.sensedData[i_mrpt].sensedDistance = _msg.sensed_data[i_mrpt].range;
52  _obj.sensedData[i_mrpt].beaconID = _msg.sensed_data[i_mrpt].id;
53  }
54  return true;
55 }
56 
58  const CObservationBeaconRanges& _obj,
59  mrpt_msgs::ObservationRangeBeacon& _msg)
60 {
61  mrpt::poses::CPose3D cpose_obj;
62 
63  _msg.header.stamp = mrpt::ros1bridge::toROS(_obj.timestamp);
64  _obj.getSensorPose(cpose_obj);
65  _msg.sensor_pose_on_robot = mrpt::ros1bridge::toROS_Pose(cpose_obj);
66 
67  _msg.sensor_std_range = _obj.stdError;
68  _msg.header.frame_id = _obj.sensorLabel;
69  _msg.max_sensor_distance = _obj.maxSensorDistance;
70  _msg.min_sensor_distance = _obj.minSensorDistance;
71 
72  ASSERT_(_obj.sensedData.size() >= 1);
73  const size_t N = _obj.sensedData.size();
74 
75  _msg.sensed_data.resize(N);
76 
77  for (std::size_t i_msg = 0; i_msg < N; i_msg++)
78  {
79  _msg.sensed_data[i_msg].range = _obj.sensedData[i_msg].sensedDistance;
80  _msg.sensed_data[i_msg].id = _obj.sensedData[i_msg].beaconID;
81  }
82  return true;
83 }
84 
86  const CObservationBeaconRanges& _obj,
87  mrpt_msgs::ObservationRangeBeacon& _msg, geometry_msgs::Pose& _pose)
88 {
89  toROS(_obj, _msg);
90  mrpt::poses::CPose3D pose;
91  _obj.getSensorPose(pose);
92  _pose = mrpt::ros1bridge::toROS_Pose(pose);
93  return true;
94 }
bool toROS(const mrpt::obs::CObservationBeaconRanges &_obj, mrpt_msgs::ObservationRangeBeacon &_msg)
bool fromROS(const mrpt_msgs::ObservationRangeBeacon &_msg, const mrpt::poses::CPose3D &_pose, mrpt::obs::CObservationBeaconRanges &_obj)


mrpt_msgs_bridge
Author(s): José Luis Blanco-Claraco
autogenerated on Thu Jun 1 2023 03:07:04