一、开篇
首先告诉大家一个坏消息,DJI提供了SDK~~~~
然后再来一个好消息,本篇博文很多干货哦~~~~~
最近比较纠结的一个问题ardupilot和pixhawk原生代码到底有什么区别和联系。经过和群友的讨论,最终方向一致认为单独的pixhawk原生代码是可以正常飞行的(群友Mr一直在用这套试飞的),其上电以后在rcS(nsh的启动脚本,其存储在ROMFS中,后面会详细介绍)中开启相应的进程对无人机进行姿态等复杂的控制,关于这个大家最先认识到的应该是各种飞行模式的确定,关于flight_mode后续再结合ardupilot介绍;ardupilot这套源代码前一篇博文已经分析过了,而且前一篇博文里面涉及的网站链接都是关于这个ardupilot的,很多人称之为APM,但是这个APM的HAL层也可以使用pixhawk硬件,此APM非彼apm,官网有介绍。Ardupilot是基于pixhawk原生代码开发的上层应用,即有了常见的mian和loop函数,正如前一篇博文中给出的一幅图,ardupilot把底层的PX4Firmware和NuttX等都抽象为HAL,developer只需要关心上层应用即可,基于pixhawk原生设计上层控制逻辑。这个非常类似于CC26xx的stack和application部分,而TI关于这个做的更好。ardupilot其实是开源的、玩具级飞控,它为了兼容各种乱七八糟的板子、机型,有很多冗余的代码,这些冗余的代码让我们理解飞控本身增加了难度和学习成本。如果我们需要一款专业的飞控,完全可以去掉这些冗余的代码,只保留我们需要的精简过的功能,这样也就能大大降低它代码的复杂程度。从程序设计的方法论来看(面向对象):就是要把一个个对象确立好,把问题的复杂程度控制住,才能设计出逻辑清晰的程序出来。但是我的博文写的没什么逻辑,水平有限,大家凑合看吧。
也就是说,假如你打算开一家无人机公司,不需要从最底层一行一行的代码写起,可以直接把这套开源的pixhawk原生代码搞透彻(这套可以不是一己之力可以完成的,这个开源项目N人N年了),然后基于它进行上层开发,加入自己NB的算法,听说进DJI的第一年就是给你一个pixhawk,玩一年。非常怀疑DJI现在是不是也是基于pixhawk(虽然DJI成立2006,ETH Zurichpixhawk项目成立2009年),有待考证或者有在DJI工作的给大家普及一下呗。
好吧,用哪套源码分析都行,我用的ardupilot,最后还是需要到底层的PX4Firmware。感谢群友彩虹小羊、灰灰、Mr等提供的帮助(排名按字母顺序,哈哈)。
三、实验平台
Software Version:ArduCopter(Ver_3.3)
Hardware Version:pixhawk
IDE:eclipse Juno (Windows)
四、基本知识介绍
1、关于坐标系
1)GeographicCoordinate System
Represents position on earth with alongitude and latitude value (Geographic_coordinate_system). Additionally thealtitude may may be included. The altitude can be expressed as distance fromthe earth center or as altitude above the mean sea level. All in all, thisgives a spherical coordinate system.
2)Earth-Fixed frame
Cartesian coordinate system at the center of the earth. Thepositive z axis goes through the north pole. The x and y axes are on theequatorial plane.
3)Body Fixed Frame
The x axis points in forward (defined bygeometry and not by movement) direction. (= roll axis)
The y axis points to the right(geometrically) (= pitch axis)
The z axis points downwards (geometrically)(= yaw axis)
4)EulerAngles
Usually a conversion between a earth fixed“ground” frame and the body fixed “in-air” frame is described via Euler-Angles.There are multiple conventions of the Euler angles.
The rotation order for the Tait-Bryan angles is Z Y’X” (see thefigure):
rotation of around Z (yaw)
rotation of around Y' (pitch)
rotation of around X” (roll)
2、pixhawk的HAL
3、pixhawk的控制图
五、正文
1、关于两个控制器和任务优先级
在PX4Firmware/src/modules中的mc_att_control:姿态控制器和mc_pos_control位置控制器(mc:multicopter),整个系统都是围绕着这两个控制器。
mc_att_control – Multirotor attitude controller
mc_pos_control – Multirotor position controller
The PX4 f