Outsource speedsensor, Display: show speed
- move speedsensor files from motorctl pcb to common - single pcb create and configure global speedsensor objects - display: create fast slow veryslow loop - clear display every 30s - show speed in rpm and km/h NOTE: speedsensor needs fix, direction unreliable
This commit is contained in:
@@ -129,6 +129,28 @@ fan_config_t configCooling = {
|
||||
|
||||
|
||||
|
||||
|
||||
//============================================
|
||||
//======== speed sensor configuration ========
|
||||
//============================================
|
||||
speedSensor_config_t speedLeft_config{
|
||||
.gpioPin = GPIO_NUM_5,
|
||||
.degreePerGroup = 360/5,
|
||||
.tireCircumferenceMeter = 210.0*3.141/1000.0,
|
||||
.directionInverted = false,
|
||||
.logName = "speedLeft",
|
||||
};
|
||||
|
||||
speedSensor_config_t speedRight_config{
|
||||
.gpioPin = GPIO_NUM_14,
|
||||
.degreePerGroup = 360/12,
|
||||
.tireCircumferenceMeter = 210.0*3.141/1000.0,
|
||||
.directionInverted = true,
|
||||
.logName = "speedRight",
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=================================
|
||||
//===== create global objects =====
|
||||
//=================================
|
||||
@@ -151,6 +173,9 @@ motorSetCommandFunc_t setRightFunc = [&sabertoothDriver](motorCommand_t cmd) {
|
||||
controlledMotor motorLeft(setLeftFunc, configMotorControlLeft);
|
||||
controlledMotor motorRight(setRightFunc, configMotorControlRight);
|
||||
|
||||
//create speedsensor instances
|
||||
speedSensor speedLeft (speedLeft_config);
|
||||
speedSensor speedRight (speedRight_config);
|
||||
|
||||
//create global joystic instance (joystick.hpp)
|
||||
evaluatedJoystick joystick(configJoystick);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "fan.hpp"
|
||||
#include "http.hpp"
|
||||
#include "auto.hpp"
|
||||
#include "speedsensor.hpp"
|
||||
|
||||
|
||||
//in IDLE mode: set loglevel for evaluatedJoystick to DEBUG
|
||||
@@ -44,3 +45,7 @@ extern automatedArmchair armchair;
|
||||
//configuration for fans / cooling
|
||||
extern fan_config_t configCooling;
|
||||
|
||||
//create global objects for measuring speed
|
||||
extern speedSensor speedLeft;
|
||||
extern speedSensor speedRight;
|
||||
|
||||
|
||||
@@ -142,15 +142,20 @@ float getBatteryPercent(){
|
||||
//============================
|
||||
//======= display task =======
|
||||
//============================
|
||||
#define VERY_SLOW_LOOP_INTERVAL 30000
|
||||
#define SLOW_LOOP_INTERVAL 1000
|
||||
#define FAST_LOOP_INTERVAL 200
|
||||
//TODO: separate taks for each loop?
|
||||
|
||||
void display_task( void * pvParameters ){
|
||||
char buf[20];
|
||||
char buf1[20];
|
||||
int len, len1;
|
||||
int countFastloop = 0;
|
||||
int countSlowLoop = 0;
|
||||
int countFastloop = SLOW_LOOP_INTERVAL;
|
||||
int countSlowLoop = VERY_SLOW_LOOP_INTERVAL;
|
||||
|
||||
display_init();
|
||||
//todo check if successfully initialized
|
||||
//TODO check if successfully initialized
|
||||
|
||||
//welcome msg
|
||||
strcpy(buf, "Hello");
|
||||
@@ -159,17 +164,43 @@ void display_task( void * pvParameters ){
|
||||
|
||||
//update stats
|
||||
while(1){
|
||||
//--- battery ---
|
||||
//TODO update only when no load (currentsensors = ~0A)
|
||||
float battVoltage = getBatteryVoltage();
|
||||
float battPercent = getBatteryPercent(battVoltage);
|
||||
len = snprintf(buf, sizeof(buf), "Bat:%.1fV %.2fV", battVoltage, battVoltage/BAT_CELL_COUNT);
|
||||
len1 = snprintf(buf1, sizeof(buf1), "B:%02.0f%%", battPercent);
|
||||
ssd1306_display_text_x3(&dev, 0, buf1, len1, false);
|
||||
ssd1306_display_text(&dev, 3, buf, len, false);
|
||||
ssd1306_display_text(&dev, 4, buf, len, true);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
if (countFastloop >= SLOW_LOOP_INTERVAL / FAST_LOOP_INTERVAL){
|
||||
//---- very slow loop ----
|
||||
if (countSlowLoop >= VERY_SLOW_LOOP_INTERVAL/SLOW_LOOP_INTERVAL){
|
||||
//clear display - workaround for bugged line order after a few minutes
|
||||
countSlowLoop = 0;
|
||||
ssd1306_clear_screen(&dev, false);
|
||||
}
|
||||
//---- slow loop ----
|
||||
countSlowLoop ++;
|
||||
countFastloop = 0;
|
||||
//--- battery stats ---
|
||||
//TODO update only when no load (currentsensors = ~0A)
|
||||
float battVoltage = getBatteryVoltage();
|
||||
float battPercent = getBatteryPercent(battVoltage);
|
||||
len = snprintf(buf, sizeof(buf), "Bat:%.1fV %.2fV", battVoltage, battVoltage/BAT_CELL_COUNT);
|
||||
len1 = snprintf(buf1, sizeof(buf1), "B:%02.0f%%", battPercent);
|
||||
ssd1306_display_text_x3(&dev, 0, buf1, len1, false);
|
||||
ssd1306_display_text(&dev, 3, buf, len, false);
|
||||
ssd1306_display_text(&dev, 4, buf, len, true);
|
||||
}
|
||||
|
||||
//---- fast loop ----
|
||||
//update speed/rpm
|
||||
float sLeft = speedLeft.getKmph();
|
||||
float rLeft = speedLeft.getRpm();
|
||||
float sRight = speedRight.getKmph();
|
||||
float rRight = speedRight.getRpm();
|
||||
len = snprintf(buf, sizeof(buf), "L:%.1f R:%.1fkm/h", fabs(sLeft), fabs(sRight));
|
||||
ssd1306_display_text(&dev, 5, buf, len, false);
|
||||
len = snprintf(buf, sizeof(buf), "L:%4.0f R:%4.0fRPM", rLeft, rRight);
|
||||
ssd1306_display_text(&dev, 6, buf, len, false);
|
||||
//debug speed sensors
|
||||
ESP_LOGD(TAG, "%s", buf);
|
||||
//TODO show currentsensor values
|
||||
|
||||
vTaskDelay(FAST_LOOP_INTERVAL / portTICK_PERIOD_MS);
|
||||
countFastloop++;
|
||||
}
|
||||
//TODO add pages and menus
|
||||
|
||||
@@ -10,6 +10,8 @@ extern "C" {
|
||||
#include "font8x8_basic.h"
|
||||
}
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
|
||||
//task that inititialized the display, displays welcome message
|
||||
//and releatedly updates the display with certain content
|
||||
|
||||
Reference in New Issue
Block a user