Ejemplo n.º 1
0
        public IEnumerator <ITask> GetHandler(Get get)
        {
            MarkRobotState getState = new MarkRobotState();

            drive.Get driveGet = new drive.Get();

            getState.DriveState = new drive.DriveDifferentialTwoWheelState();

            // Get the up-to-date drive state
            this.controllerDrivePort.Post(driveGet);
            yield return(driveGet.ResponsePort.Choice(s => getState.DriveState = s, EmptyHandler));

            // MarkRobot service specific configuration
            getState.SonarTimeValueMultiplier      = this.state.SonarTimeValueMultiplier;
            getState.SensorPollingInterval         = this.state.SensorPollingInterval;
            getState.LastStartTime                 = this.state.LastStartTime;
            getState.InfraredRawValueDivisorScalar = this.state.InfraredRawValueDivisorScalar;
            getState.InfraredDistanceExponent      = this.state.InfraredDistanceExponent;
            getState.BatteryVoltagePinIndex        = this.state.BatteryVoltagePinIndex;
            getState.BatteryVoltageDivider         = this.state.BatteryVoltageDivider;

            // Polled state
            getState.BatteryState        = this.state.BatteryState;
            getState.InfraredSensorState = this.state.InfraredSensorState;
            getState.SonarSensorState    = this.state.SonarSensorState;

            get.ResponsePort.Post(getState);
        }
 /// <summary>
 /// State and Port ctor
 /// </summary>
 /// <param name="state">Service State</param>
 /// <param name="responsePort">Response Port</param>
 public Replace(MarkRobotState state, PortSet <DefaultReplaceResponseType, Fault> responsePort)
     : base(state, responsePort)
 {
 }
 /// <summary>
 /// Service State-based ctor
 /// </summary>
 /// <param name="state">Service State</param>
 public Replace(MarkRobotState state)
     : base(state)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Allocation and assignments for first run
        /// </summary>
        /// <returns>True if initialization succeeded, otherwise False</returns>
        private bool Initialize()
        {
            if (this.initialized)
            {
                return(this.initialized);
            }

            try
            {
                // No persisted state file, create a new one
                if (this.state == null)
                {
                    this.state = new MarkRobotState();
                }

                // Populate the IR sensor state
                if (this.state.InfraredSensorState == null)
                {
                    this.state.InfraredSensorState = new ir.InfraredSensorArrayState();
                }

                if (this.state.InfraredSensorState.Sensors == null)
                {
                    this.state.InfraredSensorState.Sensors = new List <Services.Infrared.InfraredState>();
                }

                if (this.state.InfraredSensorState.Sensors.Count == 0)
                {
                    foreach (int irIdentifier in DefaultInfraredArrayIdentifiers)
                    {
                        this.state.InfraredSensorState.Sensors.Add(new Services.Infrared.InfraredState()
                        {
                            HardwareIdentifier = irIdentifier
                        });
                    }
                }

                // Populate the Sonar sensor state
                if (this.state.SonarSensorState == null)
                {
                    this.state.SonarSensorState = new sonar.SonarSensorArrayState();
                }

                if (this.state.SonarSensorState.Sensors == null)
                {
                    this.state.SonarSensorState.Sensors = new List <Services.Sonar.SonarState>();
                }

                if (this.state.SonarSensorState.Sensors.Count == 0)
                {
                    foreach (int sonarIdentifier in DefaultSonarArrayIdentifiers)
                    {
                        this.state.SonarSensorState.Sensors.Add(new Services.Sonar.SonarState()
                        {
                            HardwareIdentifier = sonarIdentifier
                        });
                    }
                }

                this.state.DriveState = new drive.DriveDifferentialTwoWheelState();

                if (this.state.BatteryState == null)
                {
                    this.state.BatteryState = new Services.Battery.BatteryState();
                }

                if (this.state.BatteryState.MaxBatteryPower == 0)
                {
                    this.state.BatteryState.MaxBatteryPower = DefaultMaxBatteryPower;
                }
            }
            catch (Exception e)
            {
                LogError(e);
                this.Shutdown();
                return(false);
            }

            this.state.LastStartTime = DateTime.Now;

            SaveState(this.state);

            base.Start();

            // Make sure the pin polling port is in the main interleave because it modifies service state
            MainPortInterleave.CombineWith(
                new Interleave(
                    new ExclusiveReceiverGroup(
                        Arbiter.ReceiveWithIterator(true, this.sensorPollingPort, this.PollSensors)),
                    new ConcurrentReceiverGroup(
                        Arbiter.Receive <drive.Update>(true, this.driveNotifyPort, this.DriveNotification))));

            this.controllerDrivePort.Post(new drive.Subscribe()
            {
                NotificationPort = this.driveNotifyPort
            });
            this.controllerDrivePort.Post(new drive.ReliableSubscribe()
            {
                NotificationPort = this.driveNotifyPort
            });

            // Start the pin polling interval
            this.sensorPollingPort.Post(DateTime.Now);

            return(true);
        }