Exemple #1
0
        public override void Init()
        {
            this.proc = new Thread(new ThreadStart(Loop));

            this.dist  = new IRSensor(SensorPort.In1, IRMode.Proximity);
            this.color = new EV3ColorSensor(SensorPort.In2, ColorMode.Color);
        }
Exemple #2
0
        private void rock_Load(object sender, EventArgs e)
        {
            // create brick object and connect it to robot
            brick = new Brick <Sensor, Sensor, Sensor, Sensor>(Connect.Globalvariable.sComPort);
            //brick.Connection.Open();

            // Create touch sensor and connect it to port 2
            sensorTouch   = new TouchSensor();
            brick.Sensor2 = sensorTouch;

            // update form with brick details
            lblConnnection.Text = "Connected to EV3 Robot";

            // Create an IR sensor and connect it to port 4
            sensorDistance = new IRSensor();
            brick.Sensor4  = sensorDistance;

            // Create a colour sensor and connect it to port 3
            sensorColour  = new ColorSensor();
            brick.Sensor3 = sensorColour;

            // Set ports for synchronised motor vehicle
            brick.Vehicle.LeftPort  = MotorPort.OutB;
            brick.Vehicle.RightPort = MotorPort.OutC;
        }
Exemple #3
0
 public override void Init()
 {
     this.proc  = new Thread(new ThreadStart(Loop));
     this.move  = new Movement();
     this.touch = new TouchSensor(SensorPort.In4);
     this.dist  = new IRSensor(SensorPort.In1, IRMode.Proximity);
     this.rand  = new Random();
 }
Exemple #4
0
        public override void Init()
        {
            this.proc = new Thread(new ThreadStart(Loop));

            this.move = new Movement();
            this.dist = new IRSensor(SensorPort.In1, IRMode.Proximity);

            this.speak = new Speaker(100);
        }
Exemple #5
0
 private void UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, CheckBox chkFound, Color color)
 {
     chkFound.Checked = irSensor.Found;
     if (irSensor.Found)
     {
         lblNorm.Text = string.Concat(irSensor.Position.ToString(), ", ", irSensor.Size);
         lblRaw.Text  = irSensor.RawPosition.ToString();
         this.g.DrawEllipse(new Pen(color), irSensor.RawPosition.X / 4, irSensor.RawPosition.Y / 4, irSensor.Size + 1, irSensor.Size + 1);
     }
 }
Exemple #6
0
        public static void Main()
        {
            var irSensor = new IRSensor(Pins.GPIO_PIN_A0, 10, 80);

            while (true)
            {
                LcdWriter.Instance.Write(irSensor.PrettyDistance());
                Thread.Sleep(1000);
            }
        }
Exemple #7
0
 /// <summary>
 /// returns either the current irdistance or a default
 /// value that indicates, that the irsensor is currently
 /// covered by the grappler and can't see in the
 /// distance
 /// </summary>
 /// <returns></returns>
 public static int GetIRDistance()
 {
     if (GrapplerPosition == GrapplerPosition.Up)
     {
         return(IRSensor.ReadDistance());
     }
     else
     {
         return(Constants.IR_VALUES_NOT_INTERPRETABLE_VALUE);
     }
 }
        private void UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, int index, Color color)
        {
            clbIR.SetItemChecked(index, irSensor.Found);

            if (irSensor.Found)
            {
                lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
                lblRaw.Text  = irSensor.RawPosition.ToString();
                g.DrawEllipse(new Pen(color), (int)(irSensor.RawPosition.X / 4), (int)(irSensor.RawPosition.Y / 4),
                              irSensor.Size + 1, irSensor.Size + 1);
            }
        }
Exemple #9
0
        private void UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, CheckBox chkFound, Color color)
        {
            chkFound.Checked = irSensor.Found;

            if (irSensor.Found)
            {
                lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
                lblRaw.Text  = irSensor.RawPosition.ToString();
                g.DrawEllipse(new Pen(color), (int)(irSensor.RawPosition.X / 4), (int)(irSensor.RawPosition.Y / 4),
                              irSensor.Size + 1, irSensor.Size + 1);
            }
        }
Exemple #10
0
        private void UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, CheckBox chkFound, Color color, float penwidth)
        {
            chkFound.Checked = irSensor.Found;

            if (irSensor.Found)
            {
                lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
                lblRaw.Text  = irSensor.RawPosition.ToString();
                g.DrawEllipse(new Pen(color, penwidth), (int)(drawscale * irSensor.RawPosition.X), (int)(drawscale * irSensor.RawPosition.Y),
                              (int)((irSensor.Size + 1) / drawscale), (int)((irSensor.Size + 1) / drawscale));
            }
        }
        private void UpdateIR(IRSensor irSensor, TextBlock lblNorm, TextBlock lblRaw, CheckBox chkFound, Color color)
        {
            chkFound.IsChecked = irSensor.Found;

            if (irSensor.Found)
            {
                lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
                lblRaw.Text  = irSensor.RawPosition.ToString();
                b.DrawEllipse((int)(irSensor.RawPosition.X / 4), (int)(irSensor.RawPosition.Y / 4),
                              irSensor.Size + 1, irSensor.Size + 1, color);
            }
        }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ws.winx.devices.WiimoteDevice"/> class.
        /// </summary>
        /// <param name="index">Index.</param>
        /// <param name="pid">Pid.</param>
        /// <param name="vid">Vid.</param>
        /// <param name="ID">I.</param>
        /// <param name="axes">Axes.</param>
        /// <param name="buttons">Buttons.</param>
        /// <param name="leds">Leds.</param>
        /// <param name="irs">Irs.</param>
        /// <param name="driver">Driver.</param>
        public WiimoteDevice(int index, int pid, int vid, string ID, int axes, int buttons, int leds, int irs, IDriver driver)
            : base(index, pid, vid, ID, axes, buttons, driver)
        {
            _IR_SENSORS = new IRSensor[irs];
            _irPoint    = new Vector2();

            for (int i = 0; i < irs; i++)
            {
                IR_SENSORS[i] = new IRSensor();
            }



            _LED = new bool[leds];
        }
