Hi @dotanAtTrim , thanks for the reply
I think you may have misunderstood (or more likely I did not explain very well
)
The driver itself for the IMU is already written and publishing in the uORB topic described above. The confusion has probably come from my use of the word “position”, I mean that it describes the exact orientation of the IMU, not the rates of the IMU unlike other IMU’s that PX4 supports.
My specific issue is the actual message being sent over the canbus, as I cant use the standard messages as they are setup for receiving accelerometer and gyro rates.
I’ve attempted to write the publishing file and subscribing files with little success. I cant share my GitHub repo for various reasons but I can copy in my code here
Subscription cpp and hpp
// guess at attitude.cpp
#include "attitude.hpp"
#include <drivers/drv_hrt.h>
#include <uORB/topics/sensor_attitude.h>
const char *const UavcanAttitudeBridge::NAME = "attitude";
UavcanAttitudeBridge::UavcanAttitudeBridge(uavcan::INode &node) :
UavcanSensorBridgeBase("uavcan_attitude", ORB_ID(sensor_attitude)),
_sub_bno_data(node)
{ }
int UavcanAttitudeBridge::init()
{
int res = _sub_bno_data.start(BnoCbBinder(this, &UavcanAttitudeBridge::bno_sub_cb));
if (res < 0) {
DEVICE_LOG("failed to start uavcan sub: %d", res);
return res;
}
return 0;
}
void UavcanAttitudeBridge::bno_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::ahrs::Bno> &msg)
{
auto report = ::sensor_attitude_s();
report.timestamp = hrt_absolute_time();
report.device_id = get_device_id();
report.heading_deg = msg.heading;
report.pitch_deg = msg.pitch;
report.roll_deg = msg.roll;
publish(msg.getSrcNodeID().get(), &report);
}
int UavcanAttitudeBridge::init_driver(uavcan_bridge::Channel *channel)
{
return PX4_OK;
}
// guess at uavcan-sensors-hpp file for BNO055
#pragma once
#include "sensor_bridge.hpp"
#include <uavcan/equipment/ahrs/Bno.hpp>
class UavcanAttitudeBridge : public UavcanSensorBridgeBase
{
public:
static const char *const NAME;
UavcanAttitudeBridge(uavcan::INode &node);
const char *get_name() const override { return NAME; }
int init() override;
private:
void bno_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::ahrs::Bno> &msg);
int init_driver(uavcan_bridge::Channel *channel) override;
typedef uavcan::MethodBinder < UavcanAttitudeBridge *,
void (UavcanAttitudeBridge::*)
(const uavcan::ReceivedDataStructure<uavcan::equipment::ahrs::Bno> &) >
BnoCbBinder;
uavcan::Subscriber<uavcan::equipment::ahrs::Bno, BnoCbBinder> _sub_bno_data;
};
publisher
// attempt at uavcannode-publishers-Bno.hpp
#pragma once
#include "UavcanPublisherBase.hpp"
#include <uavcan/equipment/ahrs/Bno.hpp>
#include <uORB/SubscriptionCallback.hpp>
#include <uORB/topics/sensor_attitude.h>
namespace uavcannode
{
class Bno :
public UavcanPublisherBase,
public uORB::SubscriptionCallbackWorkItem,
private uavcan::Publisher<uavcan::equipment::ahrs::Bno>
{
public:
Bno(px4::WorkItem *work_item, uavcan::INode &node) :
UavcanPublisherBase(uavcan::equipment::ahrs::Bno::DefaultDataTypeID),
uORB::SubscriptionCallbackWorkItem(work_item, ORB_ID(sensor_attitude)),
uavcan::Publisher<uavcan::equipment::ahrs::Bno>(node)
{
this->setPriority(uavcan::TransferPriority::MiddleLower);
}
void PrintInfo() override
{
if (uORB::SubscriptionCallbackWorkItem::advertised()) {
printf("\t%s -> %s:%d\n",
uORB::SubscriptionCallbackWorkItem::get_topic()->o_name,
uavcan::equipment::ahrs::Bno::getDataTypeFullName(),
uavcan::equipment::ahrs::Bno::DefaultDataTypeID);
}
}
void BroadcastAnyUpdates() override
{
sensor_attitude_s _sensor_att;
if (uORB::SubscriptionCallbackWorkItem::update(&_sensor_att)) {
if (!getNode().getUtcTime().isZero()) {
uavcan::equipment::ahrs::Bno bno{};
bno.timestamp.usec = getNode().getUtcTime().toUSec() - (hrt_absolute_time() - _sensor_att.timestamp);
bno.
//bno.(this part will come from uavcan/snesor/.cpp file, see gyro.cpp for more) = xxx(from bno055 driver)
bno.heading = _sensor_att.heading_deg;
bno.pitch = _sensor_att.pitch_deg;
bno.roll = _sensor_att.roll_deg;
uavcan::Publisher<uavcan::equipment::ahrs::Bno>::broadcast(bno);
}
uORB::SubscriptionCallbackWorkItem::registerCallback();
}
}
};
} // namespace uavcannode
Thanks
Owen