/// <summary>
            /// Request PersonFinder to find specified person
            /// </summary>
            /// <param name="humanName">Name of the person to find</param>
            /// <param name="hFOVorX">When this method returns contains one of the following values:
            /// a) The horizontal fov if the response contains 3 parameters (name and FOVs)
            /// b) The x coordinate of the centroid of the face based on the center of the camera lens if the response contains 4 parameters (name and coords)
            /// c) Double.NaN if no response was received or the response does not contain position data</param>
            /// <param name="vFOVorY">When this method returns contains one of the following values:
            /// a) The vertical fov if the response contains 3 parameters (name and FOVs)
            /// b) The y coordinate of the centroid of the face based on the center of the camera lens if the response contains 4 parameters (name and coords)
            /// c) Double.NaN if no response was received or the response does not contain position data</param>
            /// <param name="z">When this method returns contains one of the following values:
            /// a) The z coordinate of the centroid of the face based on the center of the camera lens if the response contains 4 parameters (name and coords)
            /// b) Double.NaN if no response was received or the response does not contain coordinate position data</param>
            /// <param name="timeOut">Amout of time to wait for a response in milliseconds</param>
            /// <returns>true if specified person was found. false otherwise</returns>
            public virtual bool FindHuman(ref string humanName, out double hFOVorX, out double vFOVorY, out double z, int timeOut)
            {
                // Stores the command to be sent to person finder
                Command cmdFindHuman;
                // Stores the response from person finder and the candidate while moving
                Response rspFindHuman = null;

                hFOVorX = Double.NaN;
                vFOVorY = Double.NaN;
                z       = Double.NaN;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                cmdFindHuman = new Command(sgnFindHuman.CommandName, humanName, CmdMan.AutoId++);

                // 2. Send the person finderGoto command
                CmdMan.Console("\tFinding human [" + humanName + "]");
                if (!CmdMan.SendAndWait(cmdFindHuman, timeOut, out rspFindHuman))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse human finder response
                if (!rspFindHuman.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tHuman not found");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult result = sgnFindHuman.Analyze(rspFindHuman);

                if (result.Success)
                {
                    result.Update(0, ref humanName);
                    if (result.ParameterCount >= 3)
                    {
                        result.Update(1, ref hFOVorX);
                        result.Update(2, ref vFOVorY);
                    }
                    if (result.ParameterCount >= 4)
                    {
                        result.Update(3, ref z);
                    }
                }

                CmdMan.Console("\tFind human complete");
                return(result.Success);
            }
            /// <summary>
            /// Request the manipulator aperture pecentage and tilt angle
            /// </summary>
            /// <param name="aperturePercentage">Percentage aperture of the gripper of the manipulator.</param>
            /// <param name="tilt">Tilt angle of the manipulator.</param>
            /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param>
            /// <returns>true if data fetch was successfully. false otherwise</returns>
            public virtual bool Status(out int aperturePercentage, out double tilt, int timeOut)
            {
                // Stores the command to be sent to man
                Command cmdStatus;
                // Stores the response from man and the candidate while moving
                Response rspStatus = null;
                bool     result;

                aperturePercentage = 0;
                tilt = 0;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                string parameters = "";

                cmdStatus = new Command(sgnStatus.CommandName, parameters, CmdMan.AutoId++);

                // 2. Send the manAbsPos command
                CmdMan.Console("\tReading man orientation " + parameters);
                if (!CmdMan.SendAndWait(cmdStatus, timeOut, out rspStatus))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse man response
                if (!rspStatus.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tManipulator did not respond");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnStatus.Analyze(rspStatus);

                result = saResult.Success &&
                         (saResult.ParameterCount == 2) &&
                         (saResult.Update <int>(0, ref aperturePercentage) &
                          saResult.Update <double>(1, ref tilt));
                if (!result)
                {
                    CmdMan.Console("\tInvalid response");
                }
                else
                {
                    CmdMan.Console("\tGet man position complete");
                }
                return(result);
            }
            /// <summary>
            /// Request manipulator to move to the specified tilt angle in radians
            /// </summary>
            /// <param name="tilt">The specified tilt angle in radians</param>
            /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param>
            /// <returns>true if manipulator moved to specified tilt. false otherwise</returns>
            public virtual bool Tilt(ref double tilt, int timeOut)
            {
                // Stores the command to be sent to man
                Command cmdTilt;
                // Stores the response from man and the candidate while moving
                Response rspTilt = null;
                bool     result;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                cmdTilt = new Command(sgnTilt.CommandName, tilt.ToString("0.00"), CmdMan.AutoId++);

                // 2. Send the manGoto command
                CmdMan.Console("\tSetting manipulator tilt [" + tilt + "]");
                if (!CmdMan.SendAndWait(cmdTilt, timeOut, out rspTilt))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse manipulator response
                if (!rspTilt.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tManipulator did not move");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnTilt.Analyze(rspTilt);

                result = saResult.Success &&
                         (saResult.ParameterCount == 1) &&
                         (saResult.Update <double>(0, ref tilt));
                if (!result)
                {
                    CmdMan.Console("\tInvalid response");
                }
                else
                {
                    CmdMan.Console("\tSet manipulator tilt complete");
                }
                return(result);
            }
            /// <summary>
            /// Request KinectTracker for the centroid of the skeleton
            /// </summary>
            /// <param name="centroidX">X coordinate of the centroid of the Skeleton</param>
            /// <param name="centroidY">Y coordinate of the centroid of the Skeleton</param>
            /// <param name="centroidZ">Z coordinate of the centroid of the Skeleton</param>
            /// <param name="timeOut">Amout of time to wait for a response in milliseconds</param>
            /// <returns>true if centroid was retrieved successfully, false otherwise</returns>
            public virtual bool LocateSkeleton(out double centroidX, out double centroidY, out double centroidZ, int timeOut)
            {
                // Stores the command to be sent to object finder
                Command cmdLocate;
                // Stores the response from object finder and the candidate while moving
                Response rspLocate = null;

                centroidX = 0;
                centroidY = 0;
                centroidZ = 0;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                cmdLocate = new Command(sgnLocate.CommandName, "skeleton", CmdMan.AutoId++);

                // 2. Send the object finderGoto command
                CmdMan.Console("\tLocating skeleton");
                if (!CmdMan.SendAndWait(cmdLocate, timeOut, out rspLocate))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse human finder response
                if (!rspLocate.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tSkeleton centroid not found");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnCalibrate.Analyze(rspLocate);

                if (saResult.Success && (saResult.ParameterCount == 3))
                {
                    saResult.Update <double>(0, ref centroidX);
                    saResult.Update <double>(1, ref centroidY);
                    saResult.Update <double>(2, ref centroidZ);
                }

                CmdMan.Console("\tLocate Skeleton complete!");
                return(true);
            }
Esempio n. 5
0
            /// <summary>
            /// Request robot base to move to the specified region
            /// </summary>
            /// <param name="x">The x coordinate position of the robot in the map</param>
            /// <param name="y">The y coordinate position of the robot in the map</param>
            /// <param name="angle">The angle the robot must turn on arrival</param>
            /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param>
            /// <returns>true if robot moved to the specified location. false otherwise</returns>
            public bool Position(out double x, out double y, out double angle, int timeOut)
            {
                // Stores the command to be sent to robot base
                Command cmdPosition;
                // Stores the response from robot base and the candidate while lookingfor
                Response rspPosition = null;

                x     = 0;
                y     = 0;
                angle = 0;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }
                cmdPosition = new Command(sgnPosition.CommandName, "", CmdMan.AutoId++);

                // 2. Send the lookat command
                CmdMan.Console("\tGeting robot position " + cmdPosition.StringToSend);
                if (!CmdMan.SendAndWait(cmdPosition, timeOut, out rspPosition))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.2. Parse base response
                if (!rspPosition.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tCan not get robot position");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnPosition.Analyze(rspPosition);

                if (saResult.Success && saResult.ParameterCount >= 3)
                {
                    saResult.Update <double>(0, ref x);
                    saResult.Update <double>(1, ref y);
                    saResult.Update <double>(2, ref angle);
                }

                CmdMan.Console("\tRobot Position [" + rspPosition.Parameters + "]");
                return(true);
            }
Esempio n. 6
0
            /// <summary>
            /// Request head to move the specified orientation
            /// </summary>
            /// <param name="neck">The neck angle of the face</param>
            /// <param name="pan">The pan  of the face</param>
            /// <param name="tilt">The tilt of the face</param>
            /// <param name="timeOut">Amout of time to wait for a head response in milliseconds</param>
            /// <returns>true if head moved to the specified location. false otherwise</returns>
            public bool LookAt(ref double neck, ref double pan, ref double tilt, int timeOut)
            {
                // Stores the command to be sent to head
                Command cmdLookAt;
                // Stores the response from head and the candidate while lookingfor
                Response rspLookAt = null;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }
                string parameters = neck.ToString("0.00") + " " + pan.ToString("0.00") + " " + tilt.ToString("0.00");

                cmdLookAt = new Command(sgnHeadLookAt.CommandName, parameters, CmdMan.AutoId++);

                // 2. Send the lookat command
                CmdMan.Console("\tMoving head to position " + parameters);
                if (!CmdMan.SendAndWait(cmdLookAt, timeOut, out rspLookAt))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse head response
                if (!rspLookAt.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tHead did not move");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnHeadLookAt.Analyze(rspLookAt);

                if (saResult.Success && (saResult.ParameterCount == 3))
                {
                    saResult.Update <double>(0, ref neck);
                    saResult.Update <double>(1, ref pan);
                    saResult.Update <double>(2, ref tilt);
                }

                CmdMan.Console("\tMoving head to position complete");
                return(true);
            }
Esempio n. 7
0
            /// <summary>
            /// Request robot base to move to the specified region
            /// </summary>
            /// <param name="x">The x coordinate position of the robot in the map</param>
            /// <param name="y">The y coordinate position of the robot in the map</param>
            /// <param name="angle">The angle the robot must turn on arrival</param>
            /// <param name="timeOut">Amout of time to wait for an arm response in milliseconds</param>
            /// <returns>true if robot moved to the specified location. false otherwise</returns>
            public bool GoToXY(ref double x, ref double y, ref double angle, int timeOut)
            {
                // Stores the command to be sent to robot base
                Command cmdGoToXY;
                // Stores the response from robot base and the candidate while lookingfor
                Response rspGoToXY = null;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }
                string parameters = "xy " + x.ToString("0.00") + " " + y.ToString("0.00") + " " + angle.ToString("0.00");

                cmdGoToXY = new Command(sgnGoTo.CommandName, parameters, CmdMan.AutoId++);

                // 2. Send the lookat command
                CmdMan.Console("\tMoving base to region " + cmdGoToXY.StringToSend);
                if (!CmdMan.SendAndWait(cmdGoToXY, timeOut, out rspGoToXY))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.2. Parse base response
                if (!rspGoToXY.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tRobot's base did not move");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnMove.Analyze(rspGoToXY);

                if (saResult.Success)
                {
                    saResult.Update <double>(1, ref x);
                    saResult.Update <double>(2, ref y);
                    saResult.Update <double>(3, ref angle);
                }

                CmdMan.Console("\tMove robot complete to region [" + rspGoToXY.Parameters + "]");
                return(true);
            }
Esempio n. 8
0
            /// <summary>
            /// Request head to show the specified expression
            /// </summary>
            /// <param name="expression">The expression to be shown by the face</param>
            /// <param name="showTime">The amoun of time in seconds the expression will be shown</param>
            /// <param name="timeOut">Amout of time to wait for a head response in milliseconds</param>
            /// <returns>true if head showed the specified expression. false otherwise</returns>
            public bool Show(string expression, double showTime, int timeOut)
            {
                // Stores the command to be sent to head
                Command cmdShow;
                // Stores the response from head and the candidate while lookingfor
                Response rspShow = null;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }
                string parameters = expression + " " + showTime.ToString("0.00");

                cmdShow = new Command(sgnHeadShow.CommandName, parameters, CmdMan.AutoId++);

                // 2. Send the show command
                CmdMan.Console("\tShowing head expression " + parameters);
                if (!CmdMan.SendAndWait(cmdShow, timeOut, out rspShow))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse head response
                if (!rspShow.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tHead did not move");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnHeadLookAt.Analyze(rspShow);

                if (saResult.Success && (saResult.ParameterCount == 2))
                {
                    saResult.Update <string>(0, ref expression);
                    saResult.Update <double>(1, ref showTime);
                }

                CmdMan.Console("\tShow expression complete");
                return(true);
            }
            /// <summary>
            /// Request KinectTracker to find specified object
            /// </summary>
            /// <param name="skeletonId">Id of the skeleton calibrated</param>
            /// <param name="timeOut">Amout of time to wait for a response in milliseconds</param>
            /// <returns>true if calibration was successfull, false otherwise</returns>
            public virtual bool Calibrate(out int skeletonId, int timeOut)
            {
                // Stores the command to be sent to object finder
                Command cmdCalibrate;
                // Stores the response from object finder and the candidate while moving
                Response rspCalibrate = null;

                skeletonId = -1;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                cmdCalibrate = new Command(sgnCalibrate.CommandName, "", CmdMan.AutoId++);

                // 2. Send the object finderGoto command
                CmdMan.Console("\tCalibrating skeleton [" + skeletonId + "]");
                if (!CmdMan.SendAndWait(cmdCalibrate, timeOut, out rspCalibrate))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse human finder response
                if (!rspCalibrate.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tCalibration failed");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnCalibrate.Analyze(rspCalibrate);

                if (saResult.Success && (saResult.ParameterCount == 1))
                {
                    saResult.Update <int>(0, ref skeletonId);
                }

                CmdMan.Console("\tCalibrate complete");
                return(true);
            }
Esempio n. 10
0
            /// <summary>
            /// Request manipulator to open the grip
            /// </summary>
            /// <param name="percentage">Percentage aperture of the grip</param>
            /// <param name="timeOut">Amout of time to wait for an man response in milliseconds</param>
            /// <returns>true if manipulator opend the grip. false otherwise</returns>
            public virtual bool OpenGrip(ref int percentage, int timeOut)
            {
                // Stores the command to be sent to man
                Command cmdOpenGrip;
                // Stores the response from man and the candidate while moving
                Response rspOpenGrip = null;
                bool     result;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                if ((percentage >= 0) || (percentage <= 100))
                {
                    cmdOpenGrip = new Command(sgnOpenGrip.CommandName, percentage.ToString(), CmdMan.AutoId++);
                }
                else
                {
                    cmdOpenGrip = new Command(sgnOpenGrip.CommandName, "", CmdMan.AutoId++);
                    percentage  = 50;
                }

                // 2. Send the manOpenGrip command
                CmdMan.Console("\tClosing manipulator grip to [" + percentage.ToString() + "%]");
                if (!CmdMan.SendAndWait(cmdOpenGrip, timeOut, out rspOpenGrip))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse manipulator response
                if (!rspOpenGrip.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tManipulator did not move");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult saResult = sgnOpenGrip.Analyze(rspOpenGrip);

                result = saResult.Success &&
                         (saResult.ParameterCount == 1) &&
                         (saResult.Update <int>(0, ref percentage));
                if (!result)
                {
                    CmdMan.Console("\tInvalid response");
                }
                else
                {
                    CmdMan.Console("\tOpen manipulator grip complete");
                }
                return(result);
            }
Esempio n. 11
0
        /// <summary>
        /// Analyzes the arguments of the provided BaseMessage object
        /// </summary>
        /// <param name="message">The BaseMessage object to match</param>
        /// <returns>The result of the analisys</returns>
        public SignatureAnalysisResult Analyze(BaseMessage message)
        {
            if (message == null) throw new ArgumentNullException("message");

            if (message.CommandName != this.commandName)
                return new SignatureAnalysisResult(message, false, null);

            Dictionary<string, object> parameters;
            SignatureAnalysisResult result = new SignatureAnalysisResult(message, false, null);
            // Find adequate delegate
            string[] sParams;
            Delegate d = GetDelegate(message.Parameters, out sParams);
            if (d != null)
            {
                // Extract parameters
                ExtractParameters(d, sParams, out parameters);
                // Generate result
                result = new SignatureAnalysisResult(message, true, d, parameters);
                return result;
            }
            // If there is no delegate, try with array of types
            Type[] typeArray = GetTypeArray(message.Parameters, out sParams);
            if (typeArray != null)
            {
                // Extract parameters
                ExtractParameters(typeArray, sParams, out parameters);
                // Generate result
                result = new SignatureAnalysisResult(message, true, d, parameters);
            }
            return result;
        }
Esempio n. 12
0
        public static void MainSignature()
        {
            Signature        s;
            bool             result;
            SignatureBuilder sb = new SignatureBuilder();

            System.Diagnostics.Stopwatch sw;
            sw = new System.Diagnostics.Stopwatch();

            sb.AddNewFromDelegate(new DoubleEventHandler(Doble));
            sb.AddNewFromDelegate(new VoidEventHandler(Vacio));
            sb.AddNewFromDelegate(new DosDobles(Suma));
            sb.AddNewFromDelegate(new DoubleArrayDelegate(DoubleArray));
            sb.AddNewFromDelegate(new StringArrayEventHandler(StringArray));

            //Console.WriteLine(sb.RegexPattern);

            s = sb.GenerateSignature("command");

            Command cmd = new Command("command", "Hola Mundo!");

            sw.Start();
            result = s.CallIfMatch(cmd);
            sw.Stop();
            Console.WriteLine("Elapsed: " + sw.ElapsedMilliseconds);
            cmd.Parameters = "";
            result         = s.CallIfMatch(cmd);
            cmd.Parameters = "3";
            result         = s.CallIfMatch(cmd);
            cmd.Parameters = "3.141592 2.71";
            result         = s.CallIfMatch(cmd);
            cmd.Parameters = "3.141592 2.71 3.141592 2.71 3.141592 2.71 3.141592 2.71 3.141592 2.71";
            result         = s.CallIfMatch(cmd);

            Response rsp = Response.CreateFromCommand(cmd, false);

            rsp.Parameters = "3.1416 1";
            SignatureAnalysisResult sar = s.Analyze(rsp);
            double a = 0;
            double b = 0;

            sar.Update("d1", ref a);
            Console.WriteLine("a: " + a.ToString());
            sar.GetParameter("d2", out b);
            Console.WriteLine("b: " + b.ToString());
            sar.Execute();

            Console.WriteLine();
            Console.WriteLine("Ejecutando Benchmark");

            //TextWriter cout = Console.Out;
            //Console.SetOut(TextWriter.Null);
            //Thread thread = new Thread(new ThreadStart(new VoidEventHandler(delegate()
            //{
            //	while (true) { sar = s.Analyze(rsp); sar.Execute(); }
            //})));
            //i = 0;
            //thread.Start();
            //Thread.Sleep(1000);
            //thread.Abort();

            sb.Clear();
            sb.AddNewFromDelegate(new DosDobles(Nothing));
            sb.AddNewFromDelegate(new VoidEventHandler(Nothing));
            s   = sb.GenerateSignature("command");
            rsp = new Response("command", "1 2", true, -1);
            TimeSpan total = new TimeSpan(0);

            sw  = new Stopwatch();
            sar = s.Analyze(rsp);
            for (int count = 0; count < 100; ++count)
            {
                Console.Write("\r");
                Console.Write(count);
                Console.Write("%\t");
                sw.Reset();
                sw.Start();
                for (i = 0; i < 100000; ++i)
                {
                    sar.Execute();
                }
                sw.Stop();
                total += sw.Elapsed;
            }
            Console.WriteLine();

            total = new TimeSpan(total.Ticks / 100);
            //Console.SetOut(cout);
            Console.WriteLine("Ejecutado 100 veces 100k ciclos. Promedio de rafaga: " + total.TotalMilliseconds + "ms");
            Console.WriteLine("Promedio de ejecucion: " + (total.TotalMilliseconds / (100.0)) + "us");

            //s.Parse(null, a, b, c);
        }
Esempio n. 13
0
            /// <summary>
            /// Request ObjectFinder to find specified object with the camera located on Bottom
            /// </summary>
            /// <param name="objectName">Name of the object to find</param>
            /// <param name="x">When this method returns contains one of this values:
            /// a) The x-coordinate of the object position if the response contains three position values
            /// b) The location of the object respect to the HFOV of the camera (angle measured in radians) if the response contains two position values.
            /// c) Double.NaN if the response does not contains position values
            /// </param>
            /// <param name="y">When this method returns contains one of this values:
            /// a) The y-coordinate of the object position if the response contains three position values
            /// b) The location of the object respect to the VFOV of the camera (angle measured in radians) if the response contains two position values.
            /// c) Double.NaN if the response does not contains position values
            /// </param>
            /// <param name="z">When this method returns contains one of this values:
            /// a) The z-coordinate of the object position if the response contains three position values
            /// b) Double.NaN
            /// </param>
            /// <param name="timeOut">Amout of time to wait for a response in milliseconds</param>
            /// <returns>true if specified object was found. false otherwise</returns>
            public virtual bool FindObjectBottom(ref string objectName, out double x, out double y, out double z, int timeOut)
            {
                // Stores the command to be sent to object finder
                Command cmdFindObjectBottom;
                // Stores the response from object finder and the candidate while moving
                Response rspFindObjectBottom = null;

                x = Double.NaN;
                y = Double.NaN;
                z = Double.NaN;

                // 1. Prepare the command
                if (!GetResource())
                {
                    return(false);
                }

                cmdFindObjectBottom = new Command(sgnFindObjectBottom.CommandName, objectName, CmdMan.AutoId++);

                // 2. Send the object finderGoto command
                CmdMan.Console("\tFinding object [" + objectName + "]");
                if (!CmdMan.SendAndWait(cmdFindObjectBottom, timeOut, out rspFindObjectBottom))
                {
                    // 2.1. Cant send socket. Operation canceled.
                    CmdMan.Console("\tCan't send command. Operation canceled");
                    FreeResource();
                    return(false);
                }

                // 3. End of move
                FreeResource();

                // 3.1. Parse head response
                if (!rspFindObjectBottom.Success)
                {
                    // 3.2. Failed response
                    CmdMan.Console("\tHuman not found");
                    return(false);
                }

                // 4.0 Recover values from response
                SignatureAnalysisResult result = sgnFindObjectBottom.Analyze(rspFindObjectBottom);

                if (result.Success)
                {
                    result.Update <string>(0, ref objectName);
                    if (result.ParameterCount == 4)
                    {
                        result.Update <double>(1, ref x);
                        result.Update <double>(2, ref y);
                        result.Update <double>(3, ref z);
                    }
                    else if (result.ParameterCount == 3)
                    {
                        result.Update <double>(1, ref x);
                        result.Update <double>(2, ref y);
                        z = Double.NaN;
                    }
                }

                CmdMan.Console("\tFind object complete");
                return(true);
            }