0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

发表于 2022-4-26 19:45:56 1995 浏览 8 回复

[新手上路] 解释Prometheus_px4 geo.cpp中一个函数 map_projection_project

prometheus问答
提问前请先确定以下问题:: 是的
第一步:问题BUG描述: 这个函数如何解算得到 x y z的?
第二步:PX4版本是否为Prometheus_PX4_V1.11.1分支?: 是 Prometheus_PX4_V1.11.1
第三步:测试prometheus_px4是否正常: 正常
第四步:Prometheus版本是否为最新master?: 是master版本
第五步:测试Prometheus是否正常: 正常
geo.cpp中有个函数map_projection_project/* Transforms a point in the geographic coordinate system to the local
* azimuthal equidistant plane using the projection given by the argument
* @param x north
* @param y east
* @param lat in degrees (47.1234567掳, not 471234567掳)
* @param lon in degrees (8.1234567掳, not 81234567掳)
* @return 0 if map_projection_init was called before, -1 else
* */
int map_projection_project(const struct map_projection_reference_s *ref, double lat, double lon, float *x,float *y);


我将这个函数单独复制出来运算,发现运算结果与如下网址的计算结果有较大误差。
GPS经度纬度距离计算  GPS经度纬度距离计算 - 计算专家 (jisuan.mobi)
能否解释下函数中解算x y的原理? 也就是根据代码,解释计算原理。



我知道答案 回答被采纳将会获得3 阿木币 已有8人回答

扫一扫浏览分享
回复

使用道具 举报

0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2022-4-26 19:55:48
如果您能解释通,并且最后计算偏差较小,可以再追加。
回复 点赞

使用道具 举报

29

阿木币

0

精华

91 小时

在线时间

技术大V

Rank: 4

发表于 2022-4-27 09:20:16
youxia23 发表于 2022-4-26 19:55
如果您能解释通,并且最后计算偏差较小,可以再追加。

您可以了解一下mavros中local_position相关的代码
回复 点赞

使用道具 举报

209

阿木币

1

精华

52 小时

在线时间

老司机

Rank: 2

发表于 2022-4-27 10:31:07
你这个是要GPS位置转换成本地坐标系的x y点么   这个geo.cpp 是px4中的代码 还是prometheus中的代码呢
回复 点赞

使用道具 举报

209

阿木币

1

精华

52 小时

在线时间

老司机

Rank: 2

发表于 2022-4-27 10:40:42
根据代码,解释计算原理。  你可以把代码贴出来啊 C++的代码 挨个分析计算可以吗
回复 点赞

使用道具 举报

0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2022-4-27 19:43:54
blueboats 发表于 2022-4-27 10:31
你这个是要GPS位置转换成本地坐标系的x y点么   这个geo.cpp 是px4中的代码 还是prometheus中的代码呢 ...

是的。geo.cpp 是px4中的代码。
回复 点赞

使用道具 举报

0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2022-4-27 19:45:03
BOSHEN97 发表于 2022-4-27 09:20
您可以了解一下mavros中local_position相关的代码

其实我说的就是GPS转本地坐标系。
回复 点赞

使用道具 举报

0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2022-4-27 19:47:03
blueboats 发表于 2022-4-27 10:40
根据代码,解释计算原理。  你可以把代码贴出来啊 C++的代码 挨个分析计算可以吗 ...

int map_projection_project(const struct map_projection_reference_s *ref, double lat, double lon, float *x, float *y)
{
        if (!map_projection_initialized(ref)) {
                return -1;
        }

        const double lat_rad = math::radians(lat);
        const double lon_rad = math::radians(lon);

        const double sin_lat = sin(lat_rad);
        const double cos_lat = cos(lat_rad);

        const double cos_d_lon = cos(lon_rad - ref->lon_rad);

        const double arg = math::constrain(ref->sin_lat * sin_lat + ref->cos_lat * cos_lat * cos_d_lon, -1.0,  1.0);
        const double c = acos(arg);

        double k = 1.0;

        if (fabs(c) > 0) {
                k = (c / sin(c));
        }

        *x = static_cast<float>(k * (ref->cos_lat * sin_lat - ref->sin_lat * cos_lat * cos_d_lon) * CONSTANTS_RADIUS_OF_EARTH);
        *y = static_cast<float>(k * cos_lat * sin(lon_rad - ref->lon_rad) * CONSTANTS_RADIUS_OF_EARTH);

        return 0;
}
回复 点赞

使用道具 举报

0

阿木币

0

精华

12 小时

在线时间

应届白菜

Rank: 1

 楼主| 发表于 2022-4-27 19:49:12
blueboats 发表于 2022-4-27 10:40
根据代码,解释计算原理。  你可以把代码贴出来啊 C++的代码 挨个分析计算可以吗 ...

贴出来了,请看下。
回复 点赞

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表