Cannot Receive Custom Mavlink Message in Qgroundcontrol

Hello,

I have an issue with sending a custom mavlink message from px4 SITL and receiving it in QGroundControl.

Here is what I did so far

created file test_types.msg in /Firmware/msg
uint64 timestamp
float32[3] t
also added to CMakeLists.txt

created module template in Firmware/src/modules/module
module.cpp

void Module::run()
{
// Example: run the loop synchronized to the sensor_combined topic publication
int sensor_combined_sub = orb_subscribe(ORB_ID(sensor_combined));

struct test_types_s test;
memset(&test, 0, sizeof(test));
orb_advert_t test_pub = orb_advertise(ORB_ID(test_types), &test);

px4_pollfd_struct_t fds[1];
fds[0].fd = sensor_combined_sub;
fds[0].events = POLLIN;

// initialize parameters
parameters_update(true);

while (!should_exit()) {

// wait for up to 1000ms for data
int pret = px4_poll(fds, (sizeof(fds) / sizeof(fds[0])), 1000);

if (pret == 0) {
	// Timeout: let the loop run anyway, don't do `continue` here

} else if (pret < 0) {
	// this is undesirable but not much we can do
	PX4_ERR("poll error %d, %d", pret, errno);
	px4_usleep(50000);
	continue;

} else if (fds[0].revents & POLLIN) {

	struct sensor_combined_s sensor_combined;
	orb_copy(ORB_ID(sensor_combined), sensor_combined_sub, &sensor_combined);

    test.t[0] = sensor_combined.accelerometer_m_s2[0];
    test.t[1] = sensor_combined.accelerometer_m_s2[1];
    test.t[2] = sensor_combined.accelerometer_m_s2[2];

    orb_publish(ORB_ID(test_types), test_pub, &test);
	// TODO: do something with the data...

}

parameters_update();

}

orb_unsubscribe(sensor_combined_sub);

}

and added module start /home/niketan/Firmware/ROMFS/px4fmu_common/init.d-posix

created test_types.xml file Firmware/mavlink/include/mavlink/v2.0/message_definitions <?xml version="1.0"?>

common.xml 0 The attitude in the aeronautical frame (right-handed, Z-down, X-front, Y-right). Timestamp (time since system boot). Roll angle (-pi…+pi) Pitch angle (-pi…+pi) Yaw angle (-pi…+pi)

generated the files with Mavgenerate (GUI) 0utput Firmware/mavlink/include/mavlink/v2.0
i copy mavlink_msg_test_types.h to Firmware/mavlink/include/mavlink/v2.0/common
and include file in common.h

created class in mavlink_messages.cpp
class MavlinkStreamTestTypes : public MavlinkStream
{
public:
const char *get_name() const
{
return MavlinkStreamTestTypes::get_name_static();
}
static const char *get_name_static()
{
return “TEST_TYPES”;
}
static uint16_t get_id_static()
{
return MAVLINK_MSG_ID_TEST_TYPES;
}
uint16_t get_id()
{
return get_id_static();
}
static MavlinkStream *new_instance(Mavlink *mavlink)
{
return new MavlinkStreamTestTypes(mavlink);
}
unsigned get_size()
{
return MAVLINK_MSG_ID_TEST_TYPES_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
}

private:
MavlinkOrbSubscription *_sub;
uint64_t _ca_traj_time;

/* do not allow top copying this class */
MavlinkStreamTestTypes(MavlinkStreamTestTypes &);
MavlinkStreamTestTypes& operator = (const MavlinkStreamTestTypes &);

protected:
explicit MavlinkStreamTestTypes(Mavlink *mavlink) : MavlinkStream(mavlink),
_sub(_mavlink->add_orb_subscription(ORB_ID(test_types))), // make sure you enter the name of your uORB topic here
_ca_traj_time(0)
{}

bool send(const hrt_abstime t)
{
struct test_types_s _test; //make sure ca_traj_struct_s is the definition of your uORB topic

if (_sub->update(&_ca_traj_time, &_test)) {
    mavlink_test_types_t _msg_test_types{};  //make sure mavlink_ca_trajectory_t is the definition of your custom MAVLink message

    _msg_test_types.time_boot_ms_nik = _test.timestamp;
    _msg_test_types.roll_nik = _test.t[0];
    _msg_test_types.pitch_nik  = _test.t[1];
    _msg_test_types.yaw_nik = _test.t[2];

    //PX4_INFO("msg!");
    mavlink_msg_test_types_send_struct(_mavlink->get_channel(), &_msg_test_types);
}

return true;

}

};

