mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 19:32:36 +08:00
Merge remote-tracking branch 'upstream/uorbtinymerge' into dev_ros
This commit is contained in:
@@ -65,7 +65,7 @@ RoboClaw::RoboClaw(const char *deviceName, uint16_t address,
|
|||||||
_pulsesPerRev(pulsesPerRev),
|
_pulsesPerRev(pulsesPerRev),
|
||||||
_uart(0),
|
_uart(0),
|
||||||
_controlPoll(),
|
_controlPoll(),
|
||||||
_actuators(NULL, ORB_ID(actuator_controls_0), 20),
|
_actuators(ORB_ID(actuator_controls_0), 20),
|
||||||
_motor1Position(0),
|
_motor1Position(0),
|
||||||
_motor1Speed(0),
|
_motor1Speed(0),
|
||||||
_motor1Overflow(0),
|
_motor1Overflow(0),
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ void Block::updateParams()
|
|||||||
|
|
||||||
void Block::updateSubscriptions()
|
void Block::updateSubscriptions()
|
||||||
{
|
{
|
||||||
uORB::SubscriptionBase *sub = getSubscriptions().getHead();
|
uORB::SubscriptionNode *sub = getSubscriptions().getHead();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (sub != NULL) {
|
while (sub != NULL) {
|
||||||
@@ -119,7 +119,7 @@ void Block::updateSubscriptions()
|
|||||||
|
|
||||||
void Block::updatePublications()
|
void Block::updatePublications()
|
||||||
{
|
{
|
||||||
uORB::PublicationBase *pub = getPublications().getHead();
|
uORB::PublicationNode *pub = getPublications().getHead();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (pub != NULL) {
|
while (pub != NULL) {
|
||||||
|
|||||||
@@ -46,8 +46,8 @@
|
|||||||
|
|
||||||
// forward declaration
|
// forward declaration
|
||||||
namespace uORB {
|
namespace uORB {
|
||||||
class SubscriptionBase;
|
class SubscriptionNode;
|
||||||
class PublicationBase;
|
class PublicationNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace control
|
namespace control
|
||||||
@@ -83,15 +83,15 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// accessors
|
// accessors
|
||||||
SuperBlock *getParent() { return _parent; }
|
SuperBlock *getParent() { return _parent; }
|
||||||
List<uORB::SubscriptionBase *> & getSubscriptions() { return _subscriptions; }
|
List<uORB::SubscriptionNode *> & getSubscriptions() { return _subscriptions; }
|
||||||
List<uORB::PublicationBase *> & getPublications() { return _publications; }
|
List<uORB::PublicationNode *> & getPublications() { return _publications; }
|
||||||
List<BlockParamBase *> & getParams() { return _params; }
|
List<BlockParamBase *> & getParams() { return _params; }
|
||||||
// attributes
|
// attributes
|
||||||
const char *_name;
|
const char *_name;
|
||||||
SuperBlock *_parent;
|
SuperBlock *_parent;
|
||||||
float _dt;
|
float _dt;
|
||||||
List<uORB::SubscriptionBase *> _subscriptions;
|
List<uORB::SubscriptionNode *> _subscriptions;
|
||||||
List<uORB::PublicationBase *> _publications;
|
List<uORB::PublicationNode *> _publications;
|
||||||
List<BlockParamBase *> _params;
|
List<BlockParamBase *> _params;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -82,16 +82,16 @@ void BlockWaypointGuidance::update(vehicle_global_position_s &pos,
|
|||||||
BlockUorbEnabledAutopilot::BlockUorbEnabledAutopilot(SuperBlock *parent, const char *name) :
|
BlockUorbEnabledAutopilot::BlockUorbEnabledAutopilot(SuperBlock *parent, const char *name) :
|
||||||
SuperBlock(parent, name),
|
SuperBlock(parent, name),
|
||||||
// subscriptions
|
// subscriptions
|
||||||
_att(&getSubscriptions(), ORB_ID(vehicle_attitude), 20),
|
_att(ORB_ID(vehicle_attitude), 20, &getSubscriptions()),
|
||||||
_attCmd(&getSubscriptions(), ORB_ID(vehicle_attitude_setpoint), 20),
|
_attCmd(ORB_ID(vehicle_attitude_setpoint), 20, &getSubscriptions()),
|
||||||
_ratesCmd(&getSubscriptions(), ORB_ID(vehicle_rates_setpoint), 20),
|
_ratesCmd(ORB_ID(vehicle_rates_setpoint), 20, &getSubscriptions()),
|
||||||
_pos(&getSubscriptions() , ORB_ID(vehicle_global_position), 20),
|
_pos(ORB_ID(vehicle_global_position), 20, &getSubscriptions()),
|
||||||
_missionCmd(&getSubscriptions(), ORB_ID(position_setpoint_triplet), 20),
|
_missionCmd(ORB_ID(position_setpoint_triplet), 20, &getSubscriptions()),
|
||||||
_manual(&getSubscriptions(), ORB_ID(manual_control_setpoint), 20),
|
_manual(ORB_ID(manual_control_setpoint), 20, &getSubscriptions()),
|
||||||
_status(&getSubscriptions(), ORB_ID(vehicle_status), 20),
|
_status(ORB_ID(vehicle_status), 20, &getSubscriptions()),
|
||||||
_param_update(&getSubscriptions(), ORB_ID(parameter_update), 1000), // limit to 1 Hz
|
_param_update(ORB_ID(parameter_update), 1000, &getSubscriptions()), // limit to 1 Hz
|
||||||
// publications
|
// publications
|
||||||
_actuators(&getPublications(), ORB_ID(actuator_controls_0))
|
_actuators(ORB_ID(actuator_controls_0), &getPublications())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ mTecs::mTecs() :
|
|||||||
_mTecsEnabled(this, "ENABLED"),
|
_mTecsEnabled(this, "ENABLED"),
|
||||||
_airspeedMin(this, "FW_AIRSPD_MIN", false),
|
_airspeedMin(this, "FW_AIRSPD_MIN", false),
|
||||||
/* Publications */
|
/* Publications */
|
||||||
_status(&getPublications(), ORB_ID(tecs_status)),
|
_status(ORB_ID(tecs_status), &getPublications()),
|
||||||
/* control blocks */
|
/* control blocks */
|
||||||
_controlTotalEnergy(this, "THR"),
|
_controlTotalEnergy(this, "THR"),
|
||||||
_controlEnergyDistribution(this, "PIT", true),
|
_controlEnergyDistribution(this, "PIT", true),
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ namespace uORB {
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Publication<T>::Publication(
|
Publication<T>::Publication(
|
||||||
List<PublicationBase *> * list,
|
const struct orb_metadata *meta,
|
||||||
const struct orb_metadata *meta) :
|
List<PublicationNode *> * list) :
|
||||||
T(), // initialize data structure to zero
|
T(), // initialize data structure to zero
|
||||||
PublicationBase(list, meta) {
|
PublicationNode(meta, list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
#include <containers/List.hpp>
|
#include <containers/List.hpp>
|
||||||
|
|
||||||
@@ -49,55 +51,112 @@ namespace uORB
|
|||||||
* Base publication warapper class, used in list traversal
|
* Base publication warapper class, used in list traversal
|
||||||
* of various publications.
|
* of various publications.
|
||||||
*/
|
*/
|
||||||
class __EXPORT PublicationBase : public ListNode<uORB::PublicationBase *>
|
class __EXPORT PublicationBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PublicationBase(
|
/**
|
||||||
List<PublicationBase *> * list,
|
* Constructor
|
||||||
const struct orb_metadata *meta) :
|
*
|
||||||
|
*
|
||||||
|
* @param meta The uORB metadata (usually from the ORB_ID()
|
||||||
|
* macro) for the topic.
|
||||||
|
*/
|
||||||
|
PublicationBase(const struct orb_metadata *meta) :
|
||||||
_meta(meta),
|
_meta(meta),
|
||||||
_handle(-1) {
|
_handle(-1) {
|
||||||
if (list != NULL) list->add(this);
|
|
||||||
}
|
}
|
||||||
void update() {
|
|
||||||
|
/**
|
||||||
|
* Update the struct
|
||||||
|
* @param data The uORB message struct we are updating.
|
||||||
|
*/
|
||||||
|
void update(void * data) {
|
||||||
if (_handle > 0) {
|
if (_handle > 0) {
|
||||||
orb_publish(getMeta(), getHandle(), getDataVoidPtr());
|
orb_publish(getMeta(), getHandle(), data);
|
||||||
} else {
|
} else {
|
||||||
setHandle(orb_advertise(getMeta(), getDataVoidPtr()));
|
setHandle(orb_advertise(getMeta(), data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void *getDataVoidPtr() = 0;
|
|
||||||
|
/**
|
||||||
|
* Deconstructor
|
||||||
|
*/
|
||||||
virtual ~PublicationBase() {
|
virtual ~PublicationBase() {
|
||||||
orb_unsubscribe(getHandle());
|
orb_unsubscribe(getHandle());
|
||||||
}
|
}
|
||||||
|
// accessors
|
||||||
const struct orb_metadata *getMeta() { return _meta; }
|
const struct orb_metadata *getMeta() { return _meta; }
|
||||||
int getHandle() { return _handle; }
|
int getHandle() { return _handle; }
|
||||||
protected:
|
protected:
|
||||||
|
// accessors
|
||||||
void setHandle(orb_advert_t handle) { _handle = handle; }
|
void setHandle(orb_advert_t handle) { _handle = handle; }
|
||||||
|
// attributes
|
||||||
const struct orb_metadata *_meta;
|
const struct orb_metadata *_meta;
|
||||||
orb_advert_t _handle;
|
orb_advert_t _handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* alias class name so it is clear that the base class
|
||||||
|
* can be used by itself if desired
|
||||||
|
*/
|
||||||
|
typedef PublicationBase PublicationTiny;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The publication base class as a list node.
|
||||||
|
*/
|
||||||
|
class __EXPORT PublicationNode :
|
||||||
|
public PublicationBase,
|
||||||
|
public ListNode<PublicationNode *>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param meta The uORB metadata (usually from the ORB_ID()
|
||||||
|
* macro) for the topic.
|
||||||
|
* @param list A pointer to a list of subscriptions
|
||||||
|
* that this should be appended to.
|
||||||
|
*/
|
||||||
|
PublicationNode(const struct orb_metadata *meta,
|
||||||
|
List<PublicationNode *> * list=nullptr) :
|
||||||
|
PublicationBase(meta) {
|
||||||
|
if (list != nullptr) list->add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is the callback for list traversal
|
||||||
|
* updates, a child class must implement it.
|
||||||
|
*/
|
||||||
|
virtual void update() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publication wrapper class
|
* Publication wrapper class
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
class Publication :
|
class Publication :
|
||||||
public T, // this must be first!
|
public T, // this must be first!
|
||||||
public PublicationBase
|
public PublicationNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param list A list interface for adding to list during construction
|
* @param meta The uORB metadata (usually from
|
||||||
* @param meta The uORB metadata (usually from the ORB_ID() macro)
|
* the ORB_ID() macro) for the topic.
|
||||||
* for the topic.
|
* @param list A list interface for adding to
|
||||||
|
* list during construction
|
||||||
*/
|
*/
|
||||||
Publication(List<PublicationBase *> * list,
|
Publication(const struct orb_metadata *meta,
|
||||||
const struct orb_metadata *meta);
|
List<PublicationNode *> * list=nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deconstructor
|
||||||
|
**/
|
||||||
virtual ~Publication();
|
virtual ~Publication();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
* This function gets the T struct, assuming
|
* This function gets the T struct, assuming
|
||||||
@@ -106,6 +165,13 @@ public:
|
|||||||
* seem to be available
|
* seem to be available
|
||||||
*/
|
*/
|
||||||
void *getDataVoidPtr();
|
void *getDataVoidPtr();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an update function that uses the embedded struct.
|
||||||
|
*/
|
||||||
|
void update() {
|
||||||
|
PublicationBase::update(getDataVoidPtr());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace uORB
|
} // namespace uORB
|
||||||
|
|||||||
@@ -56,21 +56,13 @@
|
|||||||
namespace uORB
|
namespace uORB
|
||||||
{
|
{
|
||||||
|
|
||||||
bool __EXPORT SubscriptionBase::updated()
|
|
||||||
{
|
|
||||||
bool isUpdated = false;
|
|
||||||
orb_check(_handle, &isUpdated);
|
|
||||||
return isUpdated;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Subscription<T>::Subscription(
|
Subscription<T>::Subscription(
|
||||||
List<SubscriptionBase *> * list,
|
const struct orb_metadata *meta,
|
||||||
const struct orb_metadata *meta, unsigned interval) :
|
unsigned interval,
|
||||||
|
List<SubscriptionNode *> * list) :
|
||||||
T(), // initialize data structure to zero
|
T(), // initialize data structure to zero
|
||||||
SubscriptionBase(list, meta) {
|
SubscriptionNode(meta, interval, list) {
|
||||||
setHandle(orb_subscribe(getMeta()));
|
|
||||||
orb_set_interval(getHandle(), interval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
#include <containers/List.hpp>
|
#include <containers/List.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace uORB
|
namespace uORB
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -49,8 +50,7 @@ namespace uORB
|
|||||||
* Base subscription warapper class, used in list traversal
|
* Base subscription warapper class, used in list traversal
|
||||||
* of various subscriptions.
|
* of various subscriptions.
|
||||||
*/
|
*/
|
||||||
class __EXPORT SubscriptionBase :
|
class __EXPORT SubscriptionBase
|
||||||
public ListNode<SubscriptionBase *>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// methods
|
// methods
|
||||||
@@ -58,23 +58,42 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param meta The uORB metadata (usually from the ORB_ID() macro)
|
* @param meta The uORB metadata (usually from the ORB_ID()
|
||||||
* for the topic.
|
* macro) for the topic.
|
||||||
|
*
|
||||||
|
* @param interval The minimum interval in milliseconds
|
||||||
|
* between updates
|
||||||
*/
|
*/
|
||||||
SubscriptionBase(
|
SubscriptionBase(const struct orb_metadata *meta,
|
||||||
List<SubscriptionBase *> * list,
|
unsigned interval=0) :
|
||||||
const struct orb_metadata *meta) :
|
|
||||||
_meta(meta),
|
_meta(meta),
|
||||||
_handle() {
|
_handle() {
|
||||||
if (list != NULL) list->add(this);
|
setHandle(orb_subscribe(getMeta()));
|
||||||
|
orb_set_interval(getHandle(), interval);
|
||||||
}
|
}
|
||||||
bool updated();
|
|
||||||
void update() {
|
/**
|
||||||
|
* Check if there is a new update.
|
||||||
|
* */
|
||||||
|
bool updated() {
|
||||||
|
bool isUpdated = false;
|
||||||
|
orb_check(_handle, &isUpdated);
|
||||||
|
return isUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the struct
|
||||||
|
* @param data The uORB message struct we are updating.
|
||||||
|
*/
|
||||||
|
void update(void * data) {
|
||||||
if (updated()) {
|
if (updated()) {
|
||||||
orb_copy(_meta, _handle, getDataVoidPtr());
|
orb_copy(_meta, _handle, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual void *getDataVoidPtr() = 0;
|
|
||||||
|
/**
|
||||||
|
* Deconstructor
|
||||||
|
*/
|
||||||
virtual ~SubscriptionBase() {
|
virtual ~SubscriptionBase() {
|
||||||
orb_unsubscribe(_handle);
|
orb_unsubscribe(_handle);
|
||||||
}
|
}
|
||||||
@@ -90,30 +109,79 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription wrapper class
|
* alias class name so it is clear that the base class
|
||||||
*/
|
*/
|
||||||
template<class T>
|
typedef SubscriptionBase SubscriptionTiny;
|
||||||
class __EXPORT Subscription :
|
|
||||||
public T, // this must be first!
|
/**
|
||||||
public SubscriptionBase
|
* The publication base class as a list node.
|
||||||
|
*/
|
||||||
|
class __EXPORT SubscriptionNode :
|
||||||
|
|
||||||
|
public SubscriptionBase,
|
||||||
|
public ListNode<SubscriptionNode *>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param list A list interface for adding to list during construction
|
*
|
||||||
* @param meta The uORB metadata (usually from the ORB_ID() macro)
|
* @param meta The uORB metadata (usually from the ORB_ID()
|
||||||
* for the topic.
|
* macro) for the topic.
|
||||||
* @param interval The minimum interval in milliseconds between updates
|
* @param interval The minimum interval in milliseconds
|
||||||
|
* between updates
|
||||||
|
* @param list A pointer to a list of subscriptions
|
||||||
|
* that this should be appended to.
|
||||||
*/
|
*/
|
||||||
Subscription(
|
SubscriptionNode(const struct orb_metadata *meta,
|
||||||
List<SubscriptionBase *> * list,
|
unsigned interval=0,
|
||||||
const struct orb_metadata *meta, unsigned interval);
|
List<SubscriptionNode *> * list=nullptr) :
|
||||||
|
SubscriptionBase(meta, interval) {
|
||||||
|
if (list != nullptr) list->add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is the callback for list traversal
|
||||||
|
* updates, a child class must implement it.
|
||||||
|
*/
|
||||||
|
virtual void update() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscription wrapper class
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
class __EXPORT Subscription :
|
||||||
|
public T, // this must be first!
|
||||||
|
public SubscriptionNode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param meta The uORB metadata (usually from
|
||||||
|
* the ORB_ID() macro) for the topic.
|
||||||
|
* @param interval The minimum interval in milliseconds
|
||||||
|
* between updates
|
||||||
|
* @param list A list interface for adding to
|
||||||
|
* list during construction
|
||||||
|
*/
|
||||||
|
Subscription(const struct orb_metadata *meta,
|
||||||
|
unsigned interval=0,
|
||||||
|
List<SubscriptionNode *> * list=nullptr);
|
||||||
/**
|
/**
|
||||||
* Deconstructor
|
* Deconstructor
|
||||||
*/
|
*/
|
||||||
virtual ~Subscription();
|
virtual ~Subscription();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an update function that uses the embedded struct.
|
||||||
|
*/
|
||||||
|
void update() {
|
||||||
|
SubscriptionBase::update(getDataVoidPtr());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
* This function gets the T struct, assuming
|
* This function gets the T struct, assuming
|
||||||
|
|||||||
Reference in New Issue
Block a user