fix: bringup with full project

This commit is contained in:
2025-04-02 19:55:29 +02:00
parent 5ca595eddc
commit decaf80d1f
16 changed files with 79 additions and 75 deletions
+16 -16
View File
@@ -1583,24 +1583,24 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
auto nextWdTrigger = fos::Timing::getMilliSec() + WATCHDOGTIME; auto nextWdTrigger = fos::Timing::getMilliSec() + WATCHDOGTIME;
auto nextWdCheck = nextWdTrigger + WATCHDOGTIME; auto nextWdCheck = nextWdTrigger + WATCHDOGTIME;
while (true) { while (true) {
auto time = fos::Timing::getMilliSec(); // auto time = fos::Timing::getMilliSec();
if (time > nextWdTrigger) { // if (time > nextWdTrigger) {
instance.sAnswered = false; // instance.sAnswered = false;
instance.sendWatchdog(); // // instance.sendWatchdog();
nextWdTrigger = nextWdCheck + WATCHDOGTIME; // nextWdTrigger = nextWdCheck + WATCHDOGTIME;
} // }
if (time > nextWdCheck) { // if (time > nextWdCheck) {
if (!instance.sAnswered) { // if (!instance.sAnswered) {
ESP_LOGW(TAG, "TimeOut"); // ESP_LOGW(TAG, "TimeOut");
instance.eventWatchdogLost(); // instance.eventWatchdogLost();
break; // break;
} // }
nextWdCheck = nextWdTrigger + WATCHDOGTIME; // nextWdCheck = nextWdTrigger + WATCHDOGTIME;
} // }
fos::Task::delayMs(25); fos::Task::delayMs(25);
if (instance.m_StopReceiveSPITMessages) // if (instance.m_StopReceiveSPITMessages)
break; // break;
} }
} }
} }
+3
View File
@@ -40,6 +40,9 @@ class WatchMotor {
_currentIndex = sign; _currentIndex = sign;
} }
float getScaled() { return _stepper.getScaledPos() * 6; }
uint8_t getIndex() { return _currentIndex; }
private: private:
StepperMotor &_stepper; StepperMotor &_stepper;
OutputPort &_motorSleep; OutputPort &_motorSleep;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+46 -45
View File
@@ -77,17 +77,16 @@ struct DeviceState {
uint8_t minJumps{6}; uint8_t minJumps{6};
uint8_t maxJumps{32}; uint8_t maxJumps{32};
uint8_t profile{}; uint8_t profile{};
uint8_t restTime{}; uint8_t shuffleRate{};
float speed = 1.0; // Rad/sec float speed = 1.0; // Rad/sec
float accel = 1.0; // Rad/sec^2 float accel = 1.0; // Rad/sec^2
Color color{0x80, 0x80, 0x80}; Color color{0x80, 0x80, 0x80};
uint8_t pictogram{}; // 0..5 active Pictogramm
}; };
enum class MoveType { enum class MoveType {
StepTo, StepTo,
Demo,
Shuffle, Shuffle,
Demo
}; };
enum class ResponseType { enum class ResponseType {
StepAt, StepAt,
@@ -98,7 +97,7 @@ struct MoveCommand {
// 1..6 // 1..6
uint8_t pos; uint8_t pos;
}; };
struct Arrived { struct WatchIndex {
ResponseType type; ResponseType type;
// 1..6 // 1..6
uint8_t pos; uint8_t pos;
@@ -108,7 +107,7 @@ struct PictoIllumCommand {
}; };
static fos::Queue<MoveCommand> commandQueue(8); static fos::Queue<MoveCommand> commandQueue(8);
static fos::Queue<Arrived> responseQueue(8); static fos::Queue<WatchIndex> responseQueue(8);
static fos::Queue<PictoIllumCommand> pictoIllumQue(2); static fos::Queue<PictoIllumCommand> pictoIllumQue(2);
DeviceState activeState; DeviceState activeState;
@@ -286,7 +285,7 @@ static void UniverseCallback(const uint8_t *data, const uint16_t size) {
Syslog::logv(Syslog::Severity::Debug, "Got DMX: r%0x g%0x b%0x i%0x m%i M%i p%i a%i w%i r%i", Syslog::logv(Syslog::Severity::Debug, "Got DMX: r%0x g%0x b%0x i%0x m%i M%i p%i a%i w%i r%i",
/* RGB*/ data[0], data[1], data[2], /*Intens*/ data[3], /* RGB*/ data[0], data[1], data[2], /*Intens*/ data[3],
/* MinMaxJumps */ data[4], data[5], /*profile*/ data[6], /*accel/speed*/ data[7], data[8], /* MinMaxJumps */ data[4], data[5], /*profile*/ data[6], /*accel/speed*/ data[7], data[8],
/*RestTime*/ data[9]); /*shuffleRate*/ data[9]);
float intens = (float)data[3] / UINT8_MAX; float intens = (float)data[3] / UINT8_MAX;
activeState.color = Color{ activeState.color = Color{
@@ -304,7 +303,7 @@ static void UniverseCallback(const uint8_t *data, const uint16_t size) {
activeState.accel = (float)accel / 100 + 0.5; // min .5 / max 3 activeState.accel = (float)accel / 100 + 0.5; // min .5 / max 3
activeState.speed = (float)velo / 100 + 0.5; // min .5 / max 3 activeState.speed = (float)velo / 100 + 0.5; // min .5 / max 3
activeState.restTime = data[9]; activeState.shuffleRate = data[9];
} }
void moveToSubs(std::string data) { void moveToSubs(std::string data) {
@@ -521,7 +520,7 @@ void LightingTask() {
Effect::macStartFlicker, Effect::macStartFlicker,
Effect::macDemoPulse}; // 6 Effect::macDemoPulse}; // 6
uint8_t lastPicto = 0; uint8_t lastPicto = 1;
std::array<uint16_t *, 6> startPoints{ std::array<uint16_t *, 6> startPoints{
&(values[0][4]), // 1 &(values[0][4]), // 1
@@ -592,16 +591,27 @@ void MovementTask() {
StepperMotor stepper(stepperCfg, stepperDriver, initSens); StepperMotor stepper(stepperCfg, stepperDriver, initSens);
WatchMotor watch(stepper, motorSleep);
ESP_LOGI("Stepper", "Find Home"); ESP_LOGI("Stepper", "Find Home");
stepper.findRef(); stepper.findRef();
// Illum 1 // Todo Set by User-Interface
pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(6)); for (size_t i = 0; i < 7; i++) {
stepper.fullStep(1);
fos::Task::delayMs(40);
}
(void)stepper.zeroPosition();
while (!stepper.isIdle()) {
fos::Task::delayMs(40);
}
// watch.moveTo(1, ProfileGenerator::Unitform);
ESP_LOGI("Stepper", "Got to 1");
// Illum 6
pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(0));
ESP_LOGI(TAG, "Fist Position is %f.2", stepper.getScaledPos() * 6); ESP_LOGI(TAG, "Fist Position is %.2f", watch.getScaled());
fos::Task::delayMs(1000); fos::Task::delayMs(1000);
activeState.pictogram = 0;
while (true) { while (true) {
ESP_LOGD(TAG, "Waiting for command"); ESP_LOGD(TAG, "Waiting for command");
auto cmd = commandQueue.dequeue(); auto cmd = commandQueue.dequeue();
@@ -609,7 +619,6 @@ void MovementTask() {
if (stepper.isIdle()) { if (stepper.isIdle()) {
int newPos = cmd->pos; int newPos = cmd->pos;
if ((newPos >= 1) && (newPos <= 6)) { if ((newPos >= 1) && (newPos <= 6)) {
auto idx = newPos - 1;
Syslog::logv(Syslog::Severity::Informational, Syslog::logv(Syslog::Severity::Informational,
"Triggered movement to picto pos:%i ", newPos); "Triggered movement to picto pos:%i ", newPos);
} else { } else {
@@ -617,43 +626,35 @@ void MovementTask() {
"Got invalid index for illuminated pictogram =%i ", newPos); "Got invalid index for illuminated pictogram =%i ", newPos);
continue; continue;
} }
int delta = newPos - activeState.pictogram;
if (delta <= 0) { int jumps = newPos - watch.getIndex();
delta += 6; if (jumps <= 0) {
jumps += 6;
} }
delta = delta + (activeState.minJumps % 6) * 6; jumps = jumps + (activeState.minJumps % 6) * 6;
if (delta < activeState.minJumps) { if (jumps < activeState.minJumps) {
delta += 6; jumps += 6;
} }
Syslog::logv(Syslog::Severity::Notice, Syslog::logv(Syslog::Severity::Notice,
"Running Stepper by %i steps with prof=%i a=%.2f w=%.2f", "Running Stepper by %i steps with prof=%i a=%.2f w=%.2f",
delta, activeState.profile, activeState.accel, activeState.speed); jumps, activeState.profile, activeState.accel, activeState.speed);
pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(0)); pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(0));
responseQueue.enqueue(std::make_unique<Arrived>(ResponseType::StartMoving, 0)); responseQueue.enqueue(std::make_unique<WatchIndex>(ResponseType::StartMoving, 0));
stepper.moveBy(delta * std::numbers::pi / 3, watch.moveTo(newPos, activeState.profile);
activeState.profile, activeState.accel, activeState.speed);
pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(newPos)); pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(newPos));
responseQueue.enqueue(std::make_unique<Arrived>(ResponseType::StepAt, newPos)); responseQueue.enqueue(std::make_unique<WatchIndex>(ResponseType::StepAt, newPos));
activeState.pictogram = newPos;
} }
} else if (cmd->type == MoveType::Demo) { } else if (cmd->type == MoveType::Demo) {
int i = 0; ESP_LOGI(TAG, "Running Demo");
while (i++ < 80) { for (size_t i = ProfileGenerator::Smooth; i < ProfileGenerator::NumProfiles; i++) {
stepperDriver.step(1); ESP_LOGI(TAG, "Running Profile %d ", i);
stepperDriver.getSubPos(); fos::Task::delayMs(1000);
fos::Task::delayMs(100); int steps[3]{4, 2, 0};
} for (size_t j = 0; j < 3; j++) {
ESP_LOGI("Stepper", "Find Home"); watch.moveTo(steps[j], i);
stepper.findRef();
activeState.pictogram = -1;
stepper.findRef();
fos::Task::delayMs(1000); fos::Task::delayMs(1000);
for (size_t i = 0; i < 6; i++) {
stepper.moveBy(std::numbers::pi / 3);
while (!stepper.isIdle()) {
fos::Task::delayMs(100);
} }
ESP_LOGI(TAG, "Position is %f.2", stepper.getScaledPos() * 6);
} }
} else { } else {
fos::Task::delayMs(100); fos::Task::delayMs(100);
@@ -913,7 +914,7 @@ void onPlaySpitType(string p_PlayerID, string spitTypeId, bool p_PlayerIsRunning
auto command = ProvidedSpitActions[spitTypeId]; auto command = ProvidedSpitActions[spitTypeId];
ESP_LOGI(TAG, "Player: %s is running: %s Object", p_PlayerID.data(), spitTypeId.c_str()); ESP_LOGI(TAG, "Player: %s is running: %s Object", p_PlayerID.data(), spitTypeId.c_str());
commandQueue.enqueue(std::make_unique<MoveCommand>(command)); commandQueue.enqueue(std::make_unique<MoveCommand>(command));
ESP_LOGI(TAG, "MyApp AKTION 1 started Value: %f and running: %d", p_Value, p_PlayerIsRunning); Syslog::logv(Syslog::Severity::Informational, "Got SPIT command for move ot : r%d", command.pos);
} }
} }
@@ -980,7 +981,6 @@ void SpitClientApp() {
} }
while (true) { while (true) {
fos::Task::delayMs(10000);
auto res = responseQueue.dequeue(); auto res = responseQueue.dequeue();
if (res->type == ResponseType::StartMoving) { if (res->type == ResponseType::StartMoving) {
spitClient.sendRemoteObject(ExpectedObjects[expected.changingPos]); spitClient.sendRemoteObject(ExpectedObjects[expected.changingPos]);
@@ -999,10 +999,11 @@ void app_main(void) {
ESP_ERROR_CHECK(ret); ESP_ERROR_CHECK(ret);
initialize_ethernet(); initialize_ethernet();
NvsApi::init(); NvsApi::init();
static fos::Task lightingTask(LightingTask, "Lights", 0x4000uL); static fos::Task lightingTask(LightingTask, "Lights", 0x8000uL);
static fos::Task movementTask(MovementTask, "Motor", 0x4000uL); static fos::Task movementTask(MovementTask, "Motor", 0x8000uL);
etherActive.take(); etherActive.take();
fos::Task::delayMs(10000);
ESP_LOGI(TAG, "Start net services"); ESP_LOGI(TAG, "Start net services");
static int ipVersion = AF_INET; static int ipVersion = AF_INET;
+3 -3
View File
@@ -247,7 +247,7 @@ void testMovementTask() {
} }
/// ///
/// /// Homing
/// ///
ESP_LOGD(TAG, "Find Home"); ESP_LOGD(TAG, "Find Home");
stepper.findRef(); stepper.findRef();
@@ -289,8 +289,8 @@ void testMovementTask() {
/// All other Profiles /// All other Profiles
/// ///
if constexpr (DoTurnProfiles) { if constexpr (DoTurnProfiles) {
// for (size_t i = ProfileGenerator::Smooth; i < ProfileGenerator::NumProfiles; i++) { for (size_t i = ProfileGenerator::Smooth; i < ProfileGenerator::NumProfiles; i++) {
for (size_t i = ProfileGenerator::JumpIn; i < ProfileGenerator::NumProfiles; i++) { // for (size_t i = ProfileGenerator::JumpIn; i < ProfileGenerator::NumProfiles; i++) { // If only part is needed
ESP_LOGI(TAG, "Running Profile %d ", i); ESP_LOGI(TAG, "Running Profile %d ", i);
ESP_LOGD(TAG, "Fist Position is %3d / %.2f / Micro %d", stepper.getQuanted(), stepper.getScaledPos() * 6, stepper.getSubPos()); ESP_LOGD(TAG, "Fist Position is %3d / %.2f / Micro %d", stepper.getQuanted(), stepper.getScaledPos() * 6, stepper.getSubPos());
fos::Task::delayMs(1000); fos::Task::delayMs(1000);