I want to add custom mavlink msg which could show in QGC. Here is my process.
1 creat .msg files to msg, generate mavlink head files, and add it to the common floder
2 create my custom class in mavlink_messages.cpp and add it to the streams_list, finaly, add configure_stream(“Filter_Angle”, 10.0f); to the mavlink_main.cpp
3 write a file to publish my uorb msg.
But I dont know why it dont work. This my code.
.msg file and filter_angle.msg
uint32 timestamp_ms # in milliseconds since system start
char[10] key # max. 10 characters as key / name
float32 value # the value to send as debug output
//xml files
<?xml version="2.0"?>
<mavlink>
<include>common.xml</include>
<!-- NOTE: If the included file already contains a version tag, remove the version tag here, else uncomment to enable. -->
<!--<version>3</version>-->
<enums>
</enums>
<messages>
<message id="166" name="Filter_Angle">
<description>This message encodes all of the raw rudder sensor data from the USV.
</description>
<field type="uint32_t" name="time_boot_ms">Timestamp in milliseconds since system boot</field>
<field type="char[10]" name="name"></field>
<field type="float" name="value"></field>
</message>
</messages>
</mavlink>
Then generate the mavlink head files to the common folds
2 create my custom class in mavlink_message.cpp
class MavlinkStreamFilterAngle : public MavlinkStream
{
public:
const char *get_name() const
{
return MavlinkStreamFilterAngle::get_name_static();
}
static const char *get_name_static()
{
return "Filter_Angle";
}
static uint16_t get_id_static()
{
return MAVLINK_MSG_ID_Filter_Angle;
}
uint16_t get_id()
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamFilterAngle(mavlink);
}
unsigned get_size()
{
return (_debug_time > 0) ? MAVLINK_MSG_ID_Filter_Angle_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES : 0;
}
private:
MavlinkOrbSubscription *_debug_sub;
uint64_t _debug_time;
/* do not allow top copying this class */
MavlinkStreamFilterAngle(MavlinkStreamFilterAngle &) = delete;
MavlinkStreamFilterAngle &operator = (const MavlinkStreamFilterAngle &) = delete;
protected:
explicit MavlinkStreamFilterAngle(Mavlink *mavlink) : MavlinkStream(mavlink),
_debug_sub(_mavlink->add_orb_subscription(ORB_ID(vehicle_filter_attitude))),
_debug_time(0)
{}
bool send(const hrt_abstime t)
{
struct vehicle_filter_attitude_s debug;
if (_debug_sub->update(&_debug_time, &debug)) {
mavlink_filter_angle_t msg = {};
msg.time_boot_ms = debug.timestamp_ms;
memcpy(msg.name, debug.key, sizeof(msg.name));
/* enforce null termination */
msg.name[sizeof(msg.name) - 1] = '\0';
msg.value = debug.value;
mavlink_msg_filter_angle_send_struct(_mavlink->get_channel(), &msg);
return true;
}
return false;
}
};
and add it to the streams_list, finaly, add configure_stream(“Filter_Angle”, 10.0f); to the mavlink_main.cpp
finaly, write a file to publish my uorb msg.