Example #1
0
        public AlarmSystem()
        {
            m_WatchDogTimeout = new TimeSpan(0, 0, 0, 0, 800);
            DefaultTimeout    = new TimeSpan(0, 0, 0, 2);

            try
            {
                if (ProfileKeeper.IsExists())
                {
                    TheProfile = ProfileKeeper.LoadProfile();
                }
            }
            catch (Exception)
            {
                // ignore
            }
            if (TheProfile == null)
            {
                var ports = SerialPort.GetPortNames();
                var name  = ports.Length == 0 ? "COM1" : ports[0];
                TheProfile =
                    new Profile
                {
                    Name     = name,
                    BaudRate = 115200,
                    DataBits = 8,
                    StopBits = StopBits.One,
                    Parity   = Parity.None
                };
                ProfileKeeper.SaveProfile(TheProfile);
            }

            ShakingEnabled      = true;
            IlluminanceEnabled  = true;
            DistanceEnabled     = true;
            ConnectivityEnabled = true;

            RealState  = AlarmingState.None;
            State      = AlarmingState.Unarmed;
            m_Watchdog = new Timer(WatchDogTimeout.TotalMilliseconds)
            {
                AutoReset = false
            };
            m_Watchdog.Elapsed += Watchdog_Triggered;

            //m_IllumSmoother = new ExponentSmoother(0.2);
            m_AccSmoother  = new CuSumEventDetecter(0.5, 0.9, MaxAcc);
            m_DistSmoother = new MinSmoother(5);

            m_Port                 = new AsyncSerialPort(TheProfile, 12);
            m_Port.OpenPort       += Port_Open;
            m_Port.ClosePort      += Port_Close;
            m_Port.PackageArrived += Port_Package;
            m_Port.ReadWriteError += Port_Error;

            IsOpen = false;
        }
 public PeaksAnalyzer(IDataCursor cursor, IPeaksFinder finder, ISmoother smoother,
                      IPeaksRepository peaksRepository, ILorentzian lorentzianModel)
 {
     lorentzian   = lorentzianModel;
     dataCursor   = cursor;
     peaksFinder  = finder;
     dataSmoother = smoother;
     peaks        = peaksRepository;
 }
Example #3
0
        /// <summary>
        /// Creates an instance of a <c>SmoothedBody</c> using the referenced smoothing
        /// parameters object.
        /// </summary>
        public SmoothedBody(ISmootherParameters parameters)
            : base()
        {
            ISmoother smoother = (ISmoother)Activator.CreateInstance(typeof(T));

            _joints.Clear();
            _jointOrientations.Clear();
            foreach (var jointType in JointTypeEx.AllJoints)
            {
                _joints.Add(jointType, (IJoint)Activator.CreateInstance(smoother.CustomJointType, (JointType)jointType, parameters));
                _jointOrientations.Add(jointType, (IJointOrientation)Activator.CreateInstance(smoother.CustomJointOrientationType, (JointType)jointType, parameters));
            }
        }
Example #4
0
        /// <summary>
        /// Creates a tracker node with the given 6DOF device identifier (see InputMapper class
        /// for the identifier strings).
        /// </summary>
        /// <param name="name">The name of this node</param>
        /// <param name="deviceIdentifier">The 6DOF device identifier (see InputMapper class)</param>
        /// <exception cref="GoblinException">If the given device identifier is not a 6DOF device</exception>
        public TrackerNode(String name, String deviceIdentifier) :
            base(name)
        {
            worldTransform = Matrix.Identity;
            this.deviceIdentifier = deviceIdentifier;
            if (!InputMapper.Instance.Contains6DOFInputDevice(deviceIdentifier))
                throw new GoblinException(deviceIdentifier + " is not recognized. Only 6DOF devices " +
                    "are allowed to be used with TrackerNode.");

            smoother = null;
            predictor = null;
            smooth = false;
            predict = false;
        }
