Ejemplo n.º 1
0
        public SensorsControllerPlucky(IAbstractRobotHardware brick, double _mainLoopCycleMs)
        {
            hardwareBrick   = brick;
            mainLoopCycleMs = _mainLoopCycleMs;

            RPiCameraSensor = new RPiCamera("RPiCamera", 9097);
        }
        public SensorsControllerPlucky(IAbstractRobotHardware brick, double _mainLoopCycleMs)
        {
            hardwareBrick = brick;
            mainLoopCycleMs = _mainLoopCycleMs;

            RPiCameraSensor = new RPiCamera("RPiCamera", 9097);
        }
Ejemplo n.º 3
0
        public SensorsControllerShorty(IAbstractRobotHardware brick, double _mainLoopCycleMs, string pixyComPort, ISpeaker _speaker)
        {
            hardwareBrick   = brick;
            mainLoopCycleMs = _mainLoopCycleMs;
            speaker         = _speaker;

            if (!string.IsNullOrWhiteSpace(pixyComPort))
            {
                // See C:\Projects\Arduino\Sketchbook\PixyToSerial\PixyToSerial.ino
                PixyCameraSensor = new PixyCamera("PixyCamera", pixyComPort, 115200);
            }
        }
Ejemplo n.º 4
0
        /*
         *              // Set these properties based on your robot drivetrain/encoder config:
         *              encoder.Resolution = 44;       // 44 ticks per revolution
         *              encoder.WheelDiameter = 2.0;   // 2 inch wheel diameter
         *              encoder.WheelEncoderId = WheelEncoderId.Encoder1;
         *
         *              // Clear encoder value:
         *              encoder.Clear();
         *
         *              // If you're interested in absolute distance, then use this:
         *              encoder.DistanceChangedThreshold = 0.25;  // 0.25 inches
         *              encoder.DistanceChanged += new
         *              HardwareComponentEventHandler(encoder_DistanceChanged);
         *
         *              // If you're interested in ticks, then use this:
         *              encoder.CountChangedThreshold = 10;  // 10 ticks;
         *              encoder.CountChanged += new
         *              HardwareComponentEventHandler(encoder_CountChanged);
         */

        private IWheelEncoder CreateWheelEncoder(IAbstractRobotHardware brick, WheelEncoderId id, int frequency, int threshold)
        {
            IWheelEncoder encoder = brick.produceWheelEncoder(id, frequency, 1, threshold);

            // Frequency  milliseconds
            // Resolution must be set to avoid divide by zero in WheelEncoder.cs
            // CountChangedThreshold ticks

            encoder.CountChanged += new HardwareComponentEventHandler(encoder_CountChanged);

            return(encoder);
        }
Ejemplo n.º 5
0
        public RangerSensorSonar(string name, SensorPose pose, IAbstractRobotHardware brick, GpioPinId triggerPin, GpioPinId outputPin, int frequency, double threshold)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.04d; // shows 3cm all right
            this.MaxDistanceMeters = 2.5d;  // shows 2.55m at infinity

            this.srf04 = brick.produceSonarSRF04(triggerPin, outputPin, frequency, threshold);

            srf04.DistanceChanged += new HardwareComponentEventHandler(ir_DistanceChanged);
        }
        public RangerSensorParkingSonar(string name, SensorPose pose, IAbstractRobotHardware brick, int frequency)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.0d;  // shows 0cm all right
            this.MaxDistanceMeters = 2.5d;  // shows 2.55m at infinity

            this.parkingSonar = brick.produceParkingSonar(frequency);

            parkingSonar.DistanceChanged += new HardwareComponentEventHandler(psonar_DistanceChanged);        
        }
Ejemplo n.º 7
0
        public RangerSensorParkingSonar(string name, SensorPose pose, IAbstractRobotHardware brick, int frequency)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.0d;  // shows 0cm all right
            this.MaxDistanceMeters = 2.5d;  // shows 2.55m at infinity

            this.parkingSonar = brick.produceParkingSonar(frequency);

            parkingSonar.DistanceChanged += new HardwareComponentEventHandler(psonar_DistanceChanged);
        }
Ejemplo n.º 8
0
        public RangerSensorIR20_150(string name, SensorPose pose, IAbstractRobotHardware brick, AnalogPinId pinId, int frequency, double threshold)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.26d;     // shows 0.22 when too close
            this.MaxDistanceMeters = 1.52d;     // shows 1.60 at infinity

            this.gp2d12 = brick.produceSharpGP2D12(pinId, frequency, threshold);

            gp2d12.DistanceChanged += new HardwareComponentEventHandler(ir_DistanceChanged);
        }
