001/* This source code is released under the new BSD license, a copy of the
002 * license is in the distribution directory. */
003
004package mazerob.pc;
005
006import java.io.IOException;
007
008/** Main PC application for the mazerob system.
009 *
010 * <p>Uses an instance of {@link mazerob.pc.Robot} for solving a maze with
011 * the program stored at {@link mazerob.pc.MazeSolver#solveMaze}.</p>
012 *
013 * @author Pedro I. López
014 *
015 */
016public class PC {
017
018    /** Main application entry point.
019     *
020     * <p>Command line positional arguments to configure an instance of {@link
021     * mazerob.pc.Robot} providing arguments for its constructor {@link
022     * mazerob.pc.Robot#Robot}:</p>
023     *
024     * <ol>
025     * <li>{@code nxtName} argument to {@link
026     * mazerob.pc.Robot#Robot}</li>
027     * <li>{@code nxtAddr} argument to {@link
028     * mazerob.pc.Robot#Robot}</li>
029     * <li>{@code wheelDiameter} argument to {@link
030     * mazerob.pc.Robot#Robot}</li>
031     * <li>{@code trackWidth} argument to {@link
032     * mazerob.pc.Robot#Robot}</li>
033     * <li>{@code reverse} argument to {@link
034     * mazerob.pc.Robot#Robot}</li>
035     * <li>{@code rotationSpeed} argument to {@link
036     * mazerob.pc.Robot#Robot}</li>
037     * <li>{@code translationMagnitude} argument to {@link
038     * mazerob.pc.Robot#Robot}</li>
039     * <li>{@code rotationMagnitude} argument to {@link
040     * mazerob.pc.Robot#Robot}</li>
041     * </ol>
042     *
043     * <p>This method gets a {@link mazerob.pc.Robot} instance
044     * configured with the command line positional arguments, executes
045     * {@link mazerob.pc.MazeSolver#solveMaze} and exits.</p>
046     *
047     */
048    public static void main(String[] args) {
049        String r0Name, r0Address;
050        double r0WheelDiameter, r0TrackWidth, r0RotationSpeed,
051               r0TranslationMagnitude, r0RotationMagnitude;
052        boolean r0Reverse;
053        LogListener logListener;
054        Robot r0;
055
056        assert args.length == 8;
057
058        r0Name = args[0];
059        r0Address = args[1];
060        r0WheelDiameter = Double.parseDouble(args[2]);
061        r0TrackWidth = Double.parseDouble(args[3]);
062        r0Reverse = Boolean.parseBoolean(args[4]);
063        r0RotationSpeed = Double.parseDouble(args[5]);
064        r0TranslationMagnitude = Double.parseDouble(args[6]);
065        r0RotationMagnitude = Double.parseDouble(args[7]);
066        System.out.println(r0Name + " : " + r0Address);
067        logListener = new LogListener();
068        r0 = new Robot( r0Name,
069                        r0Address,
070                        logListener,
071                        r0WheelDiameter,
072                        r0TrackWidth,
073                        r0Reverse,
074                        r0RotationSpeed,
075                        r0TranslationMagnitude,
076                        r0RotationMagnitude
077                        );
078
079        try {
080            new MazeSolver().solveMaze(r0);
081        } catch(Exception e) {
082            System.out.println(e);
083            System.exit(1);
084        }
085    }
086
087}