Set max interval for sleep + use first gyro temp
This commit is contained in:
parent
c1c325a2bc
commit
1269bf6f0e
@ -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 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 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)
|
* 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)
|
* 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......
|
* Testing, Testing and more testing......
|
||||||
|
|
||||||
# Functionallity
|
# 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.
|
* 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.
|
* 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.
|
||||||
|
|
||||||

|

|
||||||
|
@ -108,7 +108,7 @@
|
|||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="sleep-interval" class="col-sm-4 col-form-label">Interval (seconds):</label>
|
<label for="sleep-interval" class="col-sm-4 col-form-label">Interval (seconds):</label>
|
||||||
<div class="col-sm-4">
|
<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>
|
</div>
|
||||||
<label for="sleep-interval" class="col-sm-4 col-form-label" id="sleep-interval-info"></label>
|
<label for="sleep-interval" class="col-sm-4 col-form-label" id="sleep-interval-info"></label>
|
||||||
</div>
|
</div>
|
||||||
|
File diff suppressed because one or more lines are too long
@ -211,10 +211,16 @@ bool GyroSensor::read() {
|
|||||||
} else {
|
} else {
|
||||||
validValue = true;
|
validValue = true;
|
||||||
angle = calculateAngle( raw );
|
angle = calculateAngle( raw );
|
||||||
sensorTemp = ((float) raw.temp) / 340 + 36.53;
|
|
||||||
//Log.notice(F("GYRO: Calculated angle %F" CR), angle );
|
//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;
|
return validValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ struct RawGyroDataL { // Used for average multiple readings
|
|||||||
long temp; // Only for information (temperature of chip)
|
long temp; // Only for information (temperature of chip)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define INVALID_TEMPERATURE -273
|
||||||
|
|
||||||
class GyroSensor {
|
class GyroSensor {
|
||||||
private:
|
private:
|
||||||
MPU6050 accelgyro;
|
MPU6050 accelgyro;
|
||||||
@ -52,6 +54,7 @@ class GyroSensor {
|
|||||||
bool validValue = false;
|
bool validValue = false;
|
||||||
double angle = 0;
|
double angle = 0;
|
||||||
float sensorTemp = 0;
|
float sensorTemp = 0;
|
||||||
|
float initialSensorTemp = INVALID_TEMPERATURE;
|
||||||
RawGyroData calibrationOffset;
|
RawGyroData calibrationOffset;
|
||||||
|
|
||||||
void debug();
|
void debug();
|
||||||
@ -68,6 +71,7 @@ class GyroSensor {
|
|||||||
|
|
||||||
double getAngle() { return angle; };
|
double getAngle() { return angle; };
|
||||||
float getSensorTempC() { return sensorTemp; };
|
float getSensorTempC() { return sensorTemp; };
|
||||||
|
float getInitialSensorTempC() { return initialSensorTemp; };
|
||||||
bool isConnected() { return sensorConnected; };
|
bool isConnected() { return sensorConnected; };
|
||||||
bool hasValue() { return validValue; };
|
bool hasValue() { return validValue; };
|
||||||
void enterSleep();
|
void enterSleep();
|
||||||
|
@ -180,12 +180,11 @@ void loop() {
|
|||||||
//
|
//
|
||||||
if( myGyro.hasValue() ) {
|
if( myGyro.hasValue() ) {
|
||||||
angle = myGyro.getAngle(); // Gyro angle
|
angle = myGyro.getAngle(); // Gyro angle
|
||||||
sensorTemp = myGyro.getSensorTempC(); // Temp in the Gyro
|
|
||||||
|
|
||||||
stableGyroMillis = millis(); // Reset timer
|
stableGyroMillis = millis(); // Reset timer
|
||||||
|
|
||||||
LOG_PERF_START("loop-temp-read");
|
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_STOP("loop-temp-read");
|
||||||
|
|
||||||
//LOG_PERF_START("loop-gravity-calc"); // Takes less than 2ms , so skip this measurment
|
//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");
|
//LOG_PERF_STOP("loop-gravity-calc");
|
||||||
|
|
||||||
#if LOG_LEVEL==6
|
#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
|
#endif
|
||||||
if( myConfig.isGravityTempAdj() ) {
|
if( myConfig.isGravityTempAdj() ) {
|
||||||
LOG_PERF_START("loop-gravity-corr");
|
LOG_PERF_START("loop-gravity-corr");
|
||||||
@ -206,7 +205,7 @@ void loop() {
|
|||||||
|
|
||||||
// Limit the printout when sleep mode is not active.
|
// Limit the printout when sleep mode is not active.
|
||||||
if( loopCounter%10 == 0 || sleepModeActive ) {
|
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");
|
LOG_PERF_START("loop-push");
|
||||||
|
@ -97,8 +97,9 @@ float TempSensor::getValue() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( USE_GYRO_TEMP )
|
#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");
|
//LOG_PERF_START("temp-get");
|
||||||
float c = myGyro.getSensorTempC();
|
float c = myGyro.getInitialSensorTempC();
|
||||||
//LOG_PERF_STOP("temp-get");
|
//LOG_PERF_STOP("temp-get");
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
return c;
|
return c;
|
||||||
|
Loading…
Reference in New Issue
Block a user