Example #5
0
        /// <summary>
        /// Creates a tracker node with the given 6DOF device identifier (see InputMapper class
        /// for the identifier strings).
        /// </summary>
        /// <param name="name">The name of this node</param>
        /// <param name="deviceIdentifier">The 6DOF device identifier (see InputMapper class)</param>
        /// <exception cref="GoblinException">If the given device identifier is not a 6DOF device</exception>
        public TrackerNode(String name, String deviceIdentifier) :
            base(name)
        {
            worldTransform        = Matrix.Identity;
            this.deviceIdentifier = deviceIdentifier;
            if (!InputMapper.Instance.Contains6DOFInputDevice(deviceIdentifier))
            {
                throw new GoblinException(deviceIdentifier + " is not recognized. Only 6DOF devices " +
                                          "are allowed to be used with TrackerNode.");
            }

            smoother  = null;
            predictor = null;
            smooth    = false;
            predict   = false;
        }
Example #6
0
 public TrigramWithLinearInterpolationLanguageModel(double l1, double l2, double l3, ISmoother smoother)
 {
     UnigramLM = new UnigramLanguageModel {
         Smoother = smoother
     };
     BigramLM = new BigramLanguageModel {
         Smoother = smoother
     };
     TrigramLM = new TrigramLanguageModel {
         Smoother = smoother
     };
     Smoother = smoother;
     L1       = l1;
     L2       = l2;
     L3       = l3;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractParticleFilter"/> class.
 /// </summary>
 /// <param name="resampler"><see cref="resampler"/></param>
 /// <param name="noiseGenerator"><see cref="noiseGenerator"/></param>
 /// <param name="particleControllerX"><see cref="ParticleControllerX"/></param>
 /// <param name="particleControllerY">The particles for the y dimension</param>
 /// <param name="particleControllerZ">The particles for the z dimension</param>
 /// <param name="resampleNoiseSize"><see cref="resampleNoiseSize"/></param>
 /// <param name="smoother"><see cref="smoother"/></param>
 /// <param name="averageCalculator"><see cref="averageCalculator"/></param>
 protected AbstractParticleFilter(
     IResampler resampler,
     INoiseGenerator noiseGenerator,
     AbstractParticleController particleControllerX,
     AbstractParticleController particleControllerY,
     AbstractParticleController particleControllerZ,
     float resampleNoiseSize,
     ISmoother smoother,
     Func <float[], float> averageCalculator)
 {
     this.resampler           = resampler;
     this.noiseGenerator      = noiseGenerator;
     this.ParticleControllerX = particleControllerX;
     this.ParticleControllerY = particleControllerY;
     this.ParticleControllerZ = particleControllerZ;
     this.resampleNoiseSize   = resampleNoiseSize;
     this.smoother            = smoother;
     this.averageCalculator   = averageCalculator;
     this.CurrentTimeStamp    = -1;
     this.Measurements        = new List <Measurement <Vector3> >();
 }
Example #8
0
        /// <summary>
        /// Repopulates the properties of a smoother from Xml
        /// </summary>
        /// <param name="smoother">The smoother to repopulate</param>
        /// <param name="properties">The values of the properties within
        /// the Xml</param>
        private void _populateSmoother(ISmoother smoother, IEnumerable <XElement> properties)
        {
            Type smootherType  = smoother.GetType();
            var  propertyInfos = smootherType.GetProperties();

            foreach (XElement element in properties)
            {
                XAttribute nameAttr = element.Attribute("name");
                if (nameAttr == null)
                {
                    continue;
                }

                PropertyInfo prop = propertyInfos.FirstOrDefault(x => x.Name == nameAttr.Value);
                if (prop == null)
                {
                    continue;
                }

                prop.SetValue(smoother, _stringToObj(element.Value));
            }
        }
Example #9
0
        /// <summary>
        /// Creates a node that is tracked by fiducial marker (can be either an array or
        /// a single marker) and updated automatically.
        /// </summary>
        /// <param name="name">Name of this marker node</param>
        /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
        /// <param name="markerConfigs">A list of configs that specify the fiducial marker
        /// (can be either an array or a single marker) to look for</param>
        public MarkerNode(String name, IMarkerTracker tracker, params Object[] markerConfigs)
            : base(name)
        {
            this.tracker = tracker;
            if (tracker != null)
            {
                markerID           = tracker.AssociateMarker(markerConfigs);
                this.markerConfigs = markerConfigs;
            }
            found       = false;
            maxDropouts = 5;
            prevMatrix  = Matrix.Identity;
            dropout     = 0;
            optimize    = false;

            smoother       = null;
            predictor      = null;
            smooth         = false;
            predict        = false;
            predictionTime = 0;

            inverseCameraView = Matrix.Identity;
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PositionParticleFilter"/> class.
 /// </summary>
 /// <param name="noiseGenerator">See noiseGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampleNoiseSize">See resampleNoiseSize argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampler">See resampler argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleGenerator">See particleGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleAmount">See particleAmount argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="fieldSize">The dimensions of the area where the user can be.</param>
 /// <param name="smoother">See smoother argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 public PositionParticleFilter(
     INoiseGenerator noiseGenerator,
     float resampleNoiseSize,
     IResampler resampler,
     IParticleGenerator particleGenerator,
     int particleAmount,
     FieldSize fieldSize,
     ISmoother smoother)
     : base(
         resampler,
         noiseGenerator,
         new LinearParticleController(particleGenerator, particleAmount, fieldSize.Xmin, fieldSize.Xmax),
         new LinearParticleController(particleGenerator, particleAmount, fieldSize.Ymin, fieldSize.Ymax),
         new LinearParticleController(particleGenerator, particleAmount, fieldSize.Zmin, fieldSize.Zmax),
         resampleNoiseSize,
         smoother,
         Enumerable.Average)
 {
     this.displacementSources = new List <IDisplacementSource>();
     this.positionSources     = new List <IPositionSource>();
     this.iex = new LinearRegression();
     this.iey = new LinearRegression();
     this.iez = new LinearRegression();
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParticleFilter"/> class.
 /// </summary>
 /// <param name="noiseGenerator">See noiseGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampleNoiseSize">See resampleNoiseSize argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampler">See resampler argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleGenerator">See particleGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleAmount">See particleAmount argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="fieldSize">The dimensions of the area where the user can be.</param>
 /// <param name="smoother">See smoother argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 public ParticleFilter(int particleAmount, float resampleNoiseSize, FieldSize fieldSize, IParticleGenerator particleGenerator, IResampler resampler, INoiseGenerator noiseGenerator, ISmoother smoother)
 {
     this.posReceivers      = new List <IPositionFeedbackReceiver>();
     this.oriReceivers      = new List <IOrientationFeedbackReceiver>();
     this.positionFilter    = new PositionParticleFilter(noiseGenerator, resampleNoiseSize, resampler, particleGenerator, particleAmount, fieldSize, smoother);
     this.orientationFilter = new OrientationParticleFilter(noiseGenerator, resampleNoiseSize, resampler, particleGenerator, particleAmount, smoother.Clone());
 }
Example #12
0
        public static LanguageModelHyperparameters GenerateFromArguments(string args)
        {
            args = args.ToLower();
            var splittedArgs = args.Split(' ', StringSplitOptions.RemoveEmptyEntries);

            // Smoothers
            // Create the collection-level unigram model with no smoothing (max-likelihood) used in some smoothing techniques
            INGramLanguageModel collectionLevelLanguageModel = new UnigramLanguageModel {
                Smoother = new MaxLikelihoodSmoother()
            };
            ISmoother smoother = null;

            switch (splittedArgs[Array.IndexOf(splittedArgs, "-smoothingtechnique") + 1])
            {
            case "ml":
                smoother = new MaxLikelihoodSmoother();
                break;

            case "addk":
                smoother = new AddKSmoother {
                    K = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1])
                };
                break;

            case "jm":
                smoother = new JelinekMercerSmoother {
                    CollectionLevelLanguageModel = collectionLevelLanguageModel, L = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1])
                };
                break;

            case "dirichlet":
                smoother = new DirichletSmoother {
                    CollectionLevelLanguageModel = collectionLevelLanguageModel, M = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1])
                };
                break;

            case "ad":
                smoother = new AbsoluteDiscountSmoother {
                    CollectionLevelLanguageModel = collectionLevelLanguageModel, D = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1])
                };
                break;

            case "ts":
                smoother = new TwoStageSmoother {
                    CollectionLevelLanguageModel = collectionLevelLanguageModel, L = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1]), M = Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l2") + 1])
                };
                break;
            }

            // LM
            var nGramLanguageModels = Corpus.CategoriesMap.ToDictionary(cdp => cdp.Key, cdp =>
            {
                INGramLanguageModel modelToUse = null;
                switch (splittedArgs[Array.IndexOf(splittedArgs, "-lm") + 1])
                {
                case "unigram":
                    modelToUse = new UnigramLanguageModel {
                        Smoother = smoother
                    };
                    break;

                case "bigram":
                    modelToUse = new BigramLanguageModel {
                        Smoother = smoother
                    };
                    break;

                case "trigram":
                    modelToUse = new TrigramLanguageModel {
                        Smoother = smoother
                    };
                    break;

                case "trigramwithlinearinterpolation":
                    modelToUse = new TrigramWithLinearInterpolationLanguageModel(
                        Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1]),
                        Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l2") + 1]),
                        Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l3") + 1]),
                        smoother);
                    break;
                }

                return(modelToUse);
            });

            return(new LanguageModelHyperparameters
            {
                CategoryNGramLanguageModelsMap = nGramLanguageModels,
                UnkRatio = Array.IndexOf(splittedArgs, "-unkratio") >= 0 ? Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-unkratio") + 1]) : 0.1,
                IgnoreCase = Array.IndexOf(splittedArgs, "-ignorecase") >= 0,
                L1 = Array.IndexOf(splittedArgs, "-l1") >= 0 ? Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l1") + 1]) : 0.0,
                L2 = Array.IndexOf(splittedArgs, "-l2") >= 0 ? Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l2") + 1]) : 0.0,
                L3 = Array.IndexOf(splittedArgs, "-l3") >= 0 ? Double.Parse(splittedArgs[Array.IndexOf(splittedArgs, "-l3") + 1]) : 0.0,
                CollectionLevelLanguageModel = collectionLevelLanguageModel,
            });
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OrientationParticleFilter"/> class.
 /// </summary>
 /// <param name="noiseGenerator">See noiseGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampleNoiseSize">See resampleNoiseSize argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="resampler">See resampler argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleGenerator">See particleGenerator argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="particleAmount">See particleAmount argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 /// <param name="smoother">See smoother argument of the constructor of <seealso cref="AbstractParticleFilter"/></param>
 public OrientationParticleFilter(INoiseGenerator noiseGenerator, float resampleNoiseSize, IResampler resampler, IParticleGenerator particleGenerator, int particleAmount, ISmoother smoother)
     : base(
         resampler,
         noiseGenerator,
         new CircularParticleController(particleGenerator, particleAmount),
         new CircularParticleController(particleGenerator, particleAmount),
         new CircularParticleController(particleGenerator, particleAmount),
         resampleNoiseSize,
         smoother,
         AngleMath.Average)
 {
     this.orientationSources = new List <IOrientationSource>();
 }
Example #14
0
        /// <summary>
        /// Creates a node that is tracked by fiducial marker (can be either an array or
        /// a single marker) and updated automatically.
        /// </summary>
        /// <param name="name">Name of this marker node</param>
        /// <param name="tracker">A marker tracker used to track this fiducial marker</param>
        /// <param name="markerConfigs">A list of configs that specify the fiducial marker 
        /// (can be either an array or a single marker) to look for</param>
        public MarkerNode(String name, IMarkerTracker tracker, params Object[] markerConfigs)
            : base(name)
        {
            this.tracker = tracker;
            if (tracker != null)
            {
                markerID = tracker.AssociateMarker(markerConfigs);
                this.markerConfigs = markerConfigs;
            }
            found = false;
            maxDropouts = 5;
            prevMatrix = Matrix.Identity;
            dropout = 0;
            optimize = false;

            smoother = null;
            predictor = null;
            smooth = false;
            predict = false;
            predictionTime = 0;

            inverseCameraView = Matrix.Identity;
        }