From 0e79a45c466ea3fccd142634a98015660f921c4a Mon Sep 17 00:00:00 2001 From: EnricoGuccii Date: Mon, 15 Jun 2026 00:29:06 +0200 Subject: added curious emotion --- src/main.cpp | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 9d60f96..56ea47c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include +#include "esp32-hal.h" #include "settings.h" #include "motors.h" #include "rgb.h" @@ -27,7 +28,8 @@ enum RobotEmotion { E_NEUTRAL, E_HAPPY, E_SAD, - E_ANGRY + E_ANGRY, + E_CURIOUS }; volatile RobotEmotion currentState = E_NEUTRAL; @@ -36,9 +38,8 @@ volatile RobotEmotion currentState = E_NEUTRAL; volatile int fatigueLevel = 0; volatile bool isTired = false; - volatile int sleepTimer = 0; -volatile bool isSleepy = false; +volatile bool isSleepy = true; volatile char manualMotors = '0'; volatile char manualRGB = '0'; @@ -92,13 +93,16 @@ void wifiTask(void * pvParameters) { if (cmd == 'H') { currentState = E_HAPPY; emotionStartTime = millis(); manualMotors = '0'; } else if (cmd == 'S') { currentState = E_SAD; emotionStartTime = millis(); manualMotors = '0'; } else if (cmd == 'A') { currentState = E_ANGRY; emotionStartTime = millis(); manualMotors = '0'; } + else if (cmd == 'C') { currentState = E_CURIOUS; emotionStartTime = millis(); manualMotors = '0'; } else if (cmd == 'N') { currentState = E_NEUTRAL; emotionStartTime = millis(); manualMotors = '0'; } else if (cmd == 'M') { currentState = MANUAL; manualMotors = '0'; } } } if (currentState != MANUAL) { - if (millis() - emotionStartTime >= EMOTION_DURATION_MS) { + unsigned long limit = (currentState == E_CURIOUS) ? 5000 : EMOTION_DURATION_MS; + + if (millis() - emotionStartTime >= limit) { currentState = MANUAL; manualMotors = '0'; manualRGB = '0'; @@ -175,19 +179,29 @@ void oledTask(void * pvParameters) { switch(currentState) { case E_HAPPY: + roboEyes.setCuriosity(OFF); roboEyes.setMood(HAPPY); break; + case E_CURIOUS: + roboEyes.setCuriosity(ON); + roboEyes.setIdleMode(ON, 1, 1); + break; case E_SAD: + roboEyes.setCuriosity(OFF); roboEyes.setMood(TIRED); break; case E_ANGRY: + roboEyes.setCuriosity(OFF); roboEyes.setMood(ANGRY); break; default: + roboEyes.setCuriosity(OFF); + roboEyes.setIdleMode(ON,2,2); roboEyes.setMood(DEFAULT); break; - } + } } + roboEyes.setSweat(isTired); if (isSleepy != wasSleepy) { @@ -218,10 +232,11 @@ void rgbTask(void * pvParameters) { for(;;) { if (currentState != lastAction) { switch(currentState) { - case E_HAPPY: rgb.fadeColor(255, 250, 0, 500); break; - case E_SAD: rgb.fadeColor(118, 116, 237, 500); break; - case E_ANGRY: rgb.fadeColor(255, 0, 0, 500); break; - default: rgb.fadeColor(0, 0, 0, 500); break; + case E_HAPPY: rgb.fadeColor(255, 250, 0, 300); break; + case E_SAD: rgb.fadeColor(118, 116, 237, 300); break; + case E_CURIOUS: rgb.setColorRGB(0, 0, 255, 300); break; + case E_ANGRY: rgb.fadeColor(255, 0, 0, 300); break; + default: rgb.fadeColor(0, 0, 0, 300); break; } lastAction = currentState; } @@ -246,6 +261,9 @@ void rgbTask(void * pvParameters) { rgb.setBrightness(40); rgb.rainbowCycle(1000, 2); break; + case E_CURIOUS: + rgb.setBrightness(80); + break; case E_SAD: rgb.setBrightness(40); break; @@ -281,9 +299,18 @@ void motorsTask(void * pvParameters) { motors.leftTurn(100, 130); motors.rightTurn(100, 130); break; + case E_CURIOUS: + motors.leftTurn(100, 150); + vTaskDelay(1000 / portTICK_PERIOD_MS); + motors.rightTurn(100, 300); + vTaskDelay(2500 / portTICK_PERIOD_MS); + motors.leftTurn(100, 150); + motors.stop(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + break; case E_ANGRY: - motors.forward(100, 130); - motors.backward(100, 130); + motors.forward(100, 80); + motors.backward(100, 80); break; default: motors.stop(); -- cgit v1.2.3