コード例 #1
0
 private void LegoBrick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     if (BrickChanged != null)
     {
         BrickChanged(this, e);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: velchev/LegoMindstormEv3
 static void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     foreach (var port in e.Ports)
     {
         Console.WriteLine(port.Key + "  " + port.Value);
     }
 }
コード例 #3
0
 private void  Brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     //throw new NotImplementedException();
     gyroTextBox.Text   = legobot.GyroSensor.SIValue.ToString();
     colourTextBox.Text = legobot.ColourSensor.SIValue.ToString();
     ultraTextBox.Text  = legobot.UltrasonicSensor.SIValue.ToString();
 }
コード例 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     textBoxReturns.Text  = "-----------------------------------------------------------------------" + Environment.NewLine + textBoxReturns.Text;
     textBoxReturns.Text += "Sensorwert 1 (One)  :  " + brick.Ports[InputPort.One].SIValue.ToString() + Environment.NewLine + textBoxReturns.Text;
     textBoxReturns.Text += "Sensorwert 2 (Two)  :  " + brick.Ports[InputPort.Two].SIValue.ToString() + Environment.NewLine + textBoxReturns.Text;
     textBoxReturns.Text += "Sensorwert 3 (Three):  " + brick.Ports[InputPort.Three].SIValue.ToString() + Environment.NewLine + textBoxReturns.Text;
     textBoxReturns.Text += "Sensorwert 4 (Four) :  " + brick.Ports[InputPort.Four].SIValue.ToString() + Environment.NewLine + textBoxReturns.Text;
 }
コード例 #5
0
 private void Brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     //throw new NotImplementedException();
     //Console.WriteLine(DateTime.Now);
     //Console.WriteLine(DateTime.Now + " + " +  DateTime.Now.Millisecond);
     sensorStored = brick.Ports[InputPort.Four].SIValue;
     notifyObservers((int)brick.Ports[InputPort.Four].SIValue, "realtime");
 }
コード例 #6
0
        private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            Debug.WriteLine("Brick changed!");

            this._distanceMeasured = (int)e.Ports[InputPort.Four].SIValue;
            txtDistance.Text       = this._distanceMeasured.ToString();

            Debug.WriteLine(this._distanceMeasured.ToString());
        }
コード例 #7
0
ファイル: Motion.cs プロジェクト: Rotvig/AI-Robotics-Project
        private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            if (Commands.Count <= 0)
            {
                return;
            }
            var com = Commands.Dequeue();

            com();
        }
コード例 #8
0
        //Event Fired when the brick changes
        private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            float portOneValue = e.Ports[InputPort.One].SIValue;

            Debug.WriteLine("Port One Results: " + portOneValue);

            //Update the Ui With the Ports Value
            UpdateUi("Proximity: " + portOneValue.ToString());

            CheckForCollision(portOneValue);
        }
コード例 #9
0
        public static void EventCalled(object sender, BrickChangedEventArgs e)
        {
            int[] colorArray = new int[10];
            for (int i = 0; i < 10; i++)
            {
                float color = e.Ports[InputPort.Four].SIValue;
                colorArray[0] = Convert.ToInt32(color);
            }

            Console.WriteLine(Convert.ToString(colorArray));
        }
コード例 #10
0
        void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            MotorA.Update(_brick);
            MotorB.Update(_brick);
            MotorC.Update(_brick);
            MotorD.Update(_brick);

            InputOne.Update(_brick);
            InputTwo.Update(_brick);
            InputThree.Update(_brick);
            InputFour.Update(_brick);
        }
コード例 #11
0
        public void ColorAverage(BrickChangedEventArgs e, Brick brick)
        {
            colorArray = new int[10];

            for (int i = 0; i < 10; i++)
            {
                float color = e.Ports[InputPort.Four].SIValue;
                colorArray[i++] = Convert.ToInt32(color);
            }

            Console.WriteLine(colorArray);
        }
コード例 #12
0
        private void brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            _portText.Clear();

            foreach (Port port in e.Ports.Values)
            {
                _portText.AppendFormat("{0}: {1}, {2}, {3}", port.Name, port.Type, port.Mode, port.SIValue);
                _portText.AppendLine();
            }

            _ports.Text = _portText.ToString();
        }
コード例 #13
0
        private void Brick_BrickChanged1(object sender, BrickChangedEventArgs e)
        {
            if (BrickManager.Bricks.All(x => x.Brick != sender))
            {
                return;
            }

            var brickControler = BrickManager.Bricks.First(x => x.Brick == sender);
            var data           = (ColorSensorColor)e.Ports[InputPort.One].RawValue;

            Console.WriteLine(data);
            UpdateColor(brickControler, data);
        }
