Manually sending and receiving MAVLink Messages to/from Gazebo

Hi all,

I am trying to manually send HIL_ACTUATOR_CONTROLS MAVLink messages directly to Gazebo through a Python script to control a drone. I am sending MAVLink messages through the pymavlink library.

When I start Gazebo, through ROS, it starts, and hangs with a black screen until I start a TCP MAVLink connection with

connection = mavutil.mavtcp("localhost:4560")'

At which point Gazebo will finish starting up, and run for 5 seconds, until it hangs again.

According to the simulation documentation, because Gazebo is running in Lockstep mode, Gazebo should be freewheeling HIL_SENSOR messages to me until it receives its first HIL_ACTUATOR_CONTROLS message. However, when I check the_connection.messages (as is suggested to check the messages received), the only messages that I see I’ve gotten are a ‘MAV’ message and a ‘HOME’ message, neither of which are valid messages. I have tried sending HIL_ACTUATOR_CONTROLS messages nonetheless, but Gazebo does not respond.

Note that I have been able to connect and control a drone in Microsoft AirSim this way (by connecting with connection.mavtcp(“localhost:4560”) and manually sending HIL_ACTUATOR_CONTROLS messages.)

To summarize, my questions are as follows:

  1. Why isn’t Gazebo sending me any HIL_SENSOR messages?
  2. Why isn’t Gazebo listening to my HIL_ACTUATOR_CONTROLS messages?

EDIT: I’ve found where the HIL_SENSOR messages are. Instead of calling connection.messages, I need to call connection.recv_match() or connection.recv_msg(). Not sure why connection.messages doesn’t work, though.


Can you explain what you’re actually trying to achieve? I’m not sure what you’re trying to do makes much sense.

Hi! I figured it out.

I was trying to manually send and receive MAVLink messages to/from a simulator via pymavlink.

After running connection = mavutil.mavtcp("localhost:4560"), I was able to call msg = connection.recv_msg() to access the HIL_SENSOR mavlink message.

Furthermore, I was able to send HIL_ACTUATOR_COMMANDS messages by calling

Now, I am able to intercept messages from the PX4 and forward them to Gazebo, and vice versa!

1 Like