pymavlink icon indicating copy to clipboard operation
pymavlink copied to clipboard

BAD_DATA reception on PyMAVLink

Open TonyJacb opened this issue 1 year ago • 0 comments

I am trying to use PyMAVLink to communicate between a vehicle and another laptop. I am using the 3DR telemetry modules connected to serial to implement the same.

I wrote a simple script to send and receive the messages. The below script sends the messages.

from pymavlink import mavutil
import generated_messages

mavlink_connection = mavutil.mavlink_connection(device='/dev/ttyUSB1', baudrate=115200)
mavlink = generated_messages.MAVLink(mavlink_connection)
msg = mavlink.heartbeat_encode(mavutil.mavlink.MAV_TYPE_GCS, mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)
msg.pack(mavlink)

while 1:
    mavlink_connection.mav.send(msg)
    print(msg)

The reception script however, ouputs BAD_DATA{Bad prefix} no matter what I send. (I have tried sending a LONG message and a HEARTBEAT message)

from pymavlink import mavutil
import generated_messages

mavlink_connection = mavutil.mavlink_connection(device='/dev/ttyUSB0', baudrate=115200, input=False)
while True:
    msg = mavlink_connection.recv_match()
    if msg:
        print(msg)

It would be great help if I am directed as to why the script is behaving as such.

TonyJacb avatar May 22 '23 18:05 TonyJacb