Exemple #13
0
        private void UpdateIR(Graphics g, IRSensor irSensor, Label lblRaw, Color color, float penwidth)
        {
            if (irSensor.Found)
            {
                //lblNorm.Text = irSensor.Position.ToString() + ", " + irSensor.Size;
                lblRaw.Text = irSensor.RawPosition.ToString();
                g.DrawEllipse(new Pen(color, penwidth), (int)(drawscale * irSensor.RawPosition.X), (int)(drawscale * (760 - irSensor.RawPosition.Y)),
                              (int)((irSensor.Size + 1) / drawscale), (int)((irSensor.Size + 1) / drawscale));

                if (irSensor.RawPosition.Y < 0)
                {
                    float temp = irSensor.Position.Y;
                }
            }
            else
            {
                lblRaw.Text = "No IR";
            }
        }
Exemple #14
0
 private void UpdateIR(IRSensor irSensor, Label lblNorm, Label lblRaw, CheckBox chkFound, Color color)
 {
     //chkFound.Checked = irSensor.Found;
 }
      /// <summary>
      /// Initializes a new instance of the <see cref="ws.winx.devices.WiimoteDevice"/> class.
      /// </summary>
      /// <param name="index">Index.</param>
      /// <param name="pid">Pid.</param>
      /// <param name="vid">Vid.</param>
      /// <param name="ID">I.</param>
      /// <param name="axes">Axes.</param>
      /// <param name="buttons">Buttons.</param>
      /// <param name="leds">Leds.</param>
      /// <param name="irs">Irs.</param>
      /// <param name="driver">Driver.</param>
        public WiimoteDevice(int index,int pid,int vid,string ID, int axes, int buttons,int leds,int irs,IDriver driver)
            : base(index,pid,vid,ID,axes,buttons,driver)
        {

            _IR_SENSORS = new IRSensor[irs];
            _irPoint = new Vector2();
                  
               for(int i=0;i<irs;i++)
                   IR_SENSORS[i]=new IRSensor();


              
            _LED = new bool[leds];

        }
Exemple #16
0
        void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
        {
            lock (lockObj)
            {
                WiimoteLib.ButtonState bs = args.WiimoteState.ButtonState;

                //extract the wiimote state
                IRSensor ws = args.WiimoteState.IRState.IRSensors[0];

                if (ws.Found) //move cursor
                {
                    PointF position  = new PointF(ws.RawPosition.X, ws.RawPosition.Y);
                    PointF warpedPos = position;
                    warper.warp(position, ref warpedPos);

                    SmoothingBuffer[SmoothingBufferIndex % SMOOTHING_BUFFER_SIZE] = warpedPos;
                    SmoothingBufferIndex++;

                    if (!lastWiiState.Found)      //mouse down
                    {
                        SmoothingBufferIndex = 0; //resets the count

                        if (CursorEnabled)
                        {
                            InputCont.MoveMouse(warpedPos); //move the mouse to x,y
                            InputCont.LeftMouseDown();      //left click down
                        }
                        else if (CalibrationState.State > 0)
                        {
                            ContinueCalibration(position);
                        }
                    }
                    else if (CursorEnabled) //dragging
                    {
                        //if (((x != lastWiiState.RawPosition.X) || (y != lastWiiState.RawPosition.Y)) && cursorControl)
                        if (SmoothingEnabled)
                        {
                            PointF s = GetSmoothedCursor(SmoothingAmount);
                            InputCont.MoveMouse(s); //move the mouse to x,y
                        }
                        else
                        {
                            InputCont.MoveMouse(warpedPos); //move the mouse to x,y
                        }
                    }
                }
                else if (lastWiiState.Found && CursorEnabled)
                {                                          //mouse up
                    InputCont.LeftMouseUp();
                    InputCont.MoveMouse(new PointF(0, 0)); //move the mouse to x,y
                }

                if (!lastButtonState.A && bs.A)
                {
                    Calibrate();
                }

                lastButtonState = bs;
                lastWiiState    = ws;

                if (StatusInfoChanged != null)
                {
                    StatusInfoChanged(this, new EventArgs <WiimoteState>(args.WiimoteState));
                }
            }
        }