change direction add commutask

This commit is contained in:
2022-09-16 09:32:03 +02:00
parent c465a9ed93
commit 708cc2f83d
9 changed files with 74 additions and 7 deletions

1
.gitignore vendored
View File

@@ -29,3 +29,4 @@ build/
__pycache__
**/.DS_Store

View File

@@ -0,0 +1,28 @@
#include "commu_task.h"
#include "semaphore_guard.h"
CommuTask::CommuTask(const uint8_t task_core) : Task{"Communication", 4048, 1, task_core} {
mutex_ = xSemaphoreCreateMutex();
assert(mutex_ != NULL);
}
CommuTask::~CommuTask()
{
}
void CommuTask::run() {
WiFi.begin("poes", "Rijnstraat214");
while(1)
{
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
delay(100);
}
}

25
firmware/src/commu_task.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <Arduino.h>
#include <WiFi.h>
#include "knob_data.h"
#include "task.h"
class CommuTask : public Task<CommuTask> {
friend class Task<CommuTask>; // Allow base Task to invoke protected run()
public:
CommuTask(const uint8_t task_core);
~CommuTask();
protected:
void run();
private:
SemaphoreHandle_t mutex_;
};

View File

@@ -189,6 +189,7 @@ void DisplayTask::run() {
SemaphoreGuard lock(mutex_);
ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, brightness_);
}
delay(2);
}
}

View File

@@ -35,6 +35,8 @@ class DisplayTask : public Task<DisplayTask> {
SemaphoreHandle_t mutex_;
uint16_t brightness_;
uint32_t last_printupdate = 0;
};
#else

View File

@@ -195,7 +195,8 @@ void InterfaceTask::run() {
float lux = veml.readLux();
lux_avg = lux * LUX_ALPHA + lux_avg * (1 - LUX_ALPHA);
static uint32_t last_als;
if (millis() - last_als > 1000) {
if (millis() - last_als >5000) {
Serial.print("millilux: "); Serial.println(lux*1000);
last_als = millis();
}
@@ -220,7 +221,7 @@ void InterfaceTask::run() {
press_value_unit = 1. * (value - lower) / (upper - lower);
static bool pressed;
if (!pressed && press_value_unit > 0.75) {
if (!pressed && press_value_unit > 0.3) {
motor_task_.playHaptic(true);
pressed = true;
changeConfig(true);
@@ -241,7 +242,7 @@ void InterfaceTask::run() {
}
#endif
uint16_t brightness = UINT16_MAX;
// TODO: brightness scale factor should be configurable (depends on reflectivity of surface)
#if SK_ALS
brightness = (uint16_t)CLAMP(lux_avg * 13000, (float)1280, (float)UINT16_MAX);

View File

@@ -7,6 +7,8 @@
#include "motor_task.h"
#include "task.h"
#define ALSCHECKINTERVAL 4000
class InterfaceTask : public Task<InterfaceTask>, public ace_button::IEventHandler {
friend class Task<InterfaceTask>; // Allow base Task to invoke protected run()
@@ -25,5 +27,7 @@ class InterfaceTask : public Task<InterfaceTask>, public ace_button::IEventHandl
int current_config_ = 0;
uint16_t brightness = UINT16_MAX;
void changeConfig(bool next);
};

View File

@@ -4,14 +4,16 @@
#include "display_task.h"
#include "interface_task.h"
#include "motor_task.h"
#include "commu_task.h"
#if SK_DISPLAY
static DisplayTask display_task = DisplayTask(0);
static DisplayTask display_task = DisplayTask(1);
static DisplayTask* display_task_p = &display_task;
#else
static DisplayTask* display_task_p = nullptr;
#endif
static MotorTask motor_task = MotorTask(1);
static MotorTask motor_task = MotorTask(0);
static CommuTask commu_Task = CommuTask(1);
InterfaceTask interface_task = InterfaceTask(0, motor_task, display_task_p);
@@ -23,6 +25,7 @@ void setup() {
motor_task.begin();
interface_task.begin();
//commu_Task.begin();
#if SK_DISPLAY
display_task.begin();
@@ -61,6 +64,8 @@ void loop() {
#endif
Serial.printf("motor: %d\n", uxTaskGetStackHighWaterMark(motor_task.getHandle()));
Serial.printf("interface: %d\n", uxTaskGetStackHighWaterMark(interface_task.getHandle()));
Serial.printf("communication: %d\n", uxTaskGetStackHighWaterMark(commu_Task.getHandle()));
last_stack_debug = millis();
}
}

View File

@@ -53,8 +53,8 @@ void MotorTask::run() {
// float zero_electric_offset = -0.8; // handheld 2
// float zero_electric_offset = 2.93; //0.15; // 17mm test
// float zero_electric_offset = 0.66; // 15mm handheld
float zero_electric_offset = 7.34;
Direction foc_direction = Direction::CW;
float zero_electric_offset = 7.07;
Direction foc_direction = Direction::CCW;
motor.pole_pairs = 7;
driver.voltage_power_supply = 5;