public HAL9000Brain() { this.isAware = false; this.currentRoom = "unknown"; this.currentRegion = "unknown"; this.currentLocation = "unknown"; this.knownPersons = new SortedList<string, Person>(); this.knownRooms = new SortedList<string, string>(); this.knownRegions = new SortedList<string, string>(); this.knownLocations = new SortedList<string, string>(); this.knownObjects = new SortedList<string, PhysicalObject>(); this.languageProcessor = new NaturalLanguageProcessor(this); this.actionsToPerform = new List<SentenceImperative>(); this.recognizedSentences = new Queue<string>(); this.lastRecoGestures = new Queue<Gesture>(); this.lastPersonFallDetected = new Queue<string>(); this.sensorLectures = new Queue<string>(); this.validRoomsFile = "ValidRooms.txt"; this.validNamesFile = "ValidNames.txt"; this.knownObjectsFile = "KnownObjects.txt"; this.world = new World(); this.foundHumans = new List<string>(); this.currentRoomSharedVar = new StringSharedVariable("robotRoom"); this.currentRegionSharedVar = new StringSharedVariable("robotRegion"); this.currentLocationSharedVar = new StringSharedVariable("robotLocation"); this.gestureSharedVariable = new StringSharedVariable("gesture"); this.recogSpeechsSharedVar = new RecognizedSpeechSharedVariable("recognizedSpeech"); this.skeletonsSharedVariable = new StringSharedVariable("hf_skeletons"); this.nearestObjForLocDirection = new DoubleSharedVariable("mp_objforloc"); this.svInGoorRegionForLoc = new IntSharedVariable("mp_ingoodregion"); this.cell_phoneSharedVariable = new StringSharedVariable("cell_phone"); this.fallSharedVariable = new StringSharedVariable("positionhumanfall"); this.sensorsSharedVariable = new StringSharedVariable("home_sensors"); this.isSuscribedToGestureVar = false; this.isSuscribedToLocationVar = false; this.isSuscribedToRegionVar = false; this.isSuscribedToRoomVar = false; this.isSuscribedToRecoSpeechs = false; this.isSuscribedToSkeletons = false; this.isSuscribedToNearesObjForLoc = false; this.isSuscribedToInGoodRegion = false; this.isSuscribedToCellphone = false; this.isSuscribedToFall = false; this.isSuscribedToHomeSensors = false; this.status = new HAL9000Status(); this.status.BrainWaveType = BrainWaveType.Alpha; this.cmdMan = new HAL9000CmdMan(this.status); this.cnnMan = new ConnectionManager("ACT-PLN", 2025, this.cmdMan); this.cnnMan.ClientConnected += new System.Net.Sockets.TcpClientConnectedEventHandler(cnnMan_ClientConnected); this.cnnMan.ClientDisconnected += new System.Net.Sockets.TcpClientDisconnectedEventHandler(cnnMan_ClientDisconnected); this.cnnMan.DataReceived += new ConnectionManagerDataReceivedEH(cnnMan_DataReceived); this.cmdMan.SharedVariablesLoaded += new SharedVariablesLoadedEventHandler(cmdMan_SharedVariablesLoaded); this.SetupCommandExecuters(); this.cnnMan.Start(); this.cmdMan.Start(); }
private void SuscribeToSharedVars() { if (!this.isSuscribedToGestureVar) { try { if (!this.cmdMan.SharedVariables.Contains(this.gestureSharedVariable.Name)) this.cmdMan.SharedVariables.Add(this.gestureSharedVariable); else this.gestureSharedVariable = (StringSharedVariable)this.cmdMan.SharedVariables[this.gestureSharedVariable.Name]; this.gestureSharedVariable.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.gestureSharedVariable.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(gestureSharedVariable_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to gesture variable"); this.status.IsSuscribedToGestureVar = true; this.isSuscribedToGestureVar = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to gesture variable"); } } if (!this.isSuscribedToLocationVar) { try { if (!this.cmdMan.SharedVariables.Contains(this.currentLocationSharedVar.Name)) this.cmdMan.SharedVariables.Add(this.currentLocationSharedVar); else this.currentLocationSharedVar = (StringSharedVariable)this.cmdMan.SharedVariables[this.currentLocationSharedVar.Name]; this.currentLocationSharedVar.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.currentLocationSharedVar.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(currentLocationSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to location variable"); this.status.IsSuscribedToLocationVar = true; this.isSuscribedToLocationVar = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to location variable"); } } if (!this.isSuscribedToRegionVar) { try { if (!this.cmdMan.SharedVariables.Contains(this.currentRegionSharedVar.Name)) this.cmdMan.SharedVariables.Add(this.currentRegionSharedVar); else this.currentRegionSharedVar = (StringSharedVariable)this.cmdMan.SharedVariables[this.currentRegionSharedVar.Name]; this.currentRegionSharedVar.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.currentRegionSharedVar.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(currentRegionSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to region variable"); this.status.IsSuscribedToRegionVar = true; this.isSuscribedToRegionVar = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to region variable"); } } if (!this.isSuscribedToRoomVar) { try { if (!this.cmdMan.SharedVariables.Contains(this.currentRoomSharedVar.Name)) this.cmdMan.SharedVariables.Add(this.currentRoomSharedVar); else this.currentRoomSharedVar = (StringSharedVariable)this.cmdMan.SharedVariables[this.currentRoomSharedVar.Name]; this.currentRoomSharedVar.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.currentRoomSharedVar.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(currentRoomSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to room variable"); this.status.IsSuscribedToRoomVar = true; this.isSuscribedToRoomVar = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to room variable"); } } if (!this.isSuscribedToRecoSpeechs) { try { if (!this.cmdMan.SharedVariables.Contains(this.recogSpeechsSharedVar.Name)) this.cmdMan.SharedVariables.Add(this.recogSpeechsSharedVar); else this.recogSpeechsSharedVar = (RecognizedSpeechSharedVariable)this.cmdMan.SharedVariables[this.recogSpeechsSharedVar.Name]; this.recogSpeechsSharedVar.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.recogSpeechsSharedVar.WriteNotification += new SharedVariableSubscriptionReportEventHadler<Robotics.HAL.Sensors.RecognizedSpeech>(recogSpeechsSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to reco speech variable"); this.status.IsSuscribedToRecoSpeechVar = true; this.isSuscribedToRecoSpeechs = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to reco speech variable"); } } if (!this.isSuscribedToSkeletons) { try { if (!this.cmdMan.SharedVariables.Contains(this.skeletonsSharedVariable.Name)) this.cmdMan.SharedVariables.Add(this.skeletonsSharedVariable); else this.skeletonsSharedVariable = (StringSharedVariable)this.cmdMan.SharedVariables[this.skeletonsSharedVariable.Name]; this.skeletonsSharedVariable.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.skeletonsSharedVariable.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(skeletonsSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to skeletons."); this.status.IsSuscribedToRoomVar = true; this.isSuscribedToSkeletons = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to skeletons variable"); } } if (!this.isSuscribedToNearesObjForLoc) { try { if (!this.cmdMan.SharedVariables.Contains(this.nearestObjForLocDirection.Name)) this.cmdMan.SharedVariables.Add(this.nearestObjForLocDirection); else this.nearestObjForLocDirection = (DoubleSharedVariable)this.cmdMan.SharedVariables[this.nearestObjForLocDirection.Name]; this.nearestObjForLocDirection.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.nearestObjForLocDirection.WriteNotification += new SharedVariableSubscriptionReportEventHadler<double>(nearestObjForLocDirection_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to " + this.nearestObjForLocDirection.Name + " shared var"); this.status.IsSuscribedToNearObjForLoc = true; this.isSuscribedToNearesObjForLoc = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to " + this.nearestObjForLocDirection.Name + " shared var"); } } if (!this.isSuscribedToInGoodRegion) { try { if (!this.cmdMan.SharedVariables.Contains(this.svInGoorRegionForLoc.Name)) this.cmdMan.SharedVariables.Add(this.svInGoorRegionForLoc); else this.svInGoorRegionForLoc = (IntSharedVariable)this.cmdMan.SharedVariables[this.svInGoorRegionForLoc.Name]; this.svInGoorRegionForLoc.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.svInGoorRegionForLoc.WriteNotification += new SharedVariableSubscriptionReportEventHadler<int>(svInGoorRegionForLoc_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to " + this.svInGoorRegionForLoc.Name + " shared var"); this.status.IsSuscribedToInGoodRegion = true; this.isSuscribedToInGoodRegion = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HA9000.-> Can't suscribe to " + this.svInGoorRegionForLoc.Name + " shared var"); } } if (!this.isSuscribedToCellphone) { try { if (!this.cmdMan.SharedVariables.Contains(this.cell_phoneSharedVariable.Name)) this.cmdMan.SharedVariables.Add(this.cell_phoneSharedVariable); else this.cell_phoneSharedVariable = (StringSharedVariable)this.cmdMan.SharedVariables[this.cell_phoneSharedVariable.Name]; this.cell_phoneSharedVariable.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.cell_phoneSharedVariable.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(cellphoneSharedVar_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to Cellphone."); this.status.IsSuscribedToRoomVar = true; this.isSuscribedToCellphone = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to cellphone variable"); } } if (!this.isSuscribedToFall) { try { if (!this.cmdMan.SharedVariables.Contains(this.fallSharedVariable.Name)) this.cmdMan.SharedVariables.Add(this.fallSharedVariable); else this.fallSharedVariable = (StringSharedVariable)this.cmdMan.SharedVariables[this.fallSharedVariable.Name]; this.fallSharedVariable.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.fallSharedVariable.WriteNotification += new SharedVariableSubscriptionReportEventHadler<string>(fallSharedVariable_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Suscribed to Fall variable."); this.isSuscribedToFall = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> Can't suscribe to fall variable"); } } if (!this.isSuscribedToHomeSensors) { try { if (!this.cmdMan.SharedVariables.Contains(this.sensorsSharedVariable.Name)) this.cmdMan.SharedVariables.Add(this.sensorsSharedVariable); else this.sensorsSharedVariable = (StringSharedVariable)this.cmdMan.SharedVariables[this.sensorsSharedVariable.Name]; this.sensorsSharedVariable.Subscribe(SharedVariableReportType.SendContent, SharedVariableSubscriptionType.WriteOthers); this.sensorsSharedVariable.WriteNotification+=new SharedVariableSubscriptionReportEventHadler<string>(sensorsSharedVariable_WriteNotification); TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000 -> Subscibed to Home Sensors variable."); this.isSuscribedToHomeSensors = true; } catch { TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000 -> Can't subscribe to Home Sensors variable"); } } }
/// <summary> /// Registers an existing variable within the list /// </summary> /// <param name="type">The type of the variable to register</param> /// <param name="isArray">Indicates if the variable is an array</param> /// <param name="name">The name of the variable to register</param> /// <param name="data">The data of the variable to register received in the read operation</param> private bool RegisterVar(string type, bool isArray, string name, string data) { SharedVariable variable; variable = null; switch (type) { case "double": if (isArray) { variable = new DoubleArraySharedVariable(this.owner, name, false); } else { variable = new DoubleSharedVariable(this.owner, name, false); } break; case "HumanFace": if (!isArray) { variable = new DetectedHumanFaces(this.owner, name, false); } break; case "int": if (isArray) { variable = new IntArraySharedVariable(this.owner, name, false); } else { variable = new IntSharedVariable(this.owner, name, false); } break; case "LaserReadingArray": if (!isArray) { variable = new LaserReadingArrayShV(this.owner, name, false); } break; case "long": if (isArray) { variable = new LongArraySharedVariable(this.owner, name, false); } else { variable = new LongSharedVariable(this.owner, name, false); } break; case "Matrix": if (!isArray) { variable = new MatrixSharedVariable(this.owner, name, false); } break; case "RecognizedSpeech": if (!isArray) { variable = new RecognizedSpeechSharedVariable(this.owner, name, false); } break; case "var": variable = new VarSharedVariable(this.owner, name, false); isArray = false; break; case "Vector": if (!isArray) { variable = new VectorSharedVariable(this.owner, name, false); } break; case "string": if (!isArray) { variable = new StringSharedVariable(this.owner, name, false); } break; } if (variable == null) { return(false); } rwLock.AcquireWriterLock(-1); if (!variables.ContainsKey(name)) { variables.Add(name, variable); } else { rwLock.ReleaseWriterLock(); return(false); } rwLock.ReleaseWriterLock(); Exception ex; variable.UpdateInfo(500, out ex); variable.Initialized = true; return(variable.Update(type, isArray, -1, name, data, out ex)); }