The examples (https://github.com/ArduPilot/pymavlink/tree/master/generator/Ada/examples) are implemented using Serial communication. When I tried to update one of the examples with UDP protocol, Mav_Conn.Parse_Byte()
is not returning true (But I'm receiving the data). I'm not sure, what I've done wrong, Can someone help me with this?
Also, adding the code for your reference, Thank you:
with Ada.Streams; with Ada.Text_IO; with Interfaces; with Ada.Numerics.Generic_Elementary_Functions; with GNAT.Sockets; use GNAT.Sockets; with Ada.Unchecked_Conversion; with Mavlink; with Mavlink.Connection; with Mavlink.Messages; with Mavlink.Types; procedure Attitude is use type Ada.Streams.Stream_Element_Offset; use type Interfaces.Unsigned_8; package Short_Float_Text_IO is new Ada.Text_IO.Float_IO(Short_Float); Server : Socket_Type; Address, From : Sock_Addr_Type; Input : Ada.Streams.Stream_Element_Array(1..1024); Input_Last : Ada.Streams.Stream_Element_Offset; Count : Integer := 0; Mav_Conn : Mavlink.Connection.Connection (System_Id => 250); procedure Handler_Attitude is Attitude : Mavlink.Messages.Attitude; K_Rad2Deg : Short_Float := 180.0 / Ada.Numerics.Pi; begin Mav_Conn.Unpack (Attitude); Ada.Text_IO.Put ("Pitch: "); Short_Float_Text_IO.Put(Attitude.Pitch * K_Rad2Deg, Aft => 4, Exp => 0); Ada.Text_IO.Put (" Roll: "); Short_Float_Text_IO.Put(Attitude.Roll * K_Rad2Deg, Aft => 4, Exp => 0); Ada.Text_IO.Put (" Yaw: "); Short_Float_Text_IO.Put(Attitude.Yaw * K_Rad2Deg, Aft => 4, Exp => 0); Ada.Text_IO.New_Line; end Handler_Attitude; begin Create_Socket (Server, Family_Inet, Socket_Datagram); Set_Socket_Option (Server, Socket_Level, (Reuse_Address, True)); Address.Addr := Inet_Addr("127.0.0.1"); Address.Port := 14551; Ada.Text_IO.Put_Line ("Connects to ardupilot (baud rate 115200) via ttyUSB0 and reads attitude angles"); Bind_Socket (Server, Address); loop Receive_Socket (Server, Input, Input_Last, From); for B of Input (Input'First .. Input_Last) loop if Mav_Conn.Parse_Byte(Interfaces.Unsigned_8(B)) then if Mav_Conn.Get_Msg_Id = Mavlink.Messages.Attitude_Id then Handler_Attitude; end if; end if; end loop; end loop; end Attitude;
submitted by
/u/technicalvillager [link] [comments]