Beispiel #1
0
        /**
         * Executes the automated system
         */
        public void Execute()
        {
            InputThread a = new InputThread(PYT.Properties.Settings.Default.IncomingHost, PYT.Properties.Settings.Default.IncomingCommandPort);
            Thread aThread = new Thread(new ThreadStart(a.process));
            aThread.Start();
            Console.WriteLine("Waiting for Automated Input Command thread to start...");
            while (!aThread.IsAlive) ;
            Console.WriteLine("Automated input command thread started");

            Coordinate previous = new Coordinate(this.coordinates);
            foreach (string coord in this.coordinates)
            {
                previous.setCoordinate(coord, -1000.0);
            }

            TrajectoryDispatcher tjd = new TrajectoryDispatcher(this.coordinates, ref this.i);

            while (true)
            {
                try
                {
                    Coordinate next = Coordinate.fromString(this.coordinates, a.getLastReceived());
                    if (next.getCompareString() != previous.getCompareString())
                    {
                        previous = next;
                        // wait for the last one to finish excuting
                        tjd.wait();
                        tjd.setData(next, 1, 35);
                        Coordinate last = Coordinate.fromString(this.coordinates, this.i.getLastReceived());
                        //last.setCoordinate("y", last.getCoordinate("y") - 6);
                        tjd.Execute(last);
                    }

                }
                catch (Exception e) { }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please select (a)uto or (m)anual mode");
            string mode = Console.ReadLine().ToLower().Trim();

            List<string> coordinates = new List<string>(new string[] { "x", "y", "z" });

            if (mode == "a" || mode == "auto")
            {
                Console.WriteLine("Welcome to Auto mode");

                Console.WriteLine("Initialising AutomatedCommander");
                AutomatedCommander ac = new AutomatedCommander(coordinates);

                string input = "";
                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("Please input a command:");
                    input = Console.ReadLine();
                    switch (input.Trim())
                    {
                        case "go":
                        case "g":
                        case "start":
                            ac.Start();
                            break;
                        case "stop":
                        case "s":
                        case "panic":
                        case "p":
                        case "x":
                            ac.Stop();
                            break;
                        case "help":
                        case "h":
                        case "?":
                            Console.WriteLine("Available commands: (g)o / start, (s)top / (p)anic / x, (h)elp / ?, (q)uit / exit");
                            break;
                        case "exit":
                        case "quit":
                        case "q":
                            exit = true;
                            break;
                        default:
                            break;
                    }
                }
            }
            else if (mode == "m" || mode == "manual")
            {
                Console.WriteLine("Welcome to Manual mode");

                Console.WriteLine("Initialising Input thread");
                InputThread i = new InputThread(PYT.Properties.Settings.Default.IncomingHost, PYT.Properties.Settings.Default.IncomingDataPort);
                Thread iThread = new Thread(new ThreadStart(i.process));
                iThread.Start();
                Console.WriteLine("Waiting for Input thread to start...");
                while (!iThread.IsAlive) ;
                Console.WriteLine("Input thread started");

                string input = "";
                bool exit = false;
                while (!exit)
                {
                    Console.WriteLine("Please input a command:");
                    input = Console.ReadLine();
                    switch (input.Trim())
                    {
                        case "latest":
                        case "l":
                            Console.WriteLine("Latest message on Input: " + i.getLastReceived());
                            break;
                        case "send":
                        case "s":
                            // collect required information from user
                            Console.WriteLine("Preparing to send...");

                            TrajectoryDispatcher tjd = new TrajectoryDispatcher(coordinates, ref i);
                            tjd.collectData();
                            Console.WriteLine("Enter 'execute' and press return to dispatch. Enter anything else to abort");
                            if (Console.ReadLine() != "execute")
                            {
                                Console.WriteLine("Aborting");
                                break;
                            }

                            Console.WriteLine("Collecting last known position...");
                            Coordinate start = Coordinate.fromString(coordinates, i.getLastReceived());
                            Console.WriteLine("... captured");

                            tjd.Execute(start);

                            Console.WriteLine("Done");
                            break;
                        case "help":
                        case "h":
                        case "?":
                            Console.WriteLine("Available commands: (l)atest, (s)end, (h)elp / ?, (q)uit / exit");
                            break;
                        case "exit":
                        case "quit":
                        case "q":
                            exit = true;
                            break;
                        default:
                            break;
                    }
                }

                Console.WriteLine("Closing Input thread");
                iThread.Abort();
                Console.WriteLine("Waiting for Input thread to terminate...");
                iThread.Join();
                Console.WriteLine("Input thread closed");
            }
            else
            {
                Console.WriteLine("Unknown command. Terminating");
            }
        }