飞行的高度是如何测量的?地面的高度和海平面的高度差别很大,飞控又是如何有效判别进行降落的?这是我脑子里的疑问。搜索的一圈发现很少有人讨论这方面的问题,于是本次我就直接看一下源代码,一起分析一下PX4中关于高度的相关问题,以及如何利用高度实现自动降落的。

注:看文档最好还是看英文的,有时候翻译的没有把关键信息给翻译出来,会有很多误解。

1、PX4降落的几种模式

Fixed Wing:

先看看land mode是什么:

Land mode causes the vehicle to turn and land at the location at which the mode was engaged. Fixed wing landing logic and parameters are explained in the topic: Landing (Fixed Wing)

“Land mode 让飞行器调转方向,并且在该模式被激发的那个位置着陆。”这句话的意思是,给飞机下达land mode指令,飞机就会立刻着陆的意思。不管之前的规划路线了么?看一下代码是怎么写的。

再看第二句:

Fixed Wing - Landing Path

In Land mode the ground altitude is not known and the vehicle will use assume it is at 0m (sea level). Often the ground level will be much higher than sea level, so the vehicle will land in the first phase (it will land on the ground before it reaches the flare altitude).

“在land mode地面高度是未知的,并且飞机会假定地面高度是0m(海平面),通常地面高度远高于海平面,所以飞机将在降落的第一阶段着陆(也就是在到底 flare高度之前就会着陆)”。 也就是说,在land mode,飞行器不判断地面的高度,直接用0m作为地面高度进行降落程序。看起来好像有点傻,但可能因为飞到了一个任意地点,不知道当地的高度信息。

再看:

In a mission, Return mode, or if the vehicle has a range sensor fitted then ground level can be accurately estimated and landing behaviour will be as shown in the preceding diagram.

“在mission mode / return mode,或者飞机有一个距离传感器时,地面高度将被准确的估计,这样的话降落行为就看上去跟上面的图一样了。” 也就是说,在return mode等模式中,是有参考的地平面的(在飞机arm的时候,更新当前位置为home position,里面包括一个当前位置的高度,作为降落时候的地平面),所以可以实现flared landing。

再看一下QGC的一段文档:

The Fly View displays the actual home position set by the vehicle firmware when it arms (this where the vehicle will return in Return/RTL mode).

当飞机arm的时候,由固件来设置真实的home position,在QGC上规划的那个lanch点不是真实的home pos,只是规划而已。这个点也是return mode的返回点。

2、地面高度和海拔高度

查询了一下MAVLINK里面关于高度的消息。

