コード例 #1
0
        /// <summary>
        /// Start the service
        /// </summary>
        protected override void Start()
        {
            if (this.state == null)
            {
                this.state = new ObstacleAvoidanceDriveState();
            }

            if (this.state.RobotWidth == 0)
            {
                this.state.RobotWidth = DefaultRobotWidthInMeters;
            }

            if (this.state.DepthCameraPosition.Y == 0)
            {
                this.state.DepthCameraPosition = new PhysicalModel.Vector3(0, 0.6f, -0.15f);
            }

            if (this.state.Controller == null)
            {
                this.state.Controller = new PIDController();
            }

            if (this.state.MaxPowerPerWheel <= 0 || this.state.MaxPowerPerWheel > 1)
            {
                this.state.MaxPowerPerWheel = DefaultMaximumMotorSpeed;
            }

            if (this.state.MinRotationSpeed <= 0 || this.state.MinRotationSpeed > this.state.MaxPowerPerWheel)
            {
                this.state.MinRotationSpeed = DefaultMinimumRotateInPlaceSpeed;
            }

            if (this.state.MaxDeltaPower == 0)
            {
                this.state.MaxDeltaPower = DefaultMaxDeltaPower;
            }

            this.depthCameraDefaultPose.Position = this.state.DepthCameraPosition;

            // C:\Microsoft Robotics Dev Studio 4\samples\Config\obstacleavoidancedrive.user.config.xml
            this.SaveState(this.state);
            base.Start();

            // 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.
            MainPortInterleave.CombineWith(
            Arbiter.Interleave(
                new TeardownReceiverGroup(),
                new ExclusiveReceiverGroup(
                    Arbiter.ReceiveWithIterator<OnLoad>(true, this.eventsPort, this.OnLoadHandler),
                    Arbiter.Receive<OnClosed>(true, this.eventsPort, this.OnClosedHandler),
                    Arbiter.ReceiveWithIterator(true, this.samplePort, this.SampleSensors),
                    Arbiter.ReceiveWithIterator<OnPIDChanges>(true, this.eventsPort, this.OnPIDChangesHandler)),
                new ConcurrentReceiverGroup(
                    Arbiter.ReceiveWithIterator<game.UpdateButtons>(true, this.gameControllerNotify, this.JoystickUpdateButtonsHandler))));

            WinFormsServicePort.Post(new RunForm(this.CreateForm));

            // kick off sampling interval
            this.samplePort.Post(DateTime.UtcNow);
        }