示例#1
0
        static void Main(string[] args)
        {
            if (Settings.UseCommProtocol)
            {
                commProtocol = new CommProtocol(Settings.CommNode);
                commProtocol.initializeConnection(Settings.CommPort, Settings.CommBaud);
                //parse address to add
                //this is a bad way to do this should be changed michael wallace 5/12/2017
                string[] words       = Settings.CommAddresses.Split(null);
                int[]    destNode    = Array.ConvertAll(words.Where((str, ix) => ix % 2 == 0).ToArray(), int.Parse); //even
                string[] destAddress = words.Where((str, ix) => ix % 2 == 1).ToArray();                              //odd
                if (destNode.Length == destAddress.Length)
                {
                    for (int x = 0; x < destNode.Length; x++)
                    {
                        commProtocol.addAddress(destNode[x], destAddress[x]);
                    }
                }
                //link call backs
                commProtocol.LinkCallback(new NGCP.VehicleWaypointCommand(), new Comnet.CallBack(VehicleWaypointCommandCallback));
                commProtocol.LinkCallback(new NGCP.VehicleModeCommand(), new Comnet.CallBack(VehicleModeCommandCallback));
                commProtocol.LinkCallback(new NGCP.ArmCommand(), new Comnet.CallBack(ArmCommandCallback));
                commProtocol.LinkCallback(new NGCP.VehicleSystemStatus(), new Comnet.CallBack(VehicleSystemStatusCallback));

                commProtocol.start();
            }

            State = NGCP.UGV.UGV.DriveState.DriveAwayFromTarget;

            while (true)
            {
                Console.ReadLine();
                Console.WriteLine("test package sent\n");
                commProtocol.SendState(new UGVState(), 100);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            commProtocol = new CommProtocol(UGVStationNodeID);
            commProtocol.initializeConnection(commPort, 57600);
            // Add UGV destination node and MAC address
            commProtocol.addAddress(7, "0013A20040A54318");

            //link call backs
            commProtocol.LinkCallback(new NGCP.VehicleWaypointCommand(), new Comnet.CallBack(VehicleWaypointCommandCallback));
            commProtocol.LinkCallback(new NGCP.VehicleModeCommand(), new Comnet.CallBack(VehicleModeCommandCallback));
            commProtocol.LinkCallback(new NGCP.ArmCommand(), new Comnet.CallBack(ArmCommandCallback));
            commProtocol.LinkCallback(new NGCP.VehicleSystemStatus(), new Comnet.CallBack(VehicleSystemStatusCallback));
            commProtocol.LinkCallback(new NGCP.VehicleGlobalPosition(), new Comnet.CallBack(VehicleGlobalPositionCallback));
            commProtocol.LinkCallback(new NGCP.SpeedSteeringCommand(), new Comnet.CallBack(SpeedSteeringCommandCallback));

            commProtocol.start();
        }