mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 12:53:34 +08:00
initial minimal PX4_ROS2 platform and px4_ros2_default build (#20689)
- new ROS2 platform in PX4 intended for creating configs that build and run entirely in ROS2 - PX4_CONFIG defaults to px4_ros2_default if no config specified and in a colcon workspace with ROS_VERSION=2 - currently doesn't do much other than allow you to build px4 msgs interface package
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file Publication.hpp
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "uORB.h"
|
||||
|
||||
namespace uORB
|
||||
{
|
||||
|
||||
template <typename U> class DefaultQueueSize
|
||||
{
|
||||
private:
|
||||
template <typename T>
|
||||
static constexpr uint8_t get_queue_size(decltype(T::ORB_QUEUE_LENGTH) *)
|
||||
{
|
||||
return T::ORB_QUEUE_LENGTH;
|
||||
}
|
||||
|
||||
template <typename T> static constexpr uint8_t get_queue_size(...)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public:
|
||||
static constexpr unsigned value = get_queue_size<U>(nullptr);
|
||||
};
|
||||
|
||||
/**
|
||||
* uORB publication wrapper class
|
||||
*/
|
||||
template<typename T, uint8_t ORB_QSIZE = DefaultQueueSize<T>::value>
|
||||
class Publication
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param meta The uORB metadata (usually from the ORB_ID() macro) for the topic.
|
||||
*/
|
||||
Publication(rclcpp::Node *node, ORB_ID id) : _node(*node), _id(id)
|
||||
{
|
||||
_publisher = _node.create_publisher<T>(::get_topic_string(_id), ORB_QSIZE); // TODO
|
||||
}
|
||||
|
||||
bool advertised() { return (_publisher != nullptr); }
|
||||
|
||||
bool advertise()
|
||||
{
|
||||
if (!advertised()) {
|
||||
_publisher = _node.create_publisher<T>(get_topic_string(_id), ORB_QSIZE);
|
||||
}
|
||||
|
||||
return advertised();
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the struct
|
||||
* @param data The uORB message struct we are updating.
|
||||
*/
|
||||
bool publish(const T &data)
|
||||
{
|
||||
if (!advertised()) {
|
||||
advertise();
|
||||
}
|
||||
|
||||
_publisher->publish(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typename rclcpp::Publisher<T>::SharedPtr _publisher{nullptr};
|
||||
|
||||
rclcpp::Node &_node;
|
||||
|
||||
const ORB_ID _id;
|
||||
};
|
||||
|
||||
/**
|
||||
* The publication class with data embedded.
|
||||
*/
|
||||
template<typename T>
|
||||
class PublicationData : public Publication<T>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param meta The uORB metadata (usually from the ORB_ID() macro) for the topic.
|
||||
*/
|
||||
PublicationData(ORB_ID id) : Publication<T>(id) {}
|
||||
//PublicationData(const orb_metadata *meta) : Publication<T>(meta) {}
|
||||
|
||||
T &get() { return _data; }
|
||||
void set(const T &data) { _data = data; }
|
||||
|
||||
// Publishes the embedded struct.
|
||||
bool update() { return Publication<T>::publish(_data); }
|
||||
bool update(const T &data)
|
||||
{
|
||||
_data = data;
|
||||
return Publication<T>::publish(_data);
|
||||
}
|
||||
|
||||
private:
|
||||
T _data{};
|
||||
};
|
||||
|
||||
} // namespace uORB
|
||||
@@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file Subscription.hpp
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "uORB.h"
|
||||
|
||||
using std::placeholders::_1;
|
||||
|
||||
namespace uORB
|
||||
{
|
||||
|
||||
class SubscriptionCallback;
|
||||
|
||||
template<typename S>
|
||||
class Subscription2
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param id The uORB ORB_ID enum for the topic.
|
||||
* @param instance The instance for multi sub.
|
||||
*/
|
||||
Subscription2(rclcpp::Node *node, ORB_ID id, uint8_t instance = 0) :
|
||||
_node(*node),
|
||||
_id(id)
|
||||
{
|
||||
subscribe();
|
||||
|
||||
(void)instance; // TODO:
|
||||
}
|
||||
|
||||
~Subscription2()
|
||||
{
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
bool subscribe()
|
||||
{
|
||||
if (_subscription == nullptr) {
|
||||
_subscription = _node.create_subscription<S>(::get_topic_string(_id), 1, std::bind(&Subscription2<S>::topic_callback,
|
||||
this, _1));
|
||||
}
|
||||
|
||||
return (_subscription != nullptr);
|
||||
}
|
||||
|
||||
void unsubscribe() {}
|
||||
|
||||
bool valid() const { return _subscription != nullptr; }
|
||||
bool advertised()
|
||||
{
|
||||
if (valid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// try to initialize
|
||||
if (subscribe()) {
|
||||
// check again if valid
|
||||
if (valid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a new update.
|
||||
*/
|
||||
//bool updated() { return advertised() && _node->updates_available(_last_generation); }
|
||||
bool updated() { return true; }
|
||||
|
||||
/**
|
||||
* Update the struct
|
||||
* @param dst The uORB message struct we are updating.
|
||||
*/
|
||||
bool update(void *dst) { return updated() && copy(dst); }
|
||||
|
||||
/**
|
||||
* Copy the struct
|
||||
* @param dst The uORB message struct we are updating.
|
||||
*/
|
||||
bool copy(void *dst)
|
||||
{
|
||||
if (advertised()) {
|
||||
S msg{};
|
||||
//_subscription->return_message(&msg);
|
||||
memcpy(dst, &msg, sizeof(S));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change subscription instance
|
||||
* @param instance The new multi-Subscription instance
|
||||
*/
|
||||
bool ChangeInstance(uint8_t instance);
|
||||
|
||||
uint8_t get_instance() const { return _instance; }
|
||||
unsigned get_last_generation() const { return _last_generation; }
|
||||
orb_id_t get_topic() const { return get_orb_meta(_id); }
|
||||
|
||||
protected:
|
||||
|
||||
typename rclcpp::Subscription<S>::SharedPtr _subscription{nullptr};
|
||||
rclcpp::Node &_node;
|
||||
|
||||
unsigned _last_generation{0}; /**< last generation the subscriber has seen */
|
||||
|
||||
ORB_ID _id{ORB_ID::INVALID};
|
||||
uint8_t _instance{0};
|
||||
|
||||
private:
|
||||
void topic_callback(const typename S::SharedPtr msg)
|
||||
{
|
||||
(void)msg; // TODO
|
||||
//_msg_buffer = msg;
|
||||
_topic_generation++;
|
||||
}
|
||||
|
||||
S _msg_buffer[1];
|
||||
|
||||
uint32_t _topic_generation{0};
|
||||
};
|
||||
|
||||
} // namespace uORB
|
||||
@@ -0,0 +1,155 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file Subscription.hpp
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
#include "rclcpp/subscription_base.hpp"
|
||||
|
||||
#include "uORB.h"
|
||||
|
||||
namespace uORB
|
||||
{
|
||||
|
||||
// Base subscription wrapper class
|
||||
class SubscriptionBasic
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param id The uORB ORB_ID enum for the topic.
|
||||
* @param instance The instance for multi sub.
|
||||
*/
|
||||
Subscription(rclcpp::Node *node, ORB_ID id, uint8_t instance = 0) :
|
||||
_node(*node),
|
||||
_id(id)
|
||||
{
|
||||
subscribe();
|
||||
|
||||
(void)instance; // TODO:
|
||||
}
|
||||
|
||||
~Subscription()
|
||||
{
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
bool subscribe()
|
||||
{
|
||||
if (_subscription == nullptr) {
|
||||
//_subscription = _node.create_subscription<px4::msg::VehicleStatus>("vehicle_status", 1, std::bind(&Subscription::topic_callback, this, _1));
|
||||
}
|
||||
|
||||
return (_subscription != nullptr);
|
||||
}
|
||||
|
||||
void unsubscribe() {}
|
||||
|
||||
bool valid() const { return _subscription != nullptr; }
|
||||
bool advertised()
|
||||
{
|
||||
if (valid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// try to initialize
|
||||
if (subscribe()) {
|
||||
// check again if valid
|
||||
if (valid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is a new update.
|
||||
*/
|
||||
//bool updated() { return advertised() && _node->updates_available(_last_generation); }
|
||||
bool updated() { return true; }
|
||||
|
||||
/**
|
||||
* Update the struct
|
||||
* @param dst The uORB message struct we are updating.
|
||||
*/
|
||||
bool update(void *dst) { return updated() && copy(dst); }
|
||||
|
||||
/**
|
||||
* Copy the struct
|
||||
* @param dst The uORB message struct we are updating.
|
||||
*/
|
||||
bool copy(void *dst)
|
||||
{
|
||||
if (advertised()) {
|
||||
//_subscription->return_message(&msg);
|
||||
//memcpy(dst, &msg, sizeof(px4::msg::VehicleStatus));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change subscription instance
|
||||
* @param instance The new multi-Subscription instance
|
||||
*/
|
||||
bool ChangeInstance(uint8_t instance);
|
||||
|
||||
uint8_t get_instance() const { return _instance; }
|
||||
unsigned get_last_generation() const { return _last_generation; }
|
||||
orb_id_t get_topic() const { return get_orb_meta(_id); }
|
||||
|
||||
protected:
|
||||
|
||||
rclcpp::SubscriptionBase::SharedPtr _subscription{nullptr};
|
||||
rclcpp::Node &_node;
|
||||
|
||||
unsigned _last_generation{0}; /**< last generation the subscriber has seen */
|
||||
|
||||
ORB_ID _id{ORB_ID::INVALID};
|
||||
uint8_t _instance{0};
|
||||
|
||||
private:
|
||||
|
||||
uint32_t _topic_generation{0};
|
||||
};
|
||||
|
||||
} // namespace uORB
|
||||
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2021 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/**
|
||||
* Object metadata.
|
||||
*/
|
||||
struct orb_metadata {
|
||||
const char *o_name; /**< unique object name */
|
||||
const uint16_t o_size; /**< object size */
|
||||
const uint16_t o_size_no_padding; /**< object size w/o padding at the end (for logger) */
|
||||
const char *o_fields; /**< semicolon separated list of fields (with type) */
|
||||
uint8_t o_id; /**< ORB_ID enum */
|
||||
};
|
||||
|
||||
typedef const struct orb_metadata *orb_id_t;
|
||||
|
||||
/**
|
||||
* Maximum number of multi topic instances. This must be <= 10 (because it's the last char of the node path)
|
||||
*/
|
||||
#if defined(CONSTRAINED_MEMORY)
|
||||
# define ORB_MULTI_MAX_INSTANCES 4
|
||||
#else
|
||||
# define ORB_MULTI_MAX_INSTANCES 10
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define ORB_ID(_name) &__orb_##_name
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# define ORB_DECLARE(_name) extern "C" const struct orb_metadata __orb_##_name __EXPORT
|
||||
#else
|
||||
# define ORB_DECLARE(_name) extern const struct orb_metadata __orb_##_name __EXPORT
|
||||
#endif
|
||||
|
||||
|
||||
#define ORB_DEFINE(_name, _struct, _size_no_padding, _fields, _orb_id_enum) \
|
||||
const struct orb_metadata __orb_##_name = { \
|
||||
#_name, \
|
||||
sizeof(_struct), \
|
||||
_size_no_padding, \
|
||||
_fields, \
|
||||
_orb_id_enum \
|
||||
}; struct hack
|
||||
|
||||
/**
|
||||
* Print a topic to console. Do not call this directly, use print_message() instead.
|
||||
* @param meta orb topic metadata
|
||||
* @param data expected to be aligned to the largest member
|
||||
*/
|
||||
void orb_print_message_internal(const struct orb_metadata *meta, const void *data, bool print_topic_name);
|
||||
|
||||
#ifndef PX4_INFO_RAW
|
||||
# define PX4_INFO_RAW printf
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <uORBTopics.hpp>
|
||||
|
||||
#endif // __cplusplus
|
||||
Reference in New Issue
Block a user