Ejemplo n.º 1
0
        public PersonControl(PairablePerson pairablePerson)
        {
            InitializeComponent();

            person = pairablePerson;

            //Setup Events
            pairablePerson.LocationChanged += OnLocationChanged;
            pairablePerson.OrientationChanged += OnOrientationChanged;
            pairablePerson.PairingStateChanged += OnPairingStateChanged;
            pairablePerson.CalibrationStateChanged += onCalibrationStateChanged;

            //Setup the person's 'dot'
            PersonEllipse.StrokeThickness = DrawingResources.STROKE_WIDTH;
            PersonEllipse.Stroke = DrawingResources.unpairedBrush;

            // Assuming people have a diameter of about 0.5m
            double personWidth = 0.5 * MainWindow.SharedCanvas.ActualWidth / DrawingResources.ROOM_WIDTH;
            PersonEllipse.Width = personWidth;
            PersonEllipse.Height = personWidth;

            //Setup the person's identifier
            IdentifierLabel.Content = "ID: " + pairablePerson.Identifier;
            IdentifierLabel.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            IdentifierLabel.Width = 100;
            Canvas.SetTop(IdentifierLabel, 130);
            Canvas.SetLeft(IdentifierLabel, -5);

            //Setup the person's identifier
            CoordinatesLabel.Content = pairablePerson.Identifier;
            CoordinatesLabel.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            CoordinatesLabel.Width = 300;
            Canvas.SetTop(CoordinatesLabel, 150);
            Canvas.SetLeft(CoordinatesLabel, -150);
        }
Ejemplo n.º 2
0
        public void DeviceLost(IADevice iaDevice)
        {
            List <PairablePerson> pairablePersons = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
            List <PairableDevice> pairableDevices = locator.Devices.OfType <PairableDevice>().ToList <PairableDevice>();

            // Find and remove the pairable device from the Locator's list of devices
            PairableDevice pairableDevice = pairableDevices.Find(d => d.Identifier.Equals(iaDevice.Name));

            locator.Devices.Remove(pairableDevice);


            // If the device was paired, we mark its corresponding person unpaired.
            PairablePerson person = pairablePersons.Find(p => p.Identifier.Equals(pairableDevice.HeldByPersonIdentifier));

            if (person != null)
            {
                //Remove the pairing information associated with the Perpon
                person.HeldDeviceIdentifier = null;
                person.PairingState         = PairingState.NotPaired;
            }
            pairableDevice.HeldByPersonIdentifier = null;

            if (pairableDevice == null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR: tried to remove nonexistent pairable device.");
            }

            if (DeviceRemoved != null)
            {
                DeviceRemoved(this, pairableDevice);
            }
        }
Ejemplo n.º 3
0
        //TODO Deal with the cause where more then two Devices (or persons) are Attempting to Pair
        //TODO Consider how the timer
        /// <summary>
        /// This function attempts to pair a Person and a Device. This occurs if both have had their states
        /// sets to 'PairingAttempt'.
        /// </summary>
        /// <param name="devices"> The list of current devices</param>
        /// <param name="persons"> The list of current persons</param>
        /// <returns></returns>
        internal bool AttemptPairing(List <PairableDevice> devices, List <PairablePerson> persons)
        {
            //Find a device set to PairingAttempt
            PairableDevice pairingDevice = devices.Find(device => device.PairingState == PairingState.PairingAttempt);

            //Find a person set to PairingAttempt
            PairablePerson pairingPerson = persons.Find(person => person.PairingState == PairingState.PairingAttempt);

            //Check Device & Person
            if (pairingDevice == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "Cannot Pair Because No Device Is Marked For Pairing");
            }

            if (pairingPerson == null)
            {
                logger.TraceEvent(TraceEventType.Error, 0, "Cannot Pair Because No Person Is Marked For Pairing");
            }

            //Debug Intermittent Failure
            String deviceExists = (pairingDevice != null) ? "Pairing Device" : "Null";
            String personExists = (pairingPerson != null) ? "Pairing Person" : "Null";

            logger.TraceEvent(TraceEventType.Verbose, 0, "Device: {0} and Person: {1}", deviceExists, personExists);

            if (pairingDevice != null && pairingPerson != null)
            {
                Pair(pairingDevice, pairingPerson);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 public void onCalibrationStateChanged(PairablePerson pairablePerson)
 {
     //Dispatch Brush Change to Main Thread
     Application.Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         //Set Color of Ellipse to Appropriate Color
         PersonEllipse.Stroke = DrawingResources.GetBrushFromCalibrationState(pairablePerson.CalibrationState);
     }));
 }
Ejemplo n.º 5
0
 private void RemovePerson(List <PairablePerson> vanishedPersons, PairablePerson person)
 {
     //Remove Held-Device Identifier
     person.HeldDeviceIdentifier = null;
     vanishedPersons.Add(person);
     if (PersonRemoved != null)
     {
         PersonRemoved(this, person);
     }
 }
Ejemplo n.º 6
0
        // #region Process Persons Tests
        internal PairablePerson CreateTestPerson(int newId, int? holdsId = null)
        {
            PairablePerson person = new PairablePerson
            {
                Identifier = newId.ToString(),
                HeldDeviceIdentifier = holdsId.ToString() ?? null,
                Location = null,
                Orientation = null,
                PairingState = PairingState.NotPaired
            };

            return person;
        }
Ejemplo n.º 7
0
        internal void PersonPairAttempt(String SkeletonId, List <PairablePerson> Persons)
        {
            //Set the Person involved to the AttemptingPair state
            //PairablePerson p = Persons.Find(person => person.Identifier.Equals(SkeletonId));
            PairablePerson p = Persons.Find(person => SkeletonId.Equals(person.Identifier));


            //Because the pairing can overlap, we do not want to reset a paired state
            if (p != null && p.PairingState != PairingState.Paired)
            {
                p.PairingState = PairingState.PairingAttempt;
            }
            AttemptPairing();

            logger.TraceEvent(TraceEventType.Information, 0, "Kinect Wave Gesture Recognized");
        }
Ejemplo n.º 8
0
        public void UnpairDevice(PairableDevice pairingDevice)
        {
            if (pairingDevice.PairingState != PairingState.NotPaired)
            {
                List <PairablePerson> pPersons      = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
                PairablePerson        pairingPerson = pPersons.Find(p => p.HeldDeviceIdentifier == pairingDevice.Identifier);

                pairingDevice.HeldByPersonIdentifier = null;
                pairingDevice.PairingState           = PairingState.NotPaired;

                pairingPerson.PairingState         = PairingState.NotPaired;
                pairingPerson.HeldDeviceIdentifier = null;

                // Dispatch a message to the device
                IARequest request = new IARequest(Routes.BecomeUnpairedRoute);
                // Find the IntAirAct device matching the current device.
                IADevice iaDevice = intAirAct.Devices.Find(d => d.Name == pairingDevice.Identifier);
                intAirAct.SendRequest(request, iaDevice);
                System.Diagnostics.Debug.WriteLine(iaDevice.Name + " " + iaDevice.Host);
            }
        }
Ejemplo n.º 9
0
        public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson)
        {
            //Change the Pairing State
            pairingDevice.PairingState = PairingState.Paired;
            pairingPerson.PairingState = PairingState.Paired;

            //Create a Holds-Device and Held-By-Person Relationship
            pairingPerson.HeldDeviceIdentifier = pairingDevice.Identifier;
            pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier;

            List<IADevice> devices = intAirAct.Devices;
            IADevice device = devices.Find(d => d.Name == pairingDevice.Identifier);
            if (device != null)
            {
                IARequest request = new IARequest(Routes.BecomePairedRoute);
                intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception)
                {
                    logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier);
                });

            }

            logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier);
        }
Ejemplo n.º 10
0
        public void Pair(PairableDevice pairingDevice, PairablePerson pairingPerson)
        {
            //Change the Pairing State
            pairingDevice.PairingState = PairingState.Paired;
            pairingPerson.PairingState = PairingState.Paired;

            //Create a Holds-Device and Held-By-Person Relationship
            pairingPerson.HeldDeviceIdentifier   = pairingDevice.Identifier;
            pairingDevice.HeldByPersonIdentifier = pairingPerson.Identifier;

            List <IADevice> devices = intAirAct.Devices;
            IADevice        device  = devices.Find(d => d.Name == pairingDevice.Identifier);

            if (device != null)
            {
                IARequest request = new IARequest(Routes.BecomePairedRoute);
                intAirAct.SendRequest(request, device, delegate(IAResponse response, Exception exception)
                {
                    logger.TraceEvent(TraceEventType.Information, 0, "Error notifying Device {0} that it became paired.", pairingDevice.Identifier, pairingPerson.Identifier);
                });
            }

            logger.TraceEvent(TraceEventType.Information, 0, "Pairing Succeeded with Device {0} and Person {1}", pairingDevice.Identifier, pairingPerson.Identifier);
        }
Ejemplo n.º 11
0
 private void RemovePerson(List<PairablePerson> vanishedPersons, PairablePerson person)
 {
     //Remove Held-Device Identifier
     person.HeldDeviceIdentifier = null;
     vanishedPersons.Add(person);
     if (PersonRemoved != null)
         PersonRemoved(this, person);
 }
Ejemplo n.º 12
0
        private void AddNewPeople(List<Skeleton> skeletons, List<PairablePerson> pairablePersons, String kinectID)
        {
            //if a skeleton is very close to an existing person, that kinect will be added to the person's list of TrackerIDwithSkeletonID
            //this is how one person can be tracked by multiple kinects.
            foreach (Skeleton skeleton in skeletons)
            {
                Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                foreach (PairablePerson pairablePerson in pairablePersons)
                {
                    if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - PROXIMITYDISTANCE))
                    {
                        if (!pairablePerson.TrackerIDwithSkeletonID.ContainsKey(kinectID))
                        {
                            pairablePerson.TrackerIDwithSkeletonID.Add(kinectID, skeleton.TrackingId.ToString());
                        }
                        break;
                    }
                }
            }

            // Then, test each new skeleton to see if it matches an occluded person
            foreach (Skeleton skeleton in skeletons)
            {
                //if (pairablePersons.Find(x => x.Identifier.Equals(skeleton.TrackingId.ToString())) == null)
                if (pairablePersons.Find(x => skeleton.TrackingId.ToString().Equals(x.Identifier)) == null)
                {
                    foreach (PairablePerson pairablePerson in pairablePersons)
                    {
                        if (pairablePerson.PairingState == PairingState.PairedButOccluded)
                        {
                            Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                            if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - SAVINGDISTANCE))
                            {
                                // "Repair them"
                                pairablePerson.Identifier = skeleton.TrackingId.ToString();
                                pairablePerson.PairingState = PairingState.Paired;

                                PairableDevice device = (PairableDevice)locator.Devices.Find(x => x.Identifier == pairablePerson.HeldDeviceIdentifier);
                                device.HeldByPersonIdentifier = pairablePerson.Identifier;
                            }
                        }
                    }
                }
            }

            // For any skeletons that could not be matched to an existing person or if it wasn't matched to an occluded person, we create a new PairablePerson
            foreach (Skeleton skeleton in skeletons)
            {
                if (skeleton.TrackingId == 0)
                    continue;

                //New Skeleton Found
                if(pairablePersons.Find(x => x.TrackerIDwithSkeletonID.ContainsValue(skeleton.TrackingId.ToString())) == null)
                {
                    PairablePerson person = new PairablePerson
                    {
                        Location = new Point(0, 0),
                        Orientation = 0.0,
                        Identifier = skeleton.TrackingId.ToString(),
                        PairingState = PairingState.NotPaired,
                        CalibrationState = PairablePerson.CallibrationState.NotUsedCalibration,
                        TrackerIDwithSkeletonID = new Dictionary<string, string>(),
                        TrackedByIdentifier = kinectID
                    };

                    //add the tracker id to the top of the list
                    person.TrackerIDwithSkeletonID.Add(kinectID,skeleton.TrackingId.ToString());

                    pairablePersons.Add(person);

                    if (PersonAdded != null)
                        PersonAdded(this, person);
                }
            }
        }
Ejemplo n.º 13
0
 public static Brush GetBrushFromCalibrationState(PairablePerson.CallibrationState state)
 {
     switch (state)
     {
         case (PairablePerson.CallibrationState.UsedForCalibration): return Brushes.Blue;
         case(PairablePerson.CallibrationState.NotUsedCalibration): return Brushes.DarkRed;
         default: return Brushes.White;
     }
 }
Ejemplo n.º 14
0
        private void AddNewPeople(List <Skeleton> skeletons, List <PairablePerson> pairablePersons, String kinectID)
        {
            //if a skeleton is very close to an existing person, that kinect will be added to the person's list of TrackerIDwithSkeletonID
            //this is how one person can be tracked by multiple kinects.
            foreach (Skeleton skeleton in skeletons)
            {
                Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                foreach (PairablePerson pairablePerson in pairablePersons)
                {
                    if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + PROXIMITYDISTANCE) &&
                        skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - PROXIMITYDISTANCE))
                    {
                        if (!pairablePerson.TrackerIDwithSkeletonID.ContainsKey(kinectID))
                        {
                            pairablePerson.TrackerIDwithSkeletonID.Add(kinectID, skeleton.TrackingId.ToString());
                        }
                        break;
                    }
                }
            }

            // Then, test each new skeleton to see if it matches an occluded person
            foreach (Skeleton skeleton in skeletons)
            {
                //if (pairablePersons.Find(x => x.Identifier.Equals(skeleton.TrackingId.ToString())) == null)
                if (pairablePersons.Find(x => skeleton.TrackingId.ToString().Equals(x.Identifier)) == null)
                {
                    foreach (PairablePerson pairablePerson in pairablePersons)
                    {
                        if (pairablePerson.PairingState == PairingState.PairedButOccluded)
                        {
                            Point skeletonInRoomSpace = locator.Trackers.Find(x => x.Identifier.Equals(kinectID)).ConvertSkeletonToRoomSpace(new Vector(skeleton.Position.Z, skeleton.Position.X));

                            if (skeletonInRoomSpace.X < (pairablePerson.Location.Value.X + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.X > (pairablePerson.Location.Value.X - SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y < (pairablePerson.Location.Value.Y + SAVINGDISTANCE) &&
                                skeletonInRoomSpace.Y > (pairablePerson.Location.Value.Y - SAVINGDISTANCE))
                            {
                                // "Repair them"
                                pairablePerson.Identifier   = skeleton.TrackingId.ToString();
                                pairablePerson.PairingState = PairingState.Paired;

                                PairableDevice device = (PairableDevice)locator.Devices.Find(x => x.Identifier == pairablePerson.HeldDeviceIdentifier);
                                device.HeldByPersonIdentifier = pairablePerson.Identifier;
                            }
                        }
                    }
                }
            }

            // For any skeletons that could not be matched to an existing person or if it wasn't matched to an occluded person, we create a new PairablePerson
            foreach (Skeleton skeleton in skeletons)
            {
                if (skeleton.TrackingId == 0)
                {
                    continue;
                }

                //New Skeleton Found
                if (pairablePersons.Find(x => x.TrackerIDwithSkeletonID.ContainsValue(skeleton.TrackingId.ToString())) == null)
                {
                    PairablePerson person = new PairablePerson
                    {
                        Location                = new Point(0, 0),
                        Orientation             = 0.0,
                        Identifier              = skeleton.TrackingId.ToString(),
                        PairingState            = PairingState.NotPaired,
                        CalibrationState        = PairablePerson.CallibrationState.NotUsedCalibration,
                        TrackerIDwithSkeletonID = new Dictionary <string, string>(),
                        TrackedByIdentifier     = kinectID
                    };

                    //add the tracker id to the top of the list
                    person.TrackerIDwithSkeletonID.Add(kinectID, skeleton.TrackingId.ToString());

                    pairablePersons.Add(person);

                    if (PersonAdded != null)
                    {
                        PersonAdded(this, person);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void calibrate()
        {
            List <PairablePerson> pairablePersons           = locator.Persons.OfType <PairablePerson>().ToList <PairablePerson>();
            List <PairablePerson> personsUsedForCalibration = pairablePersons.FindAll(x => x.CalibrationState == PairablePerson.CallibrationState.UsedForCalibration);

            if (personsUsedForCalibration.Count > 1)
            {
                Dictionary <PairablePerson, Tracker> personsAndTheirTrackers = new Dictionary <PairablePerson, Tracker>();

                foreach (PairablePerson person in personsUsedForCalibration)
                {
                    Tracker tracker = locator.Trackers.Find(x => x.Identifier.Equals(person.TrackerIDwithSkeletonID.Keys.ToList()[0]));
                    personsAndTheirTrackers.Add(person, tracker);
                }

                Tracker        mainTracker = null;
                PairablePerson mainPerson  = null;

                foreach (KeyValuePair <PairablePerson, Tracker> entry in personsAndTheirTrackers)
                {
                    if (entry.Value.State == Tracker.CallibrationState.Calibrated)
                    {
                        mainTracker = entry.Value;
                        mainPerson  = entry.Key;
                        break;
                    }
                }

                if (mainTracker == null)
                {
                    mainTracker = personsAndTheirTrackers.Values.ToList()[0];
                    mainPerson  = personsAndTheirTrackers.Keys.ToList()[0];
                }

                mainTracker.State = Tracker.CallibrationState.Calibrated;

                foreach (KeyValuePair <PairablePerson, Tracker> entry in personsAndTheirTrackers)
                {
                    PairablePerson person  = entry.Key;
                    Tracker        tracker = entry.Value;

                    if (tracker.State == Tracker.CallibrationState.Calibrated)
                    {
                        continue;
                    }

                    double xValue = mainPerson.Location.Value.X - person.Location.Value.X;
                    double yValue = mainPerson.Location.Value.Y - person.Location.Value.Y;

                    try
                    {
                        Point newPosition = new Point(tracker.Location.Value.X + xValue, tracker.Location.Value.Y + yValue);
                        tracker.Location = newPosition;

                        tracker.State = Tracker.CallibrationState.Calibrated;
                    }
                    catch (NullReferenceException nullReferenceException)
                    {
                        System.Console.WriteLine(nullReferenceException);
                    }
                }

                foreach (PairablePerson person in personsAndTheirTrackers.Keys.ToList())
                {
                    person.CalibrationState = PairablePerson.CallibrationState.NotUsedCalibration;
                }
            }
        }
Ejemplo n.º 16
0
 void personAdded(PersonManager personManager, PairablePerson pairablePerson)
 {
     this.Dispatcher.Invoke(new Action(delegate()
     {
         if (!PersonControlDictionary.ContainsKey(pairablePerson))
         {
             PersonControlDictionary[pairablePerson] = new PersonControl(pairablePerson);
             canvas.Children.Add(PersonControlDictionary[pairablePerson]);
         }
     }));
 }
Ejemplo n.º 17
0
 void personRemoved(PersonManager personManager, PairablePerson pairablePerson)
 {
     this.Dispatcher.Invoke(new Action(delegate()
     {
         if (PersonControlDictionary.ContainsKey(pairablePerson))
         {
             canvas.Children.Remove(PersonControlDictionary[pairablePerson]);
             PersonControlDictionary.Remove(pairablePerson);
         }
     }));
 }
Ejemplo n.º 18
0
        public void GetOffsetAngleTest()
        {
            Setup();

            // Create a person and device, paired and positioned
            PairablePerson person = new PairablePerson
            {
                PairingState = PairingState.Paired,
                Identifier = "Bob",
                Location = new Point(1, 1),
                HeldDeviceIdentifier = "myPad"
            };

            PairableDevice device = new PairableDevice
            {
                HeldByPersonIdentifier = "Bob",
                Identifier = "myPad",
                Location = new Point(1, 1),
                PairingState = PairingState.Paired
            };

            // Position the tracker
            //Server.PersonManager.Tracker.Location = new Point(0, 2);
            //Server.PersonManager.Tracker.Orientation = 270;
            Server.Locator.Devices.Add(device);
            Server.Locator.Persons.Add(person);

            Server.Start();
            Client.Start();
            WaitForConnections();

            IARequest request = new IARequest(Routes.GetOffsetAngleRoute);
            request.Parameters["identifier"] = "myPad";

            Client.SendRequest(request, Server.IntAirAct.OwnDevice, delegate(IAResponse response, Exception exception)
            {
                double offsetOrientation = double.Parse(response.BodyAsString());
                // The angle between the device and the tracker should be 135 degrees
                Assert.AreEqual(135, offsetOrientation, 0.01);
            });

            Teardown();
        }