Skip to content

Commit fa507ea

Browse files
FromLLArray - update after review
1 parent cbcd769 commit fa507ea

File tree

2 files changed

+41
-61
lines changed

2 files changed

+41
-61
lines changed

include/robot_localization/navsat_transform.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <Eigen/Dense>
4242
#include <GeographicLib/Geocentric.hpp>
4343
#include <GeographicLib/LocalCartesian.hpp>
44+
#include <geographic_msgs/msg/geo_point.hpp>
45+
#include <geometry_msgs/msg/point.hpp>
4446
#include <nav_msgs/msg/odometry.hpp>
4547
#include <rclcpp/rclcpp.hpp>
4648
#include <sensor_msgs/msg/imu.hpp>
@@ -51,6 +53,7 @@
5153
#include <tf2_ros/transform_listener.h>
5254

5355
#include <memory>
56+
#include <stdexcept>
5457
#include <string>
5558

5659
namespace robot_localization
@@ -106,6 +109,10 @@ class NavSatTransform : public rclcpp::Node
106109
const std::shared_ptr<robot_localization::srv::FromLLArray::Request> request,
107110
std::shared_ptr<robot_localization::srv::FromLLArray::Response> response);
108111

112+
//! @brief Method for convert point from Lat Lon to the map coordinates system
113+
//!
114+
geometry_msgs::msg::Point fromLL(const geographic_msgs::msg::GeoPoint & geo_point);
115+
109116
/**
110117
* @brief Given the pose of the navsat sensor in the Cartesian frame, removes the
111118
* offset from the vehicle's centroid and returns the Cartesian-frame pose of said

src/navsat_transform.cpp

Lines changed: 34 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,38 @@ bool NavSatTransform::fromLLCallback(
408408
const std::shared_ptr<robot_localization::srv::FromLL::Request> request,
409409
std::shared_ptr<robot_localization::srv::FromLL::Response> response)
410410
{
411-
double altitude = request->ll_point.altitude;
412-
double longitude = request->ll_point.longitude;
413-
double latitude = request->ll_point.latitude;
411+
try {
412+
response->map_point = fromLL(request->ll_point);
413+
}
414+
catch(const std::runtime_error& e) {
415+
return false;
416+
}
417+
418+
return true;
419+
}
420+
421+
bool NavSatTransform::fromLLArrayCallback(
422+
const std::shared_ptr<robot_localization::srv::FromLLArray::Request> request,
423+
std::shared_ptr<robot_localization::srv::FromLLArray::Response> response)
424+
{
425+
for (auto it = request->ll_points.begin(); it != request->ll_points.end(); ++it) {
426+
try {
427+
response->map_points.push_back(fromLL(*it));
428+
}
429+
catch(const std::runtime_error& e) {
430+
return false;
431+
}
432+
}
433+
434+
return true;
435+
}
436+
437+
geometry_msgs::msg::Point NavSatTransform::fromLL(
438+
const geographic_msgs::msg::GeoPoint& geo_point)
439+
{
440+
double altitude = geo_point.altitude;
441+
double longitude = geo_point.longitude;
442+
double latitude = geo_point.latitude;
414443

415444
tf2::Transform cartesian_pose;
416445

@@ -438,67 +467,11 @@ bool NavSatTransform::fromLLCallback(
438467

439468
cartesian_pose.setOrigin(tf2::Vector3(cartesian_x, cartesian_y, altitude));
440469

441-
nav_msgs::msg::Odometry gps_odom;
442-
443470
if (!transform_good_) {
444-
return false;
471+
throw std::runtime_error("Invalid transform.");
445472
}
446473

447-
response->map_point = cartesianToMap(cartesian_pose).pose.pose.position;
448-
449-
return true;
450-
}
451-
452-
bool NavSatTransform::fromLLArrayCallback(
453-
const std::shared_ptr<robot_localization::srv::FromLLArray::Request> request,
454-
std::shared_ptr<robot_localization::srv::FromLLArray::Response> response)
455-
{
456-
double altitude, longitude, latitude;
457-
double cartesian_x {};
458-
double cartesian_y {};
459-
double cartesian_z {};
460-
tf2::Transform cartesian_pose;
461-
std::string utm_zone_tmp;
462-
for (auto it = request->ll_points.begin(); it != request->ll_points.end(); ++it) {
463-
//
464-
altitude = it->altitude;
465-
longitude = it->longitude;
466-
latitude = it->latitude;
467-
cartesian_x = 0.0;
468-
cartesian_y = 0.0;
469-
cartesian_z = 0.0;
470-
//
471-
if (use_local_cartesian_) {
472-
gps_local_cartesian_.Forward(
473-
latitude,
474-
longitude,
475-
altitude,
476-
cartesian_x,
477-
cartesian_y,
478-
cartesian_z);
479-
} else {
480-
481-
navsat_conversions::LLtoUTM(
482-
latitude,
483-
longitude,
484-
cartesian_y,
485-
cartesian_x,
486-
utm_zone_tmp);
487-
}
488-
489-
cartesian_pose.setOrigin(tf2::Vector3(cartesian_x, cartesian_y, altitude));
490-
491-
// nav_msgs::msg::Odometry gps_odom; // it's unused?
492-
493-
if (!transform_good_) {
494-
return false;
495-
}
496-
497-
response->map_points.push_back(cartesianToMap(cartesian_pose).pose.pose.position);
498-
499-
}
500-
501-
return true;
474+
return cartesianToMap(cartesian_pose).pose.pose.position;
502475
}
503476

504477
nav_msgs::msg::Odometry NavSatTransform::cartesianToMap(

0 commit comments

Comments
 (0)