Exemplo n.º 1
0
        private void InitEncoder(bool reverseDirection)
        {
            switch (m_encodingType)
            {
                case EncodingType.K4X:
                    m_encodingScale = 4;
                    int status = 0;
                    m_encoder = InitializeEncoder(m_aSource.ModuleForRouting,
                        (uint)m_aSource.ChannelForRouting,
                        m_aSource.AnalogTriggerForRouting, m_bSource.ModuleForRouting,
                        (uint)m_bSource.ChannelForRouting,
                        m_bSource.AnalogTriggerForRouting, reverseDirection, ref m_index, ref status);
                    CheckStatus(status);
                    m_counter = null;
                    MaxPeriod = 0.5;
                    break;
                case EncodingType.K2X:
                    m_encodingScale = 2;
                    m_counter = new Counter(m_encodingType, m_aSource, m_bSource, reverseDirection);
                    m_index = m_counter.FPGAIndex;
                    break;
                case EncodingType.K1X:
                    m_encodingScale = 1;
                    m_counter = new Counter(m_encodingType, m_aSource, m_bSource, reverseDirection);
                    m_index = m_counter.FPGAIndex;
                    break;
            }
            DistancePerPulse = 1.0;

            m_pidSource = PIDSourceParameter.Distance;

            LiveWindow.AddSensor("Encoder", m_aSource.ChannelForRouting, this);
            Report(ResourceType.kResourceType_Encoder, (byte)m_index, (byte)m_encodingType);
        }
Exemplo n.º 2
0
        private void Initialize()
        {

            bool originalMode = s_automaticRoundRobinEnabled;
            SetAutomaticMode(false);
            lock (s_syncRoot)
            {
                s_currentSensors.Add(this);
            }
            m_counter = new Counter { MaxPeriod = 1.0 };
            m_counter.SetSemiPeriodMode(true);
            m_counter.Reset();
            Enabled = true;

            SetAutomaticMode(originalMode);
            ++s_instances;
            HAL.Base.HAL.Report(ResourceType.kResourceType_Ultrasonic, s_instances);
            LiveWindow.LiveWindow.AddSensor("Ultrasonic", m_echoChannel.Channel, this);

        }
Exemplo n.º 3
0
        public override void Dispose()
        {
            if (m_aSource != null && m_allocatedA)
            {
                m_aSource.Dispose();
                m_allocatedA = false;
            }
            if (m_bSource != null && m_allocatedB)
            {
                m_bSource.Dispose();
                m_allocatedB = false;
            }
            if (m_indexSource != null && m_allocatedI)
            {
                m_indexSource.Dispose();
                m_allocatedI = false;
            }

            m_aSource = null;
            m_bSource = null;
            m_indexSource = null;
            if (m_counter != null)
            {
                m_counter.Dispose();
                m_counter = null;
            }
            else
            {
                int status = 0;
                FreeEncoder(m_encoder, ref status);
                CheckStatus(status);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Assigns the <see cref="Counter"/> to this glitch filter
 /// </summary>
 /// <param name="counter">The <see cref="Counter"/> to add.</param>
 public void Add(Counter counter)
 {
     Add(counter.m_upSource);
     Add(counter.m_downSource);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Removes the <see cref="Counter"/> from this glitch filter
 /// </summary>
 /// <param name="counter">The <see cref="Counter"/> to remove.</param>
 public void Remove(Counter counter)
 {
     Remove(counter.m_upSource);
     Remove(counter.m_downSource);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Destructor for the ultrasonic sensor.
        /// </summary>
        /// <remarks>Delete the instance of the ultrasonic sensor by freeing the allocated digital channels. 
        /// If the system was in automatic mode (round robin), then it is stopped, then started again after 
        /// this sensor is removed (provided this wasn't the last sensor).
        /// </remarks>
        public override void Dispose()
        {
            base.Dispose();
            bool previousAutoMode = s_automaticRoundRobinEnabled;
            SetAutomaticMode(false);
            lock (s_syncRoot)
            {
                s_currentSensors.Remove(this);
            }
            if (m_allocatedChannels)
            {
                m_pingChannel?.Dispose();
                m_echoChannel?.Dispose();
            }
            m_counter?.Dispose();
            m_pingChannel = null;
            m_echoChannel = null;
            m_counter = null;
            lock (s_syncRoot)
            {
                if (!s_currentSensors.Any()) return;
            }
            SetAutomaticMode(previousAutoMode);

        }