Beispiel #1
0
        public RouterUI()
        {
            InitializeComponent();
            serial = new SerialPortWrapper();
            robot  = new Robot.Robot(serial);
            hw     = robot as IHardware;
            router = new Router.Router(hw);
            hw.onPositionUpdate += new EventHandler(PosUpdate);

            // Setup for doing our own form painting
            //this.SetStyle(
            //  ControlStyles.AllPaintingInWmPaint |
            //  ControlStyles.UserPaint |
            //  ControlStyles.DoubleBuffer, true);
            t          = new Timer();
            t.Interval = 25;
            t.Tick    += new EventHandler(t_Tick);
            t.Enabled  = false;
            //t.Start();

            this.propertyGrid.SelectedGridItemChanged += new SelectedGridItemChangedEventHandler(propertyGrid_SelectedGridItemChanged);

            userControl11.SelectedItemChanged += new EventHandler(userControl11_SelectedItemChanged);
            userControl11.AddObject(router);
            //g1 = new InvoluteGear();
            //g2 = new InvoluteGear();
            //userControl11.AddObject(g1);
            //g2.X = 122.5493f * 2;
            //g2.Rotation = 180.0f / 11.0f + 0.425f;
            //userControl11.AddObject(g2);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var robot = new Robot.Robot();
            robot.Initialize();

            //var robotCleaner = new Robot.RobotCleaner();
            //robot.Initialize();
        }
Beispiel #3
0
 public void TestInitialize()
 {
     List<string[]> commmaList= new List<string[]>();
     commmaList.Add(new []{"E", "2"});
     commmaList.Add(new []{"N", "1"});
     robot = new Robots(2, 10, 22, commmaList);
     robot.Initialize();
 }
Beispiel #4
0
        public void TestNumberOfBlocks_InputTwo_ReturnsTwo()
        {
            var robot = new Robot.Robot(2);

            //const string expectedOutput = @"0:0\n1:1\2:2";
            var output = robot.NumberOfBlocks();

            Assert.Equal(2, output);
        }
Beispiel #5
0
        public void TestOutput_InputTwo_ReturnsTwo()
        {
            var robot = new Robot.Robot(2);

            var n = Environment.NewLine;
            var expectedOutput = $"0: 0{n}1: 1{n}2: 2{n}";
            var output         = robot.Output();

            Assert.Equal(expectedOutput, output);
        }
Beispiel #6
0
        public void VerificationCommandsRobot()
        {
            var robot   = new Robot.Robot("#1");
            var invoker = new Invoker(robot);

            invoker.AddCommand(new CommandBeep());
            invoker.AddCommand(new CommandMove(10));
            invoker.AddCommand(new CommandTurn(20));
            invoker.Run();
            Assert.IsTrue(robot.IsBeep, "Не отработала команда beep");
            Assert.AreEqual(robot.Distance, 10, 0, "Не отработала команда move");
            Assert.AreEqual(robot.Angle, 20, 0, "Не отработала команда trun");
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Robot jhonn = new Robot();

            Robot anna = new Robot();

            if (anna.Name() == jhonn.Name())
            {
                anna = new Robot();
            }

            Console.WriteLine(jhonn.Name());

            Console.WriteLine(anna.Name());

            Console.ReadKey();
        }
Beispiel #8
0
        public void VerificationCommandsRobots()
        {
            var robot1  = new Robot.Robot("#1");
            var invoker = new Invoker(robot1);

            invoker.AddCommand(new CommandBeep());
            invoker.AddCommand(new CommandMove(10));
            invoker.AddCommand(new CommandTurn(20));
            invoker.Run();
            for (var i = 0; i < 10; i++)
            {
                var robot2 = new Robot.Robot($"#{i}");
                invoker.SetRobot(robot2);
                invoker.Run();
                Assert.AreEqual(robot1.IsBeep, robot2.IsBeep, "Не совпадают команды beep");
                Assert.AreEqual(robot1.Distance, robot2.Distance, 0, "Не совпадают команды move");
                Assert.AreEqual(robot1.Angle, robot2.Angle, 0, "Не совпадают команды trun");
            }
        }
        public static void Report(StringWriter writer, ArrayList machines, Robot robot)
        {
            writer.Write("FACTORY REPORT\n");

            foreach (Machine machine in machines)
            {
                writer.Write("Machine " + machine.Name);
                if (machine.Bin != null)
                    writer.Write(" bin=" + machine.Bin);
                writer.Write("\n");
            }
            writer.Write("\n");

            writer.Write("Robot");
            if (robot.Location != null)
                writer.Write(" location=" + robot.Location.Name);

            if (robot.Bin != null)
                writer.Write(" bin=" + robot.Bin);

            writer.Write("\n");

            writer.Write("========\n");
        }