Ejemplo n.º 9
0
        public RangerSensorIR10_80(string name, SensorPose pose, IAbstractRobotHardware brick, AnalogPinId pinId, int frequency, double threshold)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.11d;  // shows 10cm when 10 cm or closer 
            this.MaxDistanceMeters = 0.62d;  // shows 0.64 at infinity

            this.gp2d12 = brick.produceSharpGP2D12(pinId, frequency, threshold);

            gp2d12.DistanceChanged += new HardwareComponentEventHandler(ir_DistanceChanged);        
        }
Ejemplo n.º 10
0
        public RangerSensorSonar(string name, SensorPose pose, IAbstractRobotHardware brick, GpioPinId triggerPin, GpioPinId outputPin, int frequency, double threshold)
        {
            this.Name = name;
            this.Pose = pose;

            // reliably measured range:
            this.MinDistanceMeters = 0.04d; // shows 3cm all right
            this.MaxDistanceMeters = 2.5d;  // shows 2.55m at infinity

            this.srf04 = brick.produceSonarSRF04(triggerPin, outputPin, frequency, threshold);

            srf04.DistanceChanged += new HardwareComponentEventHandler(ir_DistanceChanged);        
        }
Ejemplo n.º 11
0
        private IAnalogSensor CreateBatteryVoltageMeter(IAbstractRobotHardware brick, int frequency, double thresholdVolts)
        {
            // analog pin 5 in Element board is internally tied to 1/3 of the supply voltage level. The 5.0d is 5V, microcontroller's ADC reference and 1024 is range.
            int threshold = (int)Math.Round((thresholdVolts * 1024.0d) / (3.0d * 5.0d));

            Debug.WriteLine("CreateBatteryVoltageMeter()   threshold=" + threshold);

            // analog pin 5 is internally tied to 1/3 of the supply voltage level
            IAnalogSensor bv = brick.produceAnalogSensor(AnalogPinId.A5, frequency, threshold);

            bv.AnalogValueChanged += new HardwareComponentEventHandler(batteryVoltage_ValueChanged);

            return(bv);
        }
Ejemplo n.º 12
0
        private IAnalogSensor CreateBatteryVoltageMeter(IAbstractRobotHardware brick, int frequency, double thresholdVolts)
        {
            // analog pin 5 in Element board is internally tied to 1/3 of the supply voltage level.
            // The 5.0d is 5V, microcontroller's ADC reference and 1024 is range.
            // on Plucky the battery voltage goes through 1/3 divider and comes to Arduino Pin 3, which is reported as Pin 5 to here.
            // see PluckyWheels.ino sketch
            int threshold = (int)Math.Round((thresholdVolts * 1024.0d) / (3.0d * 5.0d));

            Debug.WriteLine("CreateBatteryVoltageMeter()   threshold=" + threshold);

            // analog pin 5 is internally tied to 1/3 of the supply voltage level
            IAnalogSensor bv = brick.produceAnalogSensor(AnalogPinId.A5, frequency, threshold);

            bv.AnalogValueChanged += new HardwareComponentEventHandler(batteryVoltage_ValueChanged);

            return(bv);
        }
        /// <summary>
        /// produces hardwareBrick and sets it for communication
        /// </summary>
        /// <param name="args"></param>
        public override async Task Init(CancellationTokenSource cts, string[] args)
        {
            cancellationTokenSource = cts;

            string port = args[0];  // for Element board based robot we must pass serial port name here

            // create an instance of ConcreteRobotHardware:
            hardwareBrick = new ArduinoBrick(cts)
            {
                PortType = CommunicationPortType.Serial,
                PortName = port,
                BaudRate = 115200 // 19200
            };

            Debug.WriteLine("OK: RobotPluckyHardwareBridge: created Arduino hardware brick on port " + port);

            hardwareBrick.CommunicationsStarting += new CommunicationChannelEventHandler(bridge_CommunicationsStarting);
            hardwareBrick.CommunicationsStopping += new CommunicationChannelEventHandler(bridge_CommunicationsStopping);
            hardwareBrick.CommunicationStarted += new HardwareComponentEventHandler(bridge_CommunicationStarted);
        }
