Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            this.TextToSpeechProxy    = new TextToSpeechProxy(NAO_IP_ADDRESS, NAO_PORT);
            this.BehaviorManagerProxy = new BehaviorManagerProxy(NAO_IP_ADDRESS, NAO_PORT);
            this.LedsProxy            = new LedsProxy(NAO_IP_ADDRESS, NAO_PORT);
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            this.TextToSpeechProxy = new TextToSpeechProxy(NAO_IP_ADDRESS, NAO_PORT);
            this.BehaviorManagerProxy = new BehaviorManagerProxy(NAO_IP_ADDRESS, NAO_PORT);
            this.LedsProxy = new LedsProxy(NAO_IP_ADDRESS, NAO_PORT);
        }
Exemplo n.º 3
0
        public bool connect(string ip, bool onlymotion = false)
        {
            this.IP = ip;

            bool b = false;
            try
            {
                proxyMotion = new MotionProxy(ip, Port);


                if (onlymotion == false)
                {
	                bool bc = proxyMotion.setCollisionProtectionEnabled("Arms", false);
	                if (!bc)
	                    Console.WriteLine("Failed to disable collision protection");

                    StartMotorMonitor();
	
	                proxyBehaviorManager = new BehaviorManagerProxy(ip, Port);
	
	                // Turn off the LEDs
	                proxyLed = new LedsProxy(ip, Port);
	                List<string> ledgroups = proxyLed.listGroups();
	                foreach (string ledgroup in ledgroups)
	                {
	                	proxyLed.off(ledgroup);
	                }

                    // Speech
                    proxyTTS = new TextToSpeechProxy(ip, Port);

                    if (ip != "127.0.0.1")
                    {
	                    // Sentinel
	                    proxySentinel = new SentinelProxy(ip, Port);
	                    // Turning off "Motor hot!"
	                    proxySentinel.enableHeatMonitoring(false);
                    }

                    // camera
                    proxyCamera = new VideoDeviceProxy(ip, Port);
	
	                // IdleMovement
	                InitIdleMovement();
                }

                b = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("MotionProxy.Connect Exception: " + e);
                b = false;
            }

            IsConnected = b;
            return b;
        }
Exemplo n.º 4
0
 public bool start(string behaviorName)
 {
     try
     {
         manager = new BehaviorManagerProxy(ip, port);
         manager.runBehavior(behaviorName);
         return true;
     }
     catch(Exception)
     {
         return false;
     }
 }
Exemplo n.º 5
0
        public static void gespeicherteBewegung()
        {
            try
            {
                BehaviorManagerProxy beh = new BehaviorManagerProxy(ip, 54010);
                beh.preloadBehavior("StandUp");     //Behavior muss vorher in Tool gespeichert werden
                beh.runBehavior("StandUp");         //Behavior muss vorher in Tool gespeichert werden

            }
            catch (Exception e)
            {
                Console.WriteLine("blabla " + e.Message);
            }
        }
Exemplo n.º 6
0
        /// <summary> 
        /// Connects to the motion system in the NAO robot 
        /// </summary> 
        /// <param name="ip"> ip address of the robot </param> 
        /// 


        public void connect(string ip)
        {
            try
            {
                naoMotion = new MotionProxy(ip, 9559);
                bmp       = new BehaviorManagerProxy(ip, 9559);

                // give joints stiffness 
                naoMotion.stiffnessInterpolation("Head", 1.0f, 1.0f);
                naoMotion.stiffnessInterpolation("LArm", 1.0f, 1.0f);
                naoMotion.stiffnessInterpolation("RArm", 1.0f, 1.0f);
            }
            catch (Exception e)
            {
                //MessageBox.Show("Exception occurred, error log in C:\\NAOcam\\exception.txt");
                System.IO.File.WriteAllText(@"C:\\NAOcam\\exception.txt", e.ToString());  // write exepctions to text file 
            }
        }
        //connect to the Nao robot
        private void ConnectToNao(string nao_ip_address, int nao_port)
        {
            bool success = true;

            try
            {
                TextToSpeechProxy    = new TextToSpeechProxy(nao_ip_address, nao_port);
                BehaviorManagerProxy = new BehaviorManagerProxy(nao_ip_address, nao_port);
                LedsProxy            = new LedsProxy(nao_ip_address, nao_port);
                VideoRecorderProxy   = new VideoRecorderProxy(nao_ip_address, nao_port);
                MotionProxy          = new MotionProxy(nao_ip_address, nao_port);
                AudioProxy           = new AudioDeviceProxy(nao_ip_address, nao_port);
            }
            catch (Exception)
            {
                success = false;
            }
            ConnectButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                 new UpdateInterfaceAfterConnectDelegate(UpdateUserInterfaceAfterConnect), success);
        }
 private void ConnectToNao(string nao_ip_address, int nao_port)
 {
     bool success = true;
     try
     {
         TextToSpeechProxy = new TextToSpeechProxy(nao_ip_address, nao_port);
         BehaviorManagerProxy = new BehaviorManagerProxy(nao_ip_address, nao_port);
         LedsProxy = new LedsProxy(nao_ip_address, nao_port);
         VideoRecorderProxy = new VideoRecorderProxy(nao_ip_address, nao_port);
     }
     catch (Exception)
     {
         success = false;
     }
     ConnectButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
         new UpdateInterfaceAfterConnectDelegate(UpdateUserInterfaceAfterConnect), success);
 }
