Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="port">The <see cref="SPI.Port"/> that the gyro is connected to.</param>
        public ADXRS450_Gyro(SPI.Port port)
        {
            m_spi = new SPI(port);
            if (RobotBase.IsSimulation)
            {
                m_spi.InitAccumulator(SamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
                                      10, 16, true, true);
                m_spi.ResetAccumulator();
                return;
            }
            m_spi.SetClockRate(3000000);
            m_spi.SetMSBFirst();
            m_spi.SetSampleDataOnRising();
            m_spi.SetClockActiveHigh();
            m_spi.SetChipSelectActiveLow();

            // Validate the part ID
            if ((ReadRegister(PIDRegister) & 0xff00) != 0x5200)
            {
                m_spi.Dispose();
                m_spi = null;
                DriverStation.ReportError("could not find ADXRS450 gyro on SPI port " + port.ToString(), false);
                return;
            }


            m_spi.InitAccumulator(SamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
                                  10, 16, true, true);

            Calibrate();

            Report(ResourceType.kResourceType_ADXRS450, (byte)port);
            LiveWindow.LiveWindow.AddSensor("ADXRS450_Gyro", port.ToString(), this);
        }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="port">The <see cref="SPI.Port"/> that the gyro is connected to.</param>
        public ADXRS450_Gyro(SPI.Port port)
        {
            m_spi = new SPI(port);
            if (RobotBase.IsSimulation)
            {
                m_spi.InitAccumulator(SamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
                10, 16, true, true);
                m_spi.ResetAccumulator();
                return;
            }
            m_spi.SetClockRate(3000000);
            m_spi.SetMSBFirst();
            m_spi.SetSampleDataOnRising();
            m_spi.SetClockActiveHigh();
            m_spi.SetChipSelectActiveLow();

            // Validate the part ID 	
            if ((ReadRegister(PIDRegister) & 0xff00) != 0x5200)
            {

                m_spi.Dispose();
                m_spi = null;
                DriverStation.ReportError("could not find ADXRS450 gyro on SPI port " + port.ToString(), false);
                return;
            }


            m_spi.InitAccumulator(SamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
                10, 16, true, true);

            Calibrate();

            Report(ResourceType.kResourceType_ADXRS450, (byte)port);
            LiveWindow.LiveWindow.AddSensor("ADXRS450_Gyro", port.ToString(), this);
        }
Example #3
0
 /// <inheritdoc/>
 public override void Dispose()
 {
     m_spi.Dispose();
     base.Dispose();
 }
Example #4
0
 /// <inheritdoc/>
 public override void Dispose()
 {
     m_spi.FreeAccumulator();
     m_spi?.Dispose();
     base.Dispose();
 }