Beispiel #10
0
 static void Main(string[] args)
 {
     Robot robot = new Robot();
     robot.BuildRobot();
     Console.Read();
 }
Beispiel #11
0
 static void Main(string[] args)
 {
     Robot robots = new Robot();
     robots.StartRobots();
     robots.StartBattle();
 }
Beispiel #12
0
 public void AssignRouter(Router.Router router)
 {
     this.router = router;
     this.robot = new Robot.Robot(serial);
     this.robot.onRobotStatusChange += new EventHandler(RobotStatusUpdate);
 }
Beispiel #13
0
        public void Test1()
        {
            var robot = new Robot.Robot();

            Assert.Equal(4, robot.Add(2, 2));
        }
Beispiel #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            // initialiser

            robot = new Robot(Largeur);
            // état initial du robot
            robot.Direction = Direction.Nord;
            robot.X = 0;
            robot.Y = Largeur - 1;
            currentT = 0;

            button3.Enabled = true;
            button2.Enabled = true;
            NbBonbons = 0;
            Liste.Text = null;

            // schéma de la pièce avec les murs représentées sous la forme d'un carré
            // En fait la pièce est torique dans ses deux dimensions
            // cela signifie que si on déborde d'un bord, on arrive sur le bord opposé
            // la direction du robot ne change évidemment pas
            piece = new int[Largeur][];
            piece[0] = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            piece[1] = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            piece[2] = new int[] { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 };
            piece[3] = new int[] { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
            piece[4] = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            piece[5] = new int[] { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 };
            piece[6] = new int[] { 0, 0, 1, 1, 1, 0, 1, 0, 0, 0 };
            piece[7] = new int[] { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0 };
            piece[8] = new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
            piece[9] = new int[] { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };

            reseau = new KohonenMapRobot(256, 1.0, Piece.Width, Piece.Height);

            pasX = (int)(Piece.Width / Largeur);
            pasY = (int)(Piece.Height / Largeur);

            Graphics g = Piece.CreateGraphics();
            g.Clear(Color.White);

            DessinerMurs(g);
            DisposerBonbons(g, 5);
            DessinerRobot(g, robot);

            double[] senseurs = CapturerSenseurs(robot);

            Liste.Text += string.Format("Senseur: {0}/{1}/{2}", senseurs[0].ToString("0.0000;-0.0000"), senseurs[1].ToString("0.0000;-0.0000"), senseurs[2].ToString("0.0000;-0.0000")) + Environment.NewLine;
        }
Beispiel #15
0
        private void DessinerRobot(Graphics g, Robot robot)
        {
            Rectangle r = new Rectangle(robot.X * pasX, robot.Y * pasY, pasX, pasY);
            g.FillRectangle(Brushes.Green, r);
            Pen pen = new Pen(Color.Orange, 6);
            switch (robot.Direction)
            {
                case Direction.Nord:
                    g.DrawLine(pen, robot.X * pasX, robot.Y * pasY, robot.X * pasX + pasX, robot.Y * pasY);
                    break;
                case Direction.Sud:
                    g.DrawLine(pen, robot.X * pasX, robot.Y * pasY + pasY, robot.X * pasX + pasX, robot.Y * pasY + pasY);
                    break;
                case Direction.Ouest:
                    g.DrawLine(pen, robot.X * pasX, robot.Y * pasY, robot.X * pasX, robot.Y * pasY + pasY);
                    break;
                case Direction.Est:
                    g.DrawLine(pen, robot.X * pasX + pasX, robot.Y * pasY, robot.X * pasX + pasX, robot.Y * pasY + pasY);
                    break;
                default:
                    break;
            }

            Position.Text = string.Format("X={0}, Y={1}", robot.X,robot.Y);
        }
Beispiel #16
0
        private double[] CapturerSenseurs(Robot robot)
        {
            // http://members.ozemail.com.au/~dekker/robot.pdf

            double[] senseurs = robot.Senseur.LireSenseurs(piece, robot.Direction, robot.X, robot.Y);
            if (senseurs.Any(s => s > 0))
            {
                // on a détecté au moins un bonbon
                // dans ce cas on met à 0 les senseurs qui détectent un mur
                for (int s = 0; s < 3; s++)
                {
                    if (senseurs[s] < 0)
                    {
                        senseurs[s] = 0;
                    }
                }
            }

            return senseurs;
        }
Beispiel #17
0
 public void AssignRouter(Router.Router router)
 {
     this.router = router;
     this.robot  = new Robot.Robot(serial);
     this.robot.onRobotStatusChange += new EventHandler(RobotStatusUpdate);
 }