Exemplo n.º 9
0
        /// <summary>
        /// !!!Tested only with simulator!!!
        /// CrgBehaviors are built using TimeLineTemplate with one key pose
        /// 
        /// when two proxy instances in two threads operates different joints at the same time, 
        ///  they are executed in the same time.
        ///  
        /// when two proxy instances in two threads operates the same joints at the same time,
        ///  one will override the other; order is not definite!
        /// 
        /// SOAP error will occur if the same proxy instance in two threads  
        ///   operates at the same time!
        /// </summary>
        public void TestBehaviorManagers()
        {
            BehaviorManagerProxy bmp1 = new BehaviorManagerProxy(this.IP, Port);
            BehaviorManagerProxy bmp2 = new BehaviorManagerProxy(this.IP, Port);

            BackgroundWorker bgw1 = new BackgroundWorker();
            BackgroundWorker bgw2 = new BackgroundWorker();

            bgw1.DoWork += delegate
            {
                bmp1.runBehavior("testarm2");
            };
            bgw2.DoWork += delegate
            {
                // One will override the other; order is not definite! 
                // No problem! I can see the two behaviors running (red square) 
                //  at the same time in Choregraphe->BehaviorManager
                //bmp2.runBehavior("testarm1");

                // Executed simultaneously
                // No problem! I can see the two behaviors running (red square) 
                //  at the same time in Choregraphe->BehaviorManager
                bmp2.runBehavior("testhead1");

                // SOAP error;
                // some times no errors occurred, probably because 
                //   the two threads were not operating at the same time coincidently
                //bmp1.runBehavior("testarm1");

                // SOAP error;
                // some times no errors occurred, probably because 
                //   the two threads were not operating at the same time coincidently
                //bmp1.runBehavior("testhead1");
            };

            bgw1.RunWorkerAsync();
            bgw2.RunWorkerAsync();
        }
Exemplo n.º 10
0
        private void Disconnect()
        {
            shutdown = true;

            try
            {
                audioProxy.Dispose();
            }
            catch { }

            if (status != NaoStatus.Disconnected && status != NaoStatus.Connecting)
            {
                Console.WriteLine("Stopping idle behavior...");
                try
                {
                    if (behaviorProxy == null) behaviorProxy = new BehaviorManagerProxy(ipAddress, 9559);
                    behaviorProxy.post.stopAllBehaviors();
                }
                catch { }

                Console.WriteLine("Shutting down motors...");
                try
                {
                    MotionProxy motionProxy = new MotionProxy(ipAddress, 9559);
                    motionProxy.post.setStiffnesses("Body", 0);
                }
                catch { }
            }
            Console.WriteLine("Waiting for threads to finish...");
            lstCategories.Items.Clear();
            lstFiles.Items.Clear();
            if (tConnect != null) tConnect.Abort();
            Status = NaoStatus.Disconnected;
            Console.WriteLine("Done. Exiting.");
        }
Exemplo n.º 11
0
        private void Connect() {
            Console.WriteLine("Looking for NAO's host '" + robotAddress + "'...");
            IPAddress[] ip = Dns.GetHostAddresses(robotAddress);
            if (ip.Length == 0)
            {
                Console.WriteLine("Unable to find host '" + robotAddress + "'");
                Thread.Sleep(2000);
            }
            else
            {
                foreach (IPAddress i in ip)
                {
                    if (i.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ipAddress = i.ToString();
                        break;
                    }
                }
                Console.WriteLine("Resolved '" + robotAddress + "' as " + ipAddress + "!");
                audioProxy = new AudioPlayerProxy(ipAddress, 9559);
                Console.WriteLine("Created AudioPlayer proxy.");
                

                var files = Directory.EnumerateFiles(@"wav", "*.mp3", SearchOption.AllDirectories);
                sounds.Clear();
                lstCategories.Invoke((MethodInvoker)(() =>
                {
                    lstCategories.Items.Clear();
                    lstFiles.Items.Clear();
                    lstCategories.SelectedItem = null;
                    lstFiles.Enabled = false;
                    btnPlayRandom.Enabled = false;
                }));
                foreach (string file in files)
                {
                    string category = Path.GetDirectoryName(file).Substring(Path.GetDirectoryName(file).LastIndexOf(Path.DirectorySeparatorChar)+1);
                    string sound = Path.GetFileNameWithoutExtension(file);
                    if (!sounds.ContainsKey(category))
                    {
                        sounds[category] = new Dictionary<string, int>();
                        lstCategories.Invoke((MethodInvoker)(() =>
                        {
                            lstCategories.Items.Add(String.Format("[Shift+{0}]:{1}", (char) keyIndexes[lstCategories.Items.Count], category));
                        }));
                    }
                    int soundId = -1;
                    try {
                        soundId = audioProxy.loadFile("/var/persistent/home/nao/wav/" + category + "/" + sound + ".mp3");
                        Console.WriteLine("Loaded file '" + category + "/" + sound + ".mp3'");
                    }catch (Exception e) {
                        Console.WriteLine("Unable to load file '" + category + "/" + sound + ".mp3': " + e.Message + (e.InnerException!=null?": " + e.InnerException.Message:""));
                    }
                    if (soundId != -1)
                    {
                        sounds[category][sound] = soundId;
                    }
                    else if (sounds[category].ContainsKey(sound))
                    {
                        sounds[category].Remove(sound);
                    }
                }

                behaviorProxy = new BehaviorManagerProxy(ipAddress, 9559);
                Console.WriteLine("Created BehaviorManager proxy.");
                if (behaviorProxy.isBehaviorPresent(idleBehavior))
                {
                    if (!behaviorProxy.isBehaviorRunning(idleBehavior))
                    {   
                        behaviorProxy.post.runBehavior(idleBehavior);
                    }
                }

                Status = NaoStatus.Standby;
            }
        }