示例#1
0
//		public static void main(String[] args)
        public void start()
        {
            ev3.connect();

//			Sejway sej = new Sejway();
            getBalancePos();
            pidControl();
            shutDown();

            ev3.disconnect();
        }
示例#2
0
文件: Segway.cs 项目: rotkiv42/EV3
        public void start()
        {
            ev3.connect();

            Thread t1 = new Thread(new ThreadStart(balance));

            t1.Start();
            while (starting_balancing_task)
            {
            }
            Console.WriteLine("Complete balancing task.");

//			steering = -7;
            speed = 30;

            t1.Join();

            ev3.disconnect();
            Console.WriteLine("End");
        }
示例#3
0
文件: GyroBoy.cs 项目: rotkiv42/EV3
        // verified
        public void start()
        {
            ev3.connect();

            // verified
            initialize();

            // verified
            Thread t1 = new Thread(new ThreadStart(balance));

            t1.Start();
            // verified
            Thread t2 = new Thread(new ThreadStart(drive));

            t2.Start();

            t1.Join();
            t2.Join();

            ev3.disconnect();
        }
示例#4
0
文件: Segoway.cs 项目: rotkiv42/EV3
        public void start()
        {
            ev3.connect();

            gyro        = ev3.getGyroSensor();
            left_motor  = ev3.getMotorA();
            right_motor = ev3.getMotorD();

            // Optional code to accept BasicMotor: this.right_motor = (NXTMotor)right;
//				this.gyro = gyro;
            this.ratioWheel = wheelDiameter / 5.6;                   // Original algorithm was tuned for 5.6 cm NXT 1.0 wheels.

            // Took out 50 ms delay here.

            // Get the initial gyro offset
            getGyroOffset();

            // Play warning beep sequence before balance starts
//				startBeeps();

            // Start balance thread
//				this.setDaemon(true);
//				this.start();


//			initialize ();
            //			balance();
            Thread t1 = new Thread(new ThreadStart(balance));

            t1.Start();
//			Thread t2 = new Thread (new ThreadStart (drive));
//			t2.Start ();

            t1.Join();
//			t2.Join ();

            ev3.disconnect();
        }
示例#5
0
        private void testController()
        {
            Console.WriteLine("Testing constoller ...");
            EV3Brick ev3 = new EV3Brick();

            ev3.connect();

            // current status: normalize
            int motorAdeg = (int)(ev3.getMotorADegree() / 50.0);
            int motorBdeg = (int)(ev3.getMotorBDegree() / 300.0);

            /*
             * training data = [
             *      [[0,0,0,1], [0,1]],		// down1
             *      [[0,1,1,1], [1,0]],		// pick
             *      [[1,1,1,0], [0,-1]],	// up1
             *      [[1,0,1,1], [0,1]],		// down2
             *      [[1,1,0,1], [-1,0]],	// drop
             *      [[0,1,0,0], [0,-1]]		// up2
             * ]
             */
            var argv = new List <int[]> ();

            // current (A, B), desired (A, B)
            // down1
            argv.Add(new [] { motorAdeg, motorBdeg, 0, 1 });
//			argv.Add (new []{0,0,0,1});
            argv.Add(new [] { 0, 1 });                  // targets A, B

            // up1
//			argv.Add (new []{1,1,1,0});
//			argv.Add (new []{motorAdeg,motorBdeg,1,0});
//			argv.Add (new []{0,-1});		// targets A, B

            var engine = Python.CreateEngine();
            var paths  = engine.GetSearchPaths();

            paths.Add(pythonPath);
            engine.SetSearchPaths(paths);
            engine.GetSysModule().SetVariable("argv", argv);

            var scriptRuntime = Python.CreateRuntime();

            scriptRuntime.GetSysModule().SetVariable("argv", argv);

            try
            {
                dynamic result = engine.ExecuteFile("script.py");
                Console.WriteLine(result.outputs);
                var outputs = result.outputs;
                foreach (double output in outputs)
                {
                    Console.WriteLine(output);
                }
                motorAdeg = (int)(outputs[0] * 50);
                motorBdeg = (int)(outputs[1] * 300);
                Console.WriteLine(motorAdeg + ", " + motorBdeg);
                ev3.moveMotorA(motorAdeg);
                ev3.moveMotorB(motorBdeg);
                Thread.Sleep(5000);
            }
            catch (Exception ex)
            {
                Console.WriteLine(
                    "Oops! We couldn't execute the script because of an exception: " + ex.Message);
            }

            ev3.disconnect();

            Console.WriteLine("Complete.");
            //			Console.ReadLine();
        }
示例#6
0
文件: ev3.cs 项目: dpiquee/EV3
        private void testController()
        {
            Console.WriteLine("Testing constoller ...");
            EV3Brick ev3 = new EV3Brick ();
            ev3.connect ();

            // current status: normalize
            int motorAdeg = (int) (ev3.getMotorADegree()/50.0);
            int motorBdeg = (int) (ev3.getMotorBDegree()/300.0);

            /*
            training data = [
                [[0,0,0,1], [0,1]],		// down1
                [[0,1,1,1], [1,0]],		// pick
                [[1,1,1,0], [0,-1]],	// up1
                [[1,0,1,1], [0,1]],		// down2
                [[1,1,0,1], [-1,0]],	// drop
                [[0,1,0,0], [0,-1]]		// up2
            ]
            */
            var argv = new List<int[]> ();
            // current (A, B), desired (A, B)
            // down1
            argv.Add (new []{motorAdeg,motorBdeg,0,1});
            //			argv.Add (new []{0,0,0,1});
            argv.Add (new []{0,1});		// targets A, B

            // up1
            //			argv.Add (new []{1,1,1,0});
            //			argv.Add (new []{motorAdeg,motorBdeg,1,0});
            //			argv.Add (new []{0,-1});		// targets A, B

            var engine = Python.CreateEngine();
            var paths = engine.GetSearchPaths();
            paths.Add(pythonPath);
            engine.SetSearchPaths(paths);
            engine.GetSysModule ().SetVariable ("argv", argv);

            var scriptRuntime = Python.CreateRuntime();
            scriptRuntime.GetSysModule().SetVariable("argv", argv);

            try
            {
                dynamic result = engine.ExecuteFile("script.py");
                Console.WriteLine(result.outputs);
                var outputs = result.outputs;
                foreach (double output in outputs) {
                    Console.WriteLine(output);
                }
                motorAdeg = (int) (outputs[0]*50);
                motorBdeg = (int) (outputs[1]*300);
                Console.WriteLine(motorAdeg + ", " + motorBdeg);
                ev3.moveMotorA(motorAdeg);
                ev3.moveMotorB(motorBdeg);
                Thread.Sleep(5000);
            }
            catch (Exception ex)
            {
                Console.WriteLine(
                    "Oops! We couldn't execute the script because of an exception: " + ex.Message);
            }

            ev3.disconnect ();

            Console.WriteLine("Complete.");
            //			Console.ReadLine();
        }