예제 #1
0
        /// <summary>
        /// Function subscribed to AutonomousService's ObstacleEvent to handle an ObstacleEvent when it's triggered.
        ///
        /// This function gets the Plot representing the detected obstacles and uses the current DriveState's
        /// FindBestGap() to determine the best gap to drive toward. It then issues the corresponding DriveCommand.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">ObstacleEventArgs that contains the Plot representing the detected obstacles.</param>
        public void HandleObstacleEvent(Object sender, ObstacleEventArgs e)
        {
            DriveCommand driveCommand;
            Plot         obstacles = e.Data;

            // Find the best gap
            Line bestGap = this.driveState.FindBestGap(obstacles);

            // If bestGap exists, drive toward it's midpoint. Otherwise, turn right
            if (bestGap != null)
            {
                Coordinate midpoint = bestGap.FindMidpoint();
                double     angle    = midpoint.Theta;

                driveCommand = new DriveCommand(angle, Speed.CLEAR_OBSTACLE);
            }
            else
            {
                driveCommand = DriveCommand.RightTurn(Speed.CLEAR_OBSTACLE);
            }

            // Send driveCommand
            lock (this.sendDriveCommandLock)
            {
                DriveHandler.SendDriveCommand(driveCommand);
                this.lastObstacleDetected = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            }
        }
예제 #2
0
        public static DriveCommand RightTurn(byte speed)
        {
            // Create DriveCommand that represents a Right command of specified speed
            DriveCommand right = new DriveCommand(Angle.RIGHT, speed);

            return(right);
        }
예제 #3
0
        public static DriveCommand LeftTurn(byte speed)
        {
            // Create DriveCommand that represents a Left command of specified speed
            DriveCommand left = new DriveCommand(Angle.LEFT, speed);

            return(left);
        }
예제 #4
0
        public static DriveCommand Straight(byte speed)
        {
            // Create DriveCommand that represents a Straight command of specified speed
            DriveCommand straight = new DriveCommand(Angle.STRAIGHT, speed);

            return(straight);
        }
예제 #5
0
        /// <summary>
        /// Issue the specified DriveCommand to ROCKS through AscentPacketHandler.
        ///
        /// If the SendDriveCommandLock cannot be obtained, do not send the DriveCommand. TODO why? Shore this up
        /// </summary>
        /// <param name="driveCommand">The DriveCommand to be executed.</param>
        public void Drive(DriveCommand driveCommand)
        {
            // Obtain lock
            bool isLocked = false;

            Monitor.TryEnter(this.sendDriveCommandLock, ref isLocked);

            if (isLocked)
            {
                // Send DriveCommand to AscentPacketHandler
                DriveHandler.SendDriveCommand(driveCommand);

                // Release lock
                Monitor.Exit(this.sendDriveCommandLock);
            }
        }