Ejemplo n.º 1
0
        public void SetMotors(double leftPower, double rightPower)
        {
            if (!motorsOn)
            {
                EnableMotors();
            }

            //drive.SetDrivePowerRequest drivePowerReq = new drive.SetDrivePowerRequest();
            //drivePowerReq.LeftWheelPower = leftPower;
            //drivePowerReq.RightWheelPower = rightPower;
            //drive.SetDrivePower setDrivePower = new drive.SetDrivePower(drivePowerReq);
            //drivePort.Post(setDrivePower);

            //ManualResetEvent signal = new ManualResetEvent(false);
            //Arbiter.Activate(DssEnvironment.TaskQueue,
            //    Arbiter.Choice<DefaultUpdateResponseType, Fault>(
            //        drivePort.SetDrivePower((double)leftPower, (double)rightPower),
            //        delegate(DefaultUpdateResponseType state)
            //        {
            //            signal.Set();
            //        },
            //        delegate(Fault failure)
            //        {
            //            Console.WriteLine("*** Fault in SetMotors: ");
            //            foreach (var r in failure.Reason)
            //                Console.WriteLine("***    " + r.Value);
            //            signal.Set();
            //        }));
            //signal.WaitOne();
            RSUtils.ReceiveSync(taskQueue, drivePort.SetDrivePower(leftPower, rightPower), Myro.Utilities.Params.DefaultRecieveTimeout);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set the motor power.
 /// </summary>
 /// <param name="leftPower"></param>
 /// <param name="rightPower"></param>
 public void SetMotors(double leftPower, double rightPower)
 {
     if (!motorsOn)
     {
         EnableMotors();
     }
     RSUtils.ReceiveSync(taskQueue, drivePort.SetDrivePower(leftPower, rightPower), Myro.Utilities.Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Set a single element in the vector by name.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="value"></param>
 public void Set(string key, double value)
 {
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByKey(new List <string>()
     {
         key
     }, new List <double>()
     {
         value
     }, DateTime.Now), Myro.Utilities.Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Set a single element in the vector by index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void Set(int index, double value)
 {
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByIndex(new List <int>()
     {
         index
     }, new List <double>()
     {
         value
     }, DateTime.Now), Myro.Utilities.Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Set a group of elements in the vector by name.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void Set(List <string> keys, List <double> values)
 {
     //try
     //{
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByKey(keys, values, DateTime.Now), Myro.Utilities.Params.defaultRecieveTimeout);
     //}
     //catch (KeyNotFoundException)
     //{
     //    throw new AdapterArgumentException(Strings.KeyNotFound());
     //}
 }
Ejemplo n.º 6
0
        protected virtual void Initialize()
        {
            // Initialize the port and subscribe to the service to know when the motors are enabled
            motorsOn  = false;
            drivePort = DssEnvironment.ServiceForwarder <drive.DriveOperations>(new Uri(ServiceInfo.Service));
            drive.DriveOperations driveNotificationPort = new drive.DriveOperations();
            RSUtils.ReceiveSync(taskQueue, drivePort.Subscribe(driveNotificationPort), Params.DefaultRecieveTimeout);

            // Set up notifications
            Arbiter.Activate(DssEnvironment.TaskQueue,
                             Arbiter.Receive <drive.Update>(true, driveNotificationPort, NotifyDriveUpdate));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Retrieve a single element from the state vector, with full safety
        /// checks.  Throws AdapterArgumentException and
        /// AdapterOperationException.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public double Get(int index)
        {
            //try
            //{
            var resp = RSUtils.ReceiveSync <vector.GetElementResponseType>(taskQueue, opPort.GetByIndex(index), Myro.Utilities.Params.defaultRecieveTimeout);

            return(resp.Value);
            //}
            //catch (ArgumentOutOfRangeException)
            //{
            //    throw new AdapterArgumentException(Strings.IndexOutOfBounds(index));
            //}
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieve a single element from the state vetor, by name, with full
        /// safety checks.  Throws AdapterArgumentException and
        /// AdapterOperationException.
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public double Get(string key)
        {
            //try
            //{
            var resp = RSUtils.ReceiveSync <vector.GetElementResponseType>(taskQueue, opPort.GetByKey(key), Myro.Utilities.Params.defaultRecieveTimeout);

            return(resp.Value);
            //}
            //catch (KeyNotFoundException)
            //{
            //    throw new AdapterArgumentException(Strings.KeyNotFound(key));
            //}
        }
Ejemplo n.º 9
0
        public void QueryFrame(MyroImageType type, out int Width, out int Height, out byte[] Image)
        {
            var r = RSUtils.ReceiveSync(queue,
                                        opPort.QueryFrame(new webcam.QueryFrameRequest()
            {
                Format = type.Guid
            }),
                                        Params.DefaultRecieveTimeout);

            Width  = r.Size.Width;
            Height = r.Size.Height;
            Image  = r.Frame;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// "Darken" the camera, so that it only sees bright lights.  This
 /// turns off automatic exposure, gain, and white balance.
 /// </summary>
 /// <param name="level"></param>
 public void DarkenCamera(byte level)
 {
     RSUtils.ReceiveSync(queue, opPort.SetCamera(new fluke.CamControlState()
     {
         Darkness         = level,
         Val1             = 0,
         Val2             = 0,
         Brightness       = 0,
         Exposure         = 0,
         AutoExposure     = false,
         AutoGain         = false,
         AutoWhiteBalance = false
     }), Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Return the camera to automatic mode, auto exposure, gain, and WB.
 /// </summary>
 public void AutoCamera()
 {
     RSUtils.ReceiveSync(queue, opPort.SetCamera(new fluke.CamControlState()
     {
         Darkness         = 0,
         Val1             = 0x80,
         Val2             = 0x80,
         Brightness       = b.ScribblerHelper.CameraParams.CAM_BRT_DEFAULT,
         Exposure         = b.ScribblerHelper.CameraParams.CAM_EXP_DEFAULT,
         AutoExposure     = true,
         AutoGain         = true,
         AutoWhiteBalance = true
     }), Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Set a group of elements in the vector by index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void Set(List <int> indices, List <double> values)
 {
     //try
     //{
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByIndex(indices, values, DateTime.Now), Myro.Utilities.Params.defaultRecieveTimeout);
     //}
     //catch (ArgumentOutOfRangeException e)
     //{
     //    throw new AdapterArgumentException(
     //        e.ActualValue is Int32 ?
     //        Strings.IndexOutOfBounds((Int32)e.ActualValue) :
     //        Strings.IndexOutOfBounds());
     //}
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Set a single element in the vector by index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void Set(int index, double value)
 {
     //try
     //{
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByIndex(new List <int>()
     {
         index
     }, new List <double>()
     {
         value
     }, DateTime.Now), Myro.Utilities.Params.defaultRecieveTimeout);
     //}
     //catch (ArgumentOutOfRangeException)
     //{
     //    throw new AdapterArgumentException(Strings.IndexOutOfBounds(index));
     //}
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Set a single element in the vector by name.
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="value"></param>
 public void Set(string key, double value)
 {
     //try
     //{
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByKey(new List <string>()
     {
         key
     }, new List <double>()
     {
         value
     }, DateTime.Now), Myro.Utilities.Params.DefaultRecieveTimeout);
     //}
     //catch (KeyNotFoundException)
     //{
     //    throw new AdapterArgumentException(Strings.KeyNotFound(key));
     //}
 }
Ejemplo n.º 15
0
        /// <summary>
        /// This is a helper mehtod that connects the Scribbler on the specified
        /// COM port.  It waits for the connection to complete, and re-throws any
        /// exceptions generated by the Scribbler service.
        /// </summary>
        /// <param name="comPort"></param>
        private static void connectWaitForScribbler(string comPort)
        {
            ManualResetEvent evt = new ManualResetEvent(false);

            waitForService(new ServiceInfoType(scribbler.Contract.Identifier),
                           delegate(ServiceInfoType info) { brickService = info; evt.Set(); });
            evt.WaitOne(Params.DefaultRecieveTimeout, false);
            if (brickService == null)
            {
                throw new MyroInitException("Could not find Scribbler service");
            }
            var             scribPort = DssEnvironment.ServiceForwarder <scribbler.ScribblerOperations>(new Uri(brickService.Service));
            DispatcherQueue queue     = new DispatcherQueue("init", new Dispatcher());

            try
            {
                if (comPort != null)
                {
                    int comNumber;
                    if (comPort.ToLower().StartsWith("com"))
                    {
                        comNumber = Int32.Parse(comPort.Substring(3));
                    }
                    else
                    {
                        throw new MyroInitException("COM port string must be of the format com2, com5, etc.");
                    }
                    RSUtils.ReceiveSync(queue, scribPort.Replace(new scribbler.ScribblerState()
                    {
                        ComPort = comNumber
                    }), Params.DefaultRecieveTimeout);
                }
                DssEnvironment.LogInfo("calling reconnect...");
                RSUtils.ReceiveSync(queue, scribPort.Reconnect(), Params.DefaultRecieveTimeout);
                DssEnvironment.LogInfo("reconnect returned");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                queue.Dispose();
            }
        }
Ejemplo n.º 16
0
        private T tryCreateAdapter()
        {
            lock (this)
            {
                try
                {
                    // Query the service initially
                    PortSet <LookupResponse, Fault> responsePort = new PortSet <LookupResponse, Fault>();
                    DssEnvironment.ServiceForwarderUnknownType(new Uri("dssp.tcp://localhost/" + Name)).PostUnknownType(
                        new DsspDefaultLookup()
                    {
                        Body = new LookupRequestType(), ResponsePort = responsePort
                    });
                    ServiceInfoType responseRecord = RSUtils.ReceiveSync(responsePort, Myro.Utilities.Params.DefaultRecieveTimeout);

                    // Try to find a working contract for each adapter
                    foreach (var factory in adapterFactories)
                    {
                        try
                        {
                            ServiceInfoType serviceRecord = RSUtils.FindCompatibleContract(responseRecord, factory.SupportedContracts);
                            T ret = (T)factory.Create(serviceRecord);
                            Console.WriteLine("Attached to " + serviceRecord.Service + " as \"" + Name + "\"");
                            return(ret);
                        }
                        catch (NoContractFoundException) { }
                    }

                    // If we haven't returned already in the loop, we didn't find
                    // an adapter that works.
                    throw new NoAdapterFoundException(responseRecord);
                }
                catch (NoAdapterFoundException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    DssEnvironment.LogError("Error querying or attaching to " + "dssp.tcp://localhost/" + Name + ": " + e.ToString());
                    throw;
                }
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Modify the robot name.
 /// </summary>
 /// <param name="name"></param>
 public void SetName(string name)
 {
     RSUtils.ReceiveSync(queue, opPort.SetName(name), Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 18
0
 public drive.DriveDifferentialTwoWheelState Get()
 {
     return(RSUtils.ReceiveSync <drive.DriveDifferentialTwoWheelState>(taskQueue, drivePort.Get(), Myro.Utilities.Params.DefaultRecieveTimeout));
 }
Ejemplo n.º 19
0
        //public override bool Equals(Object obj)
        //{
        //    if (obj is String)
        //    {
        //        string truncUri = ServiceInfo.Service.Substring(ServiceInfo.Service.IndexOf('/', ServiceInfo.Service.IndexOf("//") + 2));
        //        return String.Equals(truncUri, obj);
        //    }
        //    else
        //        return String.Equals(this.ServiceInfo.Service, ((DriveAdapter)obj).ServiceInfo.Service);
        //}

        public void Stop()
        {
            RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, drivePort.AllStop(), Myro.Utilities.Params.DefaultRecieveTimeout);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Set the fluke IR obstacle sensor power.
 /// </summary>
 /// <param name="power"></param>
 public void SetIRPower(byte power)
 {
     RSUtils.ReceiveSync(queue, opPort.SetIRPower(power), Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 21
0
 protected void EnableMotors()
 {
     RSUtils.ReceiveSync(taskQueue, drivePort.EnableDrive(true), Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Retrieve a single element from the state vetor, by name, with full
        /// safety checks.  Throws AdapterArgumentException and
        /// AdapterOperationException.
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public double Get(string key)
        {
            var resp = RSUtils.ReceiveSync <vector.GetElementResponseType>(taskQueue, opPort.GetByKey(key), Myro.Utilities.Params.DefaultRecieveTimeout);

            return(resp.Value);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Retrieve the entire vector state.  State members may be null.
 /// </summary>
 /// <returns></returns>
 public vector.VectorState GetState()
 {
     return(RSUtils.ReceiveSync <vector.VectorState>(taskQueue, opPort.Get(), Myro.Utilities.Params.defaultRecieveTimeout));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Set all elements in the vector.
 /// </summary>
 /// <param name="values"></param>
 public void SetAllElements(List <double> values)
 {
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetAllElements(values, DateTime.Now), Myro.Utilities.Params.defaultRecieveTimeout);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Set a group of elements in the vector by name.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="value"></param>
 public void Set(List <string> keys, List <double> values)
 {
     RSUtils.ReceiveSync <DefaultUpdateResponseType>(taskQueue, opPort.SetByKey(keys, values, DateTime.Now), Myro.Utilities.Params.DefaultRecieveTimeout);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Return the robot name.
 /// </summary>
 /// <returns></returns>
 public string GetName()
 {
     return(RSUtils.ReceiveSync(queue, opPort.GetName(), Params.DefaultRecieveTimeout).Value);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Retrieve all vector elements at once.
 /// </summary>
 /// <returns></returns>
 public List <double> GetAllElements()
 {
     return(RSUtils.ReceiveSync <vector.GetAllElementsResponseType>(taskQueue, opPort.GetAllElements(), Myro.Utilities.Params.defaultRecieveTimeout).Values);
 }