Improved speed and distance measurement
This commit is contained in:
parent
30a463dfab
commit
2779dc6f04
@ -54,7 +54,7 @@ void DataLogger::open(const char* currentDateTime)
|
||||
char metadata[64];
|
||||
sprintf(metadata, "start time: %s\n", currentDateTime == nullptr || currentDateTime[0] == 0 ? "NA" : currentDateTime);
|
||||
if(!file.print(metadata)) Serial.println("DataLogger: failed to write to file");
|
||||
if(!file.print("time,distance,speed,battery voltage,battery output current,temperature,altitude,latitude,longitude, log button\n")) Serial.println("DataLogger: failed to write to file");
|
||||
if(!file.print("time s,distance cm,speed m/s,battery voltage V,battery output current A,temperature C,altitude m,latitude,longitude, log button\n")) Serial.println("DataLogger: failed to write to file");
|
||||
}
|
||||
|
||||
void DataLogger::close()
|
||||
@ -81,7 +81,7 @@ void DataLogger::log(unsigned long timeMilliseconds, const Entry& entry)
|
||||
{
|
||||
sprintf(coords, "%.5f,%.5f", entry.latitude, entry.longitude);
|
||||
}
|
||||
sprintf(line, "%.3f,%d, %.3f,%.3f,%.3f,%.1f,%.1f,%s,%d\n", currentTime, (int)entry.cumulatedDistance, entry.speed, entry.batteryVoltage, entry.batteryOutputCurrent, entry.temperature, entry.altitude, coords, entry.logButtonPressed ? 1 : 0);
|
||||
sprintf(line, "%.3f,%d, %.3f,%.3f,%.3f,%.1f,%.1f,%s,%d\n", currentTime, (int)(entry.cumulatedDistance/10), entry.speed, entry.batteryVoltage, entry.batteryOutputCurrent, entry.temperature, entry.altitude, coords, entry.logButtonPressed ? 1 : 0);
|
||||
file.print(line);
|
||||
|
||||
if(currentTime >= lastFlushTime + 10.0f)
|
||||
|
@ -41,7 +41,7 @@ const int8_t I2C_SCL = 4;
|
||||
//const float wheelDiameterInches = 20;
|
||||
//const float wheelTotalCircumeferenceMeters = wheelDiameterInches * 0.0254f * 3.1415f
|
||||
const float wheelTotalCircumeferenceMeters = 1.60f; // measuring how much the vehicle advances for one turn of the wheel is more precise than calculating from the wheel diameter
|
||||
const int numImpulsesPerTurn = 2;
|
||||
const int numImpulsesPerTurn = 1;
|
||||
const float wheelCircumferenceMeters = wheelTotalCircumeferenceMeters / (float)numImpulsesPerTurn;
|
||||
const uint32_t wheelCircumferenceMillimeters = (uint32_t)(wheelCircumferenceMeters * 1000.0f + 0.5f);
|
||||
|
||||
@ -81,7 +81,8 @@ void IRAM_ATTR onSpeedSensorChange(bool newState)
|
||||
unsigned long timeSinceLastImpulse = utils::elapsed(speedSensorLastImpulseTime, now);
|
||||
|
||||
// TODO: find a simple formula that works for any wheel diameter and number of magnets
|
||||
unsigned long minInterval = speedSensorLastImpulseInterval == (unsigned long)-1 ? 200 : std::min((unsigned long)200, (unsigned long)30 + speedSensorLastImpulseInterval / 2);
|
||||
//unsigned long minInterval = speedSensorLastImpulseInterval == (unsigned long)-1 ? 200 : std::min((unsigned long)200, (unsigned long)30 + speedSensorLastImpulseInterval / 2);
|
||||
unsigned long minInterval = 90; // about 60km/h with one magnet and a 20" wheel
|
||||
|
||||
if(timeSinceLastImpulse < minInterval)
|
||||
{
|
||||
@ -248,13 +249,13 @@ void handle_wifi_connection()
|
||||
// It works by broadcasting a request for a host name on the local network, and the device directly sends its IP address in response
|
||||
// Unfortunately, some systems do not support mDNS (e.g. Android), so they won't use it at all.
|
||||
// To access through mDNS, remember to add the ".local" suffix to the host name (for example if host name is "vmon", access it at URL "https://vmon.local")
|
||||
Serial.print("Starting mDNS server with hostname \"");
|
||||
/*Serial.print("Starting mDNS server with hostname \"");
|
||||
Serial.print(WiFi.getHostname());
|
||||
Serial.println("\"");
|
||||
if(!MDNS.begin(WiFi.getHostname()))
|
||||
{
|
||||
Serial.println("Error starting mDNS");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else if(newWifiStatus == WL_DISCONNECTED)
|
||||
{
|
||||
@ -288,7 +289,7 @@ void handle_wifi_connection()
|
||||
|
||||
void handle_ADC_measures()
|
||||
{
|
||||
const int numSamples = 100;
|
||||
const int numSamples = 20;
|
||||
|
||||
float averageV = 0.0f;
|
||||
float averageC = 0.0f;
|
||||
|
Loading…
Reference in New Issue
Block a user