private StatusUpdater()
 {
     roverStatus = new RoverStatus();
     //timer = new System.Timers.Timer(Properties.Settings.Default.StatusUpdateInterval) { Enabled = false };
     updatesQueue = new PriorityQueue(100);
     listener = new MessageListener(Properties.NetworkSettings.Default.StatusUpdatePort, updatesQueue, Properties.NetworkSettings.Default.RoverIPAddress);
 }
Exemplo n.º 2
0
 /// <summary>
 /// When setting mission parameters, check to see when the rover is ready to start roving
 /// </summary>
 private void CheckForOperationalReadyness()
 {
     if (this.m_currentStatus == RoverStatus.InConstruction)
     {
         if (this.m_MissionOrders != null && this.m_currentLocation != null)
         {
             m_currentStatus = RoverStatus.WaitingForDeployment;
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Start executing the Mission Orders
        /// </summary>
        public bool ExecuteOrders()
        {
            // Assumptions: The Mission Orders have already been parsed by Regex to only contain 'M', 'L' or 'R' characters.

            bool          orderCarriedOut       = false;
            RoverLocation previousRoverLocation = null;

            // Log the start of the mission
            AddToEventLog(string.Format("{0}: Starting Mission", Name));

            foreach (char currentOrder in this.m_MissionOrders.ToCharArray())
            {
                // Remember the current location, for comparison with the new location.
                previousRoverLocation = m_currentLocation.Clone();

                // Log the next order
                AddToEventLog(string.Format("{0}: Processing Order:{1}", Name, currentOrder));

                switch (currentOrder)
                {
                case Constants.INPUT_ORDER_MOVE:
                    orderCarriedOut = MoveForward();
                    break;

                case Constants.INPUT_ORDER_LEFT:
                    orderCarriedOut = TurnLeft();
                    break;

                case Constants.INPUT_ORDER_RIGHT:
                    orderCarriedOut = TurnRight();
                    break;

                default:
                    throw new Exceptions.UnknownRoverOrderException(currentOrder);
                }

                // If an order was unsuccesful, stop processing further mission orders.
                if (!orderCarriedOut)
                {
                    AddToEventLog(string.Format("{0}: Mission Failed!", Name));
                    return(false);
                }

                // Log the succesful movement
                AddToEventLog(string.Format("{0}: Succesfully changed position from '{1}' to '{2}'", Name, previousRoverLocation, m_currentLocation));
            }

            // Nothing has gone wrong, mark the mission as a success
            AddToEventLog(string.Format("{0}: Mission Completed!", Name));
            m_currentStatus = RoverStatus.MissionComplete;
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tell the rover that it has landed and is about to start wondering about.
        /// </summary>
        /// <returns></returns>
        public bool LandOnPlateau()
        {
            if (m_plateauXDimension == 0 || m_plateauYDimension == 0)
            {
                throw new Exceptions.NotReadyForLandingException("This Rover doesn't know the size of the plateau to land on.");
            }

            // Set the current location to the pre-programmed starting location
            m_currentLocation = m_startingLocation.Clone();

            // Update the status of the rover
            m_currentStatus = RoverStatus.Roving;

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Try to move 1 step forward
        /// </summary>
        /// <returns>True, if moved succesfully</returns>
        private bool MoveForward()
        {
            // Check we're not currently facing the edge of the Plateau
            if (CheckForPlateauEdge())
            {
                m_currentStatus  = RoverStatus.MissionAborted;
                m_reasonForAbort = "The edge of the plateau has been detected, I can not move another step forward.";
                AddToEventLog(string.Format("{0}: {1}", Name, m_reasonForAbort));
                return(false);
            }


            // Check to see if there are any obsticals in the way (such as another rover)
            if (CheckForObstacles())
            {
                m_currentStatus  = RoverStatus.MissionAborted;
                m_reasonForAbort = "The edge of the plateau has been detected, I can not move another step forward.";
                AddToEventLog(string.Format("{0}: {1}", Name, m_reasonForAbort));
                return(false);
            }


            // Move the Rover 1 step forward - in the correct direction.
            switch (m_currentLocation.Heading)
            {
            case CompassDirection.North:
                m_currentLocation.YPosition += 1;
                break;

            case CompassDirection.South:
                m_currentLocation.YPosition -= 1;
                break;

            case CompassDirection.East:
                m_currentLocation.XPosition += 1;
                break;

            case CompassDirection.West:
                m_currentLocation.XPosition -= 1;
                break;
            }

            return(true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Main Constructor
 /// </summary>
 public Rover()
 {
     m_currentStatus  = RoverStatus.InConstruction;
     m_reasonForAbort = string.Empty;
     m_EventLogs      = new StringBuilder(30);
 }
Exemplo n.º 7
0
        public RoverStatus Move(int startX, int startY, string direction, string directive)
        {
            RoverStatus result = new RoverStatus();

            result.IsError = false;
            try
            {
                _x = startX;
                _y = startY;

                #region validation

                if (_sizeX < _x || _sizeY < _y)
                {
                    result.IsError = true;
                    result.Message = "Start position error!";
                }

                else if (!MoveValidation(directive))
                {
                    result.IsError = true;
                    result.Message = "Directive error!";
                }


                #endregion
                else
                {
                    _direction = (int)(DirectiveEnums)Enum.Parse(typeof(DirectiveEnums), direction);

                    foreach (var item in directive)
                    {
                        MovementEnums move = (MovementEnums)Enum.Parse(typeof(MovementEnums), item.ToString());

                        if (move == MovementEnums.M)
                        {
                            //hareket
                            _x += movement[_direction].x;
                            _y += movement[_direction].y;
                            _x  = Math.Min(_x, _sizeX);
                            _y  = Math.Min(_y, _sizeY);
                        }
                        else
                        {
                            //yön belirleme
                            _direction += (int)move;
                            _direction  = _direction > 3 ? _direction - 4 : _direction;
                            _direction  = _direction < 0 ? 4 + _direction : _direction;
                        }
                    }

                    result.Position.x         = _x;
                    result.Position.y         = _y;
                    result.Position.direction = ((DirectiveEnums)_direction);
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = $"An error has occurred! Detail: {ex.Message}";
            }
            return(result);
        }