public SharpDistanceTracker(Robot robo, int pin) { robot = robo; robot.sensors.Add(this); sharp = GetPort(pin); sharp.SetLinearScale(0, 255); }
/// <summary> /// Creates an instance of the distance sensor. /// </summary> /// <param name="analogPin">The pin connected to the analog output on the sensor (AN)</param> /// <param name="controlPin">The pin connected to the receive input on the sensor (RX)</param> /// <param name="supplyVoltage">The voltage supplied to the sensor in millivolts (usually 3300 or 5000)</param> public UltrasonicDistanceSensor(AnalogIn.Pin analogPin, Cpu.Pin controlPin, int supplyVoltage = 5000) { control = new OutputPort(controlPin, true); adc = new AnalogIn(analogPin); adc.SetLinearScale(0, supplyVoltage); // scale = (Vcc / 512) / 2.54 (cm per in) => mv/cm scale = supplyVoltage / 512D / 2.54; }
private double value; /**< value of this sensor */ #endregion Fields #region Constructors /** * The constructor of AnalogSensor. * It initiates the value scale, and add itself to the global list of sensors. * * @param PinNumber the number of pin where this sensor is attached. * @param robot the robot to which this sensor belongs. */ public AnalogSensor(int PinNumber, Robot robot) : base(robot) { this.Analog = GetAnalogPort(PinNumber); this.Analog.SetLinearScale(0, 1023); this.value = 0.0d; this.addToGlobalList(); }
/// <summary> /// Lettura del valore con risultato letto di CO2 in output. /// </summary> /// <param name="pinAnalog">Pin analogico usato per l'input</param> /// <returns>CO2 attuale</returns> public double LeggiValore(AnalogIn.Pin pinAnalog) { if (tensioneCO2 == null) tensioneCO2 = new AnalogIn(PinCO2); TensioneLetta = tensioneCO2.Read(); _valoreCO2 = (TensioneLetta + 3.05) / 0.00025; //0.25 return _valoreCO2; }
public ReflectiveSensor(FEZ_Pin.AnalogIn pin, int reflection_detection_trigger_percentage) { adc = new AnalogIn((AnalogIn.Pin)pin); adc.SetLinearScale(0, 100); if (reflection_detection_trigger_percentage < 100 && reflection_detection_trigger_percentage >= 0) trigger_level = reflection_detection_trigger_percentage; else throw new Exception("You must enter a percentage value betweeon 0 and 100"); }
//---Methodes //constructeur public CCapteurIR(AnalogIn.Pin port) { m_capteur = new AnalogIn(port); m_valAnt = 0; xa = 0; xb = 0; ya = 0; yb = 0; }
// gets the distance from a MaxSonar ultrasonic sensor and returns the value // in feet. public static double getDistance(AnalogIn sensor) { uint distance = 0; for (int i = 0; i < 200; i++) distance += (uint)sensor.Read(); distance /= 200; double distInches = distance * (3300.0 / 512); Debug.Print("distance: " + (distInches / 144).ToString("F4") + ""); return distInches / 144.0; }
public ReflectanceSensor(int PinNumber, int Input_Type) { input_T = (InputType)Input_Type; if ((InputType)Input_Type == InputType.analog) { this.ReflectSensor = GetAnalogPort(PinNumber); ReflectSensor.SetLinearScale(0, 1023); } else { this.DReflectSensor = GetDigitalPort(PinNumber); } }
public static void Main() { int noBall = 350; int ball = 160; int threshold = (noBall + ball) / 2; AnalogIn photodiode = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An0); while (true) { int d = photodiode.Read(); Debug.Print(d + ": "+ (d > threshold ? "No ball" : "Ball")); Thread.Sleep(50); } }
private double voltScale; //V(in) / V(out) #endregion Fields #region Constructors public VoltageCurrentSensor(float maxVoltage, float minVoltage, ushort mAh) { this.mAh = mAh; this.maxVoltage = maxVoltage; this.minVoltage = minVoltage; current = new AnalogIn((AnalogIn.Pin)PortMap.current); voltage = new AnalogIn((AnalogIn.Pin)PortMap.voltage); voltScale = 1 / 63.69e-3; ampScale = 1 / 36.60e-3; voltage.SetLinearScale(0, 3300); current.SetLinearScale(0, 3300); }
/* Constructor * Takes a robot as argument so that the code * knows which robot to control (the main method could * theoretically control multiple robots), and so that * the robot is accesable */ public StudentCode(Robot robot) { Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO4, true, Port.ResistorMode.PullUp); lLightSens = new AnalogIn((AnalogIn.Pin) FEZ_Pin.AnalogIn.An1); rLightSens = new AnalogIn((AnalogIn.Pin) FEZ_Pin.AnalogIn.An0); // lLightSens.SetLinearScale(0, 10000); // rLightSens.SetLinearScale(0, 10000); this.robot = robot; leftMotor = new SimpleMotorController(robot, "COM1", 13); rightMotor = new SimpleMotorController(robot, "COM1", 14); //Check rightMotor.motorBrake = 0; leftMotor.motorBrake = 0; // sdt = new SharpDistanceTracker(robot, 0); }
public static void Main() { Debug.Print(Resources.GetString(Resources.StringResources.String1)); Debug.Print(Resources.GetString(Resources.StringResources.String1)); Cpu.GlitchFilterTime = TimeSpan.FromTicks(10000 * 50); //serialPort = USBClientController.StandardDevices.StartCDC_WithDebugging(); //Write("Started CDC"); state = USBClientController.GetState(); if (state == USBClientController.State.Running) { // We're currently debugging. keyboardDevice = null; } else { keyboardDevice = USBClientController.StandardDevices.StartKeyboard(); } var leftAnalogEngine = new AnalogIn((AnalogIn.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.AnalogIn.An5); var leftEngine = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di11, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); leftEngine.OnInterrupt += collector_OnInterrupt; var rightEngine = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di12, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); rightEngine.OnInterrupt += collector_OnInterrupt; var stopButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di37, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); stopButton.OnInterrupt += stopButton_OnInterrupt; var singlePlayerButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di36, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); singlePlayerButton.OnInterrupt += stopButton_OnInterrupt; led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false); led.Write(false); while (true) { // We can do other work here, like updating // an LCD display or something. Thread.Sleep(5000); //Debug.Print(leftAnalogEngine.Read().ToString()); } }
public static string Start() { AccGlobal = ""; var accX = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An3); var accY = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An4); var accZ = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An5); Accelerometer_(accX, "X"); Accelerometer_(accY, "Y"); Accelerometer_(accZ, "Z"); accX.Dispose(); accY.Dispose(); accZ.Dispose(); string ReturnValue = AccGlobal; return(ReturnValue); }
public Accelerometer(int x_pin, int y_pin, int z_pin) { if (x_pin != -1) { x_in = GetPort(x_pin); x_in.SetLinearScale(0, 255); } if (y_pin != -1) { y_in = GetPort(y_pin); y_in.SetLinearScale(0, 255); } if (z_pin != -1) { z_in = GetPort(z_pin); z_in.SetLinearScale(0, 255); } }
public static void Main() { Debug.Print(Resources.GetString(Resources.StringResources.String1)); Cpu.GlitchFilterTime = TimeSpan.FromTicks(10000 * 50); //serialPort = USBClientController.StandardDevices.StartCDC_WithDebugging(); //Write("Started CDC"); keyboardDevice = USBClientController.StandardDevices.StartKeyboard(); var leftAnalogEngine = new AnalogIn((AnalogIn.Pin)GHIElectronics.NETMF.FEZ.FEZ_Pin.AnalogIn.An5); var leftEngine = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di11, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); leftEngine.OnInterrupt += collector_OnInterrupt; var rightEngine = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di12, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth); rightEngine.OnInterrupt += collector_OnInterrupt; var stopButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di37, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); stopButton.OnInterrupt += stopButton_OnInterrupt; var singlePlayerButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di36, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow); singlePlayerButton.OnInterrupt += stopButton_OnInterrupt; led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false); led.Write(false); while (true) { // We can do other work here, like updating // an LCD display or something. Thread.Sleep(5000); //Debug.Print(leftAnalogEngine.Read().ToString()); } }
public DistanceDetector(FEZ_Pin.AnalogIn pin, SharpSensorType type) { adc = new AnalogIn((AnalogIn.Pin)pin); adc.SetLinearScale(0, 330); switch (type) { case SharpSensorType.GP2Y0A21YK: Y0 = 10; X0 = 315; Y1 = 80; X1 = 30; break; case SharpSensorType.GP2D120: Y0 = 3; X0 = 315; Y1 = 30; X1 = 30; break; } C = (Y1 - Y0) / (1 / X1 - 1 / X0); }
public SharpDistanceTracker(int pin, int sensor_type) { sharp = GetPort(pin); sharp.SetLinearScale(0, 255); SensorType = (int)sensor_type; // default calibration // students may need to provide their own calibration data to get acceptable values if ((SensorT)sensor_type == SensorT.Long_Distance) { y1 = 30; y2 = 180; x1 = .007; x2 = .05; } if ((SensorT)sensor_type == SensorT.Short_Distance) { y1 = 20; y2 = 180; x1 = .032; x2 = .226; } }
internal Pin7(TreehopperBoard device) : base(device, 7) { ioName = "RC2"; AnalogIn = new AnalogIn(this); }
internal Pin10(TreehopperUSB device) : base(device, 10) { ioName = "RB4"; AnalogIn = new AnalogIn(this); }
public AnalogReflectanceSensor(int PinNumber) { this.ReflectSensor = GetAnalogPort(PinNumber); ReflectSensor.SetLinearScale(0, 1023); }
internal Pin7(TreehopperUSB device) : base(device, 7) { ioName = "RC2"; AnalogIn = new AnalogIn(this); }
public Selector(Selectors id, AnalogIn.Pin analogPin) : base() { inputPin = analogPin; selectorId = id; selectorPort = new AnalogIn(inputPin); selectorPort.SetLinearScale(0, 3300); currentPosition = 0; }
static void AnalogIn_Changed(AnalogIn sender, double voltage) { Console.WriteLine("Pin 7 voltage: " + voltage); }
internal Pin13(TreehopperBoard device) : base(device, 13) { ioName = "RC0"; AnalogIn = new AnalogIn(this); }
public void Run() { const byte channel = 10; // all addresses need to have the same length var fezDominoAddress = Encoding.UTF8.GetBytes("DOMIN"); var fezMiniAddress = Encoding.UTF8.GetBytes("MINI."); var fezCobraAddress = Encoding.UTF8.GetBytes("COBRA"); // here we determine on which device the code is running on switch (SystemInfo.OEMString) { case "GHI Electronics, LLC": switch ((Fez)SystemInfo.SystemID.Model) { case Fez.Mini: _myAddress = fezMiniAddress; _otherBoards = new byte[2][]; _otherBoards[0] = fezDominoAddress; _otherBoards[1] = fezCobraAddress; break; case Fez.Domino: _myAddress = fezDominoAddress; _otherBoards = new byte[2][]; _otherBoards[0] = fezCobraAddress; _otherBoards[1] = fezMiniAddress; _variableResistor = new AnalogIn(AnalogIn.Pin.Ain0); _variableResistor.SetLinearScale(0, 3300); break; case Fez.Cobra: _myAddress = fezCobraAddress; _otherBoards = new byte[2][]; _otherBoards[0] = fezMiniAddress; _otherBoards[1] = fezDominoAddress; break; } break; } // here we attatch event listener _module.OnDataReceived += OnReceive; _module.OnTransmitFailed += OnSendFailure; _module.OnTransmitSuccess += OnSendSuccess; // we nned to call Initialize() and Configure() befeore we start using the module _module.Initialize(_spi, _chipSelectPin, _chipEnablePin, _interruptPin); _module.Configure(_myAddress, channel); // to start receiveing we need to call Enable(), call Disable() to stop/pause _module.Enable(); // example of reading your own address var myAddress = _module.GetAddress(AddressSlot.Zero, 5); Debug.Print("I am " + new string(Encoding.UTF8.GetChars(myAddress))); _lastActivity = DateTime.MinValue; // Fez Domino board is the one that starts the token passing and monitors if a token was lost // The timer checks each 10 sec if any token has been received since last check // If not than it might mean that a token was lost or never send - a new is created // A token may be lost if a board is reseted before sending token back if ((Fez)SystemInfo.SystemID.Model == Fez.Domino) { _timer = new Timer(CreateToken, null, new TimeSpan(0, 0, 0, 10), new TimeSpan(0, 0, 0, 10)); } }
//public static List<ErrorData> ErrorList { get; } = new List<ErrorData>(); /* * /// <summary> * /// Gets the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static CanTalonData GetCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * //CAN Talon does not exist yet. Return null. * return null; * } * } * * /// <summary> * /// Initializes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializeCanTalon(int id) * { * CanTalonData data; * bool retVal = s_canTalon.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new Can Talon data and return true. * data = new CanTalonData(); * s_canTalon.Add(id, data); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(true)); * return true; * } * } * * /// <summary> * /// Removes the can talon. * /// </summary> * /// <param name="id">The identifier.</param> * public static void RemoveCanTalon(int id) * { * s_canTalon.Remove(id); * OnTalonSRXAddedOrRemoved?.Invoke(id, new TalonSRXEventArgs(false)); * } * * /// <summary> * /// Gets the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PCMData GetPCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes the PCM. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static bool InitializePCM(int id) * { * PCMData data; * bool retVal = s_pcm.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PCMData(); * s_pcm.Add(id, data); * OnPCMAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Gets the PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns></returns> * public static PDPData GetPDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. Just return it * return data; * } * else * { * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return data; * } * } * * /// <summary> * /// Initializes a new PDP. * /// </summary> * /// <param name="id">The identifier.</param> * /// <returns>True if new PDP was created, otherwise false</returns> * public static bool InitializePDP(int id) * { * PDPData data; * bool retVal = s_pdp.TryGetValue(id, out data); * if (retVal) * { * //Contains key. return false saying we did not initialize a new one. * return false; * } * else * { * //Create a new PCM data and return true. * data = new PDPData(); * s_pdp.Add(id, data); * OnPDPAdded?.Invoke(data, null); * return true; * } * } * * /// <summary> * /// Occurs on talon SRX added or removed. * /// </summary> * public static event EventHandler<TalonSRXEventArgs> OnTalonSRXAddedOrRemoved; * /// <summary> * /// Occurs when a PCM is added. * /// </summary> * public static event EventHandler OnPCMAdded; * /// <summary> * /// Occurs when a PDP is added. * /// </summary> * public static event EventHandler OnPDPAdded; * */ static SimData() { for (int i = 0; i < HAL_GetNumPCMModules(); i++) { PCM.Add(new HALSimPCMData(i)); } for (int i = 0; i < HAL_GetNumPDPModules(); i++) { PDP.Add(new HALSimPDPData(i)); } for (int i = 0; i < HAL_GetNumAccumulators(); i++) { AnalogGyro.Add(new HALSimAnalogGyroData(i)); } for (int i = 0; i < HAL_GetNumAnalogOutputs(); i++) { AnalogOut.Add(new HALSimAnalogOutData(i)); } for (int i = 0; i < HAL_GetNumAnalogInputs(); i++) { AnalogIn.Add(new HALSimAnalogInData(i)); } for (int i = 0; i < HAL_GetNumAnalogTriggers(); i++) { AnalogTrigger.Add(new HALSimAnalogTriggerData(i)); } for (int i = 0; i < HAL_GetNumDigitalChannels(); i++) { DIO.Add(new HALSimDIOData(i)); } for (int i = 0; i < HAL_GetNumDigitalPWMOutputs(); i++) { DigitalPWM.Add(new HALSimDigitalPWMData(i)); } for (int i = 0; i < 4; i++) { //DigitalGlitchFilter.Add(new DigitalGlitchFilterData()); } for (int i = 0; i < HAL_GetNumPWMChannels(); i++) { PWM.Add(new HALSimPWMData(i)); } for (int i = 0; i < 4; i++) { Relay.Add(new HALSimRelayData(i)); } for (int i = 0; i < 8; i++) { //Counter.Add(new CounterData()); } for (int i = 0; i < 8; i++) { Encoder.Add(new HALSimEncoderData(i)); } for (int i = 0; i < 5; i++) { SPIAccelerometer.Add(new HALSimSPIAccelerometerData(i)); } for (int i = 0; i < 5; i++) { //SPIAccumulator.Add(new SPIAccumulatorData()); } //InitializePDP(0); //ErrorList.Clear(); }
public PitotTubeSpeedSensor(AnalogIn AnalogInPort) { aiPort = AnalogInPort; aiPort.SetLinearScale(0, 3300); //mV }
internal Pin4(TreehopperUSB device) : base(device, 4) { ioName = "RC3"; AnalogIn = new AnalogIn(this); }
internal Pin13(TreehopperUSB device) : base(device, 13) { ioName = "RC0"; AnalogIn = new AnalogIn(this); }
internal Pin12(TreehopperUSB device) : base(device, 12) { ioName = "RC1"; AnalogIn = new AnalogIn(this); }
internal Pin9(TreehopperBoard device) : base(device, 9) { ioName = "RB5"; AnalogIn = new AnalogIn(this); }
internal Pin10(TreehopperBoard device) : base(device, 10) { ioName = "RB4"; AnalogIn = new AnalogIn(this); }
public AnalogSonar(int pin) { SonarSensor = GetAnalogPort(pin); SonarSensor.SetLinearScale(0, 1023); SonarSensor.Read(); }
internal Pin4(TreehopperBoard device) : base(device, 4) { ioName = "RC3"; AnalogIn = new AnalogIn(this); }
public AnalogSensor(int PinNumber) { this.Analog = GetAnalogPort(PinNumber); Analog.SetLinearScale(0, 1023); }
public SharpDistanceTracker(int pin) { sharp = GetPort(pin); sharp.SetLinearScale(0, 255); }
public AnalogPotentiometer(int PinNumber) { this.Potentiometer = GetAnalogPort(PinNumber); Potentiometer.SetLinearScale(0, 1023); }
public SensoreUmidità(AnalogIn.Pin pinA) { sensore = new AnalogIn(pinA); }
internal Pin6(TreehopperUSB device) : base(device, 6) { ioName = "RC7"; AnalogIn = new AnalogIn(this); }
public static void Initialize() { LCD_RS = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di8, false); LCD_E = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di9, false); LCD_D4 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false); LCD_D5 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di5, false); LCD_D6 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di6, false); LCD_D7 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, false); AnKey = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An0); BackLight = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di10, true); LCD_RS.Write(false); // 4 bit data communication Thread.Sleep(50); LCD_D7.Write(false); LCD_D6.Write(false); LCD_D5.Write(true); LCD_D4.Write(true); LCD_E.Write(true); LCD_E.Write(false); Thread.Sleep(50); LCD_D7.Write(false); LCD_D6.Write(false); LCD_D5.Write(true); LCD_D4.Write(true); LCD_E.Write(true); LCD_E.Write(false); Thread.Sleep(50); LCD_D7.Write(false); LCD_D6.Write(false); LCD_D5.Write(true); LCD_D4.Write(true); LCD_E.Write(true); LCD_E.Write(false); Thread.Sleep(50); LCD_D7.Write(false); LCD_D6.Write(false); LCD_D5.Write(true); LCD_D4.Write(false); LCD_E.Write(true); LCD_E.Write(false); SendCmd(DISP_ON); SendCmd(CLR_DISP); }
internal Pin5(TreehopperBoard device) : base(device, 5) { ioName = "RC6"; AnalogIn = new AnalogIn(this); Pwm = new Pwm(this); }
internal Pin6(TreehopperBoard device) : base(device, 6) { ioName = "RC7"; AnalogIn = new AnalogIn(this); }
internal Pin9(TreehopperUSB device) : base(device, 9) { ioName = "RB5"; AnalogIn = new AnalogIn(this); }