also added
StreamListItem(&MavlinkStreamTestTypes::new_instance, &MavlinkStreamTestTypes::get_name_static, &MavlinkStreamTestTypes::get_id_static)

added in mavlink_main.cpp
MAVLINK_MODE_NORMAL
configure_stream_local(“TEST_TYPES”, 15.0f);
MAVLINK_MODE_ONBOARD
configure_stream_local(“TEST_TYPES”, 100.0f);
MAVLINK_MODE_EXTVISIONMIN
configure_stream_local(“TEST_TYPES”, 20.0f);
MAVLINK_MODE_OSD
configure_stream_local(“TEST_TYPES”, 25.0f);
MAVLINK_MODE_CONFIG
configure_stream_local(“TEST_TYPES”, 50.0f);
MAVLINK_MODE_MINIMAL
configure_stream_local(“TEST_TYPES”, 10.0f);

added module start and mavlink stream -r 50 -s TEST_TYPES -u $udp_gcs_port_local in /home/niketan/Firmware/ROMFS/px4fmu_common/init.d-posix

I have complie and build it with make px4_sitl_default jmavsim with no errors

In Qgroundstation

copied same xml file in qgroundcontrol/libs/mavlink/include/mavlink/v2.0/message_definitions

generated header files in qgroundcontrol/libs/mavlink/include/mavlink/v2.0 using Mavgenerate (GUI)
0utput qgroundcontrol/libs/mavlink/include/mavlink/v2.0

i copy mavlink_msg_test_types.h to qgroundcontrol/libs/mavlink/include/mavlink/v2.0/common
and include file in common.h

