mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-14 19:21:38 +08:00
Add modified Px4 Simple App for SLIP testing (couldn't compile)
This commit is contained in:
@@ -33,7 +33,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file px4_simple_app.c
|
* @file px4_simple_app.c
|
||||||
* Minimal application example for PX4 autopilot
|
*
|
||||||
|
* Simple app to test SLIP utility.
|
||||||
|
* Partial copy of platforms/nuttx/NuttX/apps/examples/thttpd/thttpd_main.c
|
||||||
*
|
*
|
||||||
* @author Example User <mail@example.com>
|
* @author Example User <mail@example.com>
|
||||||
*/
|
*/
|
||||||
@@ -41,86 +43,61 @@
|
|||||||
#include <px4_platform_common/px4_config.h>
|
#include <px4_platform_common/px4_config.h>
|
||||||
#include <px4_platform_common/tasks.h>
|
#include <px4_platform_common/tasks.h>
|
||||||
#include <px4_platform_common/posix.h>
|
#include <px4_platform_common/posix.h>
|
||||||
#include <unistd.h>
|
// #include <unistd.h>
|
||||||
#include <stdio.h>
|
// #include <stdio.h>
|
||||||
#include <poll.h>
|
// #include <poll.h>
|
||||||
#include <string.h>
|
// #include <string.h>
|
||||||
#include <math.h>
|
// #include <math.h>
|
||||||
|
|
||||||
|
// #include "netutils/netlib.h"
|
||||||
|
|
||||||
|
/* Include SLIP related libraries / macro defs */
|
||||||
|
#ifdef CONFIG_NET_SLIP
|
||||||
|
/* TTY device to use */
|
||||||
|
|
||||||
|
#pragma message "NET_SLIP is enabled, adding the libraries!"
|
||||||
|
|
||||||
|
// # include <nuttx/net/net.h>
|
||||||
|
# include <nuttx/net/slip.h>
|
||||||
|
|
||||||
|
# ifndef CONFIG_NET_SLIPTTY
|
||||||
|
# define CONFIG_NET_SLIPTTY "/dev/ttyS4"
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define SLIP_DEVNO 0
|
||||||
|
|
||||||
|
# ifndef NET_DEVNAME
|
||||||
|
# define NET_DEVNAME "sl0"
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <uORB/uORB.h>
|
|
||||||
#include <uORB/topics/vehicle_acceleration.h>
|
|
||||||
#include <uORB/topics/vehicle_attitude.h>
|
|
||||||
|
|
||||||
__EXPORT int px4_simple_app_main(int argc, char *argv[]);
|
__EXPORT int px4_simple_app_main(int argc, char *argv[]);
|
||||||
|
|
||||||
int px4_simple_app_main(int argc, char *argv[])
|
int px4_simple_app_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
PX4_INFO("Hello Sky!");
|
PX4_INFO("PX4 Simple SLIP Testing App!");
|
||||||
|
|
||||||
/* subscribe to vehicle_acceleration topic */
|
/* Sanity Checks */
|
||||||
int sensor_sub_fd = orb_subscribe(ORB_ID(vehicle_acceleration));
|
// static_assert(CONFIG_NET_SLIPTTY == "/dev/ttyS4");
|
||||||
/* limit the update rate to 5 Hz */
|
|
||||||
orb_set_interval(sensor_sub_fd, 200);
|
|
||||||
|
|
||||||
/* advertise attitude topic */
|
/* Configure SLIP */
|
||||||
struct vehicle_attitude_s att;
|
|
||||||
memset(&att, 0, sizeof(att));
|
|
||||||
orb_advert_t att_pub = orb_advertise(ORB_ID(vehicle_attitude), &att);
|
|
||||||
|
|
||||||
/* one could wait for multiple topics with this technique, just using one here */
|
#ifdef CONFIG_NET_SLIP
|
||||||
px4_pollfd_struct_t fds[] = {
|
int ret = slip_initialize(SLIP_DEVNO, CONFIG_NET_SLIPTTY);
|
||||||
{ .fd = sensor_sub_fd, .events = POLLIN },
|
|
||||||
/* there could be more file descriptors here, in the form like:
|
|
||||||
* { .fd = other_sub_fd, .events = POLLIN },
|
|
||||||
*/
|
|
||||||
};
|
|
||||||
|
|
||||||
int error_counter = 0;
|
if (ret < 0) {
|
||||||
|
printf("ERROR: SLIP initialization failed: %d\n", ret);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
#endif
|
||||||
/* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
|
|
||||||
int poll_ret = px4_poll(fds, 1, 1000);
|
|
||||||
|
|
||||||
/* handle the poll result */
|
// Idle by just sleeping for 1 second continuously
|
||||||
if (poll_ret == 0) {
|
while (true) {
|
||||||
/* this means none of our providers is giving us data */
|
px4_usleep(1E6);
|
||||||
PX4_ERR("Got no data within a second");
|
|
||||||
|
|
||||||
} else if (poll_ret < 0) {
|
|
||||||
/* this is seriously bad - should be an emergency */
|
|
||||||
if (error_counter < 10 || error_counter % 50 == 0) {
|
|
||||||
/* use a counter to prevent flooding (and slowing us down) */
|
|
||||||
PX4_ERR("ERROR return value from poll(): %d", poll_ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
error_counter++;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (fds[0].revents & POLLIN) {
|
|
||||||
/* obtained data for the first file descriptor */
|
|
||||||
struct vehicle_acceleration_s accel;
|
|
||||||
/* copy sensors raw data into local buffer */
|
|
||||||
orb_copy(ORB_ID(vehicle_acceleration), sensor_sub_fd, &accel);
|
|
||||||
PX4_INFO("Accelerometer:\t%8.4f\t%8.4f\t%8.4f",
|
|
||||||
(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] = accel.xyz[0];
|
|
||||||
att.q[1] = accel.xyz[1];
|
|
||||||
att.q[2] = accel.xyz[2];
|
|
||||||
|
|
||||||
orb_publish(ORB_ID(vehicle_attitude), att_pub, &att);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* there could be more file descriptors here, in the form like:
|
|
||||||
* if (fds[1..n].revents & POLLIN) {}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PX4_INFO("exiting");
|
PX4_INFO("exiting");
|
||||||
|
|||||||
Reference in New Issue
Block a user