From d448fd565d9f314a3d66ebae05e93f38774aba4e Mon Sep 17 00:00:00 2001 From: Roland Arsenault Date: Wed, 14 Feb 2024 11:20:53 -0500 Subject: [PATCH] Update tf2 utils to support timestamps --- include/project11/gz4d_geo.h | 9 --- include/project11/pid.h | 2 +- include/project11/tf2_utils.h | 17 ++++-- include/project11/utils.h | 22 +++---- launch/robot_core.launch | 111 ++++++++++++++++++++-------------- 5 files changed, 88 insertions(+), 73 deletions(-) diff --git a/include/project11/gz4d_geo.h b/include/project11/gz4d_geo.h index 491b3e4..baea1ff 100644 --- a/include/project11/gz4d_geo.h +++ b/include/project11/gz4d_geo.h @@ -51,15 +51,6 @@ namespace gz4d return !(i%2); } -// inline bool IsTrue(std::string const &s) -// { -// std::string l = boost::algorithm::to_lower_copy(boost::algorithm::trim_copy(s)); -// return (l == "true" || l == "yes" || l == "on" || l == "1" || l == "t" || l == "y"); -// } - -// template inline T Nan(){return std::numeric_limits::quiet_NaN();} -// template inline bool IsNan(T value){return (boost::math::isnan)(value);} - /// Used by std::shared_ptr's to hold pointers it shouldn't auto-delete. struct NullDeleter { diff --git a/include/project11/pid.h b/include/project11/pid.h index 991547a..87e64f9 100644 --- a/include/project11/pid.h +++ b/include/project11/pid.h @@ -130,7 +130,7 @@ class PID Ki_ = msg->Ki; Kd_ = msg->Kd; windup_limit_ = msg->windup_limit; - upper_limit_ = msg->windup_limit; + upper_limit_ = msg->upper_limit; lower_limit_ = msg->lower_limit; } diff --git a/include/project11/tf2_utils.h b/include/project11/tf2_utils.h index e686495..fcce9b4 100644 --- a/include/project11/tf2_utils.h +++ b/include/project11/tf2_utils.h @@ -22,23 +22,28 @@ namespace project11 } } - bool canTransform(std::string map_frame="map") + bool canTransform(std::string map_frame="map", ros::Time target_time = ros::Time(0), ros::Duration timeout = ros::Duration(0.5)) { - return buffer()->canTransform("earth", map_frame, ros::Time(0), ros::Duration(0.5)); + return buffer()->canTransform("earth", map_frame, target_time, timeout); } - geometry_msgs::Point wgs84_to_map(geographic_msgs::GeoPoint const &position, std::string map_frame="map") + geometry_msgs::Point wgs84_to_map(geographic_msgs::GeoPoint const &position, std::string map_frame="map", ros::Time target_time = ros::Time(0)) { geometry_msgs::Point ret; try { - geometry_msgs::TransformStamped t = buffer()->lookupTransform(map_frame,"earth",ros::Time(0)); + geometry_msgs::TransformStamped t = buffer()->lookupTransform(map_frame,"earth",target_time); LatLongDegrees p_ll; fromMsg(position, p_ll); + bool alt_is_nan = std::isnan(position.altitude); + if(alt_is_nan) + p_ll.altitude() = 0.0; ECEF p_ecef = p_ll; geometry_msgs::Point in; toMsg(p_ecef, in); tf2::doTransform(in,ret,t); + if(alt_is_nan) + ret.z = std::nan(""); } catch (tf2::TransformException &ex) { @@ -47,12 +52,12 @@ namespace project11 return ret; } - geographic_msgs::GeoPoint map_to_wgs84(geometry_msgs::Point const &point, std::string map_frame="map") + geographic_msgs::GeoPoint map_to_wgs84(geometry_msgs::Point const &point, std::string map_frame="map", ros::Time target_time = ros::Time(0)) { geographic_msgs::GeoPoint ret; try { - geometry_msgs::TransformStamped t = buffer()->lookupTransform("earth",map_frame,ros::Time(0)); + geometry_msgs::TransformStamped t = buffer()->lookupTransform("earth",map_frame, target_time); geometry_msgs::Point out; tf2::doTransform(point,out,t); ECEF out_ecef; diff --git a/include/project11/utils.h b/include/project11/utils.h index bc27cdf..15d02df 100644 --- a/include/project11/utils.h +++ b/include/project11/utils.h @@ -23,24 +23,24 @@ namespace project11 return v3.length(); } - typedef gz4d::GeoPointLatLongDegrees LatLongDegrees; - typedef gz4d::GeoPointECEF ECEF; - typedef gz4d::Point Point; - typedef gz4d::LocalENU ENUFrame; + using LatLongDegrees = gz4d::GeoPointLatLongDegrees; + using ECEF = gz4d::GeoPointECEF; + using Point = gz4d::Point; + using ENUFrame = gz4d::LocalENU; // angle types that do not wrap - typedef gz4d::Angle AngleDegrees; - typedef gz4d::Angle AngleRadians; + using AngleDegrees = gz4d::Angle; + using AngleRadians = gz4d::Angle; // angle types that wrap at +/- half a circle - typedef gz4d::Angle AngleDegreesZeroCentered; - typedef gz4d::Angle AngleRadiansZeroCentered; + using AngleDegreesZeroCentered = gz4d::Angle; + using AngleRadiansZeroCentered = gz4d::Angle; // angle types that wrap at 0 and full circle - typedef gz4d::Angle AngleDegreesPositive; - typedef gz4d::Angle AngleRadiansPositive; + using AngleDegreesPositive = gz4d::Angle; + using AngleRadiansPositive = gz4d::Angle; - typedef gz4d::geo::WGS84::Ellipsoid WGS84; + using WGS84 = gz4d::geo::WGS84::Ellipsoid; template void fromMsg(const A& a, LatLongDegrees &b) { diff --git a/launch/robot_core.launch b/launch/robot_core.launch index 209e6fb..24e6ace 100644 --- a/launch/robot_core.launch +++ b/launch/robot_core.launch @@ -5,53 +5,72 @@ - + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +