Beispiel #1
0
        private void SetAreasToUKS()
        {
            Thing currentlyVisibleParent = uks.GetOrAddThing("CurrentlyVisible", "Visual");

            uks.DeleteAllChilden(currentlyVisibleParent);
            Thing valueParent = uks.GetOrAddThing("Value", "Thing");

            foreach (Area a in areas)//all the areas currently visible
            {
                Thing theArea = uks.AddThing("Area*", currentlyVisibleParent);

                uks.SetValue(theArea, a.greatestLength, "Siz", 0);
                uks.SetValue(theArea, (float)a.orientation, "Ang", 2);
                uks.SetValue(theArea, (float)a.centroid.X, "CtrX", 0);
                uks.SetValue(theArea, (float)a.centroid.Y, "CtrY", 0);
                uks.SetValue(theArea, (float)a.avgColor.hue / 360f, "Hue", 2);
                uks.SetValue(theArea, (float)a.avgColor.saturation, "Sat", 2);
                uks.SetValue(theArea, (float)a.avgColor.luminance, "Lum", 2);

                List <Thing> theCorners = new List <Thing>();
                foreach (Corner c in a.areaCorners)
                {
                    theCorners.Add(uks.AddThing("Cnr*", theArea));

                    Thing theLocation = uks.Valued(c.loc, uks.Labeled("Point").Children);
                    if (theLocation == null)
                    {
                        theLocation   = uks.AddThing("p*", "Point");
                        theLocation.V = c.loc;
                    }
                    theLocation.AddParent(theCorners.Last());
                }
                //add the reference links
                if (theCorners.Count == 2)
                {
                    theCorners[0].AddReference(theCorners[1]); //add lengths to these?
                    theCorners[1].AddReference(theCorners[0]);
                }
                else
                {
                    for (int i = 0; i < theCorners.Count; i++)
                    {
                        int j = a.areaCorners.IndexOf(a.areaCorners[i].c1);
                        int k = a.areaCorners.IndexOf(a.areaCorners[i].c2);
                        if (k == -1 || j == -1 || j == k)
                        { // the area is not valid, delete it
                            uks.DeleteAllChilden(theArea);
                            uks.DeleteThing(theArea);
                            break;
                        }
                        theCorners[i].AddReference(theCorners[j]); //add lengths to these?
                        theCorners[i].AddReference(theCorners[k]);
                    }
                }
            }
        }
