I’m attempting to add a message to the PX4 firmware and I can quite seem to figure out how to fully implement it. I’m created and compiled a .msg file and began implementing functionality into mavlink_messages.cpp. Here’s the relevant code so I can highlight the problem:
versatol.msg
#VERSATOL
uint64 timestamp # time since system start (microseconds)
float32 voltage_v # Battery voltage in volts, 0 if unknown
uORB/topics/versatol.h
#pragma once
#include <uORB/uORB.h>
#ifndef __cplusplus
#endif
#ifdef __cplusplus
struct __EXPORT versatol_s {
#else
struct versatol_s {
#endif
uint64_t timestamp;
float voltage_v;
uint8_t _padding0[4]; // required for logger
#ifdef __cplusplus
#endif
};
/* register this as object request broker structure */
ORB_DECLARE(versatol);
#ifdef __cplusplus
void print_message(const versatol_s& message);
#endif
mavlink_messages.cpp
class MavlinkStreamVersatol : public MavlinkStream{
public:
const char *get_name() const override{
return MavlinkStreamVersatol::get_name_static();
}
static const char *get_name_static(){
return "VERSATOL";
}
static uint16_t get_id_static(){
return MAVLINK_MSG_ID_VERSATOL;
}
uint16_t get_id(){
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink){
return new MavlinkStreamVersatol(mavlink);
}
unsigned get_size(){
return MAVLINK_MSG_ID_VERSATOL_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
}
private:
MavlinkOrbSubscription *_sub;
uint64_t _voltage_v;
/* do not allow top copying this class */
MavlinkStreamVersatol(MavlinkStreamVersatol&);
MavlinkStreamVersatol& operator = (const MavlinkStreamVersatol &);
protected:
explicit MavlinkStreamVersatol(Mavlink *mavlink) : MavlinkStream(mavlink),
_sub(_mavlink->add_orb_subscription(ORB_ID(versatol))), // make sure you enter the name of your uORB topic here
_voltage_v(0)
{}
bool send(const hrt_abstime t)
{
struct versatol_s _versatol;
if(_sub->update(&_voltage_v, &_versatol)) {
mavlink_versatol_t _msg_versatol;
_msg_versatol.timestamp = _versatol.timestamp;
_msg_versatol.time_start_usec = _versatol.time_start_usec;
_msg_versatol.time_stop_usec = _versatol.time_stop_usec;
_msg_versatol.coefficients =_versatol.coefficients;
_msg_versatol.seq_id = _versatol.seq_id;
mavlink_msg_versatol_send_struct(_mavlink->get_channel(), &_msg_versatol);
}
return true;
}
};
The problem I’m having is the header file that contains MAVLINK_MSG_ID_VERSATOL is not being generated, so I can’t include it. I’m not sure if I’m doing this wrong or if I’m missing a step. Everything up to including that has worked fine. I know px_generate_uorb_topic.py exists but it doesn’t seem to have generated anything useful as far as I can tell either. Really not sure where to go forward. Thanks.