mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-14 21:37:34 +08:00
examples/px4_simple_app: replace sensor_combined with vehicle_acceleration
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <uORB/uORB.h>
|
||||
#include <uORB/topics/sensor_combined.h>
|
||||
#include <uORB/topics/vehicle_acceleration.h>
|
||||
#include <uORB/topics/vehicle_attitude.h>
|
||||
|
||||
__EXPORT int px4_simple_app_main(int argc, char *argv[]);
|
||||
@@ -57,8 +57,8 @@ int px4_simple_app_main(int argc, char *argv[])
|
||||
{
|
||||
PX4_INFO("Hello Sky!");
|
||||
|
||||
/* subscribe to sensor_combined topic */
|
||||
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
|
||||
/* subscribe to vehicle_acceleration topic */
|
||||
int sensor_sub_fd = orb_subscribe(ORB_ID(vehicle_acceleration));
|
||||
/* limit the update rate to 5 Hz */
|
||||
orb_set_interval(sensor_sub_fd, 200);
|
||||
|
||||
@@ -99,20 +99,20 @@ int px4_simple_app_main(int argc, char *argv[])
|
||||
|
||||
if (fds[0].revents & POLLIN) {
|
||||
/* obtained data for the first file descriptor */
|
||||
struct sensor_combined_s raw;
|
||||
struct vehicle_acceleration_s accel;
|
||||
/* copy sensors raw data into local buffer */
|
||||
orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
|
||||
orb_copy(ORB_ID(vehicle_acceleration), sensor_sub_fd, &accel);
|
||||
PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
|
||||
(double)raw.accelerometer_m_s2[0],
|
||||
(double)raw.accelerometer_m_s2[1],
|
||||
(double)raw.accelerometer_m_s2[2]);
|
||||
(double)accel.xyz[0],
|
||||
(double)accel.xyz[1],
|
||||
(double)accel.xyz[2]);
|
||||
|
||||
/* set att and publish this information for other apps
|
||||
the following does not have any meaning, it's just an example
|
||||
*/
|
||||
att.q[0] = raw.accelerometer_m_s2[0];
|
||||
att.q[1] = raw.accelerometer_m_s2[1];
|
||||
att.q[2] = raw.accelerometer_m_s2[2];
|
||||
att.q[0] = accel.xyz[0];
|
||||
att.q[1] = accel.xyz[1];
|
||||
att.q[2] = accel.xyz[2];
|
||||
|
||||
orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user