Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions mvsim_node_src/mvsim_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
// ===========================================
// ROS 1
// ===========================================
#include <mrpt/ros1bridge/gps.h>
#include <mrpt/ros1bridge/image.h>
#include <mrpt/ros1bridge/imu.h>
#include <mrpt/ros1bridge/laser_scan.h>
Expand Down Expand Up @@ -60,6 +61,7 @@ using Msg_Marker = visualization_msgs::Marker;
// ===========================================
// ROS 2
// ===========================================
#include <mrpt/ros2bridge/gps.h>
#include <mrpt/ros2bridge/image.h>
#include <mrpt/ros2bridge/imu.h>
#include <mrpt/ros2bridge/laser_scan.h>
Expand Down Expand Up @@ -1291,31 +1293,21 @@ void MVSimNode::internalOn(const mvsim::VehicleBase& veh, const mrpt::obs::CObse

// Send observation:
{
// Convert observation MRPT -> ROS
auto msg = mvsim_node::make_shared<Msg_GPS>();
msg->header.stamp = myNow();
msg->header.frame_id = obs.sensorLabel;

const auto& o = obs.getMsgByClass<mrpt::obs::gnss::Message_NMEA_GGA>();

msg->latitude = o.fields.latitude_degrees;
msg->longitude = o.fields.longitude_degrees;
msg->altitude = o.fields.altitude_meters;

if (auto& c = obs.covariance_enu; c.has_value())
{
#if PACKAGE_ROS_VERSION == 1
msg->position_covariance_type = sensor_msgs::NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
#else
msg->position_covariance_type =
sensor_msgs::msg::NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
#endif
// Convert observation MRPT -> ROS. Delegate to the library conversion
// (as the IMU handler above already does) instead of reimplementing it
// field-by-field: the hand-rolled version here never set
// msg->status.status, which ROS leaves at NavSatStatus::STATUS_UNKNOWN
// (-2) by IDL default; consumers that treat anything other than a
// definite fix as invalid (e.g. mola_state_estimation_smoother's GNSS
// fusion) would then silently reject every single reading, even
// though the simulated fix quality (mrpt::obs::gnss::Message_NMEA_GGA
// ::fields::fix_quality) was perfectly valid.
Msg_Header msg_header;
msg_header.stamp = myNow();
msg_header.frame_id = obs.sensorLabel;

msg->position_covariance.fill(0.0);
msg->position_covariance[0] = (*c)(0, 0);
msg->position_covariance[4] = (*c)(1, 1);
msg->position_covariance[8] = (*c)(2, 2);
}
auto msg = mvsim_node::make_shared<Msg_GPS>();
mrpt2ros::toROS(obs, msg_header, *msg);
Comment on lines +1309 to +1310

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the return type of mrpt2ros::toROS for GPS observations
# and check how the IMU handler calls the equivalent bridge function.

# Find the GPS bridge header and inspect the toROS declaration
fd -i 'gps.h' | xargs rg -n 'toROS.*GPS\|toROS.*NavSatFix\|toROS.*CObservationGPS' 2>/dev/null | head -20

# Alternatively search for the function signature in the mrpt ros bridge
fd -i 'gps' -e h -e hpp | xargs rg -n 'toROS' 2>/dev/null | head -20

# Check how the IMU handler calls toROS (for pattern consistency)
rg -n -A2 'toROS.*imu\|toROS.*IMU\|toROS.*Imu' mvsim_node_src/ 2>/dev/null | head -20

Repository: MRPT/mvsim

Length of output: 2003


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the mrpt2ros bridge declarations/definitions for GPS and related overloads.
rg -n --hidden --no-ignore-vcs 'namespace mrpt2ros|toROS\s*\(' . \
  -g '!**/build/**' -g '!**/dist/**' -g '!**/node_modules/**' | head -300

# Narrow to likely bridge files if present.
fd -i 'mrpt2ros' . -t f
fd -i 'ros' . -t f | head -200

Repository: MRPT/mvsim

Length of output: 2422


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the guidance around the GNSS bridge usage.
cat -n agents.md | sed -n '120,155p'

# Check whether this repo contains any mrpt ros bridge headers or generated docs.
fd -HI 'ros1bridge' .
fd -HI 'ros2bridge' .
fd -HI 'NavSatFix' .

Repository: MRPT/mvsim

Length of output: 2090


🌐 Web query:

MRPT mrpt::ros1bridge toROS CObservationGPS NavSatFix return type

💡 Result:

The function mrpt::ros1bridge::toROS, used to convert an mrpt::obs::CObservationGPS object into a sensor_msgs::NavSatFix message, has a return type of bool [1][2]. The function returns true upon a successful conversion and false if an error occurs [1]. The full function signature is: bool mrpt::ros1bridge::toROS(const mrpt::obs::CObservationGPS& obj, const std_msgs::Header& msg_header, sensor_msgs::NavSatFix& msg); [1]

Citations:


🌐 Web query:

site:github.com MRPT ros1bridge toROS CObservationGPS NavSatFix bool

💡 Result:

The MRPT library provides bridging functionality to convert between its mrpt::obs::CObservationGPS data structure and ROS navigation message types (specifically sensor_msgs/NavSatFix and gps_msgs/msg/GPSFix) [1][2][3]. In the mrpt_ros_bridge (for ROS 2) and mrpt_bridge (for ROS 1), bidirectional conversion functions are provided [1][2][3]. Specifically, for sensor_msgs/NavSatFix integration: 1. Conversion Functions: The bridge typically uses functions named toROS() and fromROS() (or navSatFixToObservation()) to translate data [2][4]. 2. Boolean Flags: When performing bulk conversions—such as using rosbag2ToGPS—the bridge often utilizes a boolean flag (e.g., isGpsFix) to distinguish whether the target message type is sensor_msgs/NavSatFix or gps_msgs/msg/GPSFix [5]. 3. Data Mapping: mrpt::obs::CObservationGPS contains internal fields such as fix_type (using the GnssFixType enum) and gnss_service_mask (using GnssService) which are mapped to ROS message status fields to ensure compatibility [6][4]. Modern versions of the bridge (MRPT 2.15.11+) include version-conditional logic to handle these mappings accurately, maintaining compatibility with older ROS message definitions [4]. For implementation details, refer to the mrpt::ros2bridge or mrpt_bridge headers, such as ros_to_mrpt_obs.h or gps.h, which define these conversion interfaces [5][2].

Citations:


🌐 Web query:

MRPT ros2bridge gps.h CObservationGPS toROS return type bool

💡 Result:

Yes, the return type of the toROS function in the mrpt::ros2bridge namespace, when converting a mrpt::obs::CObservationGPS object, is bool [1][2][3]. This function returns true upon a successful conversion and false if any error occurs during the process [1][2][4]. The bridge provides overloads for toROS to handle different target ROS message types, such as sensor_msgs::msg::NavSatFix and gps_msgs::msg::GPSFix [5][3][6].

Citations:


🌐 Web query:

site:docs.mrpt.org mrpt::ros2bridge::toROS CObservationGPS NavSatFix bool

💡 Result:

The function mrpt::ros2bridge::toROS used to convert an mrpt::obs::CObservationGPS object to a sensor_msgs::msg::NavSatFix ROS 2 message has the following signature [1]: bool mrpt::ros2bridge::toROS( const mrpt::obs::CObservationGPS& obj, const std_msgs::msg::Header& msg_header, sensor_msgs::msg::NavSatFix& msg); The function returns a boolean value indicating whether the conversion was successful [2][1]. Because the CObservationGPS class does not natively store ROS-specific header information, the user is required to provide an explicit std_msgs::msg::Header object, which is then copied into the resulting NavSatFix message [3][1]. Note: As of MRPT 3.0, the mrpt-ros2bridge library has been separated from the core MRPT repository and is maintained in its own repository at https://github.com/MRPT/mrpt_ros_bridge [4].

Citations:


🌐 Web query:

site:github.com/MRPT/mrpt_ros_bridge gps.h toROS CObservationGPS NavSatFix

💡 Result:

In the context of the MRPT (Mobile Robot Programming Toolkit) ROS bridge, conversion between MRPT's CObservationGPS and ROS's NavSatFix messages is handled through specific utility functions defined within the mrpt_ros_bridge package [1][2]. Header and Implementation Conversion logic is typically found in the header file mrpt/ros2bridge/gps.h and implemented in the corresponding source file mrpt/ros2bridge/src/gps.cpp [1]. Key Functionality The bridge provides bidirectional conversion functions: 1. toROS: Converts an mrpt::obs::CObservationGPS object into a sensor_msgs::msg::NavSatFix message [1]. 2. fromROS: Converts a sensor_msgs::msg::NavSatFix message into an mrpt::obs::CObservationGPS observation [1]. These functions manage the mapping between NMEA-based data (GGA, RMC, VTG, GSA) within MRPT and the standard ROS NavSatFix fields, including timestamp synchronization, coordinate mapping, and status/covariance propagation [1][3]. Recent updates to the bridge have added support for more advanced GPS messages (such as gps_msgs::msg::GPSFix) and version-conditional logic to support newer MRPT GNSS fix types while maintaining backward compatibility [1][3][4]. Usage Pattern While specific headers may vary by version, the standard pattern for using these bridge functions involves including the appropriate header and passing the source object to the conversion utility, similar to other MRPT-ROS type conversions [2]: // Conceptual example #include <mrpt/ros2bridge/gps.h> #include <sensor_msgs/msg/nav_sat_fix.hpp> #include <mrpt/obs/CObservationGPS.h> // MRPT to ROS mrpt::obs::CObservationGPS mrpt_obs; sensor_msgs::msg::NavSatFix ros_msg; mrpt::ros2bridge::toROS(mrpt_obs, ros_msg);

Citations:


Check mrpt2ros::toROS(...) result here
It returns false on conversion errors, so ignoring it can silently drop malformed GPS observations. Handle the failure path before publishing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mvsim_node_src/mvsim_node.cpp` around lines 1309 - 1310, Check the boolean
result of mrpt2ros::toROS(obs, msg_header, *msg) in the GPS observation handling
code before publishing the message; on false, handle the conversion failure
appropriately and return or skip publishing the malformed observation.


pub->publish(msg);
}
Expand Down
Loading