Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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);
            }
        }