Example #1
0
        /// <summary>
        /// Samples 100 values while the robot is vertical
        /// </summary>
        public void Calibrate()
        {
            // Setup averaging filter for 100 samples
            var averagingFilter = new MovingAverageFilter(100);

            // Read in tilt 100 times to get offset from 0 when the
            // robot is being held at 0 degrees.
            for (int i = 0; i < 100; i++)
            {
                // Update state/sensors
                this.Robot.UpdateSensors();

                // Add to filter
                averagingFilter.AddValue(this.Robot.Angle);
            }

            // Set point for the PID is the tilt angle when the robot
            // is vertical.
            this.AnglePID.SetPoint = averagingFilter.Value;
        }
Example #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pin"></param>
 public InfraredDistanceSensor(Cpu.Pin pin, int averagingWindow = 10)
 {
     this.sensorInput     = new AnalogInput(pin);
     this.averagingFilter = new MovingAverageFilter(averagingWindow);
 }
Example #3
0
        /// <summary>
        /// Samples 100 values while the robot is vertical
        /// </summary>
        public void Calibrate()
        {
            // Setup averaging filter for 100 samples
            var averagingFilter = new MovingAverageFilter(100);

            // Read in tilt 100 times to get offset from 0 when the
            // robot is being held at 0 degrees.
            for (int i = 0; i < 100; i++)
            {
                // Update state/sensors
                this.Robot.UpdateSensors();

                // Add to filter
                averagingFilter.AddValue(this.Robot.Angle);
            }

            // Set point for the PID is the tilt angle when the robot
            // is vertical.
            this.AnglePID.SetPoint = averagingFilter.Value;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pin"></param>
 public InfraredDistanceSensor(Cpu.Pin pin, int averagingWindow = 10)
 {
     this.sensorInput = new AnalogInput(pin);
     this.averagingFilter = new MovingAverageFilter(averagingWindow);
 }