Пример #1
0
	public static void Main (string[] args)
	{
		EventWaitHandle stopped = new ManualResetEvent(false);
		ColorMode[] modes = {ColorMode.Color, ColorMode.Reflection, ColorMode.Ambient, ColorMode.Blue};
		int modeIdx = 0;
		var sensor = new EV3ColorSensor(SensorPort.In1);
		ButtonEvents buts = new ButtonEvents ();
		LcdConsole.WriteLine("Use color on port1");
		LcdConsole.WriteLine("Up read value");
		LcdConsole.WriteLine("Down raw value");
		LcdConsole.WriteLine("Enter change mode");
		LcdConsole.WriteLine("Esc. terminate");
		buts.EscapePressed += () => { 
			stopped.Set();
		};
		buts.UpPressed += () => { 
			LcdConsole.WriteLine("Sensor value: " + sensor.ReadAsString());
		};
		buts.DownPressed += () => { 
			LcdConsole.WriteLine("Raw sensor value: " + sensor.ReadRaw());
		};
		buts.EnterPressed += () => { 
			modeIdx = (modeIdx+1)%modes.Length;
			sensor.Mode = modes[modeIdx];
			LcdConsole.WriteLine("Sensor mode is set to: " + modes[modeIdx]);
		};  
		stopped.WaitOne();
	}
Пример #2
0
        public static void Main(string[] args)
        {
            var sensor = new EV3ColorSensor(SensorPort.In1);
            sensor.Mode = ColorMode.RGB;

            Motor motorA = new Motor(MotorPort.OutA);
            Motor motorB = new Motor(MotorPort.OutB);
            Motor motorD = new Motor(MotorPort.OutD);

            string solution;

            Cube cube = new Cube (motorA, motorB, motorD); // instantiate a real cube

            // Cube cube = new Cube (); // virtual cube used for tests
            // Solver.Randomizer (cube, 5000); // scramble the virtual cube

            DateTime starttime = DateTime.Now;
            TimeSpan elapsedtime = new TimeSpan ();

            MoveCube.BuildCube2P(cube, MoveCube.BuildCube (cube, motorA, motorB, motorD, sensor));

            elapsedtime = DateTime.Now - starttime;

            Console.WriteLine (cube.GetCubeMap());
            Console.WriteLine (cube.ToString ());
            Console.WriteLine ("Elapsed time scanning cube: {0}", elapsedtime);

            starttime = DateTime.Now;

            // uncomment line below if you want to use the internal algorithm to solve the cube.
            // It's the easiest way, but also the slowest.
            // solution = Solver.Solve (cube);

            // comment the following block if you intend to use the internal algorithm to solve
            // the cube. By default the main program tries to read the solution from a solution
            // file. Just run the Kociemba algorithm on a pc and use scp, putty or any other ssh
            // tool to send the file to the intelligent Lego brick.
            Communication.ClearCube (Communication.CubePath);
            Communication.ClearCube (Communication.SolutionPath);
            Communication.SaveCube (Communication.CubePath, cube.ToString ());
            solution = Communication.ReceiveSolution ();

            elapsedtime = DateTime.Now - starttime;

            Console.WriteLine ("Solution: {0}", solution);
            Console.WriteLine ("Elapsed time receiving solution: {0}", elapsedtime);

            starttime = DateTime.Now;

            Solver.TranslateMove (solution, cube);
            Console.WriteLine (cube.GetCubeMap ());

            elapsedtime = DateTime.Now - starttime;
            Console.WriteLine ("Time elapsed moving cube: {0}", elapsedtime);

            Communication.ClearCube (Communication.CubePath);
            Communication.ClearCube (Communication.SolutionPath);
        }
