/// <summary> /// Service Startup Handler /// </summary> protected override void Start() { InitState(); // send configuration commands to partner services SpawnIterator(ConfigureDrive); _state.TimeStamp = DateTime.Now; //needed for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // Listen for each operation type and call its Service Handler ActivateDsspOperationHandlers(); // Publish the service to the local Node Directory DirectoryInsert(); // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); //for XSLT and images MountEmbeddedResources("/RoboticsCommon"); // Interleave to manage internal drive operations (driveDistance and RotateDegrees) Activate( new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIteratorFromPortSet <drive.DriveDistance>(true, _internalDriveOperationsPort, InternalDriveDistanceHandler), Arbiter.ReceiveWithIteratorFromPortSet <drive.RotateDegrees>(true, _internalDriveOperationsPort, InternalRotateDegreesHandler) ), new ConcurrentReceiverGroup()) ); }
/// <summary> /// Service start /// </summary> protected override void Start() { Tracer.Trace("TrackRoamerUsrfService::Start()"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); base.Start(); // fire up MainPortInterleave; wireup [ServiceHandler] methods MainPortInterleave.CombineWith(new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIterator <sicklrf.Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.ReceiveWithIterator <sicklrf.ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler), Arbiter.Receive <sicklrf.Get>(true, _mainPort, GetHandler), Arbiter.Receive <sicklrf.Reset>(true, _mainPort, ResetHandler), Arbiter.Receive <proxibrick.UpdateSonarData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateSonarNotification) ), new ConcurrentReceiverGroup() )); Tracer.Trace("TrackRoamerUsrfService: calling Subscribe() for UpdateSonarData"); Type[] notifyMeOf = new Type[] { typeof(proxibrick.UpdateSonarData) }; _trackRoamerBrickProximityBoardServicePort.Subscribe(_trackRoamerBrickProximityBoardServiceNotify, notifyMeOf); }
IEnumerator <ITask> DoStart() { try { _utilities = DsspHttpUtilitiesService.Create(Environment); RunForm runForm = new RunForm(CreateForm); WinFormsServicePort.Post(runForm); yield return(Arbiter.Choice( runForm.pResult, EmptyHandler, EmptyHandler )); FormInvoke invoke = new FormInvoke( delegate { _form.Initialize(_state); } ); WinFormsServicePort.Post(invoke); yield return(Arbiter.Choice( invoke.ResultPort, EmptyHandler, EmptyHandler )); } finally { FinishStarting(); } }
/// <summary> /// Handlers http query request for raw binary format. /// </summary> /// <param name="query">The http query</param> /// <param name="state">Depth camera state</param> /// <param name="transform"> XSLT transform to be applied</param> /// <param name="utilitiesPort">Utitilise port to post the response</param> /// <returns>CCR Task Chunk</returns> private static IEnumerator <ITask> HttpQueryHelperRawFormat( HttpQuery query, DepthCamSensorState state, string transform, DsspHttpUtilitiesPort utilitiesPort) { var type = query.Body.Query[QueryType]; byte[] imageByteArray = null; switch (type.ToLowerInvariant()) { case DepthPlusRgb: imageByteArray = ConvertVisibleAndDepthToByteArray( state.VisibleImage, state.DepthImage); break; case Rgb: imageByteArray = state.VisibleImage; break; case Depth: imageByteArray = new byte[state.DepthImage.Length * sizeof(short)]; Buffer.BlockCopy(state.DepthImage, 0, imageByteArray, 0, imageByteArray.Length); break; case Ir: imageByteArray = state.VisibleImage; break; } if (imageByteArray == null) { query.ResponsePort.Post( new HttpResponseType( HttpStatusCode.OK, state, transform)); } else { using (var mem = new MemoryStream(imageByteArray)) { var response = new WriteResponseFromStream( query.Body.Context, mem, OctetStream); utilitiesPort.Post(response); yield return(response.ResultPort.Choice()); } } }
/// <summary> /// Service start /// </summary> /// <summary> /// Send phase of construction. /// </summary> protected override void Start() { //if (_state == null) //{ // _state = new TrackRoamerBrickProximityBoardState(); //} Tracer.Trace("TrackRoamerBrickProximityBoardService::Start()"); LogInfo("TrackRoamerBrickProximityBoardService::Start"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // // Kick off the connection to the Proximity Board device. // SpawnIterator(0, StartProximityBoard); // This service does not use base.Start() because of the way that // the handlers are hooked up. Also, because of this, there are // explicit Get and HttpGet handlers instead of using the default ones. // Handlers that need write or Exclusive access to state go under // the Exclusive group. Handlers that need read or shared access, and can be // Concurrent to other readers, go to the Concurrent group. // Other internal ports can be included in interleave so you can coordinate // intermediate computation with top level handlers. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler)), new ExclusiveReceiverGroup( Arbiter.Receive <Replace>(true, _mainPort, ReplaceHandler), Arbiter.Receive <SonarData>(true, _pbCommanderDataEventsPort, SonarMeasurementHandler), Arbiter.Receive <DirectionData>(true, _pbCommanderDataEventsPort, DirectionMeasurementHandler), Arbiter.Receive <AccelerometerData>(true, _pbCommanderDataEventsPort, AccelerometerMeasurementHandler), Arbiter.Receive <ProximityData>(true, _pbCommanderDataEventsPort, ProximityMeasurementHandler), Arbiter.Receive <ParkingSensorData>(true, _pbCommanderDataEventsPort, ParkingSensorMeasurementHandler), Arbiter.Receive <AnalogData>(true, _pbCommanderDataEventsPort, AnalogMeasurementHandler), Arbiter.ReceiveWithIterator <ProximityBoardUsbDeviceAttached>(true, _pbCommanderDataEventsPort, UsbDeviceAttached), Arbiter.ReceiveWithIterator <ProximityBoardUsbDeviceDetached>(true, _pbCommanderDataEventsPort, UsbDeviceDetached), Arbiter.ReceiveWithIterator <Exception>(true, _pbCommanderDataEventsPort, ExceptionHandler)), new ConcurrentReceiverGroup( Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler), Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.Receive <Get>(true, _mainPort, GetHandler), Arbiter.Receive <HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive <Reset>(true, _mainPort, ResetHandler)) ) ); DirectoryInsert(); //base.Start(); }
/// <summary> /// Handles http query request. /// </summary> /// <param name="query">The http query</param> /// <param name="state">Depth camera state</param> /// <param name="transform"> XSLT transform to be applied</param> /// <param name="utilitiesPort">Utitilise port to post the response</param> /// <param name="visibleWidth">Width of a visible image - needed to blend depth and rgb pictures for a visual represenation</param> /// <param name="visibleHeight">Height of a visible image - needed to blend depth and rgb pictures for a visual represenation</param> /// <returns>CCR Task Chunk</returns> public static IEnumerator <ITask> HttpQueryHelper( HttpQuery query, DepthCamSensorState state, string transform, DsspHttpUtilitiesPort utilitiesPort, int visibleWidth, int visibleHeight) { var type = query.Body.Query[QueryType]; var format = query.Body.Query[QueryFormat]; // Default is Png if (format == null) { format = Png; } switch (type.ToLowerInvariant()) { case DepthPlusRgb: // Intentional fall through. case Rgb: if (state.ImageMode == DepthCamSensor.DepthCamSensorImageMode.Infrared) { state.ImageMode = DepthCamSensor.DepthCamSensorImageMode.Rgb; } break; case Depth: // Do nothing. break; case Ir: if (state.ImageMode == DepthCamSensor.DepthCamSensorImageMode.Rgb) { state.ImageMode = DepthCamSensor.DepthCamSensorImageMode.Infrared; } break; } if (format.ToLowerInvariant().Equals(Raw)) { return(HttpQueryHelperRawFormat(query, state, transform, utilitiesPort)); } else { return(HttpQueryHelperBitmapSource(query, state, transform, utilitiesPort, visibleWidth, visibleHeight)); } }
/// <summary> /// Initialize webcam state. /// </summary> private void DoInitializeWebcamAlternate() { this.cachedProcessedFrames.VisibleImage = new byte[this.kinectSensor.ColorStream.FrameWidth * this.kinectSensor.ColorStream.FrameHeight * 3]; this.webCamState = new webcam.WebCamSensorState { DeviceName = "Kinect", Width = this.kinectSensor.ColorStream.FrameWidth, Height = this.kinectSensor.ColorStream.FrameHeight }; this.utilitiesPort = DsspHttpUtilitiesService.Create(Environment); }
/// <summary> /// Service start /// </summary> protected override void Start() { base.Start(); // start MainPortInterleave; wireup [ServiceHandler] methods if (_state == null) { _state = new AnimatedHeadServiceState(); _state.AnimatedHeadServiceConfig = new AnimatedHeadConfig(); _state.AnimatedHeadServiceConfig.CommPort = 0; SaveState(_state); } else { // Clear old Animated Head readings //_state.Quaternion = null; _state.Connected = false; } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state.AnimatedHeadServiceConfig == null) { _state.AnimatedHeadServiceConfig = new AnimatedHeadConfig(); } // Publish the service to the local Node Directory //DirectoryInsert(); _ahConnection = new AnimatedHeadConnection(_state.AnimatedHeadServiceConfig, _ahDataPort); SpawnIterator(ConnectToAnimatedHead); //SpawnIterator(TestAnimatedHead); // if we have anything coming from Arduino - the _ahDataPort Arbiter.Receive<string[]> and others must be operational: // Listen on the main port for requests and call the appropriate handler. MainPortInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup( Arbiter.Receive <string[]>(true, _ahDataPort, DataReceivedHandler), Arbiter.Receive <Exception>(true, _ahDataPort, ExceptionHandler), Arbiter.Receive <string>(true, _ahDataPort, MessageHandler) ), new ConcurrentReceiverGroup())); //base.Start(); // can't have it here, we already started mainInterleave and added to directory via DirectoryInsert }
/// <summary> /// Send phase of construction. /// </summary> protected override void Start() { if (_state == null) { _state = new State(); } Tracer.Trace("SickLRF::Start()"); LogInfo("Start"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // // Kick off the connection to the Laser Range Finder device. // SpawnIterator(0, _state.ComPort, StartLRF); // This service does not use base.Start() because of the way that // the handlers are hooked up. Also, because of this, there are // explicit Get and HttpGet handlers instead of using the default ones. // Handlers that need write or Exclusive access to state go under // the Exclusive group. Handlers that need read or shared access, and can be // Concurrent to other readers, go to the Concurrent group. // Other internal ports can be included in interleave so you can coordinate // intermediate computation with top level handlers. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler) ), new ExclusiveReceiverGroup( Arbiter.Receive <Replace>(true, _mainPort, ReplaceHandler), Arbiter.Receive <LinkMeasurement>(true, _internalPort, MeasurementHandler), Arbiter.ReceiveWithIterator <LinkPowerOn>(true, _internalPort, PowerOn), Arbiter.ReceiveWithIterator <Exception>(true, _internalPort, ExceptionHandler)), new ConcurrentReceiverGroup( Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler), Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.ReceiveWithIterator <ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler), Arbiter.Receive <Get>(true, _mainPort, GetHandler), Arbiter.Receive <HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive <Reset>(true, _mainPort, ResetHandler)) ) ); DirectoryInsert(); }
protected override void Start() { if (_state == null) { _state = new ColorSegmentState(); } else { for (int set = 0; set < _state.Colors.Count; set++) { ColorSet colorSet = _state.Colors[set]; for (int index = 0; index < colorSet.Colors.Count; index++) { ColorDefinition color = colorSet.Colors[index]; if (!color.Validate()) { colorSet.Colors.RemoveAt(index); index--; } } if (colorSet.Colors.Count == 0) { _state.Colors.RemoveAt(set); set--; } } _state.UpdateColorSetMap(); _state.ImageSource = null; _state.Processing = false; _state.FrameCount = 0; _state.DroppedFrames = 0; _state.FoundColorAreas = null; } _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); _fwdPort = ServiceForwarder <ColorSegmentOperations>(ServiceInfo.Service); base.Start(); Activate <ITask>( Arbiter.Receive <webcam.UpdateFrame>(true, _webcamNotify, OnWebcamUpdateFrame) ); _webcamPort.Subscribe(_webcamNotify, typeof(webcam.UpdateFrame)); }
/// <summary> /// Service Start /// </summary> protected override void Start() { _notificationTarget = new simengine.SimulationEnginePort(); _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); simengine.SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget); // dont start listening to DSSP operations, other than drop, until notification of entity Activate(new Interleave( new TeardownReceiverGroup ( Arbiter.Receive <simengine.InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime), Arbiter.Receive <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler) ), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup() )); }
/// <summary> /// Service start /// </summary> protected override void Start() { base.Start(); // Needed for HttpPost this.httpUtilities = DsspHttpUtilitiesService.Create(Environment); // Register handlers for notification from speech recognizer MainPortInterleave.CombineWith(new Interleave( new ExclusiveReceiverGroup( Arbiter.Receive <sr.Replace>(true, this.speechRecoNotifyPort, this.SpeechRecognizerReplaceHandler), Arbiter.Receive <sr.SpeechDetected>(true, this.speechRecoNotifyPort, this.SpeechDetectedHandler), Arbiter.Receive <sr.SpeechRecognized>(true, this.speechRecoNotifyPort, this.SpeechRecognizedHandler), Arbiter.Receive <sr.SpeechRecognitionRejected>(true, this.speechRecoNotifyPort, this.SpeechRecognitionRejectedHandler), Arbiter.Receive <sr.BeamDirectionChanged>(true, this.speechRecoNotifyPort, this.BeamDirectionChangedHandler)), new ConcurrentReceiverGroup())); this.speechRecoPort.Subscribe(this.speechRecoNotifyPort); }
/// <summary> /// The startup method for the text to speech service /// </summary> protected override void Start() { if (_state == null) { _state = new TextToSpeechState(); _state.Volume = TextToSpeechState.DefaultVolume; } InitTextToSpeech(); _utilities = DsspHttpUtilitiesService.Create(Environment); // Set up internal port Activate( Arbiter.Receive <SayTextSynch>(true, _sayTextSynchPort, InternalSayTextSynchHandler) ); base.Start(); }
/// <summary> /// Service start /// </summary> protected override void Start() { if (_state == null) { _state = new ChrUm6OrientationSensorState(); _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig(); _state.ChrUm6OrientationSensorConfig.CommPort = 0; SaveState(_state); } else { // Clear old Chr readings _state.Quaternion = null; } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state.ChrUm6OrientationSensorConfig == null) { _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig(); } // Publish the service to the local Node Directory DirectoryInsert(); _chrConnection = new ChrConnection(_state.ChrUm6OrientationSensorConfig, _chrDataPort); SpawnIterator(ConnectToChrUm6OrientationSensor); // Listen on the main port for requests and call the appropriate handler. Interleave mainInterleave = ActivateDsspOperationHandlers(); mainInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup( Arbiter.Receive <short[]>(true, _chrDataPort, DataReceivedHandler), Arbiter.Receive <Exception>(true, _chrDataPort, ExceptionHandler), Arbiter.Receive <string>(true, _chrDataPort, MessageHandler) ), new ConcurrentReceiverGroup())); //base.Start(); -- can't have it here, we already started mainInterleave and added to directory via DirectoryInsert }
/// <summary> /// Service start /// </summary> protected override void Start() { _httpUtilities = DsspHttpUtilitiesService.Create(this.Environment); // initialize state if (_state == null) { // No persisted state file, initialize with default values. _state = new PololuMaestroState(); _state.Channels = new List<ChannelInfo>(); _state.PollingInterval = 100; // default interval 100msec // Save state to file. SaveState(_state); } base.Start(); MainPortInterleave.CombineWith( Arbiter.Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup( Arbiter.Receive<SetChannel>(true, _mainPort, SetChannelHandler), /*// http://social.msdn.microsoft.com/Forums/en-US/roboticsccr/thread/c3c27886-9cce-437e-b7bc-f0c1c0d5d9d9 Arbiter.JoinedReceiveWithIterator<DateTime, SetChannel>(true, _setChannelThrotling, _mainPort, SetChannelHandler),*/ Arbiter.ReceiveWithIterator(true, _servoPollingPort, PollChannelStatus) ), new ConcurrentReceiverGroup()) ); // Display browser accesible Service URI LogInfo("Service uri: " + ServiceInfo.Service); if (ConnectToDevice()) { // notify state has changed SendNotification(_submgrPort, new Replace()); // start polling _servoPollingPort.Post(DateTime.Now); } }
/// <summary> /// Complete second phase startup for this service /// </summary> protected override void Start() { _fwdPort = ServiceForwarder <WebCamServiceOperations>(ServiceInfo.Service); _altFwdPort = ServiceForwarder <webcam.WebCamOperations>(AlternateContractServiceInfo[0].Service); _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); _prefix = new Uri(ServiceInfo.Service).AbsolutePath; _alternatePrefix = new Uri(AlternateContractServiceInfo[0].Service).AbsolutePath; if (_state == null) { _state = new WebCamState(); } base.ActivateDsspOperationHandlers(); if (_state.FramesOnDemand) { _framesOnDemand = true; Activate(Arbiter.ReceiveWithIterator(true, _framePort, OnDemandFrameHandler)); } else { base.MainPortInterleave.CombineWith( Arbiter.Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup ( Arbiter.Receive(true, _framePort, FrameHandler) ), new ConcurrentReceiverGroup() ) ); } StartPipeServer(); SpawnIterator(_state, GetInitialState); }
/// <summary> /// Service startup /// </summary> protected override void Start() { _fwdPort = ServiceForwarder <webcam.WebCamOperations>(ServiceInfo.Service); _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); Uri httpAlias = ServiceInfo.HttpServiceAlias; if (httpAlias != null) { _prefix = httpAlias.AbsolutePath; _alternatePrefixes = AlternateContractServiceInfo.ConvertAll <string>( delegate(ServiceInfoType alternate) { return(alternate.HttpServiceAlias.AbsolutePath); } ); } try { _streamPort = mdwebcam.ReadStream.Create(_state.CaptureFile, Environment.TaskQueue); } catch (Exception e) { LogError("Unable to open stream file: " + e.Message); base.StartFailed(); return; } base.Start(); base.MainPortInterleave.CombineWith( new Interleave( new ExclusiveReceiverGroup( Arbiter.Receive <mdwebcam.Frame>(true, _streamPort, ReadFrameHandler) ), new ConcurrentReceiverGroup() ) ); }
/// <summary> /// Service start method /// </summary> protected override void Start() { if (_state == null) { _state = new IpCameraState(); } _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); Uri httpAlias = ServiceInfo.HttpServiceAlias; if (httpAlias != null) { _prefix = httpAlias.AbsolutePath; _alternatePrefix = AlternateContractServiceInfo[0].HttpServiceAlias.AbsolutePath; } else { LogError(LogGroups.Activation, "Service requires HTTP transport"); DefaultDropHandler(new DsspDefaultDrop()); return; } base.Start(); MainPortInterleave.CombineWith( new Interleave( new ExclusiveReceiverGroup( Arbiter.Receive <Bitmap>(true, _imagePort, ImageHandler) ), new ConcurrentReceiverGroup( Arbiter.Receive <DateTime>(true, _imagePort, GetImageHandler) ) ) ); _imagePort.Post(DateTime.UtcNow); }
/// <summary> /// Start initializes SimulatedDepthcamService and listens for drop messages /// </summary> protected override void Start() { const double KinectMaxValidDepthMm = 4000.0; const double KinectMinValidDepthMm = 800.0; if (this._state == null) { // no config file found, initialize default state according to KinectReservedSampleValues this._state = new DepthCamSensorState(); this._state.MaximumRange = KinectMaxValidDepthMm / 1000.0; this._state.MinimumRange = KinectMinValidDepthMm / 1000.0; this._state.FurtherThanMaxDepthValue = (short)4095.0; this._state.NearerThanMinDepthValue = (short)0.0; this.SaveState(this._state); } this._physicsEngine = physics.PhysicsEngine.GlobalInstance; _notificationTarget = new simengine.SimulationEnginePort(); utilitiesPort = DsspHttpUtilitiesService.Create(Environment); // PartnerType.Service is the entity instance name. simengine.SimulationEngine.GlobalInstancePort.Subscribe(ServiceInfo.PartnerList, _notificationTarget); // dont start listening to DSSP operations, other than drop, until notification of entity Activate(new Interleave( new TeardownReceiverGroup ( Arbiter.Receive <simengine.InsertSimulationEntity>(false, _notificationTarget, InsertEntityNotificationHandlerFirstTime), Arbiter.Receive <dssp.DsspDefaultDrop>(false, _mainPort, DefaultDropHandler) ), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup() )); }
private void StartBehavior() { _fwdPort = ServiceForwarder <Srv1CameraServiceOperations>(ServiceInfo.Service); _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); if (_state == null) { _state = new Srv1CameraState(); } // Listen on the main port for requests and call the appropriate handler. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler) ), new ExclusiveReceiverGroup ( Arbiter.ReceiveWithIterator <Replace>(true, _mainPort, ReplaceHandler), Arbiter.ReceiveWithIterator <UpdateDevice>(true, _mainPort, UpdateDeviceHandler), Arbiter.ReceiveWithIterator <UpdateFormat>(true, _mainPort, UpdateFormatHandler), Arbiter.Receive(true, _framePort, FrameHandler), Arbiter.ReceiveWithIterator <HttpPost>(true, _mainPort, HttpPostHandler) ), new ConcurrentReceiverGroup ( Arbiter.ReceiveWithIterator <Get>(true, _mainPort, GetHandler), Arbiter.ReceiveWithIterator <QueryFrame>(true, _mainPort, QueryFrameHandler), Arbiter.ReceiveWithIterator <UpdateFrame>(true, _mainPort, UpdateFrameHandler), Arbiter.ReceiveWithIterator <HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler) )) ); SpawnIterator(_state, GetInitialState); }
/// <summary> /// Service Startup Handler /// </summary> protected override void Start() { InitState(); // send configuration commands to partner services SpawnIterator(ConfigureDrive); _state.TimeStamp = DateTime.Now; //needed for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // Listen for each operation type and call its Service Handler ActivateDsspOperationHandlers(); // Publish the service to the local Node Directory DirectoryInsert(); // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); //for XSLT and images MountEmbeddedResources("/RoboticsCommon"); // Interleave to manage internal drive operations (driveDistance and RotateDegrees) Activate( new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIteratorFromPortSet<drive.DriveDistance>(true, _internalDriveOperationsPort, InternalDriveDistanceHandler), Arbiter.ReceiveWithIteratorFromPortSet<drive.RotateDegrees>(true, _internalDriveOperationsPort, InternalRotateDegreesHandler) ), new ConcurrentReceiverGroup()) ); }
/// <summary> /// Service Start /// </summary> protected override void Start() { if (_state == null) { //initialize state _state = new ScribblerState(); _state.ComPort = 0; _state.RobotName = null; //motors initially stopped _state.MotorLeft = 100; _state.MotorRight = 100; SaveState(_state); } // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); //open Scribbler Communications port if (ConnectToScribbler()) { // Listen for a single Serial port request with an acknowledgement Activate(Arbiter.ReceiveWithIterator <SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler)); PollTimer = new System.Timers.Timer(); PollTimer.Interval = TimerDelay; PollTimer.AutoReset = true; PollTimer.Elapsed += new System.Timers.ElapsedEventHandler(PollTimer_Elapsed); PollTimer.Start(); //play startup tone PlayToneBody startTone = new PlayToneBody(200, 1000, 2000); _mainPort.Post(new PlayTone(startTone)); //debug //ScribblerCommand cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.GET_INFO); //SendScribblerCommand sendcmd = new SendScribblerCommand(cmd); //_scribblerComPort.Post(sendcmd); //fix state _state.MotorLeft = 100; _state.MotorRight = 100; _state.LEDLeft = false; _state.LEDRight = false; _state.LEDCenter = false; } else { //no scribbler found. Open state page for manual settings. //OpenServiceInBrowser(); } // Listen on the main port for requests and call the appropriate handler. Interleave mainInterleave = ActivateDsspOperationHandlers(); //for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // Publish the service to the local Node Directory DirectoryInsert(); //add custom handlers to interleave mainInterleave.CombineWith(new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup( Arbiter.ReceiveWithIterator <SetMotors>(true, _mainPort, SetMotorHandler), Arbiter.ReceiveWithIterator <SetLED>(true, _mainPort, SetLEDHandler), Arbiter.ReceiveWithIterator <SetAllLEDs>(true, _mainPort, SetAllLEDsHandler), Arbiter.ReceiveWithIterator <PlayTone>(true, _mainPort, PlayToneHandler), Arbiter.ReceiveWithIterator <SetName>(true, _mainPort, SetNameHandler), Arbiter.ReceiveWithIterator <ScribblerResponseMessage>(true, _mainPort, ScribblerResponseHandler) ), new ConcurrentReceiverGroup() )); }
/// <summary> /// Provides a standard implementation of HttpQuery /// </summary> /// <param name="query">The HttpQuery message to process</param> /// <param name="state">The webcam state</param> /// <param name="transform">The embedded resource to use as the XSLT transform</param> /// <param name="utilitiesPort">The utilities port used to stream images</param> /// <returns>Stanard CCR iterator</returns> public IEnumerator <ITask> HttpQueryHelper(HttpQuery query, WebCamSensorState state, string transform, DsspHttpUtilitiesPort utilitiesPort) { var type = query.Body.Query[QueryType]; var mediaType = string.Empty; var format = default(sdi.ImageFormat); switch (type.ToLowerInvariant()) { case Jpeg: format = sdi.ImageFormat.Jpeg; mediaType = MediaTypeNames.Image.Jpeg; break; case Gif: format = sdi.ImageFormat.Gif; mediaType = MediaTypeNames.Image.Gif; break; case Png: format = sdi.ImageFormat.Png; mediaType = MediaPng; break; case Bmp: format = sdi.ImageFormat.Bmp; mediaType = MediaBmp; break; default: var copy = state.Clone() as WebCamSensorState; copy.Data = null; query.ResponsePort.Post( new HttpResponseType( HttpStatusCode.OK, copy, transform)); yield break; } if (state.Data == null || state.Data.Length == 0) { query.ResponsePort.Post( new HttpResponseType( HttpStatusCode.OK, state, transform)); yield break; } using (var image = state.Bitmap) { using (var mem = new MemoryStream()) { image.Save(mem, format); mem.Position = 0; var response = new WriteResponseFromStream( query.Body.Context, mem, mediaType); utilitiesPort.Post(response); yield return(response.ResultPort.Choice()); } } }
/// <summary> /// Service start /// </summary> /// <summary> /// Send phase of construction. /// </summary> protected override void Start() { //if (_state == null) //{ // _state = new TrackRoamerBrickProximityBoardState(); //} Tracer.Trace("TrackRoamerBrickProximityBoardService::Start()"); LogInfo("TrackRoamerBrickProximityBoardService::Start"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // // Kick off the connection to the Proximity Board device. // SpawnIterator(0, StartProximityBoard); // This service does not use base.Start() because of the way that // the handlers are hooked up. Also, because of this, there are // explicit Get and HttpGet handlers instead of using the default ones. // Handlers that need write or Exclusive access to state go under // the Exclusive group. Handlers that need read or shared access, and can be // Concurrent to other readers, go to the Concurrent group. // Other internal ports can be included in interleave so you can coordinate // intermediate computation with top level handlers. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive<DsspDefaultDrop>(false, _mainPort, DropHandler)), new ExclusiveReceiverGroup( Arbiter.Receive<Replace>(true, _mainPort, ReplaceHandler), Arbiter.Receive<SonarData>(true, _pbCommanderDataEventsPort, SonarMeasurementHandler), Arbiter.Receive<DirectionData>(true, _pbCommanderDataEventsPort, DirectionMeasurementHandler), Arbiter.Receive<AccelerometerData>(true, _pbCommanderDataEventsPort, AccelerometerMeasurementHandler), Arbiter.Receive<ProximityData>(true, _pbCommanderDataEventsPort, ProximityMeasurementHandler), Arbiter.Receive<ParkingSensorData>(true, _pbCommanderDataEventsPort, ParkingSensorMeasurementHandler), Arbiter.Receive<AnalogData>(true, _pbCommanderDataEventsPort, AnalogMeasurementHandler), Arbiter.ReceiveWithIterator<ProximityBoardUsbDeviceAttached>(true, _pbCommanderDataEventsPort, UsbDeviceAttached), Arbiter.ReceiveWithIterator<ProximityBoardUsbDeviceDetached>(true, _pbCommanderDataEventsPort, UsbDeviceDetached), Arbiter.ReceiveWithIterator<Exception>(true, _pbCommanderDataEventsPort, ExceptionHandler)), new ConcurrentReceiverGroup( Arbiter.Receive<DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler), Arbiter.ReceiveWithIterator<Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.Receive<Get>(true, _mainPort, GetHandler), Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive<Reset>(true, _mainPort, ResetHandler)) ) ); DirectoryInsert(); //base.Start(); }
/// <summary> /// Send phase of construction. /// </summary> protected override void Start() { if (_state == null) { _state = new State(); } Tracer.Trace("SickLRF::Start()"); LogInfo("Start"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // // Kick off the connection to the Laser Range Finder device. // SpawnIterator(0, _state.ComPort, StartLRF); // This service does not use base.Start() because of the way that // the handlers are hooked up. Also, because of this, there are // explicit Get and HttpGet handlers instead of using the default ones. // Handlers that need write or Exclusive access to state go under // the Exclusive group. Handlers that need read or shared access, and can be // Concurrent to other readers, go to the Concurrent group. // Other internal ports can be included in interleave so you can coordinate // intermediate computation with top level handlers. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive<DsspDefaultDrop>(false, _mainPort, DropHandler) ), new ExclusiveReceiverGroup( Arbiter.Receive<Replace>(true, _mainPort, ReplaceHandler), Arbiter.Receive<LinkMeasurement>(true, _internalPort, MeasurementHandler), Arbiter.ReceiveWithIterator<LinkPowerOn>(true, _internalPort, PowerOn), Arbiter.ReceiveWithIterator<Exception>(true, _internalPort, ExceptionHandler)), new ConcurrentReceiverGroup( Arbiter.Receive<DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler), Arbiter.ReceiveWithIterator<Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.ReceiveWithIterator<ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler), Arbiter.Receive<Get>(true, _mainPort, GetHandler), Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive<Reset>(true, _mainPort, ResetHandler)) ) ); DirectoryInsert(); }
/// <summary> /// Service Startup Handler /// </summary> protected override void Start() { LogInfo("TrackRoamerDriveService:: Start() "); InitState(); _internalPendingDriveOperation = drive.DriveRequestOperation.NotSpecified; // send configuration commands to partner services SpawnIterator(ConfigureDrive); _state.TimeStamp = DateTime.Now; //needed for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); base.Start(); // Interleave to manage internal drive operations (driveDistance and RotateDegrees) Activate( new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIterator(true, this.encodersPollingPort, this.PollEncoders), Arbiter.ReceiveWithIteratorFromPortSet<drive.DriveDistance>(true, _internalDriveOperationsPort, InternalDriveDistanceHandler), Arbiter.ReceiveWithIteratorFromPortSet<drive.RotateDegrees>(true, _internalDriveOperationsPort, InternalRotateDegreesHandler) ), new ConcurrentReceiverGroup()) ); }
/// <summary> /// Service start /// </summary> protected override void Start() { Tracer.Trace("TrackRoamerUsrfService::Start()"); _httpUtilities = DsspHttpUtilitiesService.Create(Environment); base.Start(); // fire up MainPortInterleave; wireup [ServiceHandler] methods MainPortInterleave.CombineWith(new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIterator<sicklrf.Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.ReceiveWithIterator<sicklrf.ReliableSubscribe>(true, _mainPort, ReliableSubscribeHandler), Arbiter.Receive<sicklrf.Get>(true, _mainPort, GetHandler), Arbiter.Receive<sicklrf.Reset>(true, _mainPort, ResetHandler), Arbiter.Receive<proxibrick.UpdateSonarData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateSonarNotification) ), new ConcurrentReceiverGroup() )); Tracer.Trace("TrackRoamerUsrfService: calling Subscribe() for UpdateSonarData"); Type[] notifyMeOf = new Type[] { typeof(proxibrick.UpdateSonarData) }; _trackRoamerBrickProximityBoardServicePort.Subscribe(_trackRoamerBrickProximityBoardServiceNotify, notifyMeOf); }
/// <summary> /// Service start /// </summary> protected override void Start() { if (_state == null) { _state = new ChrUm6OrientationSensorState(); _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig(); _state.ChrUm6OrientationSensorConfig.CommPort = 0; SaveState(_state); } else { // Clear old Chr readings _state.Quaternion = null; } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state.ChrUm6OrientationSensorConfig == null) _state.ChrUm6OrientationSensorConfig = new ChrUm6OrientationSensorConfig(); // Publish the service to the local Node Directory DirectoryInsert(); _chrConnection = new ChrConnection(_state.ChrUm6OrientationSensorConfig, _chrDataPort); SpawnIterator(ConnectToChrUm6OrientationSensor); // Listen on the main port for requests and call the appropriate handler. Interleave mainInterleave = ActivateDsspOperationHandlers(); mainInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup( Arbiter.Receive<short[]>(true, _chrDataPort, DataReceivedHandler), Arbiter.Receive<Exception>(true, _chrDataPort, ExceptionHandler), Arbiter.Receive<string>(true, _chrDataPort, MessageHandler) ), new ConcurrentReceiverGroup())); //base.Start(); -- can't have it here, we already started mainInterleave and added to directory via DirectoryInsert }
protected override void Start() { LogInfo("DriveBehaviorServiceBase:Start() _doUnitTest=" + _doUnitTest + " _doSimulatedLaser=" + _doSimulatedLaser + " _testBumpMode=" + _testBumpMode); base.Start(); // start MainPortInterleave; wireup [ServiceHandler] methods InitGunTurrets(); // HeadlightsOff(); -- this will be done by SafePositions in PololuMaestroService if (_state == null) { // no partner-supplied initial state found - create default one: LogInfo("DriveBehaviorServiceBase:: initial _state null"); _state = new TrackRoamerBehaviorsState(); SaveState(_state); } else { LogInfo("DriveBehaviorServiceBase:: initial _state supplied by partner"); _state.Init(); // clear and re-create some members that should not be taken from the saved state } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_doUnitTest) { Talker.Say(9, "unit test mode"); } if (_testBumpMode) { Talker.Say(9, "bumper test mode"); } if (_doSimulatedLaser) { Talker.Say(9, "laser will be simulated"); WatchdogInterval = _simulatedLaserWatchdogInterval; // about the time ultrasonic sensor makes a sweep } if (!_doUnitTest || _unitTestSensorsOn) { // Handlers that need write or exclusive access to state go under // the exclusive group. Handlers that need read or shared access, and can be // concurrent to other readers, go to the concurrent group. // Other internal ports can be included in interleave so you can coordinate // intermediate computation with top level handlers. #region request handler setup MainPortInterleave.CombineWith(new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup( Arbiter.Receive<LaserRangeFinderResetUpdate>(true, _mainPort, LaserRangeFinderResetUpdateHandler), Arbiter.Receive<LaserRangeFinderUpdate>(true, _mainPort, LaserRangeFinderUpdateHandler), Arbiter.Receive<BumpersArrayUpdate>(true, _mainPort, BumpersArrayUpdateHandler), Arbiter.Receive<BumperUpdate>(true, _mainPort, BumperUpdateHandler), Arbiter.Receive<DriveUpdate>(true, _mainPort, DriveUpdateHandler), //Arbiter.Receive<EncoderUpdate>(true, _mainPort, EncoderUpdateHandler), Arbiter.Receive<WatchDogUpdate>(true, _mainPort, WatchDogUpdateHandler) ), new ConcurrentReceiverGroup( Arbiter.Receive<Get>(true, _mainPort, GetHandler), //Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive<dssp.DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler) ) ) ); #endregion #region notification handler setup MainPortInterleave.CombineWith(new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup( Arbiter.Receive<sicklrf.Reset>(true, _laserNotify, LaserResetNotification), Arbiter.Receive<proxibrick.UpdateAccelerometerData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateAccelerometerNotification), Arbiter.Receive<proxibrick.UpdateDirectionData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateDirectionNotification), Arbiter.Receive<proxibrick.UpdateProximityData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateProximityNotification), Arbiter.Receive<proxibrick.UpdateParkingSensorData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateParkingSensorNotification), Arbiter.Receive<proxibrick.UpdateAnalogData>(true, _trackRoamerBrickProximityBoardServiceNotify, trpbUpdateAnalogNotification), Arbiter.Receive<drive.Update>(true, _driveNotify, DriveUpdateNotification), Arbiter.ReceiveWithIterator<drive.DriveDistance>(true, _driveNotify, DriveDistanceUpdateHandler), Arbiter.ReceiveWithIterator<drive.RotateDegrees>(true, _driveNotify, RotateDegreesUpdateHandler), //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyLeft, EncoderUpdateTickCountNotificationLeft), //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyRight, EncoderUpdateTickCountNotificationRight), Arbiter.Receive<powerbrick.UpdateMotorEncoder>(true, notificationPortEncoder, EncoderNotificationHandler), Arbiter.Receive<powerbrick.UpdateMotorEncoderSpeed>(true, notificationPortEncoderSpeed, EncoderSpeedNotificationHandler), Arbiter.Receive<bumper.Replace>(true, _bumperNotify, BumperReplaceNotification), Arbiter.Receive<bumper.Update>(true, _bumperNotify, BumperUpdateNotification) ) ) ); #endregion // We cannot replicate the activation of laser notifications because the // handler uses Test() to skip old laser notifications. // Activate the handler once, it will re-activate itself: Activate( Arbiter.ReceiveWithIterator<sicklrf.Replace>(false, _laserNotify, LaserReplaceNotificationHandler) ); if (USE_ORIENTATION_UM6 || USE_DIRECTION_UM6_QUATERNION || USE_DIRECTION_UM6_EULER) { // Start listening to CH Robotics UM6 Orientation Sensor: SubscribeToChrUm6OrientationSensor(); } // Start listening to GPS: SubscribeToGps(); // Start watchdog timer - we need it to detect that the laser does not return current picture and stop: _mainPort.Post(new WatchDogUpdate(new WatchDogUpdateRequest(DateTime.Now))); } else { // for unit tests - drive only operation: #region request handler setup MainPortInterleave.CombineWith(new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup( Arbiter.Receive<BumpersArrayUpdate>(true, _mainPort, BumpersArrayUpdateHandler), Arbiter.Receive<BumperUpdate>(true, _mainPort, BumperUpdateHandler), //Arbiter.Receive<EncoderUpdate>(true, _mainPort, EncoderUpdateHandler), Arbiter.Receive<DriveUpdate>(true, _mainPort, DriveUpdateHandler) ), new ConcurrentReceiverGroup( Arbiter.Receive<Get>(true, _mainPort, GetHandler), //Arbiter.Receive<HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.Receive<dssp.DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler) ) ) ); #endregion #region notification handler setup MainPortInterleave.CombineWith(new Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup(), new ConcurrentReceiverGroup( Arbiter.Receive<drive.Update>(true, _driveNotify, DriveUpdateNotification), Arbiter.ReceiveWithIterator<drive.DriveDistance>(true, _driveNotify, DriveDistanceUpdateHandler), Arbiter.ReceiveWithIterator<drive.RotateDegrees>(true, _driveNotify, RotateDegreesUpdateHandler), //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyLeft, EncoderUpdateTickCountNotificationLeft), //Arbiter.Receive<encoder.UpdateTickCount>(true, _encoderNotifyRight, EncoderUpdateTickCountNotificationRight), Arbiter.Receive<powerbrick.UpdateMotorEncoder>(true, notificationPortEncoder, EncoderNotificationHandler), Arbiter.Receive<powerbrick.UpdateMotorEncoderSpeed>(true, notificationPortEncoderSpeed, EncoderSpeedNotificationHandler), Arbiter.Receive<bumper.Replace>(true, _bumperNotify, BumperReplaceNotification), Arbiter.Receive<bumper.Update>(true, _bumperNotify, BumperUpdateNotification) ) ) ); #endregion } // Subscribe to the direct drive for notification messages: _drivePort.Subscribe(_driveNotify); //_encoderPortLeft.Subscribe(_encoderNotifyLeft); //_encoderPortRight.Subscribe(_encoderNotifyRight); SubscribeToPowerBrick(); // for Encoders distance and speed _bumperPort.Subscribe(_bumperNotify); SpawnIterator(this.AhrsZeroGyrosAndAccelerometer); SpawnIterator(this.InitializeSpeechRecognizer); // create WPF adapter this.wpfServicePort = ccrwpf.WpfAdapter.Create(TaskQueue); SpawnIterator(InitializeGui); if (!_doUnitTest || _unitTestSensorsOn) { Tracer.Trace("DriveBehaviorServiceBase:Start(): calling Subscribe() for laser range, proximity, accelerometer, compass partners"); _laserPort.Subscribe(_laserNotify); Type[] notifyMeOf = new Type[] { typeof(proxibrick.UpdateAccelerometerData), typeof(proxibrick.UpdateDirectionData), typeof(proxibrick.UpdateProximityData), typeof(proxibrick.UpdateParkingSensorData), typeof(proxibrick.UpdateAnalogData) }; _trackRoamerBrickProximityBoardServicePort.Subscribe(_trackRoamerBrickProximityBoardServiceNotify, notifyMeOf); SpawnIterator(this.InitializeKinectUI); } SafePosture(); SetLightsTest(); // SetLightsNormal() is called at the end of CalibrateKinectPlatform iteration SpawnIterator(this.LightsControlLoop); SpawnIterator(this.ConnectObstacleAvoidanceDrive); SpawnIterator(this.CalibrateKinectPlatform); SpawnIterator(this.TestAnimatedHead); if (_doUnitTest) { performUnitTest(); } else { SpawnIterator(this.InitializeDecisionMainLoop); } // we will need this later: robotCornerDistanceMeters = Math.Sqrt(_mapperVicinity.robotState.robotLengthMeters * _mapperVicinity.robotState.robotLengthMeters + _mapperVicinity.robotState.robotWidthMeters * _mapperVicinity.robotState.robotWidthMeters) / 2.0d; }
/// <summary> /// Service Start /// </summary> protected override void Start() { if (_state == null) { _state = new GpsState(); _state.MicrosoftGpsConfig = new MicrosoftGpsConfig(); _state.MicrosoftGpsConfig.CommPort = 0; _state.MicrosoftGpsConfig.CaptureHistory = true; _state.MicrosoftGpsConfig.CaptureNmea = true; _state.MicrosoftGpsConfig.RetrackNmea = false; SaveState(_state); } else { // Clear old Gps readings _state.GpGga = null; _state.GpGll = null; _state.GpGsa = null; _state.GpGsv = null; _state.GpRmc = null; _state.GpVtg = null; } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state.MicrosoftGpsConfig == null) _state.MicrosoftGpsConfig = new MicrosoftGpsConfig(); // Publish the service to the local Node Directory DirectoryInsert(); if (simulateFromLogNmea) { SpawnIterator(SimulateMicrosoftGps); } else { _gpsConnection = new GpsConnection(_state.MicrosoftGpsConfig, _gpsDataPort); setCaptureNmea(); SpawnIterator(ConnectToMicrosoftGps); } // Listen on the main port for requests and call the appropriate handler. Interleave mainInterleave = ActivateDsspOperationHandlers(); mainInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup( Arbiter.Receive<string[]>(true, _gpsDataPort, DataReceivedHandler) ,Arbiter.Receive<Exception>(true, _gpsDataPort, ExceptionHandler) #if TRACEDATA // see Info messages with data strings coming from GPS at http://localhost:50000/console/output ,Arbiter.Receive<string>(true, _gpsDataPort, MessageHandler) #endif ), new ConcurrentReceiverGroup())); // display HTTP service Uri LogInfo(LogGroups.Console, "Overhead view [" + FindServiceAliasFromScheme(Uri.UriSchemeHttp) + "/top]\r\n* Service uri: "); LogInfo(LogGroups.Console, "Map view [" + FindServiceAliasFromScheme(Uri.UriSchemeHttp) + "/map]\r\n* Service uri: "); LogInfo(LogGroups.Console, string.Format("Switches: CaptureHistory={0} CaptureNmea={1} RetrackNmea={2}", _state.MicrosoftGpsConfig.CaptureHistory, _state.MicrosoftGpsConfig.CaptureNmea, _state.MicrosoftGpsConfig.RetrackNmea)); Console.WriteLine(string.Format("Switches: CaptureHistory={0} CaptureNmea={1} RetrackNmea={2}", _state.MicrosoftGpsConfig.CaptureHistory, _state.MicrosoftGpsConfig.CaptureNmea, _state.MicrosoftGpsConfig.RetrackNmea)); }
protected override void Start() { _biclops = new BiclopsAccessWrapper(); if (_state == null) { _state = new BiclopsState(); _state.Mode = (MotorMode)_biclops.getMode(); _state.JointPositions = new List<double>(); _state.JointPositionReferences = new List<double>(); _state.JointPositions.Add(_biclops.getJointPosition(0)); _state.JointPositions.Add(_biclops.getJointPosition(1)); _state.JointPositionReferences.Add(_biclops.getDesiredJointPosition(0)); _state.JointPositionReferences.Add(_biclops.getDesiredJointPosition(1)); } base.Start(); // Create utilities port _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // start main update loop _waitPort.Post(DateTime.Now); Activate(Arbiter.Receive(true, _waitPort, UpdateLoopHandler)); }
/// <summary> /// Service start /// </summary> protected override void Start() { base.Start(); // start MainPortInterleave; wireup [ServiceHandler] methods if (_state == null) { _state = new AnimatedHeadServiceState(); _state.AnimatedHeadServiceConfig = new AnimatedHeadConfig(); _state.AnimatedHeadServiceConfig.CommPort = 0; SaveState(_state); } else { // Clear old Animated Head readings //_state.Quaternion = null; _state.Connected = false; } _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state.AnimatedHeadServiceConfig == null) { _state.AnimatedHeadServiceConfig = new AnimatedHeadConfig(); } // Publish the service to the local Node Directory //DirectoryInsert(); _ahConnection = new AnimatedHeadConnection(_state.AnimatedHeadServiceConfig, _ahDataPort); SpawnIterator(ConnectToAnimatedHead); //SpawnIterator(TestAnimatedHead); // if we have anything coming from Arduino - the _ahDataPort Arbiter.Receive<string[]> and others must be operational: // Listen on the main port for requests and call the appropriate handler. MainPortInterleave.CombineWith(new Interleave(new ExclusiveReceiverGroup( Arbiter.Receive<string[]>(true, _ahDataPort, DataReceivedHandler), Arbiter.Receive<Exception>(true, _ahDataPort, ExceptionHandler), Arbiter.Receive<string>(true, _ahDataPort, MessageHandler) ), new ConcurrentReceiverGroup())); //base.Start(); // can't have it here, we already started mainInterleave and added to directory via DirectoryInsert }
/// <summary> /// Handlers http query request for bitmap source format. /// </summary> /// <param name="query">The http query</param> /// <param name="state">Depth camera state</param> /// <param name="transform"> XSLT transform to be applied</param> /// <param name="utilitiesPort">Utitilise port to post the response</param> /// <param name="visibleWidth">Width of a visible image - needed to blend depth and rgb pictures for a visual represenation</param> /// <param name="visibleHeight">Height of a visible image - needed to blend depth and rgb pictures for a visual represenation</param> /// <returns>CCR Task Chunk</returns> private static IEnumerator <ITask> HttpQueryHelperBitmapSource( HttpQuery query, DepthCamSensorState state, string transform, DsspHttpUtilitiesPort utilitiesPort, int visibleWidth, int visibleHeight) { var type = query.Body.Query[QueryType]; BitmapSource bitmapSource = null; try { switch (type.ToLowerInvariant()) { case DepthPlusRgb: // we must downscale visible image to match the resolution of depth image - in order to merge the // two pictures. Its an expensive call - but we do it only here, where it was explicitly requested byte[] resizedVisibleImage = ResizeVisibleImageToMatchDepthImageDimentions( state.VisibleImage, visibleWidth, visibleHeight, state.DepthImageSize.Width, state.DepthImageSize.Height); bitmapSource = CreateBitmapSourceFromByteArray( ConvertVisibleAndDepthTo32bppByteArray(resizedVisibleImage, state.DepthImage), state.DepthImageSize.Width, state.DepthImageSize.Height, swm.PixelFormats.Bgra32); break; case Rgb: bitmapSource = CreateBitmapSourceFromByteArray( state.VisibleImage, visibleWidth, visibleHeight, swm.PixelFormats.Bgr24); break; case Depth: bitmapSource = CreateBitmapSourceFromShortPixelArray( state.DepthImage, state.DepthImageSize.Width, state.DepthImageSize.Height, (int)(state.MaximumRange * 1000), state.DepthImage.Clone() as short[]); break; case Ir: bitmapSource = CreateBitmapSourceFromInfraredArray( state.VisibleImage, state.DepthImageSize.Width, state.DepthImageSize.Height, swm.PixelFormats.Gray16); break; } } catch { // We do not attempt to synchronize the HTTP view with // state switching, so we might switch to RGB but still // have data from IR mode var width = state.DepthImageSize.Width; var height = state.DepthImageSize.Height; var zeroData = new byte[3 * width * height]; bitmapSource = BitmapSource.Create( width, height, 96, 96, swm.PixelFormats.Bgr24, null, zeroData, state.DepthImageSize.Width * 3); } if (bitmapSource == null) { query.ResponsePort.Post( new HttpResponseType( HttpStatusCode.OK, state, transform)); } else { using (var mem = new MemoryStream()) { BitmapEncoder encoder = null; PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); pngEncoder.Interlace = PngInterlaceOption.Off; encoder = pngEncoder; encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(mem); mem.Position = 0; var response = new WriteResponseFromStream( query.Body.Context, mem, MediaPng); utilitiesPort.Post(response); yield return(response.ResultPort.Choice()); } } }
protected override void Start() { // needed for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); if (_state == null) { //int c = 0; LogInfo("Creating new BiclopsRightCameraJointConfiguration State..."); // get state _state = new jointconfig.JointConfigurationState(); _state.NumLinks = 8; // this'll need to get updated accordingly _state.NumJoints = 2; _state.Moveable = true; _state.JointAngles = new Vector(_state.NumJoints); _state.DesiredJointAngles = new Vector(_state.NumJoints); _state.MinLimits = new Vector(_state.NumJoints); _state.MaxLimits = new Vector(_state.NumJoints); _state.MaxDelta = new Vector(_state.NumJoints); _state.LinkTypes = new List<string>(); _state.DHParams = new List<List<double>>(); // DH params will of course be totally different...but we'll need to add them in a similar fashion. /* 0.000000 -0.01 0.412 0.000000 REVOLUTE -1.570796 0.00 0.000 0.000000 REVOLUTE 1.570796 0.00 0.005 0.000000 CONSTANT -1.570796 0.00 0.000 0.000000 CONSTANT 1.570796 0.00 0.000 -1.570796 CONSTANT -1.570796 0.00 0.000 0.000000 CONSTANT 0.000000 0.00 0.040 0.000000 CONSTANT 0.000000 0.09 0.000 0.000000 CONSTANT */ //0 AddDHParameter(0, -0.01, 0.412, 0, "LINK_TYPE_REVOLUTE"); //1 AddDHParameter(-Math.PI / 2.0, 0, 0, 0, "LINK_TYPE_REVOLUTE"); //2 AddDHParameter(Math.PI / 2.0, 0, 0.005, 0, "LINK_TYPE_CONSTANT"); //3 AddDHParameter(-Math.PI / 2.0, 0, 0, 0, "LINK_TYPE_CONSTANT"); //4 AddDHParameter(Math.PI / 2.0, 0, 0, -Math.PI / 2.0, "LINK_TYPE_CONSTANT"); //5 AddDHParameter(-Math.PI / 2.0, 0, 0, 0, "LINK_TYPE_CONSTANT"); //6 AddDHParameter(0, 0, 0.04, 0, "LINK_TYPE_CONSTANT"); //7 AddDHParameter(0, 0.09, 0, 0, "LINK_TYPE_CONSTANT"); // we'll need to fix these, too _state.MinLimits.dat[0] = -2.0; _state.MinLimits.dat[1] = -0.35; _state.MaxLimits.dat[0] = 2.0; _state.MaxLimits.dat[1] = 1.2; _state.RobotName = "BiclopsRight"; _state.Lock = true; //set up default vals for (int i = 0; i < 2; i++) { _state.JointAngles.dat[i] = 0; _state.DesiredJointAngles.dat[i] = 0; _state.MaxDelta.dat[i] = 2.0; // because we're sending joint position references to drivers that already have reasonable // PD gains, we don't need to worry about max delta here (so 2 radians per cycle is fine) } for (int i = 0; i < _state.NumLinks; i++) { Console.Write("DH[{0}]=({1:F2} {2:F2} {3:F2} {4:F2})\n", i, _state.DHParams[i][0], _state.DHParams[i][1], _state.DHParams[i][2], _state.DHParams[i][3]); } for (int i = 0; i < _state.NumJoints; i++) { Console.Write("Range[{0}]=({1:F2} {2:F2})\n", i, _state.MinLimits.dat[i], _state.MaxLimits.dat[i]); } for (int i = 0; i < _state.NumJoints; i++) { Console.Write("MaxDelta[{0}]={1:F2}\n", i, _state.MaxDelta.dat[i]); } base.SaveState(_state); } _state.Moveable = true; _state.Lock = true; // // Add service specific initialization here // SpawnIterator(ConnectToBiclopsService); base.Start(); Console.WriteLine("Starting Biclops Right Camera JointConfiguration Thread"); // start main update loop _waitPort.Post(DateTime.Now); Activate(Arbiter.Receive(true, _waitPort, UpdateLoopHandler)); }
/// <summary> /// Service Start /// </summary> protected override void Start() { if (_state == null) { //initialize state _state = new ScribblerState(); _state.ComPort = 0; _state.RobotName = null; //motors initially stopped _state.MotorLeft = 100; _state.MotorRight = 100; SaveState(_state); } // display HTTP service Uri LogInfo(LogGroups.Console, "Service uri: "); //_mainPort.PostUnknownType(new Reconnect()); //open Scribbler Communications port //if (ConnectToScribbler()) //{ // Listen for a single Serial port request with an acknowledgement //debug //ScribblerCommand cmd = new ScribblerCommand((byte)ScribblerHelper.Commands.GET_INFO); //SendScribblerCommand sendcmd = new SendScribblerCommand(cmd); //_scribblerComPort.Post(sendcmd); //} //else //{ //no scribbler found. Open state page for manual settings. //OpenServiceInBrowser(); //} Activate(Arbiter.ReceiveWithIterator<SendScribblerCommand>(false, _scribblerComPort, SendScribblerCommandHandler)); // Listen on the main port for requests and call the appropriate handler. Interleave mainInterleave = ActivateDsspOperationHandlers(); //for HttpPost _httpUtilities = DsspHttpUtilitiesService.Create(Environment); // Publish the service to the local Node Directory DirectoryInsert(); //add custom handlers to interleave mainInterleave.CombineWith(new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIteratorFromPortSet<SetMotors>(true, _mainPort, SetMotorHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetLED>(true, _mainPort, SetLEDHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetAllLEDs>(true, _mainPort, SetAllLEDsHandler), Arbiter.ReceiveWithIteratorFromPortSet<PlayTone>(true, _mainPort, PlayToneHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetName>(true, _mainPort, SetNameHandler), Arbiter.ReceiveWithIteratorFromPortSet<ScribblerResponseMessage>(true, _mainPort, ScribblerResponseHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetLoud>(true, _mainPort, SetLoudHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetLEDFront>(true, _mainPort, SetLEDFrontHandler), Arbiter.ReceiveWithIteratorFromPortSet<SetLEDBack>(true, _mainPort, SetLEDBackHandler), Arbiter.ReceiveWithIteratorFromPortSet<Reconnect>(true, _mainPort, ReconnectHandler) ), new ConcurrentReceiverGroup())); // These handlers do not use the state, so can run concurrently to those above. Activate(Arbiter.ReceiveWithIteratorFromPortSet<GetObstacle>(true, _mainPort, GetObstacleHandler)); Activate(Arbiter.ReceiveWithIteratorFromPortSet<GetImage>(true, _mainPort, GetImageHandler)); Activate(Arbiter.ReceiveWithIteratorFromPortSet<GetCamParam>(true, _mainPort, GetCamParamHandler)); Activate(Arbiter.ReceiveWithIteratorFromPortSet<SetCamParam>(true, _mainPort, SetCamParamHandler)); Activate(Arbiter.ReceiveWithIteratorFromPortSet<SendScribblerCommand>(true, _mainPort, SendScribblerCommandHandlerExternal)); Activate(Arbiter.ReceiveWithIteratorFromPortSet<HttpPost>(true, _mainPort, HttpPostHandler)); // These don't use the state either. // GetWindow has to set up the window, then retrieve it, so it must run one at a time. Activate(new Interleave( new ExclusiveReceiverGroup( Arbiter.ReceiveWithIteratorFromPortSet<GetWindow>(true, _mainPort, GetWindowHandler) ), new ConcurrentReceiverGroup() )); }