ALTITUDE ( #141 )

[Message] The current system altitude.

Field NameTypeUnitsDescription
time_usecuint64_tusTimestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
altitude_monotonicfloatmThis altitude measure is initialized on system boot and monotonic (it is never reset, but represents the local altitude change). The only guarantee on this field is that it will never be reset and is consistent within a flight. The recommended value for this field is the uncorrected barometric altitude at boot time. This altitude will also drift and vary between flights.
altitude_amslfloatmThis altitude measure is strictly above mean sea level and might be non-monotonic (it might reset on events like GPS lock or when a new QNH value is set). It should be the altitude to which global altitude waypoints are compared to. Note that it is *not* the GPS altitude, however, most GPS modules already output MSL by default and not the WGS84 altitude.
altitude_localfloatmThis is the local altitude in the local coordinate frame. It is not the altitude above home, but in reference to the coordinate origin (0, 0, 0). It is up-positive.
altitude_relativefloatmThis is the altitude above the home position. It resets on each change of the current home position.
altitude_terrainfloatmThis is the altitude above terrain. It might be fed by a terrain database or an altimeter. Values smaller than -1000 should be interpreted as unknown.
bottom_clearancefloatmThis is not the altitude, but the clear space below the system according to the fused clearance estimate. It generally should max out at the maximum range of e.g. the laser altimeter. It is generally a moving target. A negative value indicates no measurement available.

这里有好几个高度,可以用QGC看一下获取到飞机的实时消息。

  • altitude_amsl:平均海拔高度(AMSL----> above mean sea level)  
  • altitude_relative: 在home position之上的高度,home点就是起飞的时候设置的位置
  • altitude_local: 这个是以NED坐标系为参考的高度,但注意,向上是正,跟NED坐标系的z轴值是相反反的。NED坐标系的原点在一开始启动飞机的时候,记录下的地方。并且不随你设置不同的home pos而变化。

感觉这三个可能比较有用。

还有一个名词 QNH,查了一下维基百科

QNH is the barometric altimeter setting that causes an altimeter to read airfield elevation above mean sea level when on the airfield. In ISA temperature conditions the altimeter will read altitude above mean sea level in the vicinity of the airfield.

3、PX4降落时用的是什么高度

按照文档描述分为两种情况:

在LAND MODE,也就是直接降落。这时候就是认为地面在海平面;

在RETURN MODE,也就是先返回到起点再降落。这时候就用的home postion里面的高度作为地平面。

对于LAND MODE 的情况:

mavlink/mavlink_mission.cpp

#1297    mission_item->altitude = mavlink_mission_item->z;  // 从mavlink消息中取出land的高度

PX4-Autopilot/src/modules/navigator/land.cpp

void
Land::on_activation()
{
	/* set current mission item to Land */
	set_land_item(&_mission_item, true);
	_navigator->get_mission_result()->finished = false;
	_navigator->set_mission_result_updated();
	reset_mission_item_reached();

	/* convert mission item to current setpoint */
	struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
	pos_sp_triplet->previous.valid = false;
	mission_apply_limitation(_mission_item);
	mission_item_to_position_setpoint(_mission_item, &pos_sp_triplet->current);
	pos_sp_triplet->next.valid = false;

	_navigator->set_can_loiter_at_sp(false);

	_navigator->set_position_setpoint_triplet_updated();
}

从mission_item 中取出当前的setpoint,来控制飞机降落。

mission_item里面的高度是什么呢?通过set_land_item(),使用当前的位置,而高度直接设置为0。貌似没有用到MAVLINK发过来的数据(发过来的数据好像高度也是0,待确认)。请看下面的代码:

void
MissionBlock::set_land_item(struct mission_item_s *item, bool at_current_location)
{
	/* VTOL transition to RW before landing */
	if (_navigator->force_vtol()) {

		vehicle_command_s vcmd = {};
		vcmd.command = NAV_CMD_DO_VTOL_TRANSITION;
		vcmd.param1 = vtol_vehicle_status_s::VEHICLE_VTOL_STATE_MC;
		vcmd.param2 = 0.0f;
		_navigator->publish_vehicle_cmd(&vcmd);
	}

	/* set the land item */
	item->nav_cmd = NAV_CMD_LAND;

	/* use current position */
	if (at_current_location) {
		item->lat = (double)NAN; //descend at current position
		item->lon = (double)NAN; //descend at current position
		item->yaw = _navigator->get_local_position()->heading;

	} else {
		/* use home position */
		item->lat = _navigator->get_home_position()->lat;
		item->lon = _navigator->get_home_position()->lon;
		item->yaw = _navigator->get_home_position()->yaw;
	}

	item->altitude = 0;
	item->altitude_is_relative = false;
	item->loiter_radius = _navigator->get_loiter_radius();
	item->acceptance_radius = _navigator->get_acceptance_radius();
	item->time_inside = 0.0f;
	item->autocontinue = true;
	item->origin = ORIGIN_ONBOARD;
}

因此,再LAND MODE ,直接就把海平面当作地面高度,直接开始降落的逻辑。 

4、QGC里面的高度

在规划路径的时候,上面显示的应该是AMSL,也就是海平面高度。同时,QGC还能够读取当前路径下的地形高度,所以有个对比示意图。

而且,如果你的高度设置的不合理,路线低于地形高度,它规划的路线会显示红色。

 例如,这个路径中,我们穿越了紫金山。但是路径点5-6-7之间的高度比紫金山的地形高度低,标记成了红色。在下方的高度示意图中,可以看到绿色是地形高度,黄色是规划的路线高度,其中有一段是红色,表示比地形高度低。

降落的地点,可以输入高度,这个高度是距离地面的相对高度,最好选择在开始点附近,不然太远了,地形如果不平,则肯定会有问题。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