我有一些gps传感器数据,用有符号的24位来表示经纬度。我想把这些数据转换成可读性更强的度、分和秒格式。在
我搜索了很多,但没有一个算法对我有效。我想用python来做这个。在
规格表说明了以下内容
Byte [8] > Value: MSB of the UP501 received Latitude
Byte [9] > Value: CSB of the UP501 received Latitude
Byte [10] > Value: LSB of the UP501 received Latitude
Byte 8, 9 and 10 represent the latitude. The north-south latitude is encoded using a signed 24 bit word where -2^23 corresponds to 90° south (the South Pole) and 2^23- 1 corresponds to 90° north (the North Pole). The equator corresponds to 0.
Byte [11] > Value: MSB of the UP501 received Longitude
Byte [12] > Value: CSB of the UP501 received Longitude
Byte [13] > Value: LSB of the UP501 received Longitude
Byte 11, 12 and 13 represent the longitude. The east-west longitude is encoded using a signed 24 bit word where -2^23 corresponds to 180° west and 2^23 -1 corresponds to 180° east. The Greenwich meridian corresponds to 0.
示例数据(8-13字节)
1E 55 9C 1C 69 5A
应该给予 北纬21°19′44〃,东经39°57′13〃
编辑: 在第一条评论之后,问题就来了 我看到的每个地方都是坐标的32位表示。这些方法对我不起作用,因为我没有得到我期望的结果。甚至没有接近。在
有没有更好的方法来进行这种转换?在
这有点棘手,因为涉及到几个尺度。首先,把你的符号值除以2**23-1,看看它代表的是半球的“分数”。在
那么,90度的23.69…%是多少?在
^{pr2}$21.几度,我们在正确的轨道上。相反,请注意赤道和极点之间有90*3600秒的纬度。让我们看看我们有多少部分:
因此,给定值是赤道以北约76784秒;将其转换为度/分/秒:
你的21度19分44秒。现在,我们知道除以
2**23 - 1
,因为我们知道这个值小于0x7fffffff,所以在北半球。(如果数值在南半球,我们需要除以2**23
,因为比例是不对称的。)对于经度,您将乘以每个半球的
180*3600
秒,而不是90*3600
,然后以相同的方式继续。在有一点需要注意的是,我没有包括南半球/西半球的例子,因为我不确定90年代是0x800000(二的补码)还是0xffffff(有符号的震级)。在
相关问题 更多 >
编程相关推荐