marker_msgs.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2022, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
17 #include <marker_msgs/MarkerDetection.h>
18 #include <mrpt/obs/CObservationBearingRange.h>
19 #include <mrpt/ros1bridge/time.h>
21 
23  const marker_msgs::MarkerDetection& src,
24  const mrpt::poses::CPose3D& sensorPoseOnRobot,
25  mrpt::obs::CObservationBearingRange& des)
26 {
27  des.timestamp = mrpt::ros1bridge::fromROS(src.header.stamp);
28  des.setSensorPose(sensorPoseOnRobot);
29  des.minSensorDistance = src.distance_min;
30  des.maxSensorDistance = src.distance_max;
31 
32  des.sensedData.resize(src.markers.size());
33  for (size_t i = 0; i < src.markers.size(); i++)
34  {
35  const marker_msgs::Marker& marker = src.markers[i];
36  // mrpt::obs::CObservationBearingRange::TMeasurement
37  auto& m = des.sensedData[i];
38  m.range = sqrt(
39  marker.pose.position.x * marker.pose.position.x +
40  marker.pose.position.y * marker.pose.position.y);
41  m.yaw = atan2(marker.pose.position.y, marker.pose.position.x);
42  m.pitch = 0.0;
43  if (marker.ids.size() > 0)
44  {
45  m.landmarkID = marker.ids[0];
46  }
47  else
48  {
49  m.landmarkID = -1;
50  }
51  }
52  return true;
53 }
54 
56  const marker_msgs::MarkerDetection& src,
57  const mrpt::poses::CPose3D& sensorPoseOnRobot,
58  mrpt::obs::CObservationBeaconRanges& des)
59 {
60  des.timestamp = mrpt::ros1bridge::fromROS(src.header.stamp);
61 
62  des.setSensorPose(sensorPoseOnRobot);
63  des.minSensorDistance = src.distance_min;
64  des.maxSensorDistance = src.distance_max;
65 
66  des.sensedData.resize(src.markers.size());
67  for (size_t i = 0; i < src.markers.size(); i++)
68  {
69  const marker_msgs::Marker& marker = src.markers[i];
70  // mrpt::obs::CObservationBeaconRanges::TMeasurement
71  auto& m = des.sensedData[i];
72  m.sensedDistance = sqrt(
73  marker.pose.position.x * marker.pose.position.x +
74  marker.pose.position.y * marker.pose.position.y);
75  m.sensorLocationOnRobot.m_coords = sensorPoseOnRobot.m_coords;
76  if (marker.ids.size() > 0)
77  {
78  m.beaconID = marker.ids[0];
79  }
80  else
81  {
82  m.beaconID = -1;
83  }
84  }
85  return true;
86 }
Funtions to convert marker_msgs to mrpt msgs.
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