Пример #1
0
        /// <summary>
        /// Creates a new Analog Potentiometer on the specified channel. [0..3] on RIO, [4..7] on MXP.
        /// </summary>
        /// <remarks>
        /// Use the fullRange and offset values so that the output produces meaningful
        /// values. I.E: you have a 270 degree potentiometer and you want the output to
        /// be degrees with the halfway point at 0 degrees. The fullRange value is 270.0(degrees)
        /// and the offset is -135.0 since the halfway point after scaling is 135 degrees.
        /// <para/>
        /// This will calculate the result from the fullRange times the fraction of the
        /// supply voltage, plus the offset.
        /// </remarks>
        /// <param name="channel">The channel this potentiometer is plugged into.</param>
        /// <param name="fullRange">The scaling to multiply the fraction by to get a
        /// meaningful unit.</param>
        /// <param name="offset">The offset to add to the scaled value for controlling the
        /// zero value.</param>
        public AnalogPotentiometer(int channel, double fullRange = 1, double offset = 0)
        {
            AnalogInput input = new AnalogInput(channel);

            m_initAnalogInput = true;
            InitPot(input, fullRange, offset);
        }
Пример #2
0
 /// <summary>
 /// Delete the analog components used for the accelerometer.
 /// </summary>
 public override void Dispose()
 {
     if (m_analogChannel != null && m_allocatedChannel)
     {
         m_analogChannel.Dispose();
     }
     m_analogChannel = null;
 }
 /// <summary>
 /// Creates a new instance of the Accelerometer from an existing <see cref="AnalogInput"/>
 /// </summary>
 /// <param name="channel">The existing <see cref="AnalogInput"/> the accelerometer is connected to.</param>
 public AnalogAccelerometer(AnalogInput channel)
 {
     m_allocatedChannel = false;
     if (channel == null)
         throw new NullReferenceException("Analog Channel given was null");
     m_analogChannel = channel;
     InitAccelerometer();
 }
Пример #4
0
 /// <summary>
 /// Creates a new instance of the Accelerometer from an existing <see cref="AnalogInput"/>
 /// </summary>
 /// <param name="channel">The existing <see cref="AnalogInput"/> the accelerometer is connected to.</param>
 public AnalogAccelerometer(AnalogInput channel)
 {
     m_allocatedChannel = false;
     if (channel == null)
         throw new ArgumentNullException(nameof(channel), "Analog Channel given was null");
     m_analogChannel = channel;
     InitAccelerometer();
 }
Пример #5
0
 /// <summary>
 /// Delete the analog components used for the accelerometer.
 /// </summary>
 public override void Dispose()
 {
     if (m_analogChannel != null && m_allocatedChannel)
     {
         m_analogChannel.Dispose();
     }
     m_analogChannel = null;
 }
Пример #6
0
 public Gyro(AnalogInput channel)
 {
     m_analog = channel;
     if (m_analog == null)
     {
         throw new NullReferenceException("AnalogInput supplied to Gyro constructor is null");
     }
     InitGyro();
 }
Пример #7
0
 /// <summary>
 /// Frees the potentiometer.
 /// </summary>
 public void Dispose()
 {
     if (m_initAnalogInput)
     {
         m_analogInput.Dispose();
         m_analogInput     = null;
         m_initAnalogInput = false;
     }
 }
Пример #8
0
        public AnalogTrigger(AnalogInput analogInput)
        {
            m_analogInput = analogInput ?? throw new ArgumentNullException(nameof(analogInput));
            m_port        = Hal.AnalogTriggerLowLevel.Initialize(analogInput.m_port);

            var index = Index;

            UsageReporting.Report(ResourceType.AnalogTrigger, index + 1);
            SendableRegistry.Instance.AddLW(this, "AnalogTrigger", index);
        }
