change direction add commutask
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -29,3 +29,4 @@ build/
|
|||||||
|
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
||||||
|
**/.DS_Store
|
||||||
|
|||||||
28
firmware/src/CommuTask.cpp
Normal file
28
firmware/src/CommuTask.cpp
Normal 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
25
firmware/src/commu_task.h
Normal 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_;
|
||||||
|
|
||||||
|
};
|
||||||
@@ -189,6 +189,7 @@ void DisplayTask::run() {
|
|||||||
SemaphoreGuard lock(mutex_);
|
SemaphoreGuard lock(mutex_);
|
||||||
ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, brightness_);
|
ledcWrite(LEDC_CHANNEL_LCD_BACKLIGHT, brightness_);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(2);
|
delay(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class DisplayTask : public Task<DisplayTask> {
|
|||||||
SemaphoreHandle_t mutex_;
|
SemaphoreHandle_t mutex_;
|
||||||
|
|
||||||
uint16_t brightness_;
|
uint16_t brightness_;
|
||||||
|
|
||||||
|
uint32_t last_printupdate = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -195,7 +195,8 @@ void InterfaceTask::run() {
|
|||||||
float lux = veml.readLux();
|
float lux = veml.readLux();
|
||||||
lux_avg = lux * LUX_ALPHA + lux_avg * (1 - LUX_ALPHA);
|
lux_avg = lux * LUX_ALPHA + lux_avg * (1 - LUX_ALPHA);
|
||||||
static uint32_t last_als;
|
static uint32_t last_als;
|
||||||
if (millis() - last_als > 1000) {
|
|
||||||
|
if (millis() - last_als >5000) {
|
||||||
Serial.print("millilux: "); Serial.println(lux*1000);
|
Serial.print("millilux: "); Serial.println(lux*1000);
|
||||||
last_als = millis();
|
last_als = millis();
|
||||||
}
|
}
|
||||||
@@ -220,7 +221,7 @@ void InterfaceTask::run() {
|
|||||||
press_value_unit = 1. * (value - lower) / (upper - lower);
|
press_value_unit = 1. * (value - lower) / (upper - lower);
|
||||||
|
|
||||||
static bool pressed;
|
static bool pressed;
|
||||||
if (!pressed && press_value_unit > 0.75) {
|
if (!pressed && press_value_unit > 0.3) {
|
||||||
motor_task_.playHaptic(true);
|
motor_task_.playHaptic(true);
|
||||||
pressed = true;
|
pressed = true;
|
||||||
changeConfig(true);
|
changeConfig(true);
|
||||||
@@ -241,7 +242,7 @@ void InterfaceTask::run() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t brightness = UINT16_MAX;
|
|
||||||
// TODO: brightness scale factor should be configurable (depends on reflectivity of surface)
|
// TODO: brightness scale factor should be configurable (depends on reflectivity of surface)
|
||||||
#if SK_ALS
|
#if SK_ALS
|
||||||
brightness = (uint16_t)CLAMP(lux_avg * 13000, (float)1280, (float)UINT16_MAX);
|
brightness = (uint16_t)CLAMP(lux_avg * 13000, (float)1280, (float)UINT16_MAX);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "motor_task.h"
|
#include "motor_task.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
|
#define ALSCHECKINTERVAL 4000
|
||||||
|
|
||||||
class InterfaceTask : public Task<InterfaceTask>, public ace_button::IEventHandler {
|
class InterfaceTask : public Task<InterfaceTask>, public ace_button::IEventHandler {
|
||||||
friend class Task<InterfaceTask>; // Allow base Task to invoke protected run()
|
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;
|
int current_config_ = 0;
|
||||||
|
|
||||||
|
uint16_t brightness = UINT16_MAX;
|
||||||
|
|
||||||
void changeConfig(bool next);
|
void changeConfig(bool next);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,14 +4,16 @@
|
|||||||
#include "display_task.h"
|
#include "display_task.h"
|
||||||
#include "interface_task.h"
|
#include "interface_task.h"
|
||||||
#include "motor_task.h"
|
#include "motor_task.h"
|
||||||
|
#include "commu_task.h"
|
||||||
|
|
||||||
#if SK_DISPLAY
|
#if SK_DISPLAY
|
||||||
static DisplayTask display_task = DisplayTask(0);
|
static DisplayTask display_task = DisplayTask(1);
|
||||||
static DisplayTask* display_task_p = &display_task;
|
static DisplayTask* display_task_p = &display_task;
|
||||||
#else
|
#else
|
||||||
static DisplayTask* display_task_p = nullptr;
|
static DisplayTask* display_task_p = nullptr;
|
||||||
#endif
|
#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);
|
InterfaceTask interface_task = InterfaceTask(0, motor_task, display_task_p);
|
||||||
@@ -23,6 +25,7 @@ void setup() {
|
|||||||
|
|
||||||
motor_task.begin();
|
motor_task.begin();
|
||||||
interface_task.begin();
|
interface_task.begin();
|
||||||
|
//commu_Task.begin();
|
||||||
|
|
||||||
#if SK_DISPLAY
|
#if SK_DISPLAY
|
||||||
display_task.begin();
|
display_task.begin();
|
||||||
@@ -61,6 +64,8 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
Serial.printf("motor: %d\n", uxTaskGetStackHighWaterMark(motor_task.getHandle()));
|
Serial.printf("motor: %d\n", uxTaskGetStackHighWaterMark(motor_task.getHandle()));
|
||||||
Serial.printf("interface: %d\n", uxTaskGetStackHighWaterMark(interface_task.getHandle()));
|
Serial.printf("interface: %d\n", uxTaskGetStackHighWaterMark(interface_task.getHandle()));
|
||||||
|
Serial.printf("communication: %d\n", uxTaskGetStackHighWaterMark(commu_Task.getHandle()));
|
||||||
|
|
||||||
last_stack_debug = millis();
|
last_stack_debug = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,8 +53,8 @@ void MotorTask::run() {
|
|||||||
// float zero_electric_offset = -0.8; // handheld 2
|
// float zero_electric_offset = -0.8; // handheld 2
|
||||||
// float zero_electric_offset = 2.93; //0.15; // 17mm test
|
// float zero_electric_offset = 2.93; //0.15; // 17mm test
|
||||||
// float zero_electric_offset = 0.66; // 15mm handheld
|
// float zero_electric_offset = 0.66; // 15mm handheld
|
||||||
float zero_electric_offset = 7.34;
|
float zero_electric_offset = 7.07;
|
||||||
Direction foc_direction = Direction::CW;
|
Direction foc_direction = Direction::CCW;
|
||||||
motor.pole_pairs = 7;
|
motor.pole_pairs = 7;
|
||||||
|
|
||||||
driver.voltage_power_supply = 5;
|
driver.voltage_power_supply = 5;
|
||||||
|
|||||||
Reference in New Issue
Block a user