|
void gps_cb(const mavros_msgs::msg::HilGPS::SharedPtr req) |
|
{ |
|
mavlink::common::msg::HIL_GPS gps = {}; |
|
|
|
gps.time_usec = get_time_usec(req->header.stamp); |
|
gps.fix_type = req->fix_type; |
|
gps.lat = req->geo.latitude * 1E7; |
|
gps.lon = req->geo.longitude * 1E7; |
|
// @warning geographic_msgs/GeoPoint.msg uses WGS 84 reference ellipsoid |
|
// @TODO: Convert altitude to AMSL to be received by the FCU |
|
// related to issue #529 |
|
gps.alt = req->geo.altitude * 1E3; |
|
// [[[cog: |
|
// for f in ( |
|
// 'eph', 'epv', 'vel', 'vn', 've', 'vd', 'cog'): |
|
// cog.outl(f"gps.{f} = req->{f} * 1E2;") |
|
// ]]] |
|
gps.eph = req->eph * 1E2; |
|
gps.epv = req->epv * 1E2; |
|
gps.vel = req->vel * 1E2; |
|
gps.vn = req->vn * 1E2; |
|
gps.ve = req->ve * 1E2; |
|
gps.vd = req->vd * 1E2; |
|
gps.cog = req->cog * 1E2; |
|
// [[[end]]] (sum: txtOM75FdG) |
|
gps.satellites_visible = req->satellites_visible; |
|
|
|
uas->send_message(gps); |
|
} |
In the HIL plugin's gps callback function, all variables such as gps.lat, gps.lon, and gps.alt are obtained by multiplying the value in the req of type mavros_msgs::msg::HilGPS by 1E7 or 1E2. This was originally intended to preserve decimal information for float or double types. However, reading the definition of the mavros_msgs::msg::HilGPS type reveals that all members of mavros_msgs::msg::HilGPS are already set to int or uint type, indicating that decimal places have been lost.
|
# HilControls.msg |
|
# |
|
# ROS representation of MAVLink HIL_GPS |
|
# See mavlink message documentation here: |
|
# https://mavlink.io/en/messages/common.html#HIL_GPS |
|
|
|
std_msgs/Header header |
|
uint8 fix_type |
|
geographic_msgs/GeoPoint geo |
|
uint16 eph |
|
uint16 epv |
|
uint16 vel |
|
int16 vn |
|
int16 ve |
|
int16 vd |
|
uint16 cog |
|
uint8 satellites_visible |
Therefore, I recommend redefine the mavros_msgs::msg::HilGPS message to preserve the decimal part of the values. For example, the lat and lon etc. should use float64 rather than int or uint.
Alternatively, the HIL plugin should be rewritten. These multiplications by 1E2 and 1E7 should be removed because the mavros_msgs::msg::HilGPS message is already considered a processed mavlink message (int and uint type, already multiplied by 1E2 or 1E7).
This problem lies both in ROS1 and ROS2 branch.
mavros/mavros_extras/src/plugins/hil.cpp
Lines 210 to 238 in 07f497d
In the HIL plugin's gps callback function, all variables such as gps.lat, gps.lon, and gps.alt are obtained by multiplying the value in the req of type mavros_msgs::msg::HilGPS by 1E7 or 1E2. This was originally intended to preserve decimal information for float or double types. However, reading the definition of the mavros_msgs::msg::HilGPS type reveals that all members of mavros_msgs::msg::HilGPS are already set to int or uint type, indicating that decimal places have been lost.
mavros/mavros_msgs/msg/HilGPS.msg
Lines 1 to 17 in 07f497d
Therefore, I recommend redefine the
mavros_msgs::msg::HilGPSmessage to preserve the decimal part of the values. For example, thelatandlonetc. should use float64 rather thanintoruint.Alternatively, the HIL plugin should be rewritten. These multiplications by 1E2 and 1E7 should be removed because the mavros_msgs::msg::HilGPS message is already considered a processed mavlink message (int and uint type, already multiplied by 1E2 or 1E7).
This problem lies both in ROS1 and ROS2 branch.