Mission Planner Ground Station architecture analysis of Mavlink waypoint reading and writing

Source: Internet
Author: User
Tags mavlink

Reprint please indicate the source: http://www.amovauto.com Itsuki Community play also want to play professional!

3DR This ground station is also very professional, recently studied Mavlink communication protocol, to analyze the structure of the Mission planner. As for the compilation of Msission planner in the previous articles have been described in detail.

Msission Planner has dozens of project components

Avifile
BaseClasses
BSE. Windows.Forms
Core
Geoutility
GMap.Net.Core
GMap.Net.WindowsForms
Kmlib
MAVLink
Metadataextractor
Missionplanner.comms
Missionplanner.controls
Missionplanner.utils
Px4uploader
Sharpkml
Zedgraph

Dozens of project call relationship is more complex, some of the library's use value is very high such as Mavlink, with this library can handle all the Mavlink protocol aspects of Things, I also started from this library to write the ground station, can focus on this library.
Mission Planner's architecture is more complex, his function is too full, so appear redundant. But very professional ground station, I like ...
An entrance function analysis, the entry function Initializes a bunch of things in the Program.cs in the entry function Gmap and so on ....
Always here.

 try {//system.diagnostics.process.getcurrentprocess ().                PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;             Thread.CurrentThread.Name = "Base Thread";             Application.Run (New MainV2 ());  } catch (Exception ex) {log.                Fatal ("Fatal app exception", ex); Console.WriteLine (ex.                ToString ());                Console.WriteLine ("\npress any key to exit!");            Console.ReadLine (); }

He launched the main form MainV2, this main form is to analyze the focus, because our first step is to analyze the use of Mavlink this protocol, other software form aspects of the setup, we do not consider.

Log. Info ("Create FD");                Flightdata = new Gcsviews.flightdata ();//                log. Info ("Create FP");               Flightplanner = new Gcsviews.flightplanner ();                Configuration = new GCSViews.ConfigurationView.Setup ();                Log. Info ("Create SIM");                Simulation = new Gcsviews.simulation ();

Gcsviews is an important class, and this is the MP control class, where

Can see FlightData.cs is the flight data display interface, is the MP in the Attitude data display interface, FlightPlanner.cs is the flight planning interface, read waypoints and write waypoints are in this interface, the previous message parsing we already know how to read through the Mavlnk APM's flight control Data, the next step is to realize the reading and writing of waypoints, and we'll focus on this FlightPlanner.cs.

   internal void But_read_click (object sender, EventArgs e) {if (Commands.Rows.Count > 0)                    {if (sender is Flightdata) {} else { if (Custommessagebox.show ("This would clear your existing planned mission, Continue?",                        "Confirm", messageboxbuttons.okcancel)! = DialogResult.OK) {                    Return            }}} Progressreporterdialogue Frmprogressreporter = new Progressreporterdialogue            {startposition = Formstartposition.centerscreen, Text = "Receiving WP S"            }; Frmprogressreporter.dowork + = getwps;//Get waypoint commissioned Frmprogressreporter.updateprogressandstatus ( -1, "Receiving WP's"            );            Thememanager.applythemeto (Frmprogressreporter); Frmprogressreporter.runBackgroundoperationasync ();        Frmprogressreporter.dispose ();  } void Getwps (object sender, Progressworkereventargs E, object passdata = null) {List CMDS = new            List ();                try {mavlinkinterface port = mainv2.comport; if (!port.                Basestream.isopen) {throw new Exception ("Please Connect first!");                } MainV2.comPort.giveComport = true; param = port.                Mav.param; Log.                Info ("Getting Home"); ((progressreporterdialogue) sender).                Updateprogressandstatus (0, "Getting WP count"); if (port. Mav.apname = = Mavlink.mav_autopilot. PX4) {try {Cmds.                    ADD (Port.gethomeposition ());                        } catch (TimeoutException ex) {//blank home Cmds.ADD (New Locationwp () {id = (byte) mavlink.mav_cmd.                    Waypoint}); }} log.                Info ("Getting WP #");                int cmdcount = Port.getwpcount (); for (ushort a = 0; a < Cmdcount; a++) {if ((progressreporterdialogue) sender). Dowor kargs.cancelrequested) {((Progressreporterdialogue) sender). Doworkargs.cancelac                        Knowledged = true;                    throw new Exception ("Cancel requested"); } log.                    Info ("Getting WP" + a); ((progressreporterdialogue) sender).                    Updateprogressandstatus (A*100/cmdcount, "Getting WP" + a); Cmds.                ADD (Port.getwp (a));                } port.setwpack (); ((progressreporterdialogue) sender).                Updateprogressandstatus ("Done"); Log.            Info ("Done");     } catch {throw;       } wptoscreen (CMDS); }

progressreporterdialogue This dialog class DoWork is a delegate, Progressreporterdialogue's background run thread executes getwps (object sender, Progressworkereventargs E, object passdata = null) This delegate, to see if the delegate
defines the list CMDS = new list ();
Mavlinkinterface port = mainv2.comport; This mavlinkinterface class is more important and is a member variable of the main interface MainV2. All the contents of the Mavlink protocol are recorded, the parameters obtained from the Mavlink protocol are stored in this member variable, such as what firmware the flight control is, the state of the flight control, and further encapsulation of the Mavlink library inside the Lib library, such as getting the heartbeat packet Function getheartbeat () , get the parameter list getparalist (), get the current waypoint getrallypoints ();
It seems that this member can implement all mavlink operations, the structure diagram is as follows:

Above you can see some of the interfaces of Mavlinkinterface, and then read the function of reading waypoint:
int cmdcount = Port.getwpcount (); Get waypoint number
Cmds. ADD (Port.getwp (a)); deposit waypoint coordinates to waypoint list, you can see detailed Getwp (a) in the Mavlinkinterface class to get waypoint implementation, read with while loop, and do a timeout setting to ensure the robustness of the software.
MP also has a waypoint class to receive waypoints in Locationwp.cs can see the detailed definition, mainly coordinates, posture, and the command ID of this waypoint.

We know how to use Mavlink to read waypoints, so it's the same if we're going to write waypoints.

For more information please visit: http://www.amovauto.com Itsuki community play also want to play professional!

QQ Group: 526221258

Mission Planner Ground Station architecture analysis of Mavlink waypoint reading and writing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.