Beispiel #1
0
        static void Main(string[] args)
        {
            //作業ディレクトリだけでなく"dlls"というフォルダのライブラリも実行中に参照できるよう設定を変更
            PathModifier.AddEnvironmentPath("dlls", PathModifyMode.RelativeToEntryAssembly);

            //HelloWorldの対象とするマシンのアドレスをIPとポート(ポートは通常9559)で指定
            string address = "tcp://127.0.0.1:9559";
            var    session = QiSession.Create(address);

            Console.WriteLine($"Connected? {session.IsConnected}");
            if (!session.IsConnected)
            {
                Console.WriteLine("end program because there is no connection");
                return;
            }

            //最も基本的なモジュールの一つとして合成音声のモジュールを取得
            var tts = session.GetService("ALTextToSpeech");

            //"say"関数に文字列引数を指定して実行
            tts["say"].Call("this is test");

            session.Close();
            session.Destroy();
        }
Beispiel #2
0
        /// <summary>指定したアドレスへ接続を試みる。</summary>
        /// <param name="address">接続先(例:"127.0.0.1", "tcp://pepper.local", "tcp://192.168.3.3:9559")</param>
        /// <returns>接続成功した場合はtrue</returns>
        public async Task <TryConnectResult> TryConnectAsync(string address)
        {
            //未初期化対策
            if (!IsInitialized)
            {
                Initialize();
            }

            //アドレスを正規化
            string normalizedAddress = GetNormalizedUrl(address);

            if (string.IsNullOrEmpty(normalizedAddress))
            {
                return(new TryConnectResult(false, null));
            }

            return(await Task.Run(() =>
            {
                //ここが重い
                var session = QiSession.Create(normalizedAddress);
                if (!session.IsConnected)
                {
                    return new TryConnectResult(false, null);
                }

                return new TryConnectResult(true, new QiSessionViewModel(session));
            }));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //作業ディレクトリだけでなく"dlls"というフォルダのライブラリも実行中に参照できるよう設定を変更
            PathModifier.AddEnvironmentPaths(Path.Combine(Environment.CurrentDirectory, "dlls"));

            //HelloWorldの対象とするマシンのアドレスをIPとポート(ポートは通常9559)で指定
            string address = "tcp://xxx.xxx.xxx.xxx:9559";
            var    session = QiSession.Create(address);


            //ALAnimatedSpeech::sayに渡す典型的なannotated text
            var text = new QiString(
                "^start(animation/Stand/Gestures/Hey_1) " +
                "Hello, this is a typical sample sentence for animated say module, to check some autonomous motion suited for the conversation " +
                "^wait(animation/Stand/Gestures/Hey_1)"
                );

            //AnimatedSay::sayの第二引数に渡す、モーションのモードを表す単一ペアの辞書
            var config = QiMap <QiString, QiString> .Create(new[]
            {
                new KeyValuePair <QiString, QiString>(
                    new QiString("bodyLanguageMode"),
                    new QiString("contextual")
                    )
            });

            var animatedSayArgs = QiTuple.Create(text, config);

            Debug.WriteLine(animatedSayArgs.Signature);
            Debug.WriteLine(animatedSayArgs.Dump());


            var animatedSpeech = session.GetService("ALAnimatedSpeech");

            //1. CallメソッドはQiMap型のシグネチャをハンドリングできない(.NETラッパー側の不備)ので
            //     低レイヤ呼び出しのCallDirectを用いる

            //2. "(sm)"はqi Frameworkの型を表す文字列で、
            //   関数の引数に文字列("s")と、動的型("m")からなるタプル(全体を囲うカッコ)であることを示す
            //   詳細はは公式の型-文字列対応表(http://doc.aldebaran.com/libqi/api/cpp/type/signature.html)などを参照

            //3. CallDirectの戻り値は非同期形式(QiFuture)なのでGetValue()での結果取得により明示的にブロックして同期処理化
            //   (非同期で使いたければGetValue()を後で呼ぶ)
            var res = animatedSpeech
                      .CallDirect("say::(sm)", animatedSayArgs.QiValue)
                      .GetValue();

            //Void型が返却されるのを確認
            Debug.WriteLine(res.ContentValueKind);
        }
