private IEnumerator <ITask> InitializeGui() { // create WPF adapter this._wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue); var runWindow = this._wpfServicePort.RunWindow(() => new libguiwpf.MainWindow()); yield return((Choice)runWindow); var exception = (Exception)runWindow; if (exception != null) { LogError(exception); StartFailed(); yield break; } // need double cast because WPF adapter doesn't know about derived window types var userInterface = ((Window)runWindow) as libguiwpf.MainWindow; if (userInterface == null) { var e = new ApplicationException("User interface was expected to be libguiwpf.MainWindow"); LogError(e); throw e; } _mainWindow = userInterface; _mainWindow.Closing += new CancelEventHandler(_mainWindow_Closing); // for convenience mark the initial robot position: DetectedObstacle dobst1 = new DetectedObstacle() { geoPosition = (GeoPosition)_mapperVicinity.robotPosition.Clone(), firstSeen = DateTime.Now.Ticks, lastSeen = DateTime.Now.Ticks, color = Colors.Green, detectorType = DetectorType.NONE, objectType = DetectedObjectType.Mark, timeToLiveSeconds = 3600 }; lock (_mapperVicinity) { _mapperVicinity.Add(dobst1); } _mainWindow.setMapper(_mapperVicinity, _routePlanner); }
protected double robotCornerDistanceMeters = 0.0d; // to account for robot dimensions when adding measurements from corner-located proximity sensors. public MainWindow() { InitializeComponent(); routePlanner = new RoutePlanner(mapperVicinity); this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); //create picpxmod device. _picpxmod = new ProximityModule(0x0925, 0x7001); // see PIC Firmware - usb_descriptors.c lines 178,179 _picpxmod.HasReadFrameEvent += pmFrameCompleteHandler; _picpxmod.DeviceAttachedEvent += new EventHandler <ProximityModuleEventArgs>(_picpxmod_DeviceAttachedEvent); _picpxmod.DeviceDetachedEvent += new EventHandler <ProximityModuleEventArgs>(_picpxmod_DeviceDetachedEvent); bool deviceAttached = _picpxmod.FindTheHid(); pmValuesLabel.Content = deviceAttached ? "Proximity Board Found" : string.Format("Proximity Board NOT Found\r\nYour USB Device\r\nmust have:\r\n vendorId=0x{0:X}\r\nproductId=0x{1:X}", _picpxmod.vendorId, _picpxmod.productId); mapperVicinity.robotPosition = (GeoPosition)robotPositionDefault.Clone(); mapperVicinity.robotDirection = (Direction)robotDirectionDefault.Clone(); // we will need this later: robotCornerDistanceMeters = Math.Sqrt(mapperVicinity.robotState.robotLengthMeters * mapperVicinity.robotState.robotLengthMeters + mapperVicinity.robotState.robotWidthMeters * mapperVicinity.robotState.robotWidthMeters) / 2.0d; // --------- debug ------------ GeoPosition pos1 = (GeoPosition)mapperVicinity.robotPosition.Clone(); //pos1.translate(new Distance(1.0d), new Distance(1.0d)); // geo coordinates - East North pos1.translate(new Direction() { heading = mapperVicinity.robotDirection.heading, bearingRelative = 45.0d }, new Distance(1.0d)); // robot coordinates - forward right DetectedObstacle dobst1 = new DetectedObstacle(pos1) { color = Colors.Red }; mapperVicinity.Add(dobst1); GeoPosition pos2 = (GeoPosition)mapperVicinity.robotPosition.Clone(); //pos2.translate(new Distance(-1.0d), new Distance(1.0d)); // geo coordinates - West North pos2.translate(new Direction() { heading = mapperVicinity.robotDirection.heading, bearingRelative = -45.0d }, new Distance(1.0d)); // robot coordinates - forward left DetectedObstacle dobst2 = new DetectedObstacle(pos2) { color = Colors.Yellow }; //mapperVicinity.Add(dobst2); mapperVicinity.computeMapPositions(); // --------- end debug ------------ }