Error from send_mavlink() function when simulating the mavlink ADSB_VEHICLE ( #246 ) message

127 views
Skip to first unread message

C. Wayne Wright

unread,
Jan 31, 2020, 12:08:25 PM1/31/20
to MAVLink


I'm attempting to generate a simulated ADSB traffic message which I'm hoping to display
on the Qgroundcontrol and MIssionPlanner GCS programs.  I have a Copter SITL
vehicle, and I have two QGCs connected an a MissionPlanner all via UDP and
mavlink-router to connect them.  

I'm getting a strange error message from send_mavlink() when I send it a 
packet encoded with message_factory_encode.  The entire output from the test program 
is below ending with the error message.  

Any help or guidance on what the problem is appreciated.

W. Wright


wright@wright-VirtualBox:~/sitl$ python dk-sim-adsb-traffic.py 
('Attempting to connecting to:%s', 'udp:192.168.66.152:14573')
Connected
LocationGlobal:lat=27.6427039,lon=-82.5583236,alt=34.35
ADSB_VEHICLE {ICAO_address : 1, lat : 276427011.0, lon : -8255832930.0, altitude_type : 0, altitude : 30000.0, heading : 0, hor_velocity : 0, ver_velocity : 0, callsign : Leader, emitter_type : 14, tslc : 1, flags : 33215, squawk : 640}
Traceback (most recent call last):
  File "dk-sim-adsb-traffic.py", line 28, in <module>
    v.send_mavlink( adsb_msg )
  File "/home/wright/.local/lib/python2.7/site-packages/dronekit/__init__.py", line 2215, in send_mavlink
    self._master.mav.send(message)
  File "/home/wright/.local/lib/python2.7/site-packages/dronekit/mavlink.py", line 146, in newsendfn
    return sendfn(mavmsg, *args, **kwargs)
  File "/home/wright/.local/lib/python2.7/site-packages/pymavlink/dialects/v10/ardupilotmega.py", line 11894, in send
    buf = mavmsg.pack(self, force_mavlink1=force_mavlink1)
  File "/home/wright/.local/lib/python2.7/site-packages/pymavlink/dialects/v10/ardupilotmega.py", line 11339, in pack
    return MAVLink_message.pack(self, mav, 184, struct.pack('<IiiiHHhHHB9sBB', self.ICAO_address, self.lat, self.lon, self.altitude, self.heading, self.hor_velocity, self.ver_velocity, self.flags, self.squawk, self.altitude_type, self.callsign, self.emitter_type, self.tslc), force_mavlink1=force_mavlink1)
struct.error: 'i' format requires -2147483648 <= number <= 2147483647
wright@wright-VirtualBox:~/sitl$ 



The Python 2. test program source code is here:

# Python 2.7
# W. Wright lidar532(AT)gmail.com
# Example Dronekit python to generate a simulated ADSB message.


import dronekit as dk
from time import sleep


v_UDP
= 'udp:192.168.66.152:14573'              # Simulated Quad.
print('Attempting to connecting to:%s', v_UDP)
v  
= dk.connect( v_UDP, wait_ready = True )
print( 'Connected' )


print( v.location.global_frame )


aflags  
= 1+2+4+8+0x10+0x20+0x80+0x100+0x8000           # See flags at https://uavionix.com/downloads/integration/uAvionix%20Ping%20Integration%20Guide.pdf
icao    
= 0xA01234
ads_lat
=  27.6427011
ads_lon
= -82.5583293
ads_alt
= 30.0
squawk  
= 0o1200
callsign
= 'Leader'


# Generate ADSB packet
adsb_msg
= v.message_factory.adsb_vehicle_encode(1,ads_lat*1e7,ads_lon*10e7,0,ads_alt*1e3,  0,0,0,'Leader',14,  1, aflags, 01200 )
print(adsb_msg)


# Transmit.   Intended ito be received by ground stations
v
.send_mavlink( adsb_msg )






C. Wayne Wright

unread,
Feb 1, 2020, 5:10:50 AM2/1/20
to mav...@googlegroups.com

I managed to figure this one out.   I had accidentally multiplied ads_lon by 10e7 instead of 1e7 thus overflowing the packed 32 bit integer space reserved for it.  

It is interesting that it passed the “message factory” with the bug, but not the send_mavlink.

W.  Wright

--
Sie erhalten diese Nachricht, weil Sie in Google Groups E-Mails von der Gruppe "MAVLink" abonniert haben.
Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an mavlink+u...@googlegroups.com.
Wenn Sie diese Diskussion im Web verfolgen möchten, rufen Sie https://groups.google.com/d/msgid/mavlink/622de287-68ae-4fb3-8e7f-448ce68f4067%40googlegroups.com auf.
--
“In theory, theory and practice are the same. In practice, they are not.”
-Albert Einstein 

Cell: 443-783-3319
Fax: 603-994-8796

Reply all
Reply to author
Forward
0 new messages