// see http://code.jonwagner.com/2012/09/06/best-practices-for-c-asyncawait/ // http://www.c-sharpcorner.com/UploadFile/pranayamr/difference-between-await-and-continuewith-keyword-in-C-Sharp/ // http://code.jonwagner.com/2012/09/04/deadlock-asyncawait-is-not-task-wait/ // https://msdn.microsoft.com/en-us/library/ff963550.aspx - Parallel Programming book public override async Task Init(CancellationTokenSource cts, string[] args) { await base.Init(cts, args); // produces hardwareBrick and sets it for communication joystick.joystickEvent += Joystick_joystickEvent; sensorsController = new SensorsControllerShorty(hardwareBrick, loopTimeMs, PIXY_COM_PORT, speaker); await sensorsController.InitSensors(cts); InitDrive(); behaviorFactory = new BehaviorFactory(subsumptionTaskDispatcher, driveGeometry, speaker); // we can set behavior combo now, or allow ControlDeviceCommand to set it later. //behaviorFactory.produce(BehaviorCompositionType.JoystickAndStop); robotState = new RobotState(); robotPose = new RobotPose(); robotState.powerLevelPercent = 100; // can be changed any time. Used by behaviors. robotPose.geoPosition.moveTo(lng, lat, elev); // will be set to GPS coordinates, if available robotPose.direction.heading = headingDegrees; // will be set to Compass Heading, if available robotPose.reset(); robotSlam = new RobotSLAM() { useOdometryHeading = true }; await InitComm(cts); // may throw exceptions // see what kind of timer we have to measure durations: if (Stopwatch.IsHighResolution) { Debug.WriteLine("OK: operations are timed using the system's high-resolution performance counter."); } else { Debug.WriteLine("Warning: operations are timed using the DateTime class."); } stopWatch.Start(); if (isCommError) { speaker.Speak("Shorty cannot see his brick"); } else { speaker.Speak("I am Shorty"); } }
// see http://code.jonwagner.com/2012/09/06/best-practices-for-c-asyncawait/ // http://www.c-sharpcorner.com/UploadFile/pranayamr/difference-between-await-and-continuewith-keyword-in-C-Sharp/ // http://code.jonwagner.com/2012/09/04/deadlock-asyncawait-is-not-task-wait/ // https://msdn.microsoft.com/en-us/library/ff963550.aspx - Parallel Programming book public override async Task Init(CancellationTokenSource cts, string[] args) { await base.Init(cts, args); // produces hardwareBrick and sets it for communication joystick.joystickEvent += Joystick_joystickEvent; sensorsController = new SensorsControllerShorty(hardwareBrick, loopTimeMs); sensorsController.InitSensors(cts); InitDrive(); behaviorFactory = new BehaviorFactory(subsumptionTaskDispatcher, driveGeometry, speaker); // we can set behavior combo now, or allow ControlDeviceCommand to set it later. //behaviorFactory.produce(BehaviorCompositionType.JoystickAndStop); robotState = new RobotState(); robotPose = new RobotPose(); robotState.powerLevelPercent = 100; // can be changed any time. Used by behaviors. robotPose.geoPosition.moveTo(lng, lat, elev); // will be set to GPS coordinates, if available robotPose.direction.heading = headingDegrees; // will be set to Compass Heading, if available robotPose.resetXY(); robotSlam = new RobotSLAM(); await InitComm(cts); // may throw exceptions // see what kind of timer we have to measure durations: if (Stopwatch.IsHighResolution) { Debug.WriteLine("OK: operations are timed using the system's high-resolution performance counter."); } else { Debug.WriteLine("Warning: operations are timed using the DateTime class."); } stopWatch.Start(); if (isCommError) { speaker.Speak("Shorty cannot see his brick"); } else { speaker.Speak("I am Shorty"); } }