mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-03 04:21:36 +08:00
Upgrade UAVCAN to multi pub/sub A API
This commit is contained in:
@@ -70,7 +70,7 @@ MODULES += modules/commander
|
|||||||
MODULES += modules/navigator
|
MODULES += modules/navigator
|
||||||
MODULES += modules/mavlink
|
MODULES += modules/mavlink
|
||||||
MODULES += modules/gpio_led
|
MODULES += modules/gpio_led
|
||||||
#MODULES += modules/uavcan
|
MODULES += modules/uavcan
|
||||||
MODULES += modules/land_detector
|
MODULES += modules/land_detector
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2013 PX4 Development Team. All rights reserved.
|
# Copyright (c) 2013-2015 PX4 Development Team. All rights reserved.
|
||||||
# Author: Pavel Kirienko <pavel.kirienko@gmail.com>
|
# Author: Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -38,15 +38,10 @@
|
|||||||
#include "baro.hpp"
|
#include "baro.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
static const orb_id_t BARO_TOPICS[2] = {
|
|
||||||
ORB_ID(sensor_baro0),
|
|
||||||
ORB_ID(sensor_baro1)
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *const UavcanBarometerBridge::NAME = "baro";
|
const char *const UavcanBarometerBridge::NAME = "baro";
|
||||||
|
|
||||||
UavcanBarometerBridge::UavcanBarometerBridge(uavcan::INode& node) :
|
UavcanBarometerBridge::UavcanBarometerBridge(uavcan::INode& node) :
|
||||||
UavcanCDevSensorBridgeBase("uavcan_baro", "/dev/uavcan/baro", BARO_DEVICE_PATH, BARO_TOPICS),
|
UavcanCDevSensorBridgeBase("uavcan_baro", "/dev/uavcan/baro", BARO_DEVICE_PATH, ORB_ID(sensor_baro)),
|
||||||
_sub_air_data(node)
|
_sub_air_data(node)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -39,16 +39,10 @@
|
|||||||
|
|
||||||
#include <systemlib/err.h>
|
#include <systemlib/err.h>
|
||||||
|
|
||||||
static const orb_id_t MAG_TOPICS[3] = {
|
|
||||||
ORB_ID(sensor_mag0),
|
|
||||||
ORB_ID(sensor_mag1),
|
|
||||||
ORB_ID(sensor_mag2)
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *const UavcanMagnetometerBridge::NAME = "mag";
|
const char *const UavcanMagnetometerBridge::NAME = "mag";
|
||||||
|
|
||||||
UavcanMagnetometerBridge::UavcanMagnetometerBridge(uavcan::INode& node) :
|
UavcanMagnetometerBridge::UavcanMagnetometerBridge(uavcan::INode& node) :
|
||||||
UavcanCDevSensorBridgeBase("uavcan_mag", "/dev/uavcan/mag", MAG_DEVICE_PATH, MAG_TOPICS),
|
UavcanCDevSensorBridgeBase("uavcan_mag", "/dev/uavcan/mag", MAG_DEVICE_PATH, ORB_ID(sensor_mag)),
|
||||||
_sub_mag(node)
|
_sub_mag(node)
|
||||||
{
|
{
|
||||||
_device_id.devid_s.devtype = DRV_MAG_DEVTYPE_HMC5883;
|
_device_id.devid_s.devtype = DRV_MAG_DEVTYPE_HMC5883;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ UavcanCDevSensorBridgeBase::~UavcanCDevSensorBridgeBase()
|
|||||||
(void)unregister_class_devname(_class_devname, _channels[i].class_instance);
|
(void)unregister_class_devname(_class_devname, _channels[i].class_instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] _orb_topics;
|
|
||||||
delete [] _channels;
|
delete [] _channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,11 +115,10 @@ void UavcanCDevSensorBridgeBase::publish(const int node_id, const void *report)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Publish to the appropriate topic, abort on failure
|
// Publish to the appropriate topic, abort on failure
|
||||||
channel->orb_id = _orb_topics[class_instance];
|
|
||||||
channel->node_id = node_id;
|
channel->node_id = node_id;
|
||||||
channel->class_instance = class_instance;
|
channel->class_instance = class_instance;
|
||||||
|
|
||||||
channel->orb_advert = orb_advertise(channel->orb_id, report);
|
channel->orb_advert = orb_advertise_multi(_orb_topic, report, &channel->orb_instance, ORB_PRIO_HIGH);
|
||||||
if (channel->orb_advert < 0) {
|
if (channel->orb_advert < 0) {
|
||||||
log("ADVERTISE FAILED");
|
log("ADVERTISE FAILED");
|
||||||
(void)unregister_class_devname(_class_devname, class_instance);
|
(void)unregister_class_devname(_class_devname, class_instance);
|
||||||
@@ -132,7 +130,7 @@ void UavcanCDevSensorBridgeBase::publish(const int node_id, const void *report)
|
|||||||
}
|
}
|
||||||
assert(channel != nullptr);
|
assert(channel != nullptr);
|
||||||
|
|
||||||
(void)orb_publish(channel->orb_id, channel->orb_advert, report);
|
(void)orb_publish(_orb_topic, channel->orb_advert, report);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned UavcanCDevSensorBridgeBase::get_num_redundant_channels() const
|
unsigned UavcanCDevSensorBridgeBase::get_num_redundant_channels() const
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 PX4 Development Team. All rights reserved.
|
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -90,28 +90,27 @@ class UavcanCDevSensorBridgeBase : public IUavcanSensorBridge, public device::CD
|
|||||||
struct Channel
|
struct Channel
|
||||||
{
|
{
|
||||||
int node_id = -1;
|
int node_id = -1;
|
||||||
orb_id_t orb_id = nullptr;
|
|
||||||
orb_advert_t orb_advert = -1;
|
orb_advert_t orb_advert = -1;
|
||||||
int class_instance = -1;
|
int class_instance = -1;
|
||||||
|
int orb_instance = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const unsigned _max_channels;
|
const unsigned _max_channels;
|
||||||
const char *const _class_devname;
|
const char *const _class_devname;
|
||||||
orb_id_t *const _orb_topics;
|
const orb_id_t _orb_topic;
|
||||||
Channel *const _channels;
|
Channel *const _channels;
|
||||||
bool _out_of_channels = false;
|
bool _out_of_channels = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <unsigned MaxChannels>
|
template <unsigned MaxChannels>
|
||||||
UavcanCDevSensorBridgeBase(const char *name, const char *devname, const char *class_devname,
|
UavcanCDevSensorBridgeBase(const char *name, const char *devname, const char *class_devname,
|
||||||
const orb_id_t (&orb_topics)[MaxChannels]) :
|
const orb_id_t orb_topic_sensor) :
|
||||||
device::CDev(name, devname),
|
device::CDev(name, devname),
|
||||||
_max_channels(MaxChannels),
|
_max_channels(MaxChannels),
|
||||||
_class_devname(class_devname),
|
_class_devname(class_devname),
|
||||||
_orb_topics(new orb_id_t[MaxChannels]),
|
_orb_topic(orb_topic_sensor),
|
||||||
_channels(new Channel[MaxChannels])
|
_channels(new Channel[MaxChannels])
|
||||||
{
|
{
|
||||||
memcpy(_orb_topics, orb_topics, sizeof(orb_id_t) * MaxChannels);
|
|
||||||
_device_id.devid_s.bus_type = DeviceBusType_UAVCAN;
|
_device_id.devid_s.bus_type = DeviceBusType_UAVCAN;
|
||||||
_device_id.devid_s.bus = 0;
|
_device_id.devid_s.bus = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user