public Thing CreateLandmark(List <Thing> near) { //a landmark is a collection of nearby segments //these must be cloned so they can be fixed in position rather than being adjusted relative to Sallie's position ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (UKS is null) { return(null); } Thing newLandmark = UKS.AddThing("Lm" + landmarkCount++.ToString(), "Landmark"); foreach (Thing t in near) { Segment s = Module2DModel.SegmentFromUKSThing(t); Thing P1 = UKS.AddThing("lmp" + pointCount++.ToString(), "Point"); //These points are not included in the model and do don't move with poin of view P1.V = s.P1.Clone(); Thing P2 = UKS.AddThing("lmp" + pointCount++.ToString(), "Point"); P2.V = s.P2.Clone(); Thing S = UKS.AddThing("l" + t.Label.ToString(), "SSegment"); S.AddReference(P1); S.AddReference(P2); S.AddReference(t.References[2].T);//the color newLandmark.AddReference(S); } return(newLandmark); }
public override void Initialize() { //scanning = false; orienting = false; auto = false; lastLandmark = null; currentLandmark = null; currentEvent = null; ClearNeurons(); //randomize rand = new Random((int)DateTime.Now.Ticks); AddLabel("Auto"); AddLabel("Found"); //this is the first test of building a sequence of behaviors ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (UKS != null) { Thing t = UKS.AddThing("LTurnS", "Action"); t = UKS.AddThing("RTurnS", "Action"); t = UKS.AddThing("UTurnS", "Action"); t = UKS.AddThing("GoS", "Action"); } }
public void AddOutcomePair(Thing Event, Thing theAction, Thing theOutcome) { ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (UKS is null) { return; } Thing newOutcomePair = UKS.AddThing("x" + pairCount++, Event); //creates new thing as it as a child newOutcomePair.AddReference(theAction); newOutcomePair.AddReference(theOutcome); }
public Thing CreateEvent(Thing newLandmark) { ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (UKS is null) { return(null); } Thing retVal = UKS.AddThing("E" + eventCount++.ToString(), "Event"); retVal.AddReference(newLandmark); return(retVal); }
public override void Fire() { Init(); //be sure to leave this here if (words.Count > 0) { string word = words[0]; na.BeginEnum(); for (Neuron n = na.GetNextNeuron(); n != null; n = na.GetNextNeuron()) { if (n.Label == word) { n.SetValue(1); // n.CurrentCharge = 1; break; } else if (n.Label == "") { //the word has not been heard before, add it n.Label = word; n.CurrentCharge = 1; //connection to UKS ModuleUKSN nmUKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (nmUKS != null) { List <Thing> words = nmUKS.Labeled("Word").Children; Thing w = nmUKS.Valued(word, words); if (w == null) { string label = "w" + char.ToUpper(word[0]) + word.Substring(1); w = nmUKS.AddThing(label, new Thing[] { nmUKS.Labeled("Word") }, word); } Neuron n1 = nmUKS.GetNeuron(w); if (n1 != null) { n.AddSynapse(n1.Id, 1); } //TODO: add a synapse to the speakwords module as well } break; } } words.RemoveAt(0); } }
public override void Fire() { Init(); //be sure to leave this here if (synth == null) { return; } bool paused = true; for (int i = 1; i < na.NeuronCount; i++) { Neuron n = na.GetNeuronAt(i); if (n.Fired()) { if (n.Label.Length == 1) { phraseToSpeak += n.Label; paused = false; } if (n.Synapses.Count == 0) { //if a neuron fired and it has no connection, connect it to the knowledge store //connection to KB ModuleUKSN nmKB = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (nmKB != null) { string label = "pn" + n.Label; List <Thing> phonemes = nmKB.Labeled("Phoneme").Children; Thing pn = nmKB.Labeled(label, phonemes); if (pn == null) //this should always be null { pn = nmKB.AddThing(label, new Thing[] { nmKB.Labeled("Phoneme") }, pn); } Neuron n1 = nmKB.GetNeuron(pn); if (n1 != null) { n.AddSynapse(n1.Id, 1); n1.SetValue(1); } } } } } if (phonemesToFire != "") { char c = phonemesToFire[0]; bool fired = false; for (int i = 0; i < na.NeuronCount; i++) { Neuron n = na.GetNeuronAt(i); if (n.Label == c.ToString()) { n.SetValue(1); fired = true; break; } } if (!fired) { Utils.Noop(); } phonemesToFire = phonemesToFire.Substring(1); } if (paused && phraseToSpeak != "") { if (dlg != null) { ((ModuleSpeakPhonemesDlg)dlg).SetLabel(phraseToSpeak); } if (na.GetNeuronAt("Enable").Fired()) { ModuleSpeechIn msi = (ModuleSpeechIn)FindModuleByType(typeof(ModuleSpeechIn)); if (msi != null) { msi.PauseRecognition(); //if there is a recognizer active } //synth.SpeakAsync(phraseToSpeak + "."); //phraseToSpeak = ""; PromptBuilder pb1 = new PromptBuilder(); if (typedIn) { pb1.StartVoice("Microsoft David Desktop"); pb1.StartStyle(new PromptStyle(PromptRate.Medium)); } else { pb1.StartVoice("Microsoft Zira Desktop"); pb1.StartStyle(new PromptStyle(PromptRate.ExtraSlow)); } pb1.AppendTextWithPronunciation("not used", phraseToSpeak); pb1.EndStyle(); pb1.EndVoice(); string x = pb1.ToXml(); Debug.WriteLine(debugString(phraseToSpeak)); //synth.Speak(pb1); synth.SpeakAsync(pb1); } //string heard = GetPronunciationFromText("", phraseToSpeak); //it would be nice to hear what was said but it doesn't work with this engine phraseToSpeak = ""; typedIn = false; } }
//get input from touch... accurate locations, no color public bool AddSegmentFromTouch(PointPlus P1, PointPlus P2, PointPlus motion, int arm) { //if conf=0, it's a known endpoint. conf=1, not an endpoint ModuleUKSN UKS = (ModuleUKSN)FindModuleByType(typeof(ModuleUKSN)); if (UKS is null) { return(false); } if (UKSSegments is null) { return(false); } if (imagining) { return(false); } ColorInt theColor = Utils.ColorToInt(Colors.Wheat); Segment newSegment = new Segment() { P1 = P1, P2 = P2, theColor = theColor }; //OrderSegment(newSegment); Thing t1 = GetNearestThing(newSegment.MidPoint.Theta, out float dist1); //TODO: for motion testing t1 = UKS.Labeled("s0"); if (t1 == null) { //TODO: merge mutliple segments // AddSegmentToUKS(P1, P2, theColor, motion); //don't store motion with the segment (yet) AddSegmentToUKS(P1, P2, theColor); } else if (dist1 < 1) { Segment prevSegment = SegmentFromUKSThing(t1); PointPlus prevMidpoint = prevSegment.MidPoint; Angle oldM = prevSegment.Angle; Angle newM = newSegment.Angle; PointPlus offset = new PointPlus() { R = prevSegment.Length, Theta = newM }; if (P1.Conf == 0 && P2.Conf == 0) //we're given both endpoints { prevSegment.P1.P = P1.P; prevSegment.P1.Conf = 0; prevSegment.P2.P = P2.P; prevSegment.P2.Conf = 0; } else if (P1.Conf == 0) { prevSegment.P1.P = P1.P; prevSegment.P1.Conf = 0; prevSegment.P2.P = P1.P - offset.V; } else if (P2.Conf == 0) { prevSegment.P1.P = P2.P; prevSegment.P2.Conf = 0; prevSegment.P2.P = P2.P + offset.V; } else { //we're not near an endpoint--match the modpoint as close as possible & preserve length //make the segment match the two points PointPlus newMidpoint1 = new PointPlus() { P = (Point)GetClosestPointOnLine(P1.V, P2.V, prevMidpoint.V), }; //offset is the dietance from the midpoint to each end offset.R = offset.R / 2; PointPlus newP1 = new PointPlus() { P = newMidpoint1.P + offset.V }; PointPlus newP2 = new PointPlus() { P = newMidpoint1.P - offset.V }; prevSegment.P1.R = newP1.R; prevSegment.P1.Theta = newP1.Theta; prevSegment.P2.R = newP2.R; prevSegment.P2.Theta = newP2.Theta; } PointPlus newMidpoint = prevSegment.MidPoint; newMidpoint.P = newMidpoint.P - prevMidpoint.V; if (newMidpoint.R > 0.01 && motion.R != 0) { if (prevSegment.Motion == null) { prevSegment.Motion = new PointPlus(); Thing tMotion = UKS.AddThing("m" + mCount++, UKS.Labeled("Point")); tMotion.V = prevSegment.Motion; t1.AddReference(tMotion); } prevSegment.Motion.R = motion.R; prevSegment.Motion.Theta = motion.Theta; prevSegment.Motion.Conf = newM - oldM; } } UpdateDialog(); return(false); }
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); }