This project has moved and is read-only. For the latest updates, please go here.

No Rate from Gyro

Sep 11, 2014 at 6:43 PM
Hi,

i try to check my Gyro. So i wrote a short Programm zu check all possible values from my Gyro. But i get allway the Angle.

My Programm
        void ausgabe(string s)
        {
            while (s.Length < 10)
            { 
                s += " "; 
            }
            richTextBox1.Text+=s;
        }
        void OnBrickChanged(object sender, BrickChangedEventArgs e)
        {
            string s="";

            brick.Ports[InputPort.Three].SetMode(GyroscopeMode.Angle);
            s = brick.Ports[InputPort.Three].RawValue.ToString();
            ausgabe(s);
            s = brick.Ports[InputPort.Three].SIValue.ToString();
            ausgabe(s);

            brick.Ports[InputPort.Three].SetMode(GyroscopeMode.Rate);
            s = brick.Ports[InputPort.Three].RawValue.ToString();
            ausgabe(s);
            s = brick.Ports[InputPort.Three].SIValue.ToString();
            ausgabe(s);

            brick.Ports[InputPort.Three].SetMode(GyroscopeMode.Fas);
            s = brick.Ports[InputPort.Three].RawValue.ToString();
            ausgabe(s);
            s = brick.Ports[InputPort.Three].SIValue.ToString();
            ausgabe(s);

            brick.Ports[InputPort.Three].SetMode(GyroscopeMode.GandA);
            s = brick.Ports[InputPort.Three].RawValue.ToString();
            ausgabe(s);
            s = brick.Ports[InputPort.Three].SIValue.ToString();
            ausgabe(s);

            richTextBox1.Text += (char)10;
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            brick = new Brick(new BluetoothCommunication("COM3"), true); // Bluetooth aktivieren
            brick.BrickChanged += OnBrickChanged; // Eventhandler 
            await brick.ConnectAsync();           // Verbindung zur Brick herstellen            
            await brick.DirectCommand.PlayToneAsync(50, 1000, 400); // Ein Piep 

            richTextBox1.Clear();
            richTextBox1.Text += "Angle Raw + SI     Rate Raw + SI   ........";
            richTextBox1.Text += (char)10;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            brick.Disconnect();
        }

........and what i get........

Angle Raw + SI Rate Raw + SI FAS Raw + SI GandA Raw + SI
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
3 3 3 3 3 3 3 3
6 6 6 6 6 6 6 6
10 10 10 10 10 10 10 10
13 13 13 13 13 13 13 13
15 15 15 15 15 15 15 15
16 16 16 16 16 16 16 16
18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 18
18 18 18 18 18 18 18 18
15 15 15 15 15 15 15 15
9 9 9 9 9 9 9 9
4 4 4 4 4 4 4 4
-2 -2 -2 -2 -2 -2 -2 -2
-14 -14 -14 -14 -14 -14 -14 -14
-26 -26 -26 -26 -26 -26 -26 -26
-26 -26 -26 -26 -26 -26 -26 -26

What i need is simply the angle and the rate of my gyro.

Thanks for your help!!
Sep 12, 2014 at 4:09 PM
I think calling SetMode from the OnBrickChanged callback may be the problem. Try this:
  1. Create 2 more buttons - one for setting the mode as angle and one for setting it as rate. Wire these up so that it SetMode is called appropriately.
  2. Remove the SetMode calls from OnBrickChanged and see if it works.
Sep 12, 2014 at 5:27 PM
You're calling SetMode, but you're never sending the command...SetMode just sets a property for later use. The last one that gets set in the property is the one that will be used to read the sensors in the polling loop.

Call the SetMode once, after you connect the brick, for the format you want. If you need multiple formats on every poll, you'll have to manually create your own polling loop and toggle back and forth. Look at the PollSensorsAsync() method in Brick.cs to see how that's done.
Sep 29, 2014 at 1:01 PM
Thanks for the Replys!!

I need the Angle and the Rate every 100ms, so i think i need my own polling-loop.
Is there a way to create a polling-loop without changes in the brick.cs ?

Thanks for your help!
Sep 29, 2014 at 3:08 PM
Call ConnectAsync with TimeSpan.Zero as the parameter. This will disable built-in polling. Then write your own polling loop similarly to how PollSensorsAsync does it.