Ejemplo n.º 14
0
        public static IRangerSensor produceRangerSensor(RangerSensorFactoryProducts productType, string name, SensorPose pose, IAbstractRobotHardware brick, params Object[] args)
        {
            switch (productType)
            {
                case RangerSensorFactoryProducts.RangerSensorIR10_80:
                    return new RangerSensorIR10_80(name, pose, brick, (AnalogPinId)args[0], (int)args[1], (double)args[2]);

                case RangerSensorFactoryProducts.RangerSensorIR20_150:
                    return new RangerSensorIR20_150(name, pose, brick, (AnalogPinId)args[0], (int)args[1], (double)args[2]);

                case RangerSensorFactoryProducts.RangerSensorSonar:
                    return new RangerSensorSonar(name, pose, brick, (GpioPinId)args[0], (GpioPinId)args[1], (int)args[2], (double)args[3]);

                case RangerSensorFactoryProducts.RangerSensorParkingSonar:
                    return new RangerSensorParkingSonar(name, pose, brick, (int)args[0]);

                default:
                    throw new NotImplementedException("Error: RangerSensorFactory cannot produce ranger type " + productType);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// produces hardwareBrick and sets it for communication
        /// </summary>
        /// <param name="args"></param>
        public override async Task Init(CancellationTokenSource cts, string[] args)
        {
            cancellationTokenSource = cts;

            string port = args[0];  // for Element board based robot we must pass serial port name here

            // create an instance of ConcreteRobotHardware:
            hardwareBrick = new ArduinoBrick(cts)
            {
                PortType = CommunicationPortType.Serial,
                PortName = port,
                BaudRate = 115200 // 19200
            };

            Debug.WriteLine("OK: RobotPluckyHardwareBridge: created Arduino hardware brick on port " + port);

            hardwareBrick.CommunicationsStarting += new CommunicationChannelEventHandler(bridge_CommunicationsStarting);
            hardwareBrick.CommunicationsStopping += new CommunicationChannelEventHandler(bridge_CommunicationsStopping);
            hardwareBrick.CommunicationStarted   += new HardwareComponentEventHandler(bridge_CommunicationStarted);
        }
        /// <summary>
        /// produces hardwareBrick and sets it for communication
        /// </summary>
        /// <param name="args"></param>
        public override async Task Init(CancellationTokenSource cts, string[] args)
        {
            cancellationTokenSource = cts;

            string port = args[0];  // for Element board based robot we must pass serial port name here

            // create an instance of ConcreteRobotHardware:
            hardwareBrick = new Element()
            {
                PortType = CommunicationPortType.Serial,
                PortName = port,
                BaudRate = 19200, 
                AsyncCallbacksEnabled = false   // false requires explicit call to PumpEvents from the run loop
            };

            Debug.WriteLine("OK: RobotShortyHardwareBridge: created Element hardware brick on port " + port);

            hardwareBrick.CommunicationsStarting += new CommunicationChannelEventHandler(bridge_CommunicationsStarting);
            hardwareBrick.CommunicationsStopping += new CommunicationChannelEventHandler(bridge_CommunicationsStopping);
            hardwareBrick.CommunicationStarted += new HardwareComponentEventHandler(bridge_CommunicationStarted);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// produces hardwareBrick and sets it for communication
        /// </summary>
        /// <param name="args"></param>
        public override async Task Init(CancellationTokenSource cts, string[] args)
        {
            cancellationTokenSource = cts;

            string port = args[0];  // for Element board based robot we must pass serial port name here

            // create an instance of ConcreteRobotHardware:
            hardwareBrick = new Element()
            {
                PortType = CommunicationPortType.Serial,
                PortName = port,
                BaudRate = 19200,
                AsyncCallbacksEnabled = false   // false requires explicit call to PumpEvents from the run loop
            };

            Debug.WriteLine("OK: RobotShortyHardwareBridge: created Element hardware brick on port " + port);

            hardwareBrick.CommunicationsStarting += new CommunicationChannelEventHandler(bridge_CommunicationsStarting);
            hardwareBrick.CommunicationsStopping += new CommunicationChannelEventHandler(bridge_CommunicationsStopping);
            hardwareBrick.CommunicationStarted   += new HardwareComponentEventHandler(bridge_CommunicationStarted);
        }
Ejemplo n.º 18
0
        public SensorsControllerShorty(IAbstractRobotHardware brick, double _mainLoopCycleMs)
        {
            hardwareBrick = brick;
            mainLoopCycleMs = _mainLoopCycleMs;

            //PixyCameraSensor = new PixyCamera("PixyCamera", "COM8", 115200);
        }
Ejemplo n.º 19
0
        /*
			// Set these properties based on your robot drivetrain/encoder config:
			encoder.Resolution = 44;       // 44 ticks per revolution
			encoder.WheelDiameter = 2.0;   // 2 inch wheel diameter
			encoder.WheelEncoderId = WheelEncoderId.Encoder1;
      
			// Clear encoder value:
			encoder.Clear();
      
			// If you're interested in absolute distance, then use this:
			encoder.DistanceChangedThreshold = 0.25;  // 0.25 inches
			encoder.DistanceChanged += new 
			HardwareComponentEventHandler(encoder_DistanceChanged);
      
			// If you're interested in ticks, then use this:
			encoder.CountChangedThreshold = 10;  // 10 ticks;
			encoder.CountChanged += new 
			HardwareComponentEventHandler(encoder_CountChanged);
         */

        private IWheelEncoder CreateWheelEncoder(IAbstractRobotHardware brick, WheelEncoderId id, int frequency, int threshold)
        {
            IWheelEncoder encoder = brick.produceWheelEncoder(id, frequency, 1, threshold);
            // Frequency  milliseconds
            // Resolution must be set to avoid divide by zero in WheelEncoder.cs
            // CountChangedThreshold ticks

            encoder.CountChanged += new HardwareComponentEventHandler(encoder_CountChanged);

            return encoder;
        }
Ejemplo n.º 20
0
        private IAnalogSensor CreateBatteryVoltageMeter(IAbstractRobotHardware brick, int frequency, double thresholdVolts)
        {
            // analog pin 5 in Element board is internally tied to 1/3 of the supply voltage level. The 5.0d is 5V, microcontroller's ADC reference and 1024 is range.
            int threshold = (int)Math.Round((thresholdVolts * 1024.0d) / (3.0d * 5.0d));

            Debug.WriteLine("CreateBatteryVoltageMeter()   threshold=" + threshold);

            // analog pin 5 is internally tied to 1/3 of the supply voltage level
            IAnalogSensor bv = brick.produceAnalogSensor(AnalogPinId.A5, frequency, threshold);

            bv.AnalogValueChanged += new HardwareComponentEventHandler(batteryVoltage_ValueChanged);

            return bv;
        }
Ejemplo n.º 21
0
 public DifferentialDrive(IAbstractRobotHardware brick)
 {
     this.hardwareBrick = brick;
 }
Ejemplo n.º 22
0
        public static IRangerSensor produceRangerSensor(RangerSensorFactoryProducts productType, string name, SensorPose pose, IAbstractRobotHardware brick, params Object[] args)
        {
            switch (productType)
            {
            case RangerSensorFactoryProducts.RangerSensorIR10_80:
                return(new RangerSensorIR10_80(name, pose, brick, (AnalogPinId)args[0], (int)args[1], (double)args[2]));

            case RangerSensorFactoryProducts.RangerSensorIR20_150:
                return(new RangerSensorIR20_150(name, pose, brick, (AnalogPinId)args[0], (int)args[1], (double)args[2]));

            case RangerSensorFactoryProducts.RangerSensorSonar:
                return(new RangerSensorSonar(name, pose, brick, (GpioPinId)args[0], (GpioPinId)args[1], (int)args[2], (double)args[3]));

            case RangerSensorFactoryProducts.RangerSensorParkingSonar:
                return(new RangerSensorParkingSonar(name, pose, brick, (int)args[0]));

            default:
                throw new NotImplementedException("Error: RangerSensorFactory cannot produce ranger type " + productType);
            }
        }
Ejemplo n.º 23
0
 public DifferentialDrive(IAbstractRobotHardware brick)
 {
     this.hardwareBrick = brick;
 }
Ejemplo n.º 24
0
        private IAnalogSensor CreateBatteryVoltageMeter(IAbstractRobotHardware brick, int frequency, double thresholdVolts)
        {
            // analog pin 5 in Element board is internally tied to 1/3 of the supply voltage level.
            // The 5.0d is 5V, microcontroller's ADC reference and 1024 is range.
            // on Plucky the battery voltage goes through 1/3 divider and comes to Arduino Pin 3, which is reported as Pin 5 to here.
            // see PluckyWheels.ino sketch
            int threshold = (int)Math.Round((thresholdVolts * 1024.0d) / (3.0d * 5.0d));

            Debug.WriteLine("CreateBatteryVoltageMeter()   threshold=" + threshold);

            // analog pin 5 is internally tied to 1/3 of the supply voltage level
            IAnalogSensor bv = brick.produceAnalogSensor(AnalogPinId.A5, frequency, threshold);

            bv.AnalogValueChanged += new HardwareComponentEventHandler(batteryVoltage_ValueChanged);

            return bv;
        }