Exemple #1
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);
        }
Exemple #2
0
 /// <summary>
 /// Create an instance of the <see cref="Ultrasonic"/> Sensor.
 /// </summary>
 /// <remarks>This is designed to superchannel the Deventech SRF04 and
 /// Vex ultrasonic sensors.</remarks>
 /// <param name="pingChannel">The digital output channel that sends the pulse
 /// to initiate the sensor sending the ping</param>
 /// <param name="echoChannel">The digital input channel the receives the echo.
 /// The lenght of time that the echo is high represents the round trip time of
 /// the ping, and the distance/</param>
 /// <param name="units">The units returns in either <see cref="Unit.Inches">Inches</see>
 /// or <see cref="Unit.Millimeters">Millimeters</see>. Default is inches.</param>
 public Ultrasonic(int pingChannel, int echoChannel, Unit units = Unit.Inches)
 {
     m_pingChannel       = new DigitalOutput(pingChannel);
     m_echoChannel       = new DigitalInput(echoChannel);
     m_allocatedChannels = true;
     DistanceUnits       = units;
     Initialize();
 }
Exemple #3
0
 /// <summary>
 /// Create an instance of the <see cref="Ultrasonic"/> Sensor.
 /// </summary>
 /// <remarks>This is designed to superchannel the Deventech SRF04 and
 /// Vex ultrasonic sensors.</remarks>
 /// <param name="pingChannel">The <see cref="DigitalOutput"/> channel that sends the pulse
 /// to initiate the sensor sending the ping</param>
 /// <param name="echoChannel">The <see cref="DigitalInput"/> channel the receives the echo.
 /// The lenght of time that the echo is high represents the round trip time of
 /// the ping, and the distance/</param>
 /// <param name="units">The units returns in either <see cref="Unit.Inches">Inches</see>
 /// or <see cref="Unit.Millimeters">Millimeters</see></param>
 public Ultrasonic(DigitalOutput pingChannel, DigitalInput echoChannel, Unit units = Unit.Inches)
 {
     if (pingChannel == null)
     {
         throw new ArgumentNullException(nameof(pingChannel));
     }
     if (echoChannel == null)
     {
         throw new ArgumentNullException(nameof(echoChannel));
     }
     m_pingChannel       = pingChannel;
     m_echoChannel       = echoChannel;
     m_allocatedChannels = false;
     DistanceUnits       = units;
     Initialize();
 }
Exemple #4
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);

        }
Exemple #5
0
 /// <summary>
 /// Create an instance of the <see cref="Ultrasonic"/> Sensor.
 /// </summary>
 /// <remarks>This is designed to superchannel the Deventech SRF04 and 
 /// Vex ultrasonic sensors.</remarks>
 /// <param name="pingChannel">The <see cref="DigitalOutput"/> channel that sends the pulse 
 /// to initiate the sensor sending the ping</param>
 /// <param name="echoChannel">The <see cref="DigitalInput"/> channel the receives the echo.
 /// The lenght of time that the echo is high represents the round trip time of 
 /// the ping, and the distance/</param>
 /// <param name="units">The units returns in either <see cref="Unit.Inches">Inches</see>
 /// or <see cref="Unit.Millimeters">Millimeters</see></param>
 public Ultrasonic(DigitalOutput pingChannel, DigitalInput echoChannel, Unit units = Unit.Inches)
 {
     if (pingChannel == null) throw new ArgumentNullException(nameof(pingChannel));
     if (echoChannel == null) throw new ArgumentNullException(nameof(echoChannel));
     m_pingChannel = pingChannel;
     m_echoChannel = echoChannel;
     m_allocatedChannels = false;
     DistanceUnits = units;
     Initialize();
 }
Exemple #6
0
 /// <summary>
 /// Create an instance of the <see cref="Ultrasonic"/> Sensor.
 /// </summary>
 /// <remarks>This is designed to superchannel the Deventech SRF04 and 
 /// Vex ultrasonic sensors.</remarks>
 /// <param name="pingChannel">The digital output channel that sends the pulse 
 /// to initiate the sensor sending the ping</param>
 /// <param name="echoChannel">The digital input channel the receives the echo.
 /// The lenght of time that the echo is high represents the round trip time of 
 /// the ping, and the distance/</param>
 /// <param name="units">The units returns in either <see cref="Unit.Inches">Inches</see>
 /// or <see cref="Unit.Millimeters">Millimeters</see>. Default is inches.</param>
 public Ultrasonic(int pingChannel, int echoChannel, Unit units = Unit.Inches)
 {
     m_pingChannel = new DigitalOutput(pingChannel);
     m_echoChannel = new DigitalInput(echoChannel);
     m_allocatedChannels = true;
     DistanceUnits = units;
     Initialize();
 }