Пример #3
0
        public static readonly int SensorSide = 87; //79

        #endregion Fields

        #region Methods

        /*
         * This method controls the movements of the robot to position
         * each face of the cube to be scanned by the color sensor.
         */
        public static char[] BuildCube(Cube cube, Motor motorA, Motor motorB, Motor motorD, EV3ColorSensor sensor)
        {
            char[] faces = new char[6];

            // Position face in cube
            for (int j = 0; j < 6; j++) {

                switch (j) {
                case 0:
                    BuildFace (cube.face[3], motorA, motorB, sensor);
                    cube.face [3].TurnCWCore ();
                    cube.face [3].TurnCWCore ();
                    MoveCube.Move (motorD, MoveCube.GrabArm);
                    MoveCube.Move (motorD, MoveCube.PullArm);
                    MoveCube.Move (motorD, MoveCube.RestArm);
                    break;
                case 1:
                    BuildFace (cube.face[2], motorA, motorB, sensor);
                    cube.face [2].TurnCWCore ();
                    MoveCube.Move (motorD, MoveCube.GrabArm);
                    MoveCube.Move (motorD, MoveCube.PullArm);
                    MoveCube.Move (motorD, MoveCube.RestArm);
                    break;
                case 2:
                    BuildFace (cube.face[1], motorA, motorB, sensor);
                    MoveCube.MoveRel (motorA, MoveCube.CCW90);
                    MoveCube.Move (motorD, MoveCube.GrabArm);
                    MoveCube.Move (motorD, MoveCube.PullArm);
                    MoveCube.Move (motorD, MoveCube.RestArm);
                    break;
                case 3:
                    BuildFace (cube.face[0], motorA, motorB, sensor);
                    cube.face [0].TurnCCWCore ();
                    MoveCube.MoveRel (motorA, MoveCube.CW90);
                    MoveCube.Move (motorD, MoveCube.GrabArm);
                    MoveCube.Move (motorD, MoveCube.PullArm);
                    MoveCube.Move (motorD, MoveCube.RestArm);
                    break;
                case 4:
                    BuildFace (cube.face [4], motorA, motorB, sensor);
                    MoveCube.Move (motorD, MoveCube.GrabArm);
                    MoveCube.Move (motorD, MoveCube.PullArm);
                    MoveCube.Move (motorD, MoveCube.RestArm);
                    break;
                case 5:
                    BuildFace (cube.face [5], motorA, motorB, sensor);
                    break;
                }
            }
            for (int i = 0; i < 6; i++)
                faces [i] = cube.face [i].square [1, 1];
            return faces;
        }
        // センサ/モータ
        // タッチセンサ 1
        // 超音波センサ 2
        // カラーセンサ 3
        // ジャイロセンサ 4
        // 尻尾用モータ A
        // 右車輪用モータ B
        // 左車輪用モータ C

		public EquipmentParameters ()
		{
			// 車両情報

			// ポート番号
            TailMoter = new Motor(MotorPort.OutA);
            MpRight = new Motor(MotorPort.OutB);
            MpLeft = new Motor(MotorPort.OutC);

			TouchSensors = new EV3TouchSensor(SensorPort.In1);
            // TODO : 超音波センサーはLのみ(Primary)
            DistSensors = new EV3UltrasonicSensor(SensorPort.In2, UltraSonicMode.Centimeter);
            // 反射
            LightSensors = new EV3ColorSensor(SensorPort.In3, ColorMode.Reflection);
            GyroSensors = new EV3GyroSensor(SensorPort.In4, GyroMode.AngularVelocity);
		}
Пример #5
0
		public static void Main (string[] args)
		{
			const string to = "*****@*****.**";
			const string from = "*****@*****.**";
			const string password = "******";
			
			ManualResetEvent terminateProgram = new ManualResetEvent(false);
			var colorSensor = new EV3ColorSensor(SensorPort.In1);
			ButtonEvents buts = new ButtonEvents ();
			SmtpClient smptpClient = new SmtpClient("smtp.gmail.com", 587);
			smptpClient.EnableSsl = true;
			smptpClient.UseDefaultCredentials = false;
			smptpClient.Credentials = new NetworkCredential(from, password);
			smptpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
			ServicePointManager.ServerCertificateValidationCallback = 
                delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
                    { return true; };
			MailMessage message = new MailMessage();
			message.To.Add(to);
			message.From = new MailAddress(from);
			message.Subject = "Color mail from my EV3";
			LcdConsole.Clear();
			LcdConsole.WriteLine("Use color on port1");
			LcdConsole.WriteLine("Enter send mail");
			LcdConsole.WriteLine("Esc. terminate");
			buts.EscapePressed += () => { 
				terminateProgram.Set();
			};
			buts.EnterPressed += () => { 
				LcdConsole.WriteLine("Sending email");
				try{
					message.Body = "EV3 read color: " + colorSensor.ReadColor();
					smptpClient.Send(message);
					LcdConsole.WriteLine("Done sending email");
				}
				catch(Exception e)
				{
					LcdConsole.WriteLine("Failed to send email");
					Console.WriteLine(e.StackTrace);
				}
			};
			terminateProgram.WaitOne();
			message = null;
		}