Beispiel #2
0
        //fill this method in with code which will execute
        //once for each cycle of the engine
        public override void Fire()
        {
            Init();  //be sure to leave this here

            ModuleView naSource = theNeuronArray.FindModuleByLabel("UKS");

            if (naSource == null)
            {
                return;
            }
            uks = (ModuleUKS)naSource.TheModule;

            Thing knownObjectParent      = uks.GetOrAddThing("KnownObject", "Visual");
            Thing currentlyVisibleParent = uks.GetOrAddThing("CurrentlyVisible", "Visual");

            //List<Thing> visibleKnownThings = new List<Thing>();
            foreach (Thing area in currentlyVisibleParent.Children)
            {
                Thing knownObject1 = null;
                foreach (Thing knownObject in knownObjectParent.Children)
                {
                    Thing knownObjectShape = knownObject.HasReferenceWithParent(uks.Labeled("Area"));
                    Thing areaShape        = area.HasReferenceWithParent(uks.Labeled("Area"));
                    Thing knownObjectColor = knownObject.HasReferenceWithParent(uks.Labeled("Color"));
                    Thing areaColor        = area.HasReferenceWithParent(uks.Labeled("Color"));
                    //if critical properties match, object is already known
                    if (knownObjectShape == areaShape && knownObjectColor == areaColor)
                    {
                        knownObject1 = knownObject;
                        break;
                    }
                }

                if (knownObject1 == null)
                {
                    //The object is unknown, add it to known objects for future reference
                    knownObject1 = area.Clone();
                    knownObject1.AddParent(knownObjectParent);
                    knownObject1.Label = "KnownShape*";
                }
                //visibleKnownThings.Add(knownObject1);
                uks.DeleteAllChilden(area);
                area.AddChild(knownObject1);
                //knownObject1.Label = area.Label;
            }

            //if you want the dlg to update, use the following code whenever any parameter changes
            // UpdateDialog();
        }
        public override void Fire()
        {
            Init();  //be sure to leave this here

            if (GetNeuronValue("Auto") == 0)
            {
                return;
            }
            goToGoal = GetNeuronValue("Goal") == 1;

            ModuleBehavior mBehavior = (ModuleBehavior)FindModleu(typeof(ModuleBehavior));

            if (mBehavior == null)
            {
                return;
            }
            Module2DModel mModel = (Module2DModel)FindModleu(typeof(Module2DModel));

            if (mModel is null)
            {
                return;
            }
            ModuleEvent mEvent = (ModuleEvent)FindModleu(typeof(ModuleEvent));

            if (mEvent == null)
            {
                return;
            }
            ModuleUKSN UKS = (ModuleUKSN)FindModleu(typeof(ModuleUKSN));

            if (UKS == null)
            {
                return;
            }

            if (GetNeuronValue("ModuleBehavior", "Done") == 0)
            {
                return;
            }


            mModel.GetSegmentsFromUKS();
            IList <Thing> segments = mModel.GetUKSSegments();

            if (segments.Count == 0)
            {
                return;
            }
            Thing t = segments[0]; //TODO: this only works with just a single item in the UKS

            //figure out if any motion occured
            Segment s = Module2DModel.SegmentFromUKSThing(t);

            Module2DModel.OrderSegment(s);

            if (GetNeuronValue("E0") == 1)
            {
                GoToLandmark(UKS.Labeled("E0").References[0].T, s);
                doPush    = 2;
                doBackOff = true;
                return;
            }
            if (GetNeuronValue("E1") == 1)
            {
                GoToLandmark(UKS.Labeled("E1").References[0].T, s);
                doPush    = 2;
                doBackOff = true;
                return;
            }
            if (GetNeuronValue("E2") == 1)
            {
                GoToLandmark(UKS.Labeled("E2").References[0].T, s);
                doPush    = 2;
                doBackOff = true;
                return;
            }


            if (doPush != 0)
            {
                if (doPush == 2)
                {
                    Push(s);
                }
                doPush--;
                return;
            }
            if (doFaceSegment)
            {
                DoFaceSegment(s);
                doFaceSegment = false;
                return;
            }

            Segment s1;

            if (lastPosition == null) //create objects to keep track of the target and last position
            {
                s1                 = s.Clone();
                lastPosition       = mModel.AddSegmentToUKS(s1);
                lastPosition.Label = "LastPosition";
                lastPosition.RemoveParent(UKS.Labeled("Segment"));
                lastPosition.AddParent(UKS.Labeled("SSegment"));
                Module2DSim mSim = (Module2DSim)FindModleu(typeof(Module2DSim));
                if (mSim is null)
                {
                    return;
                }
                Segment motionTarget = mSim.GetMotionTarget();
                if (motionTarget == null)
                {
                    motionTarget          = new Segment();
                    motionTarget.P1       = new PointPlus(4, 1.5f);
                    motionTarget.P2       = new PointPlus(4, -2.5f);
                    motionTarget.theColor = (ColorInt)0xff;
                }
                endTarget       = mModel.AddSegmentToUKS(motionTarget);
                endTarget.Label = "EndTarget";
                //endTarget.RemoveParent(UKS.Labeled("Segment"));
                //endTarget.AddParent(UKS.Labeled("SSegment"));
            }
            else
            {
                s1 = Module2DModel.SegmentFromUKSThing(lastPosition);
            }

            //get motion from subtracting and then updating last position
            Angle rotation = s.Angle - s1.Angle;

            if (rotation > PI / 2)
            {
                rotation = PI - rotation;
            }
            if (rotation < -PI / 2)
            {
                rotation = PI + rotation;
            }
            Motion motion = new Motion()
            {
                P        = (Point)s.MidPoint.V - s1.MidPoint.V,
                rotation = rotation,
            };

            lastPosition.References[0].T.V = s.P1.Clone();
            lastPosition.References[1].T.V = s.P2.Clone();

            if (Abs(motion.R) > .01 || Abs(motion.rotation) > .05 && !goToGoal && !doBackOff)
            {
                //check for existing Event
                Thing currentEvent = MostLikelyEvent(t);
                if (currentEvent == null)
                {                //add new Event
                    Thing lm1 = mEvent.CreateLandmark(new List <Thing>()
                    {
                        t
                    });
                    Thing t1 = mEvent.CreateEvent(lm1);
                    Thing t3 = UKS.AddThing("m" + motionCount++, UKS.Labeled("Motion"), motion);
                    mEvent.AddOutcomePair(t1, UKS.GetOrAddThing("Push", "Action"), t3);
                }
                return;
            }

            if (doBackOff)
            {
                DoBackOff(s);
                doBackOff     = false;
                doFaceSegment = true;
                return;
            }

            if (goToGoal)
            {
                if (endTarget != null)
                {
                    Segment s2 = Module2DModel.SegmentFromUKSThing(endTarget);
                    GoToGoal(s, s2);
                    return;
                }
            }

            Explore(s);
        }
Beispiel #4
0
 void AddShapeFromArea(Thing area)
 {
     area.AddParent(uks.GetOrAddThing("Area", "Shape"));
 }