Пример #9
0
 /// <summary>
 /// Creates a new instance of the Accelerometer from an existing <see cref="AnalogInput"/>
 /// </summary>
 /// <param name="channel">The existing <see cref="AnalogInput"/> the accelerometer is connected to.</param>
 public AnalogAccelerometer(AnalogInput channel)
 {
     m_allocatedChannel = false;
     if (channel == null)
     {
         throw new ArgumentNullException(nameof(channel), "Analog Channel given was null");
     }
     m_analogChannel = channel;
     InitAccelerometer();
 }
Пример #10
0
 /// <summary>
 /// Creates a new Analog Gyro with an existing <see cref="WPILib.AnalogInput"/>.
 /// </summary>
 /// <param name="channel">The analog input this gyro is attached to.</param>
 public AnalogGyro(AnalogInput channel)
 {
     if (channel == null)
     {
         throw new ArgumentNullException(nameof(channel), "Analog input must not be null");
     }
     AnalogInput = channel;
     InitGyro();
     Calibrate();
 }
Пример #11
0
 ///<inheritdoc/>
 public override void Dispose()
 {
     if (AnalogInput != null && m_channelAllocated)
     {
         AnalogInput.Dispose();
     }
     HAL_FreeAnalogGyro(m_gyroHandle);
     m_gyroHandle = HALInvalidHandle;
     AnalogInput  = null;
     base.Dispose();
 }
Пример #12
0
        public AnalogAccumulator(AnalogInput analogInput)
        {
            m_analogInput = analogInput ?? throw new ArgumentNullException(nameof(analogInput));
            if (!analogInput.IsAccumulatorChannel)
            {
                throw new ArgumentException("Analog Input must be an accumulator channel", nameof(analogInput));
            }
            m_port = analogInput.m_port;

            m_accumulatorOffset = 0;
            Hal.AnalogAccumulatorLowLevel.InitAccumulator(m_port);
        }
Пример #13
0
 /// <summary>
 /// Creates a new Analog Gyro on the specified channel.
 /// </summary>
 /// <param name="channel">The channel the gyro is on (Must be an accumulator channel). [0..1] on RIO.</param>
 public AnalogGyro(int channel)
 {
     AnalogInput aIn = new AnalogInput(channel);
     try
     {
         CreateGyro(aIn);
     }
     catch 
     {
         aIn.Dispose();
         throw;
     }
     m_channelAllocated = true;
 }
Пример #14
0
 /// <summary>
 /// Creates a new Analog Gyro on the specified channel.
 /// </summary>
 /// <param name="channel">The channel the gyro is on (Must be an accumulator channel). [0..1] on RIO.</param>
 public AnalogGyro(int channel)
 {
     AnalogInput = new AnalogInput(channel);
     try
     {
         InitGyro();
     }
     catch
     {
         AnalogInput.Dispose();
         throw;
     }
     Calibrate();
     m_channelAllocated = true;
 }
Пример #15
0
        /// <summary>
        /// Construct an analog trigger given an analog channel.
        /// </summary>
        /// <remarks>Should be used in case of sharing an analog channel
        /// between a trigger and an input.</remarks>
        /// <param name="channel">The <see cref="AnalogInput"/> to use for the analog trigger</param>
        public AnalogTrigger(AnalogInput channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel), "The Analog Input given was null");
            }
            m_analogInput = channel;

            int index  = 0;
            int status = 0;

            HALHandle = HAL_InitializeAnalogTrigger(m_analogInput.m_halHandle, ref index, ref status);
            CheckStatus(status);
            Index = index;

            Report(ResourceType.kResourceType_AnalogTrigger, m_analogInput.Channel);
        }
