Pawel1
(Pawel)
May 9, 2024, 12:03pm
1
Hello,
I would like to replace GPS, by sending coordinates as x, y, z in meters.
Right now I am getting the best results by converting the coordinates to lat, lon, alt and sending it as GPS_INPUT mavlink message. But the drone is still drifting about 0.2-0.5 m. I am also obtaining yaw angle from arcus tangent of 2 UWB sensors located on drone. The UWB accuracy should be around 10cm.
I know there is the message VISION_POSITION_ESTIMATE, but it requires the roll and pitch angles which i don’t have. When I am sending 0 for them I am getting an error that IMU stopped aiding.
Thank you for any help
Pawel1
(Pawel)
May 9, 2024, 12:16pm
2
If someone is wondering how to convert meters to gps coordinates here is an example from mavsdk(link ):
CoordinateTransformation::global_from_local(LocalCoordinate local_coordinate) const
{
const double x_rad = local_coordinate.north_m / world_radius_m;
const double y_rad = local_coordinate.east_m / world_radius_m;
const double c = sqrt(x_rad * x_rad + y_rad * y_rad);
GlobalCoordinate global{};
if (fabs(c) > 0) {
const double sin_c = sin(c);
const double cos_c = cos(c);
const double ref_sin_lat = sin(_ref_lat_rad);
const double ref_cos_lat = cos(_ref_lat_rad);
const double lat_rad = asin(cos_c * ref_sin_lat + (x_rad * sin_c * ref_cos_lat) / c);
const double lon_rad =
(_ref_lon_rad +
atan2(y_rad * sin_c, c * ref_cos_lat * cos_c - x_rad * ref_sin_lat * sin_c));
global.latitude_deg = to_deg_from_rad(lat_rad);
global.longitude_deg = to_deg_from_rad(lon_rad);
} else {
global.latitude_deg = to_deg_from_rad(_ref_lat_rad);
global.longitude_deg = to_deg_from_rad(_ref_lon_rad);
}
return global;
}
After that you need to send mavlink message of type GPS_INPUT:
mavlink_message_t msg;
uint16_t len = mavlink_msg_gps_input_pack(
1, 0, &msg,
micros(),
0, //Gps ID
IGNORE_FLAGS_MV_GPS,
time_week_ms,
time_week,
3, //Fix Type,
lat_int, lon_int,
alt_int, // altitude
0, // HDOP,
0, // VDOP
0.0f, // Vn
0.0f, // Ve
0.0f, // Vd
0.0f, // Speed accuracy
0.0f, // Horizontal accuracy
0.0f, // Vertical accuracy,
14, // Satellites visible
yaw
);
mavlink_msg_to_send_buffer((uint8_t*)io_buff, &msg);
ser.write(io_buff, len);
And set couple of parameters:
GPS_TYPE - MAV
COMPASS_ENABLE - 0
COMPASS_USE - 0
COMPASS_USE2 - 0
COMPASS_USE3 - 0
EK3_SRC1_POSXY - 3 (GPS)
EK3_SRC1_POSZ - 3 (GPS)
EK3_SRC1_VELXY - 0 (None)
EK3_SRC1_VELZ- 0 (None)