public UsbSerialCommunicationChannel(GTM.GHIElectronics.USBSerial ser) { _ser = ser; _ser.Configure(115200, SerialParity.None, SerialStopBits.One, 8, HardwareFlowControl.NotRequired); _ser.Port.DataReceived += Port_DataReceived; _ser.Port.Open(); }
public static void StartNetworkServices(GTM.GHIElectronics.EthernetENC28 ethernetENC28, string deviceName, bool connected, string uniqueDeviceIdentifier = "") { ethernetENC28.UseThisNetworkInterface(); while (!ethernetENC28.IsNetworkConnected) { Thread.Sleep(1000); } sm = Utilities.StartNetworkServices(deviceName, connected, uniqueDeviceIdentifier); }
public SensorTemp(GTM.GHIElectronics.TempHumidity tempHumidity, int sampleRateMilliseconds, string name) : base("temp", "c", ValuesPerSample.One, sampleRateMilliseconds, name) { tempHumidity.MeasurementComplete += tempHumidity_MeasurementComplete; // tempHumidity.RequestSingleMeasurement(); tempHumidity.MeasurementInterval = 5000; tempHumidity.StartTakingMeasurements(); StartMeasuring(); }
void tempHumidity_MeasurementComplete(GTM.GHIElectronics.TempHumidity sender, GTM.GHIElectronics.TempHumidity.MeasurementCompleteEventArgs e) { lastTempReading = e.Temperature; lastHumidityReading = e.RelativeHumidity; }
public SensorLight(GTM.GHIElectronics.LightSense lightSense, int sampleRateMilliseconds, string name) : base(light", "p", ValuesPerSample.One, sampleRateMilliseconds, name)
void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state) { }
void gyro_MeasurementComplete(GTM.Seeed.Gyro sender, GTM.Seeed.Gyro.SensorData sensorData) { // Grab the gyro reading and run our balancing calculations // Calculate the time delta since the last reading DateTime now = DateTime.Now; double dt = (now.Ticks - _gyroLastReadTime.Ticks) / (double)TimeSpan.TicksPerSecond; _gyroLastReadTime = now; // Get the current accelerometer readings var acceleration = accelerometer.RequestMeasurement(); var accelAngle = (System.Math.Atan2(acceleration.Y, acceleration.Z) + System.Math.PI) * RagToDeg; // Use a complementary filter to combine the data from the gyro and the accelerometer to // compensate for the gyro drift. This gives us a reasonably accurate reading for the current angle of the // FEX Cerbot _angle = GyroFactor * (_angle + sensorData.Y * dt) + AccelFactor * accelAngle; // Calculate the PID values. // P - error // I - errorSum // D - d double error = (TargetAngle - _angle); _errorSum += error; var d = (error - _prevError); // Remember this error value for the next iteration _prevError = error; // Calculate the PID output double output = Kp * error + Ki * _errorSum + Kd * d; // Calculate the required motor speed based on the PID output // This value is picked up in our control thread which will actually set the motor speed _speed = (int)(MotorSpeedFactor * output + 0.5); // Ensure the motor speed does not exceed the allowed values if (_speed > 100) _speed = 100; if (_speed < -100) _speed = -100; }