wip, working on the nuttx wrapper

This commit is contained in:
Thomas Gubler
2014-11-26 11:36:23 +01:00
parent 3c6f6618e8
commit e7c1e5b1ff
16 changed files with 101 additions and 59 deletions
+7 -6
View File
@@ -26,14 +26,15 @@
*/ */
#include <px4.h> #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. * 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"); 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 * than we can send them, the number here specifies how many messages to
* buffer up before throwing some away. * 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); 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. * 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(); msg.timestamp_last_valid = px4::get_time_micros();
PX4_INFO("%lu", msg.timestamp_last_valid); 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 * given as a template parameter to the advertise<>() call, as was done
* in the constructor above. * in the constructor above.
*/ */
rc_channels_pub.publish(msg); rc_channels_pub->publish(msg);
px4::spin_once(); px4::spin_once();
+6 -5
View File
@@ -26,19 +26,20 @@
*/ */
#include <px4.h> #include <px4.h>
#include "px4/rc_channels.h"
using namespace px4;
/** /**
* This tutorial demonstrates simple receipt of messages over the PX4 middleware system. * 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_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 * 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 * is the number of messages that will be buffered up before beginning to throw
* away the oldest ones. * 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"); PX4_INFO("subscribed");
/** /**
+4 -6
View File
@@ -46,19 +46,17 @@
* Building for running within the ROS environment * Building for running within the ROS environment
*/ */
#include "ros/ros.h" #include "ros/ros.h"
#include "px4/rc_channels.h"
#define PX4_WARN ROS_WARN
#define PX4_INFO ROS_INFO
#define PX4_TOPIC(name) #name
#else #else
/* /*
* Building for NuttX * Building for NuttX
*/ */
#include <nuttx/config.h>
#include <uORB/uORB.h> #include <uORB/uORB.h>
#include <uORB/topics/rc_channels.h>
#include <systemlib/err.h>
#define PX4_WARN warnx
#define PX4_INFO warnx
#define PX4_TOPIC(name) ORB_ID(name)
#endif #endif
#include "../platforms/px4_defines.h" #include "../platforms/px4_defines.h"
+1
View File
@@ -48,6 +48,7 @@
#include "topics/actuator_outputs.h" #include "topics/actuator_outputs.h"
#include "topics/encoders.h" #include "topics/encoders.h"
#include "topics/tecs_status.h" #include "topics/tecs_status.h"
#include "topics/rc_channels.h"
namespace uORB { namespace uORB {
+1
View File
@@ -52,6 +52,7 @@
#include "topics/vehicle_local_position.h" #include "topics/vehicle_local_position.h"
#include "topics/vehicle_attitude_setpoint.h" #include "topics/vehicle_attitude_setpoint.h"
#include "topics/vehicle_rates_setpoint.h" #include "topics/vehicle_rates_setpoint.h"
#include "topics/rc_channels.h"
namespace uORB namespace uORB
{ {
+2 -1
View File
@@ -37,6 +37,7 @@
SRCS = px4_nuttx_impl.cpp \ SRCS = px4_nuttx_impl.cpp \
px4_publisher.cpp \ px4_publisher.cpp \
px4_subscriber.cpp px4_subscriber.cpp \
px4_nodehandle.cpp
MAXOPTIMIZATION = -Os MAXOPTIMIZATION = -Os
+1 -1
View File
@@ -36,4 +36,4 @@
* *
* PX4 Middleware Wrapper Nodehandle * PX4 Middleware Wrapper Nodehandle
*/ */
#include <px4_nodehandle.h> #include <platforms/px4_nodehandle.h>
+5 -3
View File
@@ -38,6 +38,7 @@
*/ */
#include <px4.h> #include <px4.h>
#include <drivers/drv_hrt.h>
extern bool task_should_exit; extern bool task_should_exit;
@@ -46,8 +47,7 @@ namespace px4
void init(int argc, char *argv[], const char *process_name) void init(int argc, char *argv[], const char *process_name)
{ {
px4_warn("process: %s", process_name); PX4_WARN("process: %s", process_name);
return 0;
} }
uint64_t get_time_micros() uint64_t get_time_micros()
@@ -57,7 +57,9 @@ uint64_t get_time_micros()
bool ok() bool ok()
{ {
return !task_should_exit; // return !task_should_exit;
//XXX
return true;
} }
void spin_once() void spin_once()
+1
View File
@@ -36,5 +36,6 @@
* *
* PX4 Middleware Wrapper for Publisher * PX4 Middleware Wrapper for Publisher
*/ */
#include <platforms/px4_publisher.h>
+1 -1
View File
@@ -36,5 +36,5 @@
* *
* PX4 Middleware Wrapper Subscriber * PX4 Middleware Wrapper Subscriber
*/ */
#include <platforms/px4_subscriber.h>
+20 -3
View File
@@ -44,8 +44,25 @@
* Building for running within the ROS environment * Building for running within the ROS environment
*/ */
#define __EXPORT #define __EXPORT
#define PX4_MAIN_FUNCTION(_prefix) // #define PX4_MAIN_FUNCTION(_prefix)
#define PX4_MAIN_FUNCTION(_prefix) int main(int argc, char **argv)
#define PX4_WARN ROS_WARN
#define PX4_INFO ROS_INFO
#define PX4_TOPIC(name) #name
#define PX4_TOPIC_T(name) name
#else #else
#include <nuttx/config.h> /*
#define PX4_MAIN_FUNCTION(_prefix) __EXPORT int _prefix##main(int argc, char **argv)() { return main(argc, argv); } * Building for NuttX
*/
// #define PX4_MAIN_FUNCTION(_prefix) __EXPORT int _prefix##_main(int argc, char **argv)() { return main(argc, argv); }
// #define PX4_MAIN_FUNCTION(_prefix) extern "C" __EXPORT int _prefix##_main(int argc, char *argv[]) { return main(argc, argv); }
#define PX4_MAIN_FUNCTION(_prefix) extern "C" __EXPORT int _prefix##_main(int argc, char *argv[])
#define PX4_WARN warnx
#define PX4_WARN warnx
#define PX4_INFO warnx
#define PX4_TOPIC(name) ORB_ID(name)
#define PX4_TOPIC_T(name) name##_s
#endif #endif
+6 -5
View File
@@ -40,19 +40,20 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <unistd.h>
namespace px4 namespace px4
{ {
void init(int argc, char *argv[], const char *process_name); __EXPORT void init(int argc, char *argv[], const char *process_name);
uint64_t get_time_micros(); __EXPORT uint64_t get_time_micros();
bool ok(); __EXPORT bool ok();
void spin_once(); __EXPORT void spin_once();
void spin(); __EXPORT void spin();
class Rate class Rate
{ {
+12 -11
View File
@@ -39,8 +39,8 @@
#pragma once #pragma once
/* includes for all platforms */ /* includes for all platforms */
#include <px4_subscriber.h> #include "px4_subscriber.h"
#include <px4_publisher.h> #include "px4_publisher.h"
#if defined(__linux) || (defined(__APPLE__) && defined(__MACH__)) #if defined(__linux) || (defined(__APPLE__) && defined(__MACH__))
/* includes when building for ros */ /* includes when building for ros */
@@ -49,7 +49,6 @@
#include <inttypes.h> #include <inttypes.h>
#else #else
/* includes when building for NuttX */ /* includes when building for NuttX */
#include <containers/List.hpp>
#endif #endif
namespace px4 namespace px4
@@ -90,7 +89,7 @@ private:
std::list<Publisher> _pubs; std::list<Publisher> _pubs;
}; };
#else #else
class NodeHandle class __EXPORT NodeHandle
{ {
public: public:
NodeHandle() : NodeHandle() :
@@ -101,20 +100,22 @@ public:
~NodeHandle() {}; ~NodeHandle() {};
template<typename M> template<typename M>
Subscriber subscribe(const char *topic, void(*fp)(M)) { Subscriber * subscribe(const struct orb_metadata *meta, void(*fp)(M)) {
Subscriber sub(&_subs, , interval); unsigned interval = 0;//XXX decide how to wrap this, ros equivalent?
//XXX
Subscriber *sub = new Subscriber(meta, interval, fp, &_subs);
return sub; return sub;
} }
template<typename M> template<typename M>
Publisher advertise(const char *topic) { Publisher * advertise(const struct orb_metadata *meta) {
Publisher pub(ros_pub); //XXX
_pubs.push_back(pub); Publisher * pub = new Publisher(meta, &_pubs);
return pub; return pub;
} }
private: private:
List<Subscriber> _subs; List<uORB::SubscriptionNode*> _subs;
List<Publisher> _pubs; List<uORB::PublicationNode*> _pubs;
}; };
#endif #endif
+15 -6
View File
@@ -43,6 +43,7 @@
#else #else
/* includes when building for NuttX */ /* includes when building for NuttX */
#include <uORB/Publication.hpp> #include <uORB/Publication.hpp>
#include <containers/List.hpp>
#endif #endif
namespace px4 namespace px4
@@ -60,16 +61,24 @@ private:
ros::Publisher _ros_pub; ros::Publisher _ros_pub;
}; };
#else #else
template<typename M>
class Publisher : class Publisher :
public uORB::Publication<M> public uORB::PublicationNode
{
public: public:
Publisher(List<SubscriptionBase *> * list, Publisher(const struct orb_metadata *meta,
const struct orb_metadata *meta, unsigned interval) : List<uORB::PublicationNode *> * list) :
uORB::Publication(list, meta) uORB::PublicationNode(meta, list)
{} {}
~Publisher() {}; ~Publisher() {};
{ template<typename M>
int publish(const M &msg) {
uORB::PublicationBase::update((void*)&msg);
return 0;
}
void update() {
//XXX list traversal callback, needed?
} ;
}; };
#endif #endif
} }
+14 -6
View File
@@ -43,6 +43,7 @@
#else #else
/* includes when building for NuttX */ /* includes when building for NuttX */
#include <uORB/Subscription.hpp> #include <uORB/Subscription.hpp>
#include <containers/List.hpp>
#endif #endif
namespace px4 namespace px4
@@ -60,16 +61,23 @@ private:
ros::Subscriber _ros_sub; ros::Subscriber _ros_sub;
}; };
#else #else
template<typename M>
class Subscriber : class Subscriber :
public uORB::Subscription<M> public uORB::SubscriptionNode
{
public: public:
Subscriber(List<SubscriptionBase *> * list, template<typename M>
const struct orb_metadata *meta, unsigned interval) : Subscriber(const struct orb_metadata *meta,
uORB::Subsciption(list, meta, interval) unsigned interval,
void(*fp)(M),
List<uORB::SubscriptionNode *> * list) :
uORB::SubscriptionNode(meta, interval, list)
//XXX store callback
{} {}
~Subscriber() {}; ~Subscriber() {};
{
void update() {
//XXX list traversal callback, needed?
} ;
}; };
#endif #endif