mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-25 08:36:08 +08:00
wip, working on the nuttx wrapper
This commit is contained in:
@@ -26,14 +26,15 @@
|
||||
*/
|
||||
|
||||
#include <px4.h>
|
||||
#include <px4/rc_channels.h>
|
||||
|
||||
#include <sstream>
|
||||
using namespace px4;
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple sending of messages over the PX4 middleware system.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
// __EXPORT bool task_should_exit;
|
||||
|
||||
PX4_MAIN_FUNCTION(publisher)
|
||||
{
|
||||
|
||||
px4::init(argc, argv, "px4_publisher");
|
||||
@@ -57,7 +58,7 @@ int main(int argc, char **argv)
|
||||
* than we can send them, the number here specifies how many messages to
|
||||
* buffer up before throwing some away.
|
||||
*/
|
||||
px4::Publisher rc_channels_pub = n.advertise<px4::rc_channels>(PX4_TOPIC(rc_channels));
|
||||
px4::Publisher * rc_channels_pub = n.advertise<PX4_TOPIC_T(rc_channels)>(PX4_TOPIC(rc_channels));
|
||||
|
||||
|
||||
px4::Rate loop_rate(10);
|
||||
@@ -72,7 +73,7 @@ int main(int argc, char **argv)
|
||||
/**
|
||||
* This is a message object. You stuff it with data, and then publish it.
|
||||
*/
|
||||
px4::rc_channels msg;
|
||||
PX4_TOPIC_T(rc_channels) msg;
|
||||
|
||||
msg.timestamp_last_valid = px4::get_time_micros();
|
||||
PX4_INFO("%lu", msg.timestamp_last_valid);
|
||||
@@ -83,7 +84,7 @@ int main(int argc, char **argv)
|
||||
* given as a template parameter to the advertise<>() call, as was done
|
||||
* in the constructor above.
|
||||
*/
|
||||
rc_channels_pub.publish(msg);
|
||||
rc_channels_pub->publish(msg);
|
||||
|
||||
px4::spin_once();
|
||||
|
||||
|
||||
@@ -26,19 +26,20 @@
|
||||
*/
|
||||
|
||||
#include <px4.h>
|
||||
#include "px4/rc_channels.h"
|
||||
|
||||
using namespace px4;
|
||||
|
||||
/**
|
||||
* This tutorial demonstrates simple receipt of messages over the PX4 middleware system.
|
||||
*/
|
||||
void rc_channels_callback(const px4::rc_channels::ConstPtr &msg)
|
||||
void rc_channels_callback(const PX4_TOPIC_T(rc_channels) *msg)
|
||||
{
|
||||
PX4_INFO("I heard: [%lu]", msg->timestamp_last_valid);
|
||||
}
|
||||
|
||||
PX4_MAIN_FUNCTION(subscriber)
|
||||
// __EXPORT bool task_should_exit;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
PX4_MAIN_FUNCTION(subscriber)
|
||||
{
|
||||
/**
|
||||
* The ros::init() function needs to see argc and argv so that it can perform
|
||||
@@ -74,7 +75,7 @@ int main(int argc, char **argv)
|
||||
* is the number of messages that will be buffered up before beginning to throw
|
||||
* away the oldest ones.
|
||||
*/
|
||||
px4::Subscriber sub = n.subscribe(PX4_TOPIC(rc_channels), rc_channels_callback);
|
||||
n.subscribe(PX4_TOPIC(rc_channels), rc_channels_callback);
|
||||
PX4_INFO("subscribed");
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user