コード例 #14
0
ファイル: Form1.cs プロジェクト: CodyStr/AtYourService
        private async void brickChanged(object o, BrickChangedEventArgs e)
        {
            txtDistance.Text  = e.Ports[InputPort.Four].SIValue.ToString();
            txtTouch.Text     = e.Ports[InputPort.One].SIValue.ToString();
            txtColor.Text     = ((ColorSensorColor)e.Ports[InputPort.Three].SIValue).ToString();
            this.currentcolor = (ColorSensorColor)e.Ports[InputPort.Three].SIValue;
            if (this.currentcolor == ColorSensorColor.Blue)
            {
                await brick.DirectCommand.TurnMotorAtPowerForTimeAsync(OutputPort.B, 100, 500, false);

                await brick.DirectCommand.TurnMotorAtPowerForTimeAsync(OutputPort.C, -25, 500, false);
            }
        }
コード例 #15
0
 private void Brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     if (e.Buttons.Down)
     {
         brick.DirectCommand.TurnMotorAtSpeedAsync(OutputPort.C, 10);
     }
     else if (e.Buttons.Up)
     {
         brick.DirectCommand.StopMotorAsync(OutputPort.C, true);
     }
     else if (e.Ports[InputPort.Two].SIValue == 1)
     {
         brick.DirectCommand.StopMotorAsync(OutputPort.A, false);
     }
 }
コード例 #16
0
        public void HomeBase(int[] homebase, BrickChangedEventArgs e, Brick brick)
        {
            DetectColor dc    = new DetectColor();
            Turn        turns = new Turn();
            DriveMotors dm    = new DriveMotors();

            // takes two numbers as a homebase
            // reads a color and checks if that value is in the array
            int[] arena = { 2, 5, 1, 4, };

            int color = dc.ColorDetection(e, brick);

            var index = Array.IndexOf(arena, color);

            int Left;

            switch (index)
            {
            case 0:
                Left = 3;
                break;

            default:
                Left = index - 1;
                break;
            }

            if (homebase.Contains(color))
            {
                if (homebase.Contains(arena[Left]))
                {
                    turns.Turn90Left(brick);
                    dm.Drive(brick);
                }
                else
                {
                    turns.Turn90Right(brick);
                }
                dm.Drive(brick);
            }

            else
            {
                turns.Turn180(brick);
            }
            dm.Drive(brick);
            //HomeBase(dhomebase, sender, e, brick);
        }
コード例 #17
0
        void brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            // hack to workaround XAML trying to typecast the Port dictionary to something unbindable...
            List <KeyValue> temp = new List <KeyValue>();

            foreach (KeyValuePair <InputPort, Port> p in e.Ports)
            {
                temp.Add(new KeyValue {
                    Key = p.Key, Value = p.Value
                });
            }

            InputPorts.DataContext = temp;
            Buttons.DataContext    = null;
            Buttons.DataContext    = e.Buttons;
        }
コード例 #18
0
 /// <summary>
 /// Fires when new data comes from the lego _brick
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void Brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     //Console.WriteLine("Brick changed!");
     //Console.WriteLine(GetSensorValue());
     if (_mainWindow.chckFollow.IsChecked.HasValue && _mainWindow.chckFollow.IsChecked.Value)
     {
         try
         {
             //_eegControllerMindWave.Attention
             await FollowBlackLine(GetSensorValue(), _eegControllerMindWave.Attention);
         }
         catch (Exception ex)
         {
             Console.WriteLine("Error while following line. Included message: {0}", ex.Message);
         }
     }
 }
コード例 #19
0
        private static void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            // add offset to the measurements
            if (process_type == PhysicalProcessType.SEGWAY || process_type == PhysicalProcessType.INVPENDULUM)
            {
                if (measurement_offset == 0 || measurement_offset > 360 || measurement_offset < -360)
                {
                    measurement_offset = e.Ports[InputPort.One].SIValue;
                }
            }

            EV3measurement = e.Ports[InputPort.One].SIValue - measurement_offset;

            Console.WriteLine("Measurement: " + EV3measurement);
            // local controller for debugging
            //updateLocalPID();
        }
コード例 #20
0
        async void _lego_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            try
            {
                //Only send if >= 2 centimeter change
                if (Math.Abs(_distance - (int)e.Ports[InputPort.Two].SIValue) >= 2)
                {
                    _distance = (int)e.Ports[InputPort.Two].SIValue;

                    //Send the new distance to the SignalRHub
                    await _hubProxy.Invoke("SendUpdatedSensorData", _distance);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("exception:" + ex);
            }
        }
