Set max interval for sleep + use first gyro temp

This commit is contained in:
Magnus 2021-04-11 11:29:15 +02:00
parent c1c325a2bc
commit 1269bf6f0e
7 changed files with 23 additions and 10 deletions

View File

@ -10,9 +10,10 @@ I started this project out of curiosity for how a motion sensor is working and s
* Add support for https connections (push) - [need to reduce memory usage for this to work, gets out of memory error]
* Add support for https web server (will require certificates to be created as part of build process)
* Add iSpindle 3D print cradle + small PCB (what I use for my builds)
* Validate max sleep time to 70 min (max time for ESP)
* [done] Validate max sleep time to 70 min (max time for ESP)
* Validate the power consumption of the device using amp meter (integrated and/or separate)
* Add option to use temperature readings from motion sensor (longer battery life)
* [done] Add option to use temperature readings from motion sensor (longer battery life)
* [done] When using temp from motion sensor the value should be the initial read or the value will not be accurate.
* Testing, Testing and more testing......
# Functionallity
@ -57,6 +58,8 @@ http://gravmon.local/config.htm
* This page is divided into several categories of settings. The first one contains device settings, mDNS name, temperature format, sleep interval and gyro calibration data. The interval setting is the amount of time the device will be in sleep mode between readings (interval is in seconds). To simplify this you can also see the conversion to minutes / seconds next to the input field.
* The sleep interval can be set between 10 - 3600 seconds (60 minutes).
* Calibration needs to be done or the device will not work correctly. Place the device flat on a surface with gyro up and press the calibrate button when it's stable. If no calibration data exist the device will not enter sleep-mode.
![Config - Device](img/config1.png)

View File

@ -108,7 +108,7 @@
<div class="form-group row">
<label for="sleep-interval" class="col-sm-4 col-form-label">Interval (seconds):</label>
<div class="col-sm-4">
<input type="number" min="10" max="10000" class="form-control" name="sleep-interval" id="sleep-interval">
<input type="number" min="10" max="3600" class="form-control" name="sleep-interval" id="sleep-interval">
</div>
<label for="sleep-interval" class="col-sm-4 col-form-label" id="sleep-interval-info"></label>
</div>

File diff suppressed because one or more lines are too long

View File

@ -211,10 +211,16 @@ bool GyroSensor::read() {
} else {
validValue = true;
angle = calculateAngle( raw );
sensorTemp = ((float) raw.temp) / 340 + 36.53;
//Log.notice(F("GYRO: Calculated angle %F" CR), angle );
}
sensorTemp = ((float) raw.temp) / 340 + 36.53;
// The first read value is close to the DS18 value according to my tests, if more reads are
// done then the gyro temp will increase to much
if( initialSensorTemp == INVALID_TEMPERATURE )
initialSensorTemp = sensorTemp;
return validValue;
}

View File

@ -45,6 +45,8 @@ struct RawGyroDataL { // Used for average multiple readings
long temp; // Only for information (temperature of chip)
};
#define INVALID_TEMPERATURE -273
class GyroSensor {
private:
MPU6050 accelgyro;
@ -52,6 +54,7 @@ class GyroSensor {
bool validValue = false;
double angle = 0;
float sensorTemp = 0;
float initialSensorTemp = INVALID_TEMPERATURE;
RawGyroData calibrationOffset;
void debug();
@ -68,6 +71,7 @@ class GyroSensor {
double getAngle() { return angle; };
float getSensorTempC() { return sensorTemp; };
float getInitialSensorTempC() { return initialSensorTemp; };
bool isConnected() { return sensorConnected; };
bool hasValue() { return validValue; };
void enterSleep();

View File

@ -180,12 +180,11 @@ void loop() {
//
if( myGyro.hasValue() ) {
angle = myGyro.getAngle(); // Gyro angle
sensorTemp = myGyro.getSensorTempC(); // Temp in the Gyro
stableGyroMillis = millis(); // Reset timer
LOG_PERF_START("loop-temp-read");
float temp = myTempSensor.getValueCelcius(); // The code is build around using C for temp.
float temp = myTempSensor.getValueCelcius();
LOG_PERF_STOP("loop-temp-read");
//LOG_PERF_START("loop-gravity-calc"); // Takes less than 2ms , so skip this measurment
@ -193,7 +192,7 @@ void loop() {
//LOG_PERF_STOP("loop-gravity-calc");
#if LOG_LEVEL==6
Log.verbose(F("Main: Sensor values gyro angle=%F gyro temp=%F, temp=%F, gravity=%F." CR), angle, sensorTemp, temp, gravity );
Log.verbose(F("Main: Sensor values gyro angle=%F, temp=%F, gravity=%F." CR), angle, temp, gravity );
#endif
if( myConfig.isGravityTempAdj() ) {
LOG_PERF_START("loop-gravity-corr");
@ -206,7 +205,7 @@ void loop() {
// Limit the printout when sleep mode is not active.
if( loopCounter%10 == 0 || sleepModeActive ) {
Log.notice(F("Main: gyro angle=%F, gyro temp=%F, DS18B20 temp=%F, gravity=%F, batt=%F." CR), angle, sensorTemp, temp, gravity, volt );
Log.notice(F("Main: angle=%F, temp=%F, gravity=%F, batt=%F." CR), angle, temp, gravity, volt );
}
LOG_PERF_START("loop-push");

View File

@ -97,8 +97,9 @@ float TempSensor::getValue() {
#endif
#if defined( USE_GYRO_TEMP )
// When using the gyro temperature only the first read value will be accurate so we will use this for processing.
//LOG_PERF_START("temp-get");
float c = myGyro.getSensorTempC();
float c = myGyro.getInitialSensorTempC();
//LOG_PERF_STOP("temp-get");
hasSensor = true;
return c;