Пример #16
0
        public AnalogGyro(AnalogInput input, int center = 0, double offset = 0)
        {
            m_analogInput = input ?? throw new ArgumentNullException(nameof(input));

            m_gyroHandle = Hal.AnalogGyroLowLevel.Initialize(input.m_port);

            Hal.AnalogGyroLowLevel.Setup(m_gyroHandle);

            UsageReporting.Report(ResourceType.Gyro, m_analogInput.Channel + 1);
            SendableRegistry.Instance.AddLW(this, "AnalogGyro", m_analogInput.Channel);

            if (center != 0 || offset != 0)
            {
                Hal.AnalogGyroLowLevel.SetParameters(m_gyroHandle, DefaultVoltsPerDegreePerSecond, offset, center);
                Reset();
            }
            else
            {
                Calibrate();
            }
        }
Пример #17
0
 /// <summary>
 /// Creates a new Analog Gyro with an existing <see cref="WPILib.AnalogInput"/>.
 /// </summary>
 /// <param name="channel">The analog input this gyro is attached to.</param>
 public AnalogGyro(AnalogInput channel)
 {
     CreateGyro(channel);
 }
 private void InitPot(AnalogInput input, double fullRange, double offset)
 {
     m_fullRange = fullRange;
     m_offset = offset;
     m_analogInput = input;
 }
Пример #19
0
 /// <summary>
 /// Create a new instance of an accelerometer, declaring a new analog channel.
 /// </summary>
 /// <param name="channel">The channel the accelerometer is connected to. [0..3] on RIO, [4..7] on MXP</param>
 public AnalogAccelerometer(int channel)
 {
     m_allocatedChannel = true;
     m_analogChannel = new AnalogInput(channel);
     InitAccelerometer();
 }
Пример #20
0
        private void CreateGyro(AnalogInput channel)
        {
            AnalogInput = channel;
            if (AnalogInput == null)
            {
                throw new ArgumentNullException(nameof(channel), "AnalogInput supplied to Gyro constructor is null");
            }
            if (!AnalogInput.IsAccumulatorChannel)
            {
                throw new ArgumentOutOfRangeException(nameof(channel), "Channel must be an accumulator channel");
            }
            Sensitivity = kDefaultVoltsPerDegreePerSecond;
            AnalogInput.AverageBits = kAverageBits;
            AnalogInput.OversampleBits = kOversampleBits;
            double sampleRate = kSamplesPerSecond
                    * (1 << (kAverageBits + kOversampleBits));
            AnalogInput.GlobalSampleRate = sampleRate;
            Timer.Delay(0.1);

            Deadband = 0.0;

            PIDSourceType = PIDSourceType.Displacement;


            HAL.Base.HAL.Report(ResourceType.kResourceType_Gyro, (byte)AnalogInput.Channel);
            LiveWindow.LiveWindow.AddSensor("AnalogGyro", AnalogInput.Channel, this);

            Calibrate();
        }
 public SWave_Potentiometer(AnalogInput input, double fullRange, double offset)
     : base(input, fullRange, offset)
 {
 }
Пример #22
0
 public AnalogAccelerometer(AnalogInput analogInput)
 {
     m_analogInput = analogInput ?? throw new ArgumentNullException(nameof(analogInput));
     UsageReporting.Report(ResourceType.Accelerometer, analogInput.Channel + 1);
     SendableRegistry.Instance.AddLW(this, "Accelerometer", analogInput.Channel);
 }
 public SWave_Potentiometer(AnalogInput input)
     : base(input)
 {
 }
 /// <summary>
 /// Frees the potentiometer.
 /// </summary>
 public void Dispose()
 {
     if (m_initAnalogInput)
     {
         m_analogInput.Dispose();
         m_analogInput = null;
         m_initAnalogInput = false;
     }
 }
