61. /* copy sensors raw data into local buffe
r */
62. orb_copy(ORB_ID(sensor_combined), sensor_
sub_fd, &raw);
63. printf(\
%8.4f\\t%8.4f\\t%8.4f\\n\,
64. (double)raw.accelerometer_m_s2[0
],
65. (double)raw.accelerometer_m_s2[1
],
66. (double)raw.accelerometer_m_s2[2
]);
67.
68. /* set att and publish this information f
or other apps */
69. att.roll = raw.accelerometer_m_s2[0]; 70. att.pitch = raw.accelerometer_m_s2[1]; 71. att.yaw = raw.accelerometer_m_s2[2]; 72. orb_publish(ORB_ID(vehicle_attitude), att
_pub_fd, &att);
73. }
74. /* there could be more file descriptors here, in t
he form like:
75. * if (fds[1..n].revents & POLLIN) {} 76. */ 77. } 78. } 79.
80. return 0; 81. }
运行最终的程序 需要一些基础应用:
1. 2. 3.
uorb start
sh /etc/init.d/rc.sensors
mavlink start -d /dev/ttyS1 -b 115200
最终运行应用:
1.
px4_simple_app &
假如启动了QGroundControl或者Mission Planner, 可以检查在实时绘图中显示的传感器数据(Main Menu: Main Widget →Realtime Plot),这些数据反映了进程正在发送的数据。
Wrap-Up
这个教程涉及到了所有需要在PX4自驾仪应用上进行增量开发所需的内容。需要知道的是,在availablehere 这里有完整的topics列表,而且头文件都被写好,并作为参考。 该示例应用在 src/examples/px4_simple_app可用. 在app配置中,注释掉Firmware/makefiles/nuttx/config_px4fmu-v2_default.mk即可。