22 #include <GeographicLib/Geocentric.hpp> 23 #include <GeographicLib/Geoid.hpp> 25 #include <geometry_msgs/PoseStamped.h> 26 #include <geometry_msgs/TransformStamped.h> 29 namespace extra_plugins {
30 using mavlink::common::GPS_FIX_TYPE;
43 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 earth(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f())
67 double origin_lat, origin_lon, origin_alt;
74 fix_type =
static_cast<GPS_FIX_TYPE
>(ft_i);
82 fp_nh.
param(
"geo_origin/lat", origin_lat, 47.3667);
83 fp_nh.
param(
"geo_origin/lon", origin_lon, 8.5500);
84 fp_nh.
param(
"geo_origin/alt", origin_alt, 408.0);
87 map_origin = {origin_lat, origin_lon, origin_alt};
97 catch (
const std::exception&
e) {
125 <<
" -> " << tf_child_frame_id);
188 mavlink::common::msg::HIL_GPS fix {};
190 Eigen::Vector3d geodetic;
191 Eigen::Vector3d current_ecef(ecef_origin.x() + ecef_offset.x(),
192 ecef_origin.y() + ecef_offset.y(),
193 ecef_origin.z() + ecef_offset.z());
196 earth.Reverse(current_ecef.x(), current_ecef.y(), current_ecef.z(),
197 geodetic.x(), geodetic.y(), geodetic.z());
199 catch (
const std::exception&
e) {
203 Eigen::Vector3d vel = ((old_ecef - current_ecef) / (stamp.
toSec() -
old_stamp)) * 1e2;
207 if (vel.x() == 0 && vel.y() == 0) {
210 else if (vel.x() >= 0 && vel.y() < 0) {
211 cog = M_PI * 5 / 2 -
atan2(vel.x(), vel.y());
214 cog = M_PI / 2 -
atan2(vel.x(), vel.y());
218 fix.time_usec = stamp.
toNSec() / 1000;
219 fix.lat = geodetic.x() * 1e7;
220 fix.lon = geodetic.y() * 1e7;
221 fix.alt = (geodetic.z() + GeographicLib::Geoid::ELLIPSOIDTOGEOID *
223 fix.vel = vel.block<2, 1>(0, 0).norm();
234 old_stamp = stamp.
toSec();
235 old_ecef = current_ecef;
243 Eigen::Affine3d pos_enu;
251 Eigen::Affine3d pos_enu;
259 Eigen::Affine3d pos_enu;
267 Eigen::Affine3d pos_enu;
void mocap_pose_cb(const geometry_msgs::PoseStamped::ConstPtr &req)
std::shared_ptr< MAVConnInterface const > ConstPtr
GeographicLib::Geocentric earth
void mocap_tf_cb(const geometry_msgs::TransformStamped::ConstPtr &trans)
std::string tf_child_frame_id
ros::Subscriber mocap_pose_sub
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
void send_fake_gps(const ros::Time &stamp, const Eigen::Vector3d &ecef_offset)
Send fake GPS coordinates through HIL_GPS Mavlink msg.
void tf2_start(const char *_thd_name, void(FakeGPSPlugin::*cbp)(const geometry_msgs::TransformStamped &))
Subscriptions get_subscriptions()
#define ROS_INFO_STREAM_NAMED(name, args)
bool mocap_transform
set use of mocap data (TransformStamped msg)
ros::Time last_transform_stamp
Eigen::Vector3d map_origin
geodetic origin [lla]
friend class TF2ListenerMixin
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FakeGPSPlugin()
std::shared_ptr< GeographicLib::Geoid > egm96_5
#define UAS_FCU(uasobjptr)
double old_stamp
previous stamp [s]
void transform_cb(const geometry_msgs::TransformStamped &trans)
ros::Subscriber mocap_tf_sub
T transform_frame_enu_ecef(const T &in, const T &map_origin)
Eigen::Vector3d old_ecef
previous geocentric position [m]
bool tf_listen
set use of TF Listener data
void transformMsgToEigen(const geometry_msgs::Transform &m, Eigen::Affine3d &e)
#define ROS_INFO_STREAM(args)
std::vector< HandlerInfo > Subscriptions
void initialize(UAS &uas_)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Eigen::Vector3d ecef_origin
geocentric origin [m]
#define ROS_ERROR_NAMED(name,...)
void vision_cb(const geometry_msgs::PoseStamped::ConstPtr &req)
ros::Subscriber vision_pose_sub
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
bool use_vision
set use of vision data
void initialize(UAS &uas_)
constexpr std::underlying_type< _T >::type enum_value(_T e)
bool use_mocap
set use of mocap data (PoseStamped msg)