コード例 #1
0
        /// <summary>
        /// Creates a new <see cref="ADXL362"/> with the specified <see cref="SPI.Port">Port</see>
        /// and <see cref="AccelerometerRange">Range</see>.
        /// </summary>
        /// <param name="port">The SPI Port the accelerometer is connected to.</param>
        /// <param name="range">The range that the accelerometer will measure.</param>
        public ADXL362(SPI.Port port, AccelerometerRange range)
        {
            m_spi = new SPI(port);
            m_spi.SetClockRate(3000000);
            m_spi.SetMSBFirst();
            m_spi.SetSampleDataOnRising();
            m_spi.SetClockActiveHigh();
            m_spi.SetChipSelectActiveLow();

            byte[] commands = new byte[]
            {
                RegRead,
                PartIdRegister,
                0,
            };

            m_spi.Transaction(commands, commands, 3);

            if (commands[2] != 0xF2)
            {
                DriverStation.ReportError("Could not find ADXL362", false);
                m_gsPerLSB = 0.0;
                return;
            }

            AccelerometerRange = range;

            commands[0] = RegWrite;
            commands[1] = PowerCtlRegister;
            commands[2] = PowerCtlRegister | PowerCtl_UltraLowNoise;
            m_spi.Write(commands, 3);

            Report(ResourceType.kResourceType_ADXL362, (byte)port);
            LiveWindow.LiveWindow.AddSensor("ADXL362", port.ToString(), this);
        }
コード例 #2
0
ファイル: ADXRS450_Gyro.cs プロジェクト: atrimper/WPILib
        /// <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);
        }
コード例 #3
0
ファイル: NavX.cs プロジェクト: Dylan-Watson/FRC-2017
 /// <summary>
 ///     Initializes the NavX singleton
 /// </summary>
 /// <param name="spiPortId">port that the NavX is plugged into</param>
 /// <param name="spiBitrate">sets the bitrate for NavX comms</param>
 /// <param name="updateRateHz">the update rate of the NavX - default 50Hz</param>
 internal static NavX InitializeNavX(SPI.Port spiPortId, int spiBitrate, byte updateRateHz = 50)
 {
     if (_lazy != null)
     {
         Report.Error(
             @"A NavX instance already been created, someone other than Config is trying to create an instance.");
     }
     _lazy = new Lazy <NavX>(() => new NavX(spiPortId, spiBitrate, updateRateHz));
     return(Instance);
 }
コード例 #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="port">The SPI port the accelerometer is attached to</param>
 /// <param name="range">The range (+ or -) that the accelerometer will measure.</param>
 public ADXL345_SPI(SPI.Port port, AccelerometerRange range)
 {
     m_spi = new SPI(port);
     m_spi.SetClockRate(500000);
     m_spi.SetSampleDataOnFalling();
     m_spi.SetClockActiveLow();
     m_spi.SetChipSelectActiveHigh();
     byte[] commands = new byte[2];
     commands[0] = PowerCtlRegister;
     commands[1] = (byte)PowerCtl.Measure;
     m_spi.Write(commands, 2);
     AccelerometerRange = range;
     HAL.Base.HAL.Report(ResourceType.kResourceType_ADXL345, Instances.kADXL345_SPI);
     LiveWindow.LiveWindow.AddSensor("ADXL345_SPI", (byte)port, this);
 }
コード例 #5
0
ファイル: NavX.cs プロジェクト: Dylan-Watson/FRC-2017
 private NavX(SPI.Port spiPortId, int spiBitrate, byte updateRateHz = 50)
     : base(spiPortId, spiBitrate, updateRateHz)
 {
 }
コード例 #6
0
ファイル: NavX.cs プロジェクト: Dylan-Watson/FRC-2017
 private NavX(SPI.Port spiPortId, byte updateRateHz = 50) : base(spiPortId, updateRateHz)
 {
 }