Пример #6
0
		public static void Main (string[] args)
		{
			ManualResetEvent terminateProgram = new ManualResetEvent (false);
			string fbToken = "CAACpSl1Qm3cBAHAMyZAY...";//This is not valied
			var fb = new FacebookClient(fbToken);
			Font f = Font.MediumFont;
			Point offset = new Point(0,25);
			Point p = new Point(10, Lcd.Height-75);
			Point boxSize = new Point(100, 24);
			Rectangle box = new Rectangle(p, p+boxSize);
			var colorSensor = new EV3ColorSensor (SensorPort.In1);
			ButtonEvents buts = new ButtonEvents ();
			LcdConsole.WriteLine("Use color on port1");
			LcdConsole.WriteLine("Enter post value");
			LcdConsole.WriteLine("Esc. terminate");
			buts.EscapePressed += () => { 
				terminateProgram.Set();
			};
			
			buts.EnterPressed += () => { 
				Color color = colorSensor.ReadColor();
				Lcd.Clear();
				Lcd.WriteTextBox(f, box + offset*0, "Color: " + color, true);
				Lcd.WriteTextBox(f, box + offset*1, "Send to Facebook" + color, true);
				Lcd.Update();
				colorSensor.ReadColor();
				var me = fb.Get("monobrick.dk") as JsonObject;
				var uid = me["id"];
		    	string url = string.Format("{0}/{1}", uid, "feed");
		    	var argList = new Dictionary<string, object>();
		    	argList["message"] = "A program running MonoBrick Firmware was aked to read the color sensor. Color read: " + colorSensor.ReadColor().ToString();
		    	fb.Post(url, argList);
			};
			terminateProgram.WaitOne (); 
		    		
		}
Пример #7
0
        public static ISensor GetSensor(SensorPort port)
        {
            ISensor sensor = null;

            SensorType     sensorType     = SensorManager.Instance.GetSensorType(port);
            ConnectionType connectionType = SensorManager.Instance.GetConnectionType(port);

            switch (sensorType)
            {
            case SensorType.Color:
                sensor = new EV3ColorSensor(port);
                break;

            case SensorType.Gyro:
                sensor = new EV3GyroSensor(port);
                break;

            case SensorType.IR:
                sensor = new EV3IRSensor(port);
                break;

            case SensorType.NXTColor:
                sensor = new NXTColorSensor(port);
                break;

            case SensorType.NXTLight:
                sensor = new NXTLightSensor(port);
                break;

            case SensorType.NXTSound:
                sensor = new NXTSoundSensor(port);
                break;

            case SensorType.NXTTouch:
                sensor = new NXTTouchSensor(port);
                break;

            case SensorType.NXTUltraSonic:
                sensor = new NXTUltraSonicSensor(port);
                break;

            case SensorType.Touch:
                sensor = new EV3TouchSensor(port);
                break;

            case SensorType.UltraSonic:
                sensor = new EV3UltrasonicSensor(port);
                break;

            case SensorType.NXTI2c:
                var helper = new I2CHelper(port);
                sensor = helper.GetSensor();
                break;

            case SensorType.Unknown:
                if (connectionType == ConnectionType.UART)
                {
                    var uartHelper = new UARTHelper(port);
                    sensor = uartHelper.GetSensor();
                }
                if (connectionType == ConnectionType.InputResistor)
                {
                    sensor = new EV3TouchSensor(port);
                }
                break;

            case SensorType.I2CUnknown:

                break;

            case SensorType.NXTTemperature:

                break;

            case SensorType.LMotor:

                break;

            case SensorType.MMotor:

                break;

            case SensorType.NXTTest:

                break;

            case SensorType.Terminal:

                break;

            case SensorType.Test:

                break;

            case SensorType.Error:

                break;

            case SensorType.None:

                break;
            }
            return(sensor);
        }