Beispiel #4
0
 void Start(){
     initialPosition = transform.position;
     //Pepper
     if(!string.IsNullOrEmpty(pepperIP)){
         _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
         if (!_session.IsConnected){
             Debug.Log("Failed to establish connection");
             return;
         }
     //another robot (estimated)
     }else if(!string.IsNullOrEmpty(robotIP)){
         session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
         if (!_session.IsConnected){
             Debug.Log("Failed to establish connection");
             return;
         }
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            PathModifier.AddEnvironmentPath("dlls", PathModifyMode.RelativeToEntryAssembly);

            string address = "tcp://127.0.0.1:9559";
            var    s       = QiSession.Create(address);

            string text = "^start(animation/Stand/Gestures/Hey_1) " +
                          "Hello, this is a typical sample sentence for animated say module, to check some autonomous motion suited for the conversation " +
                          "^wait(animation/Stand/Gestures/Hey_1)";

            //AnimatedSay::sayの第二引数に渡す、モーションのモードを表す単一ペアの辞書
            var config = QiMap.Create(new[]
            {
                new KeyValuePair <QiString, QiString>("bodyLanguageMode", "contextual")
            });

            var animatedSpeech = s.GetService("ALAnimatedSpeech");

            var res = animatedSpeech["say"].Call(text, config);

            Console.WriteLine(res.ContentValueKind);
        }
Beispiel #6
0
        public override void OnXboxInputUpdate(XboxControllerEventData eventData){
            if (string.IsNullOrEmpty(GamePadName)){
                Debug.LogFormat("Joystick {0} with id: \"{1}\" Connected", eventData.GamePadName, eventData.SourceId);
            }

            base.OnXboxInputUpdate(eventData);

            /*get information from xbox controller*/

            if(_session.IsConnected){
                if (eventData.XboxLeftStickHorizontalAxis != 0 || eventData.XboxLeftStickVerticalAxis != 0){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(eventData.XboxLeftStickHorizontalAxis * move_scalefactor, eventData.XboxLeftStickVerticalAxis * (-1) * move_scalefactor, 0f);
                }
                if (eventData.XboxLeftBumper_Pressed){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(0f, 0f, rotation_scalefactor);
                }
                else if (eventData.XboxRightBumper_Pressed){
                    var motion = _session.GetService("ALMotion");
                    motion["moveTo"].Call(0f, 0f, (-1) * rotation_scalefactor);
                }
                if (eventData.XboxB_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        var motion = _session.GetService("ALMotion");
                        motion["setAngles"].Call("HeadYaw", angle, 0f);
                    }
                    first_buttonpressed = Time.time;
                }
                if (eventData.XboxX_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        if (pepperIP == "192.168.10.51"){
                            _session.Close();
                            _session.Destroy();
                            pepperIP = "192.168.10.48"
                            _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
                        }else{
                            _session.Close();
                            _session.Destroy();
                            pepperIP = "192.168.10.51"
                            _session = QiSession.Create(tcpPrefix + pepperIP + portSuffix);
                        } 
                    }
                    first_buttonpressed = Time.time;
                }
            
            //another robot (estimated)
            }else if(session_robot.isConnected){
                if (eventData.XboxLeftStickHorizontalAxis != 0 || eventData.XboxLeftStickVerticalAxis != 0){
                    CallRobotsAPI_move(eventData.XboxLeftStickHorizontalAxis * move_scalefactor_robot, eventData.XboxLeftStickVerticalAxis * (-1) * move_scalefactor_robot, 0f);
                }
                if (eventData.XboxLeftBumper_Pressed){
                    CallRobotsAPI_rotate(0f, 0f, rotation_scalefactor);
                }
                else if (eventData.XboxRightBumper_Pressed){
                    CallRobotsAPI_rotate(0f, 0f, (-1) * rotation_scalefactor);
                }
                if (eventData.XboxB_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        CallRobotsAPI_rotate(0f, 0f, 0f);
                    }
                    first_buttonpressed = Time.time;
                }
                if (eventData.XboxX_Pressed){
                    if (Time.time - first_buttonpressed > timeBetweenbuttonpressed){
                        if (robotIP == "192.168.10.53"){
                            session_robot.Close();
                            session_robot.Destroy();
                            robotIP = "192.168.10.54"
                            session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
                        }else{
                            session_robot.Close();
                            session_robot.Destroy();
                            robotIP = "192.168.10.53"
                            session_robot = RobotSession.Create(tcpPrefix + robotIP + portSuffix);
                        } 
                    }
                    first_buttonpressed = Time.time;
            }
        }
    }
Beispiel #7
0
        static void Main(string[] args)
        {
            PathModifier.AddEnvironmentPath("dlls", PathModifyMode.RelativeToEntryAssembly);

            string input = "";

            try
            {
                Console.WriteLine("Please input address to connect (i.e. 'tcp://127.0.0.1:9559')");
                string address = Console.ReadLine();
                var    session = QiSession.Create(address);
                if (!session.IsConnected)
                {
                    Console.WriteLine("Failed to connect. Program ends...");
                    return;
                }

                while (true)
                {
                    Console.WriteLine("Choose sample by input number 1, 2, 3, 4 or 5.");
                    Console.WriteLine("1. Motion Pose Initialize");
                    Console.WriteLine("2. Motion Stiffness On");
                    Console.WriteLine("3. Sensor Read");
                    Console.WriteLine("4. Get camera image to local");
                    Console.WriteLine("5. Video Recording");
                    Console.WriteLine("6. Speech Recognition / Robot Speech Logging");
                    Console.WriteLine("7. Sound IO");

                    input = Console.ReadLine();
                    if ((new string[] { "1", "2", "3", "4", "5", "6", "7" }).Contains(input))
                    {
                        break;
                    }

                    Console.WriteLine("could not verify input, please try again.");
                }

                if (input == "1")
                {
                    MotionPosesInit.Execute(session);
                }
                else if (input == "2")
                {
                    MotionStiffnessOn.Execute(session);
                }
                else if (input == "3")
                {
                    Sensors.Execute(session);
                }
                else if (input == "4")
                {
                    VisionRetrieveImage.Execute(session);
                }
                else if (input == "5")
                {
                    VisionVideoRecording.Execute(session);
                }
                else if (input == "6")
                {
                    DialogLogging.Execute(session);
                }
                else if (input == "7")
                {
                    SoundIO.Execute(session);
                }
            }
            catch (DllNotFoundException)
            {
                //アンマネージドのDLLを実行ファイルの"dll"に置くのを忘れていたケース
                Console.WriteLine($"Failed to load dll file. Unmanaged libraries are required to put at 'dlls' folder");
                Console.WriteLine("Ends program...");
            }

            Console.WriteLine("Press ENTER to quit program");
            Console.ReadLine();
        }