Пример #1
0
        static void Main(string[] args)
        {
            Log.Module = Module;

            robotFolder   = Path.GetDirectoryName(Application.ExecutablePath);
            motionsFolder = string.Format("{0}\\Motions", robotFolder);
            audioFolder   = string.Format("{0}\\Audio", robotFolder);

            networkBusy = false;  // There is no network traffic between server and client.

            bool newStart = true; // kan misschien weg.

            Log.WriteLineMessage("==================================");
            Log.WriteLineMessage("Roboard KHR-1HV Server Application");
            Log.WriteLineMessage("==================================");

            Network mainServer = new Network();

            Log.WriteLineMessage("Checking folder structure");
            // Does the Motions folder exists?
            if (!Directory.Exists(motionsFolder))
            {
                Log.WriteLineFail("Motions folder exist");
                // If not lets create one.
                Directory.CreateDirectory(motionsFolder);
                Log.WriteLineSucces("Motions folder created");
                // Delete the Table.ini since all the motions are gone,
                // lets create a new Table.ini
                File.Delete(string.Format("{0}\\Table.ini", robotFolder));
                Log.WriteLineSucces("Deleting existing Table.ini");
            }
            else
            {
                Log.WriteLineSucces("Motions folder exist");
            }

            // Does the Audio folder exists?
            if (!Directory.Exists(audioFolder))
            {
                Log.WriteLineFail("Audio folder exist");
                // If not lets create one
                Directory.CreateDirectory(audioFolder);
                Log.WriteLineSucces("Audio folder created");
            }
            else
            {
                Log.WriteLineSucces("Audio folder exist");
            }

            if (!Server.MainIni.Open)
            {
                Server.MainIni.Init();
            }

            if (!Server.Table.Open)
            {
                Server.Table.Init();
            }

            if (!Server.Trim.Open)
            {
                Server.Trim.Init();
            }

            if (MainIni.EnableRemoteControl)
            {
                if (!Server.XBox360.Open)
                {
                    Server.XBox360.Init();
                }
            }

//            RCServo.Close();
            RCServo.Init();
            Server.I2C.Init();
            Server.SPI.Init();
            Server.AD7918.Init();

            Server.MotionInterpreter.Init();

            // Check if start-up motion is set
            // and play that motion
            //
            if (Server.MainIni.PowerUpMotion != -1)
            {
                Log.WriteLineMessage(string.Format("Play startup motion: {0}", Server.MainIni.PowerUpMotion));
            }
            // remember that the voltage needs to be divided by 10;

            Listen(mainServer); // function call to start listening for connections.

            while (newStart)
            {
                //Network.messageHandler += new Network.NewMessageEventHandler(mainServer_messageHandler);
                infinteLoop = true;
                while (infinteLoop)
                {
                    // networkbusy werkt niet meer door de threading. Dit moet opgelost worden door
                    // 1-of de networkbusy ook te laten afhangen van playingdone.
                    // in iedergeval moet er in de motioninterpreter een property komen die laat zien dat
                    // de motion playing is of niet.
                    // 2-of in de xbox360controller een stop en start.
                    if (!networkBusy)
                    {
                        // for real time mixing, read the sensor and do the calculations
                        // and apply them to the current servo position with mixwidth as sensorvalue.

                        Server.XBox360.ControllerState();
                        if (Server.XBox360.Open)
                        {
                            //if (Server.XBox360.Buttons == 128)
                            //{
                            //    Server.MotionInterpreter.playing = false;
                            //    //newStart = false;
                            //    break;
                            //}
                            if (Server.XBox360.Buttons == 64)
                            {
                                if (RCServo.Connected)
                                {
                                    RCServo.Close();
                                }
                                else
                                {
                                    RCServo.Init();
                                }
                                Thread.Sleep(1000);
                            }
                            for (int i = 0; i < StaticUtilities.numberOfMotions; i++)
                            {
                                // check if the button pressed is linked to a motion in the table and
                                // that the controller state is not 65535 (no motion).
                                if ((Convert.ToInt32(Table.MotionTable["Motion" + (i + 1).ToString()]["Control"]) == Server.XBox360.Buttons) && (Server.XBox360.Buttons != 65535))
                                {
                                    Log.WriteLineMessage(string.Format("Playing motion: {0}, {1}", Table.MotionTable["Motion" + (i + 1).ToString()]["Name"], Table.MotionTable["Motion" + (i + 1).ToString()]["Control"]));
                                    Server.MotionInterpreter.Filename = Server.Table.MotionTable["Motion" + (i + 1).ToString()]["Filename"];
                                    Server.MotionInterpreter.Play();
                                    break;
                                }
                            } // END For
                        }     // END If
                    }         // END If
                }             // END While
            }                 // END While

            AD7918.Close();
            SPI.Close();
            I2C.Close();
            RCServo.Close();
            mainServer.StopListening();
            Log.WriteLineMessage("Exit");
            Application.Exit();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Log.Module = Module;

            robotFolder = Path.GetDirectoryName(Application.ExecutablePath);
            motionsFolder = string.Format("{0}\\Motions", robotFolder);
            audioFolder = string.Format("{0}\\Audio", robotFolder);

            networkBusy = false; // There is no network traffic between server and client.

            bool newStart = true; // kan misschien weg.
            Log.WriteLineMessage("==================================");
            Log.WriteLineMessage("Roboard KHR-1HV Server Application");
            Log.WriteLineMessage("==================================");

            Network mainServer = new Network();

            Log.WriteLineMessage("Checking folder structure");
            // Does the Motions folder exists?
            if (!Directory.Exists(motionsFolder))
            {
                Log.WriteLineFail("Motions folder exist");
                // If not lets create one.
                Directory.CreateDirectory(motionsFolder);
                Log.WriteLineSucces("Motions folder created");
                // Delete the Table.ini since all the motions are gone,
                // lets create a new Table.ini
                File.Delete(string.Format("{0}\\Table.ini",robotFolder));
                Log.WriteLineSucces("Deleting existing Table.ini");
            }
            else
                Log.WriteLineSucces("Motions folder exist");

            // Does the Audio folder exists?
            if (!Directory.Exists(audioFolder))
            {
                Log.WriteLineFail("Audio folder exist");
                // If not lets create one
                Directory.CreateDirectory(audioFolder);
                Log.WriteLineSucces("Audio folder created");
            }
            else
                Log.WriteLineSucces("Audio folder exist");

            if (!Server.MainIni.Open)
                Server.MainIni.Init();

            if (!Server.Table.Open)
                Server.Table.Init();

            if (!Server.Trim.Open)
                Server.Trim.Init();

            if (MainIni.EnableRemoteControl)
                if (!Server.XBox360.Open)
                    Server.XBox360.Init();

            //            RCServo.Close();
            RCServo.Init();
            Server.I2C.Init();
            Server.SPI.Init();
            Server.AD7918.Init();

            Server.MotionInterpreter.Init();

            // Check if start-up motion is set
            // and play that motion
            //
            if (Server.MainIni.PowerUpMotion != -1)
            {
                Log.WriteLineMessage(string.Format("Play startup motion: {0}", Server.MainIni.PowerUpMotion));
            }
            // remember that the voltage needs to be divided by 10;

            Listen(mainServer); // function call to start listening for connections.

            while (newStart)
            {
                //Network.messageHandler += new Network.NewMessageEventHandler(mainServer_messageHandler);
                infinteLoop = true;
                while (infinteLoop)
                {
                    // networkbusy werkt niet meer door de threading. Dit moet opgelost worden door
                    // 1-of de networkbusy ook te laten afhangen van playingdone.
                    // in iedergeval moet er in de motioninterpreter een property komen die laat zien dat
                    // de motion playing is of niet.
                    // 2-of in de xbox360controller een stop en start.
                    if (!networkBusy)
                    {
                        // for real time mixing, read the sensor and do the calculations
                        // and apply them to the current servo position with mixwidth as sensorvalue.

                        Server.XBox360.ControllerState();
                        if (Server.XBox360.Open)
                        {
                            //if (Server.XBox360.Buttons == 128)
                            //{
                            //    Server.MotionInterpreter.playing = false;
                            //    //newStart = false;
                            //    break;
                            //}
                            if (Server.XBox360.Buttons == 64)
                            {
                                if (RCServo.Connected)
                                    RCServo.Close();
                                else
                                    RCServo.Init();
                                Thread.Sleep(1000);
                            }
                            for (int i = 0; i < StaticUtilities.numberOfMotions; i++)
                            {
                                // check if the button pressed is linked to a motion in the table and
                                // that the controller state is not 65535 (no motion).
                                if ((Convert.ToInt32(Table.MotionTable["Motion" + (i + 1).ToString()]["Control"]) == Server.XBox360.Buttons) && (Server.XBox360.Buttons != 65535))
                                {
                                    Log.WriteLineMessage(string.Format("Playing motion: {0}, {1}", Table.MotionTable["Motion" + (i + 1).ToString()]["Name"], Table.MotionTable["Motion" + (i + 1).ToString()]["Control"]));
                                    Server.MotionInterpreter.Filename = Server.Table.MotionTable["Motion" + (i + 1).ToString()]["Filename"];
                                    Server.MotionInterpreter.Play();
                                    break;
                                }
                            } // END For
                        } // END If
                    } // END If
                } // END While
            } // END While

            AD7918.Close();
            SPI.Close();
            I2C.Close();
            RCServo.Close();
            mainServer.StopListening();
            Log.WriteLineMessage("Exit");
            Application.Exit();
        }