Пример #8
0
		public static ISensor GetSensor (SensorPort port)
		{
			ISensor sensor = null;
			
			SensorType sensorType = SensorManager.Instance.GetSensorType (port);
			ConnectionType connectionType = SensorManager.Instance.GetConnectionType (port);
			switch (sensorType) {
			case SensorType.Color:
				sensor = new EV3ColorSensor (port); 
				break;
			case SensorType.Gyro:
				sensor = new EV3GyroSensor (port); 
				break;
			case SensorType.IR:
				sensor = new EV3IRSensor (port);
				break;
			case SensorType.NXTColor:
				sensor = new NXTColorSensor (port);
				break;
			case SensorType.NXTLight:
				sensor = new NXTLightSensor (port);
				break;
			case SensorType.NXTSound:
				sensor = new NXTSoundSensor (port);
				break;
			case SensorType.NXTTouch:
				sensor = new NXTTouchSensor (port);
				break;
			case SensorType.NXTUltraSonic:
				sensor = new NXTUltraSonicSensor (port);
				break;
			case SensorType.Touch:
				sensor = new EV3TouchSensor (port);
				break;
			case SensorType.UltraSonic:
				sensor = new EV3UltrasonicSensor (port);
				break;
			case SensorType.NXTI2c:
				var helper = new I2CHelper (port);
				sensor = helper.GetSensor ();
				break;
			case SensorType.Unknown:
				if (connectionType == ConnectionType.UART) {
					var uartHelper = new UARTHelper (port);
					sensor = uartHelper.GetSensor ();
				}
				if (connectionType == ConnectionType.InputResistor) {
					sensor = new EV3TouchSensor (port);
				}
				break;
			case SensorType.I2CUnknown:
						
				break;
			case SensorType.NXTTemperature:
						
				break;
			case SensorType.LMotor:
						
				break;
			case SensorType.MMotor:
						
				break;
			case SensorType.NXTTest:
						
				break;
			case SensorType.Terminal:
						
				break;
			case SensorType.Test:
						
				break;
			case SensorType.Error:
					
				break;
			case SensorType.None:
				sensor = new NoSensor (port);
				break;
			}
			if (sensor == null) 
			{
				sensor = new UnknownSensor(port);
			}
			return sensor;
		}
Пример #9
0
 public static RGBColor[] CountFacelets(Motor a, EV3ColorSensor sensor)
 {
     RGBColor[] colors = new RGBColor[8];
     a.ResetTacho();
     for (int count = 0; count < 8;)
         if (count == a.GetTachoCount () / 45 % 8)
             colors [count++] = sensor.ReadRGB ();
     return colors;
 }
Пример #10
0
        /*
         * This method controls the movements of the robot to scan the facelets
         * of any single face of the cube.
         */
        public static void BuildFace(Face face, Motor motorA, Motor motorB, EV3ColorSensor sensor)
        {
            RGBColor[] colors = null;
            RGBColor color = null;
            Thread count = new Thread (() => colors = CountFacelets (motorA, sensor));

            MoveCube.Move (motorB, MoveCube.SensorMid, 15);
            color = sensor.ReadRGB ();
            MoveCube.Move (motorB, MoveCube.SensorSide, 15);

            count.Start ();
            while (!count.IsAlive);
            WaitHandle handle = motorA.SpeedProfile ((sbyte)100, 0, (uint) 360, 0, true);
            handle.WaitOne ();
            count.Join ();
            MoveCube.Move (motorB, MoveCube.SensorRest, 15);

            char colorvalue = ' ';
            for (int i = 0; i < 9; i++) {
                switch (i) {
                case 0:
                    colorvalue = getColorValue (color);
                    face.square[1,1] = colorvalue;
                    break;
                case 1:
                    color = colors[0];
                    colorvalue = getColorValue (color);
                    face.square[2,1] = colorvalue;
                    break;
                case 3:
                    color = colors[2];
                    colorvalue = getColorValue (color);
                    face.square[1,2] = colorvalue;
                    break;
                case 5:
                    color = colors[4];
                    colorvalue = getColorValue (color);
                    face.square[0,1] = colorvalue;
                    break;
                case 7:
                    color = colors[6];
                    colorvalue = getColorValue (color);
                    face.square[1,0] = colorvalue;
                    break;
                case 2:
                    color = colors[1];
                    colorvalue = getColorValue (color);
                    face.square[2,2] = colorvalue;
                    break;
                case 4:
                    color = colors[3];
                    colorvalue = getColorValue (color);
                    face.square[0,2] = colorvalue;
                    break;
                case 6:
                    color = colors[5];
                    colorvalue = getColorValue (color);
                    face.square[0,0] = colorvalue;
                    break;
                case 8:
                    color = colors[7];
                    colorvalue = getColorValue (color);
                    face.square[2,0] = colorvalue;
                    break;
                }
                Console.WriteLine ("Line: {0} Color: {1} RGB code: {2}", i, colorvalue, color);
            }
        }