コード例 #21
0
        private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            _distanceMeasured = (int)e.Ports[InputPort.Four].SIValue;
            //txtDistance.Text = _distanceMeasured.ToString();

            _brick.BatchCommand.Initialize(CommandType.DirectNoReply);
            _brick.BatchCommand.StopMotor(OutputPort.A, false);
            _brick.BatchCommand.StopMotor(OutputPort.D, false);
            _brick.BatchCommand.SendCommandAsync();

            if (_distanceMeasured <= 30)
            {
                _brick.DirectCommand.StopMotorAsync(OutputPort.All, true);
                //StopMoving();


                System.Console.WriteLine("StopMotor");
            }
        }
コード例 #22
0
        void OnBrickChanged(object sender, BrickChangedEventArgs e)
        {
            Debug.WriteLine("MainWindowcs:  change");
            try
            {
                LblSensor1.Content = e.Ports[InputPort.One].Type;
                LblValue1.Content  = e.Ports[InputPort.One].SIValue;

                LblSensor2.Content = e.Ports[InputPort.Two].Type;
                LblValue2.Content  = e.Ports[InputPort.Two].SIValue;

                LblSensor3.Content = e.Ports[InputPort.Three].Type;
                LblValue3.Content  = e.Ports[InputPort.Three].SIValue;

                LblSensor4.Content = e.Ports[InputPort.Four].Type;
                LblValue4.Content  = e.Ports[InputPort.Four].SIValue;
            }
            catch (System.Exception ex)
            {
                Lbl1.Content = "Brick Disconnected";
            }
        }
コード例 #23
0
        public void BrickChanged(object sender, BrickChangedEventArgs e)
        {
            DetectColor detectcolor = new DetectColor();
            DHomeBase   dhomebase   = new DHomeBase();
            DriveMotors drivemotors = new DriveMotors();
            Turn        turn        = new Turn();

            DistanceText.Text = e.Ports[InputPort.Two].SIValue.ToString();
            ColorText.Text    = e.Ports[InputPort.Four].SIValue.ToString();
            float distance = e.Ports[InputPort.Two].SIValue;
            float color    = e.Ports[InputPort.Four].SIValue;

            if (color == 1)
            {
                turn.Turn90Left(brick.brick);
            }
            else
            {
                turn.Turn90Right(brick.brick);
            }

            detectcolor.ColorDetection(e, brick.brick);

            if (distance > 10)
            {
                drivemotors.Stop(brick.brick);
                Thread.Sleep(1000);
                dhomebase.HomeBase(homebase, e, brick.brick);
            }
            if (distance <= 6)
            {
                drivemotors.Stop(brick.brick);
                Thread.Sleep(1000);
                dhomebase.HomeBase(homebase, e, brick.brick);
            }
        }
コード例 #24
0
        private async void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            label2.Text = "Gyroscope Value" + e.Ports[inputPort].SIValue;
            if (e.Ports[inputPort].SIValue < 0)
            {
                _brick.BatchCommand.TurnMotorAtPower(OutputPort.A, 100);
                _brick.BatchCommand.TurnMotorAtSpeed(OutputPort.B, 95);
                label3.Text = "Go Right";
                await _brick.BatchCommand.SendCommandAsync();
            }
            else if (e.Ports[inputPort].SIValue > 0)
            {
                _brick.BatchCommand.TurnMotorAtPower(OutputPort.A, 95);
                _brick.BatchCommand.TurnMotorAtPower(OutputPort.B, 100);
                label3.Text = "Go Left";
                await _brick.BatchCommand.SendCommandAsync();
            }
            else if (e.Ports[inputPort].SIValue == 0)
            {
                await _brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A | OutputPort.B, 100);

                label3.Text = "Go Straight";
            }
        }
コード例 #25
0
        private void buttonSensor4_Click(object sender, RoutedEventArgs e)
        {
            BrickChangedEventArgs aBrickChangedEventArgs = new BrickChangedEventArgs();

            textBoxReturns.Text = "Sensorwert 4 (Four):  " + brick.Ports[InputPort.Four].SIValue.ToString() + Environment.NewLine + textBoxReturns.Text;
        }
コード例 #26
0
 void _lego_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     txtDistance.Text = e.Ports[InputPort.Two].SIValue.ToString();
     txtTouch.Text    = e.Ports[InputPort.Four].SIValue.ToString();
 }
コード例 #27
0
 public async static void brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
 }
コード例 #28
0
 private void Brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     Console.WriteLine("brick changed");
     Distance = e.Ports[InputPort.Four].SIValue;
 }
コード例 #29
0
 private void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     Debug.WriteLine("Brick Changed!");
 }
コード例 #30
0
 static void _brick_BrickChanged(object sender, BrickChangedEventArgs e)
 {
     System.Console.WriteLine(e.Ports[InputPort.One].SIValue);
 }