Пример #25
0
 /// <summary>
 /// Creates a new Analog Potentiometer with the precreated input.
 /// </summary>
 /// <remarks>
 /// Use the fullRange and offset values so that the output produces meaningful
 /// values. I.E: you have a 270 degree potentiometer and you want the output to
 /// be degrees with the halfway point at 0 degrees. The fullRange value is 270.0(degrees)
 /// and the offset is -135.0 since the halfway point after scaling is 135 degrees.
 /// <para/>
 /// This will calculate the result from the fullRange times the fraction of the
 /// supply voltage, plus the offset.
 /// </remarks>
 /// <param name="input">The <see cref="AnalogInput"/> this potentiometer is plugged into.</param>
 /// <param name="fullRange">The scaling to multiply the fraction by to get a
 /// meaningful unit.</param>
 /// <param name="offset">The offset to add to the scaled value for controlling the
 /// zero value.</param>
 public AnalogPotentiometer(AnalogInput input, double fullRange = 1, double offset = 0)
 {
     m_initAnalogInput = false;
     InitPot(input, fullRange, offset);
 }
Пример #26
0
 ///<inheritdoc/>
 public override void Dispose()
 {
     if (m_analog != null && m_channelAllocated)
     {
         m_analog.Dispose();
     }
     m_analog = null;
     //base.Dispose();
 }
Пример #27
0
 /// <summary>
 /// Create a new instance of an accelerometer, declaring a new analog channel.
 /// </summary>
 /// <param name="channel">The channel the accelerometer is connected to. [0..3] on RIO, [4..7] on MXP</param>
 public AnalogAccelerometer(int channel)
 {
     m_allocatedChannel = true;
     m_analogChannel    = new AnalogInput(channel);
     InitAccelerometer();
 }
Пример #28
0
 private void InitPot(AnalogInput input, double fullRange, double offset)
 {
     m_fullRange   = fullRange;
     m_offset      = offset;
     m_analogInput = input;
 }
Пример #29
0
 /// <summary>
 /// Construct an analog trigger given an analog channel.
 /// </summary>
 /// <remarks>Should be used in case of sharing an analog channel
 /// between a trigger and an input.</remarks>
 /// <param name="channel">The <see cref="AnalogInput"/> to use for the analog trigger</param>
 public AnalogTrigger(AnalogInput channel)
 {
     if (channel == null)
         throw new ArgumentNullException(nameof(channel), "The Analog Input given was null");
     InitTrigger(channel.Channel);
 }
 public AnalogPotentiometer(int channel, double fullRange, double offset)
 {
     AnalogInput input = new AnalogInput(channel);
     m_initAnalogInput = true;
     InitPot(input, fullRange, offset);
 }
 public SWave_Potentiometer(AnalogInput input, double scale)
     : base(input, scale)
 {
 }
 public AnalogPotentiometer(AnalogInput input, double fullRange, double offset)
 {
     m_initAnalogInput = false;
     InitPot(input, fullRange, offset);
 }
 public AnalogPotentiometer(AnalogInput input, double scale)
     : this(input, scale, 0)
 {
 }
 /// <summary>
 /// AnalogPotentiometer constructor
 /// </summary>
 /// <param name="input">The <see cref="AnalogInput"/> this potentiometer is plugged into.</param>
 public AnalogPotentiometer(AnalogInput input)
     : this(input, 1, 0)
 {
 }
Пример #35
0
 /// <summary>
 /// Construct an analog trigger given an analog channel.
 /// </summary>
 /// <remarks>Should be used in case of sharing an analog channel
 /// between a trigger and an input.</remarks>
 /// <param name="channel">The <see cref="AnalogInput"/> to use for the analog trigger</param>
 public AnalogTrigger(AnalogInput channel)
 {
     if (channel == null)
         throw new NullReferenceException("The Analog Input given was null");
     InitTrigger(channel.Channel);
 }
Пример #36
0
 public AnalogPotentiometer(AnalogInput analogInput, Angle fullRange, Angle offset = default)
 {
     m_analogInput = analogInput;
     m_fullRange   = fullRange;
     m_offset      = offset;
 }
Пример #37
0
 ///<inheritdoc/>
 public override void Dispose()
 {
     if (AnalogInput != null && m_channelAllocated)
     {
         AnalogInput.Dispose();
     }
     AnalogInput = null;
     base.Dispose();
 }