now i added following line to vehicle.cc
switch (message.msgid) {
case MAVLINK_MSG_ID_HOME_POSITION:
_handleHomePosition(message);
break;
case MAVLINK_MSG_ID_HEARTBEAT:
_handleHeartbeat(message);
break;
case MAVLINK_MSG_ID_TEST_TYPES:
qDebug()<<"msg ";
break;

after running both i am not Receiving any msg in inspector window or in application output.
is there any additional step i am missing…??
please help me out with it i am stuck from 3 months …
thank you.

i copy mavlink_msg_test_types.h to qgroundcontrol/libs/mavlink/include/mavlink/v2.0/common
and include file in common.h

now i added following line to vehicle.cc

This is odd to me. It should not be necessary if you cleanly generated the files and then use that folder.

And you have verified that the message is actually sent on the PX4 side, right?

1 Like

I used pymavlink script to receive message

from pymavlink import mavutil
#from pymavlink.dialects.v20 import test_types_nik as mavlink2

Start a connection listening to a UDP port

the_connection = mavutil.mavlink_connection(‘udpin:localhost:14540’)

Wait for the first heartbeat

This sets the system and component ID of remote system for the link

the_connection.wait_heartbeat()
print(“Heartbeat from system (system %u component %u)” % (the_connection.target_system, the_connection.target_system))

msg = the_connection.recv_match(condition=None, type=‘TEST_TYPES_NIKETAN’, blocking=True, timeout=None)
print(‘Mode: t%8.4f’ % msg.roll_nik)

it receive to pymavlink but not in qgroundcontrol.

It looks like my data packet is getting lost.
I debug parse from qgroundcontrol.
Received message with ID 245 sequence: 27 component: 1 system: 1
0 27 27 26 3 24 ( 1 1 )
Received message with ID 0 sequence: 28 component: 1 system: 1
0 28 28 27 3 25 ( 1 1 )
Received message with ID 74 sequence: 30 component: 1 system: 1
1 30 29 28 4 26 ( 1 1 )
Received message with ID 1 sequence: 31 component: 1 system: 1
0 31 31 30 4 27 ( 1 1 )
Received message with ID 4 sequence: 32 component: 1 system: 1
0 32 32 31 4 28 ( 1 1 )
Received message with ID 24 sequence: 33 component: 1 system: 1
0 33 33 32 4 29 ( 1 1 )
Received message with ID 245 sequence: 34 component: 1 system: 1
0 34 34 33 4 30 ( 1 1 )
Received message with ID 0 sequence: 35 component: 1 system: 1
0 35 35 34 4 31 ( 1 1 )
Received message with ID 74 sequence: 37 component: 1 system: 1
1 37 36 35 5 32 ( 1 1 )
Received message with ID 1 sequence: 38 component: 1 system: 1
0 38 38 37 5 33 ( 1 1 )
Received message with ID 4 sequence: 39 component: 1 system: 1
0 39 39 38 5 34 ( 1 1 )
Received message with ID 24 sequence: 40 component: 1 system: 1
0 40 40 39 5 35 ( 1 1 )
Received message with ID 245 sequence: 41 component: 1 system: 1
0 41 41 40 5 36 ( 1 1 )
Received message with ID 0 sequence: 42 component: 1 system: 1
0 42 42 41 5 37 ( 1 1 )
Received message with ID 74 sequence: 44 component: 1 system: 1
1 44 43 42 6 38 ( 1 1 )
Received message with ID 1 sequence: 45 component: 1 system: 1
0 45 45 44 6 39 ( 1 1 )
Received message with ID 4 sequence: 46 component: 1 system: 1
0 46 46 45 6 40 ( 1 1 )
Received message with ID 24 sequence: 47 component: 1 system: 1
0 47 47 46 6 41 ( 1 1 )
Received message with ID 245 sequence: 48 component: 1 system: 1
0 48 48 47 6 42 ( 1 1 )
Received message with ID 0 sequence: 49 component: 1 system: 1
0 49 49 48 6 43 ( 1 1 )
Received message with ID 74 sequence: 51 component: 1 system: 1
1 51 50 49 7 44 ( 1 1 )
Received message with ID 1 sequence: 52 component: 1 system: 1
0 52 52 51 7 45 ( 1 1 )
Received message with ID 4 sequence: 53 component: 1 system: 1
0 53 53 52 7 46 ( 1 1 )
Received message with ID 24 sequence: 54 component: 1 system: 1
0 54 54 53 7 47 ( 1 1 )
Received message with ID 245 sequence: 55 component: 1 system: 1
0 55 55 54 7 48 ( 1 1 )
Received message with ID 0 sequence: 56 component: 1 system: 1
0 56 56 55 7 49 ( 1 1 )
Received message with ID 74 sequence: 58 component: 1 system: 1
1 58 57 56 8 50 ( 1 1 )
Received message with ID 1 sequence: 59 component: 1 system: 1
0 59 59 58 8 51 ( 1 1 )
Received message with ID 4 sequence: 60 component: 1 system: 1
0 60 60 59 8 52 ( 1 1 )
Received message with ID 24 sequence: 61 component: 1 system: 1
0 61 61 60 8 53 ( 1 1 )
Received message with ID 245 sequence: 62 component: 1 system: 1
0 62 62 61 8 54 ( 1 1 )
Received message with ID 0 sequence: 63 component: 1 system: 1
0 63 63 62 8 55 ( 1 1 )
Received message with ID 74 sequence: 65 component: 1 system: 1
1 65 64 63 9 56 ( 1 1 )
Received message with ID 1 sequence: 66 component: 1 system: 1
0 66 66 65 9 57 ( 1 1 )

what might be issue to cause this …???