From e72595e73999e6c1fd78cc145747990ec3123369 Mon Sep 17 00:00:00 2001 From: hhau Date: Sat, 25 Nov 2023 15:35:58 +0100 Subject: [PATCH 01/20] chg: dev: added method Declarations for MultiColorLight --- example/example.ino | 2 +- src/Dezibot.cpp | 2 +- src/multiColorLight/MultiColorLight.cpp | 31 ++++++++ src/multiColorLight/MultiColorLight.h | 96 ++++++++++++++++++++++++- 4 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 src/multiColorLight/MultiColorLight.cpp diff --git a/example/example.ino b/example/example.ino index 8999e5a..de6830f 100644 --- a/example/example.ino +++ b/example/example.ino @@ -1,4 +1,4 @@ -#include + #include #define GPIO_LED 48 diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index 3285444..5440a38 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -54,7 +54,7 @@ void Dezibot::begin(void) { while (1) { /* Blink off (output low) */ - ledStrip.setPixelColor(1, ledStrip.Color(100, 100, 100)); + ledStrip.setPixelColor(1, ledStrip.Color(100, 0, 0)); ledStrip.show(); // Aktualisiere die Farbe des Pixels vTaskDelay(1000); /* Blink on (output high) */ diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp new file mode 100644 index 0000000..f7ee1f4 --- /dev/null +++ b/src/multiColorLight/MultiColorLight.cpp @@ -0,0 +1,31 @@ +#include "MultiColorLight.h" + +void MultiColorLight::begin(void){ + +}; + +void MultiColorLight::setLed(uint8_t index , uint32_t color){ + +}; + + +void MultiColorLight::setLed(leds leds, uint32_t color){ + +}; + + +void MultiColorLight::setTopLeds(uint32_t color){ + +}; + +void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){ + +}; + +void MultiColorLight::turnOff(leds leds){ + +}; + +uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){ + return 0; +}; \ No newline at end of file diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index 70ea391..9231d7b 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -1,6 +1,100 @@ +/** + * @file MultiColorLight.h + * @author Saskia Duebener, Hans Haupt + * @brief This component controls the ability to show multicolored light, using the RGB-LEDs + * @version 0.1 + * @date 2023-11-25 + * + * @copyright Copyright (c) 2023 + * + */ #ifndef MultiColorLight_h #define MultiColorLight_h -class MultiColorLight{ +#include +/** + * @brief Describes combinations of leds on the Dezibot. + * With the Robot in Front of you, if you can read the Dezibotlogo, the LED left from the Logo is TOP_LEFT + * + */ +enum leds{ + TOP_LEFT, + TOP_RIGHT, + BOTTOM, + TOP, + ALL }; + +class MultiColorLight{ +public: + + /** + * @brief initialize the multicolor component + * + */ + void begin(void); + + /** + * @brief Set the specified led to the passed color + * @param index ranging from 0-2, 0: Left, 1: Right, 2: Bottom + * @param color A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. Each color can range between 0 to 100 + */ + void setLed(uint8_t index , uint32_t color); + + /** + * @brief Set the specified leds to the passed color value + * + * @param leds which leds should be updated + * @param color A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. Each color can range between 0 to 100 + */ + void setLed(leds leds, uint32_t color); + + /** + * @brief sets the two leds on the top of the robot to the specified color + * + * @param color A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. Each color can range between 0 to 100 + */ + void setTopLeds(uint32_t color); + + /** + * @brief Let LEDs blink, returns after all blinks were executed + * + * @param amount how often should the leds blink + * @param color A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. + * Each color can range between 0 to 100 + * Defaults to blue + * @param leds which LEDs should blink, default is TOP + * @param interval how many miliseconds the led is on, defaults to 1s + */ + void blink(uint16_t amount,uint32_t color = 0x00006400,leds leds=TOP, uint32_t interval=1000); + + /** + * @brief turn off the given leds + * + * @param leds which leds should be turned off, defaults to ALL + */ + void turnOff(leds leds=ALL); + + /** + * @brief wrapper to calulate the used colorformat from a rgb-value + * + * @param r red (0-100) + * @param g green (0-100) + * @param b blue (0-100) + * @return A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. + */ + uint32_t color(uint8_t r, uint8_t g, uint8_t b); + +}; + #endif //MultiColorLight_h \ No newline at end of file From 1b330e15206287ab7872e83608673643245c9497 Mon Sep 17 00:00:00 2001 From: hhau Date: Sun, 26 Nov 2023 11:28:17 +0100 Subject: [PATCH 02/20] chg: dev: first version of multiColorLight implemeted --- example/example.ino | 11 +-- src/Dezibot.cpp | 90 ++++--------------------- src/Dezibot.h | 1 + src/multiColorLight/MultiColorLight.cpp | 78 +++++++++++++++++++-- src/multiColorLight/MultiColorLight.h | 22 +++++- 5 files changed, 115 insertions(+), 87 deletions(-) diff --git a/example/example.ino b/example/example.ino index de6830f..7076d96 100644 --- a/example/example.ino +++ b/example/example.ino @@ -1,13 +1,16 @@ - #include -#define GPIO_LED 48 - Dezibot dezibot = Dezibot(); - +const uint8_t MYFOO = 10; void setup() { dezibot.begin(); + } void loop() { +dezibot.multiColorLight.setLed(TOP_LEFT,0x000000FF); +dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0)); +dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500); + +delay(1000); } diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index 5440a38..dc1dcb7 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -1,82 +1,20 @@ -// -// Created by Anton Jacker on 24.11.23. -// +/** + * @file Dezibot.cpp + * @author Anton Jacker, Hans Haupt, Saskia Duebener + * @brief + * @version 0.1 + * @date 2023-11-26 + * + * @copyright Copyright (c) 2023 + * + */ #include "Dezibot.h" -#include -#include -#include -#include +Dezibot::Dezibot():multiColorLight(){ -#define SCREEN_WIDTH 128 // OLED display width, in pixels -#define SCREEN_HEIGHT 64 // OLED display height, in pixels - -// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) -// The pins for I2C are defined by the Wire-library. -// On an arduino UNO: A4(SDA), A5(SCL) -// On an arduino MEGA 2560: 20(SDA), 21(SCL) -// On an arduino LEONARDO: 2(SDA), 3(SCL), ... -#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) -#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 - -Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); - -#define GPIO_LED 48 - +}; void Dezibot::begin(void) { - Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(3, GPIO_LED, NEO_GRB + NEO_KHZ800); - Wire.begin(1, 2); - if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { - Serial.println("SSD1306 allocation failed"); - for (;;); // Don't proceed, loop forever - } - - display.display(); - vTaskDelay(2000); - display.clearDisplay(); - vTaskDelay(2000); - - // Draw a single pixel in white - display.drawPixel(10, 10, SSD1306_WHITE); - - // Show the display buffer on the screen. You MUST call display() after - // drawing commands to make them visible on screen! - display.display(); - vTaskDelay(2000); - - Serial.begin(9600); - Serial.println("start"); - - - vTaskDelay(1000); - - while (1) { - /* Blink off (output low) */ - ledStrip.setPixelColor(1, ledStrip.Color(100, 0, 0)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - /* Blink on (output high) */ - ledStrip.setPixelColor(1, ledStrip.Color(0, 0, 0)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - int64_t time_us = (int64_t) tv_now.tv_sec * 1000000L + (int64_t) tv_now.tv_usec; - - - Serial.println(time_us); - - display.clearDisplay(); - - display.setTextSize(2); // Draw 2X-scale text - display.setTextColor(SSD1306_WHITE); - display.setCursor(10, 0); - display.println(F("scroll")); - display.display(); // Show initial text - vTaskDelay(1000); - - } -} \ No newline at end of file + multiColorLight.begin(); +}; diff --git a/src/Dezibot.h b/src/Dezibot.h index 07fe014..50fcca6 100644 --- a/src/Dezibot.h +++ b/src/Dezibot.h @@ -21,6 +21,7 @@ class Dezibot { protected: public: + Dezibot(); Motion motion; LightDetection lightDetection; ColorDetection colorDetection; diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index f7ee1f4..1b215cd 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -1,31 +1,97 @@ #include "MultiColorLight.h" -void MultiColorLight::begin(void){ +MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){ }; -void MultiColorLight::setLed(uint8_t index , uint32_t color){ +void MultiColorLight::begin(void){ + rgbLeds.begin(); +}; +void MultiColorLight::setLed(uint8_t index , uint32_t color){ + if (index > ledAmount-1){ + //TODO: logging + } + rgbLeds.setPixelColor(index, normalizeColor(color)); + rgbLeds.show(); }; void MultiColorLight::setLed(leds leds, uint32_t color){ + switch (leds){ + case TOP_LEFT: + MultiColorLight::setLed(0,color);break; + case TOP_RIGHT: + MultiColorLight::setLed(1,color);break; + case BOTTOM: + MultiColorLight::setLed(2,color);break; + case TOP: + for (int index = 0; index<2; index++){ + MultiColorLight::setLed(index,color); + }break; + case ALL: + for (int index = 0; index<3; index++){ + MultiColorLight::setLed(index,color); + }break; + default: + //TODO logging + break; + } }; void MultiColorLight::setTopLeds(uint32_t color){ - + MultiColorLight::setLed(TOP,color); }; void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){ + for(uint16_t index = 0; index < amount;index++){ + MultiColorLight::setLed(leds, color); + vTaskDelay(interval); + MultiColorLight::turnOff(leds); + vTaskDelay(interval); + } }; void MultiColorLight::turnOff(leds leds){ - + switch (leds){ + case TOP_LEFT: + MultiColorLight::setLed(0,0);break; + case TOP_RIGHT: + MultiColorLight::setLed(1,0);break; + case BOTTOM: + MultiColorLight::setLed(2,0);break; + case TOP: + for (int index = 0; index<2; index++){ + MultiColorLight::setLed(index,0); + }break; + case ALL: + rgbLeds.clear();break; + default: + //TODO logging + break; + } }; uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){ - return 0; -}; \ No newline at end of file + return rgbLeds.Color(r,g,b); +}; + +//PRIVATE +uint32_t MultiColorLight::normalizeColor(uint32_t color,uint8_t maxBrightness){ + uint8_t red = (color&0x00FF0000)>>16; + uint8_t green = (color&0x0000FF00)>>8; + uint8_t blue = (color&0x000000FF); + if (red > maxBrightness){ + red = maxBrightness; + } + if(green > maxBrightness){ + green = maxBrightness; + } + if(blue > maxBrightness){ + blue = maxBrightness; + } + return MultiColorLight::color(red,green,blue); +} \ No newline at end of file diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index 9231d7b..abe3622 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -26,8 +26,14 @@ enum leds{ }; class MultiColorLight{ +protected: + static const uint16_t ledAmount = 3; + static const int16_t ledPin = 48; + static const uint8_t maxBrightness = 100; + Adafruit_NeoPixel rgbLeds; public: + MultiColorLight(); /** * @brief initialize the multicolor component * @@ -94,7 +100,21 @@ public: * component, and BB is the blue component. */ uint32_t color(uint8_t r, uint8_t g, uint8_t b); - + +private: + /** + * @brief normalizes every component of color to not exeed the maxBrightness + * + * @param color A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. + * @param maxBrigthness maximal level of brightness that is allowed for each color + * @return uint32_t A 32-bit unsigned integer representing the color in the format + * 0x00RRGGBB, where RR is the red component, GG is the green + * component, and BB is the blue component. Where each component can be + * between 0 - maxBrightness + */ + uint32_t normalizeColor(uint32_t color, uint8_t maxBrigthness=maxBrightness); }; #endif //MultiColorLight_h \ No newline at end of file From 4546330c15cc61440876ababdd7ded100db40e40 Mon Sep 17 00:00:00 2001 From: hhau Date: Sun, 26 Nov 2023 11:34:24 +0100 Subject: [PATCH 03/20] fix: dev: bug int turnOff(ALL) fixed --- example/example.ino | 2 ++ src/multiColorLight/MultiColorLight.cpp | 4 +++- src/multiColorLight/MultiColorLight.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/example/example.ino b/example/example.ino index 7076d96..f055251 100644 --- a/example/example.ino +++ b/example/example.ino @@ -12,5 +12,7 @@ dezibot.multiColorLight.setLed(TOP_LEFT,0x000000FF); dezibot.multiColorLight.setLed(TOP_RIGHT,dezibot.multiColorLight.color(0,100,0)); dezibot.multiColorLight.blink(10,0x00FF0000,BOTTOM,500); +delay(1000); +dezibot.multiColorLight.turnOff(ALL); delay(1000); } diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index 1b215cd..8439256 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -68,7 +68,9 @@ void MultiColorLight::turnOff(leds leds){ MultiColorLight::setLed(index,0); }break; case ALL: - rgbLeds.clear();break; + for (int index = 0; index<3; index++){ + MultiColorLight::setLed(index,0); + }break; default: //TODO logging break; diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index abe3622..6a8580d 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -2,7 +2,7 @@ * @file MultiColorLight.h * @author Saskia Duebener, Hans Haupt * @brief This component controls the ability to show multicolored light, using the RGB-LEDs - * @version 0.1 + * @version 0.2 * @date 2023-11-25 * * @copyright Copyright (c) 2023 From 11ac0494d537c7fe1f436a6a5cba502a20578ba0 Mon Sep 17 00:00:00 2001 From: hhau Date: Tue, 5 Dec 2023 23:59:39 +0100 Subject: [PATCH 04/20] chg: dev: added colorconstants --- src/multiColorLight/ColorConstants.h | 9 +++++++++ src/multiColorLight/MultiColorLight.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/multiColorLight/ColorConstants.h diff --git a/src/multiColorLight/ColorConstants.h b/src/multiColorLight/ColorConstants.h new file mode 100644 index 0000000..f180f5e --- /dev/null +++ b/src/multiColorLight/ColorConstants.h @@ -0,0 +1,9 @@ +static const uint32_t RED = 0xFF0000; +static const uint32_t GREEN = 0x00FF00; +static const uint32_t BLUE = 0x0000FF; +static const uint32_t WHITE = 0xFFFFFF; +static const uint32_t ORANGE = 0x961E00; +static const uint32_t YELLOW = 0x965000; +static const uint32_t TURQUOISE = 0x005064; +static const uint32_t PURPEL = 0x320064; +static const uint32_t PINK = 0x960064; diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index 6a8580d..ecfcadb 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -11,7 +11,7 @@ #ifndef MultiColorLight_h #define MultiColorLight_h #include - +#include "ColorConstants.h" /** * @brief Describes combinations of leds on the Dezibot. * With the Robot in Front of you, if you can read the Dezibotlogo, the LED left from the Logo is TOP_LEFT From 4be496759f7b3c7fdd1eddb4981672ca6e54fb57 Mon Sep 17 00:00:00 2001 From: hhau Date: Wed, 6 Dec 2023 00:02:09 +0100 Subject: [PATCH 05/20] fix: dev: switched left and right leds --- src/multiColorLight/MultiColorLight.cpp | 6 +++++- src/multiColorLight/MultiColorLight.h | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index 8439256..02adaa2 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -20,6 +20,8 @@ void MultiColorLight::setLed(uint8_t index , uint32_t color){ void MultiColorLight::setLed(leds leds, uint32_t color){ switch (leds){ case TOP_LEFT: + MultiColorLight::setLed(1,color);break; + case TOP_RIGHT: MultiColorLight::setLed(0,color);break; case TOP_RIGHT: MultiColorLight::setLed(1,color);break; @@ -30,7 +32,7 @@ void MultiColorLight::setLed(leds leds, uint32_t color){ MultiColorLight::setLed(index,color); }break; case ALL: - for (int index = 0; index<3; index++){ + for (int index = 0; index Date: Wed, 6 Dec 2023 00:04:16 +0100 Subject: [PATCH 06/20] fix: dev: implemented different maxBrightness for the different colors --- src/multiColorLight/MultiColorLight.cpp | 8 ++++---- src/multiColorLight/MultiColorLight.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index 02adaa2..985b35a 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -93,11 +93,11 @@ uint32_t MultiColorLight::normalizeColor(uint32_t color,uint8_t maxBrightness){ if (red > maxBrightness){ red = maxBrightness; } - if(green > maxBrightness){ - green = maxBrightness; + if(green > maxBrightness-70){ + green = maxBrightness-70; } - if(blue > maxBrightness){ - blue = maxBrightness; + if(blue > maxBrightness-50){ + blue = maxBrightness-50; } return MultiColorLight::color(red,green,blue); } \ No newline at end of file diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index f611d7a..52ee75d 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -29,7 +29,7 @@ class MultiColorLight{ protected: static const uint16_t ledAmount = 3; static const int16_t ledPin = 48; - static const uint8_t maxBrightness = 100; + static const uint8_t maxBrightness = 150; Adafruit_NeoPixel rgbLeds; public: From b12e07539b801649f206a7a35b33e8988b0f4b75 Mon Sep 17 00:00:00 2001 From: hhau Date: Wed, 6 Dec 2023 00:06:10 +0100 Subject: [PATCH 07/20] chg: dev: add wrapper for setLED that takes three color arguments --- src/multiColorLight/MultiColorLight.cpp | 8 ++++++++ src/multiColorLight/MultiColorLight.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index 985b35a..f8d3a4d 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -42,11 +42,19 @@ void MultiColorLight::setLed(leds leds, uint32_t color){ }; +void MultiColorLight::setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue){ + MultiColorLight::setLed(leds, MultiColorLight::color(red,green,blue)); +}; + void MultiColorLight::setTopLeds(uint32_t color){ MultiColorLight::setLed(TOP,color); }; +void MultiColorLight::setTopLeds(uint8_t red, uint8_t green, uint8_t blue){ + MultiColorLight::setTopLeds(MultiColorLight::color(red,green,blue)); +}; + void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t interval){ for(uint16_t index = 0; index < amount;index++){ MultiColorLight::setLed(leds, color); diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index 52ee75d..ce9ba5c 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -59,6 +59,16 @@ public: */ void setLed(leds leds, uint32_t color); + /** + * @brief Set the specified leds to the passed color value + * + * @param leds which leds should be updated + * @param red brightness of red, is normalized in the function + * @param green brightness of green, is normalized in the function + * @param blue brightness of blue, is normalized in the function + */ + void setLed(leds leds, uint8_t red, uint8_t green, uint8_t blue); + /** * @brief sets the two leds on the top of the robot to the specified color * @@ -68,6 +78,15 @@ public: */ void setTopLeds(uint32_t color); + /** + * @brief sets the two leds on the top of the robot to the specified color + * + * @param red brightness of red, is normalized in the function + * @param green brightness of green, is normalized in the function + * @param blue brightness of blue, is normalized in the function + */ + void setTopLeds(uint8_t red, uint8_t green, uint8_t blue); + /** * @brief Let LEDs blink, returns after all blinks were executed * From 31f4a2b2816087ab3cb0c9c21c671e3d3c7e6dde Mon Sep 17 00:00:00 2001 From: hhau Date: Wed, 6 Dec 2023 00:08:55 +0100 Subject: [PATCH 08/20] fix: dev: equalized naming of functions in MultiColorLight --- src/multiColorLight/MultiColorLight.cpp | 8 ++------ src/multiColorLight/MultiColorLight.h | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/multiColorLight/MultiColorLight.cpp b/src/multiColorLight/MultiColorLight.cpp index f8d3a4d..f0235a4 100644 --- a/src/multiColorLight/MultiColorLight.cpp +++ b/src/multiColorLight/MultiColorLight.cpp @@ -23,8 +23,6 @@ void MultiColorLight::setLed(leds leds, uint32_t color){ MultiColorLight::setLed(1,color);break; case TOP_RIGHT: MultiColorLight::setLed(0,color);break; - case TOP_RIGHT: - MultiColorLight::setLed(1,color);break; case BOTTOM: MultiColorLight::setLed(2,color);break; case TOP: @@ -59,20 +57,18 @@ void MultiColorLight::blink(uint16_t amount,uint32_t color, leds leds, uint32_t for(uint16_t index = 0; index < amount;index++){ MultiColorLight::setLed(leds, color); vTaskDelay(interval); - MultiColorLight::turnOff(leds); + MultiColorLight::turnOffLed(leds); vTaskDelay(interval); } }; -void MultiColorLight::turnOff(leds leds){ +void MultiColorLight::turnOffLed(leds leds){ switch (leds){ case TOP_LEFT: MultiColorLight::setLed(1,0);break; case TOP_RIGHT: MultiColorLight::setLed(0,0);break; - case TOP_RIGHT: - MultiColorLight::setLed(1,0);break; case BOTTOM: MultiColorLight::setLed(2,0);break; case TOP: diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index ce9ba5c..44498cf 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -58,7 +58,7 @@ public: * component, and BB is the blue component. Each color can range between 0 to 100 */ void setLed(leds leds, uint32_t color); - + /** * @brief Set the specified leds to the passed color value * @@ -77,7 +77,7 @@ public: * component, and BB is the blue component. Each color can range between 0 to 100 */ void setTopLeds(uint32_t color); - + /** * @brief sets the two leds on the top of the robot to the specified color * @@ -106,7 +106,7 @@ public: * * @param leds which leds should be turned off, defaults to ALL */ - void turnOff(leds leds=ALL); + void turnOffLed(leds leds=ALL); /** * @brief wrapper to calulate the used colorformat from a rgb-value From 68883dadb8c3a9de2cb2e1f3218ec2bcb0072cb4 Mon Sep 17 00:00:00 2001 From: n1i9c9k9 Date: Wed, 13 Dec 2023 12:29:44 +0100 Subject: [PATCH 09/20] functions to implement --- src/motion/Motion.h | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/motion/Motion.h b/src/motion/Motion.h index 99cb603..16353d8 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -1,7 +1,48 @@ +/** + * @file Motion.h + * @author Jonathan Schulze, Nick Hübenthal + * @brief This component controls the ability to rotate and change position. + * @version 0.1 + * @date 2023-12-13 + * + * @copyright Copyright (c) 2023 + * + */ + #ifndef Motion_h #define Motion_h class Motion{ +protected: + +public: + Motion(); + + /** + * @brief Initialize the movement component. + * + */ + void begin(void); + + /** + * @brief Move forward for a certain amount of time. + * @param moveForMs Representing the duration of forward moving in milliseconds. + */ + void move(u8int moveForMs); + + /** + * @brief Rotate left for a certain amount of time. + * @param rotateForMs Representing the duration of rotating left in milliseconds. + */ + void rotateLeft(u8int rotateForMs); + + /** + * @brief Rotate right for a certain amount of time. + * @param rotateForMs Representing the duration of rotating right in milliseconds. + */ + void rotateRight(u8int rotateForMs); }; -#endif //Motion_h \ No newline at end of file +#endif //Motion_h + + From 0d1854c8d7db2ca6be588117d4639d29290f8669 Mon Sep 17 00:00:00 2001 From: n1i9c9k9 Date: Wed, 13 Dec 2023 17:12:02 +0100 Subject: [PATCH 10/20] suggestion for motion.h --- src/motion/Motion.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/motion/Motion.h b/src/motion/Motion.h index 16353d8..7199ef7 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -28,21 +28,19 @@ public: * @brief Move forward for a certain amount of time. * @param moveForMs Representing the duration of forward moving in milliseconds. */ - void move(u8int moveForMs); + void move(uint8_t moveForMs); /** * @brief Rotate left for a certain amount of time. * @param rotateForMs Representing the duration of rotating left in milliseconds. */ - void rotateLeft(u8int rotateForMs); + void rotateLeft(uint8_t rotateForMs); /** * @brief Rotate right for a certain amount of time. * @param rotateForMs Representing the duration of rotating right in milliseconds. */ - void rotateRight(u8int rotateForMs); + void rotateRight(uint8_t rotateForMs); }; -#endif //Motion_h - - +#endif //Motion_h \ No newline at end of file From 32f82557b3f2dadb377afd5a6c4df3393287506d Mon Sep 17 00:00:00 2001 From: n1i9c9k9 Date: Wed, 3 Jan 2024 11:37:58 +0100 Subject: [PATCH 11/20] changed int to 32 bits and method names --- src/motion/Motion.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/motion/Motion.h b/src/motion/Motion.h index 7199ef7..e0edb66 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -11,6 +11,8 @@ #ifndef Motion_h #define Motion_h +#include + class Motion{ protected: @@ -28,19 +30,19 @@ public: * @brief Move forward for a certain amount of time. * @param moveForMs Representing the duration of forward moving in milliseconds. */ - void move(uint8_t moveForMs); + void move(uint32_t moveForMs); /** - * @brief Rotate left for a certain amount of time. - * @param rotateForMs Representing the duration of rotating left in milliseconds. + * @brief Rotate clockwise for a certain amount of time. + * @param rotateForMs Representing the duration of rotating clockwise in milliseconds. */ - void rotateLeft(uint8_t rotateForMs); - + void rotateClockwise(uint32_t rotateForMs); + /** - * @brief Rotate right for a certain amount of time. - * @param rotateForMs Representing the duration of rotating right in milliseconds. + * @brief Rotate anticlockwise for a certain amount of time. + * @param rotateForMs Representing the duration of rotating anticlockwise in milliseconds. */ - void rotateRight(uint8_t rotateForMs); + void rotateAnticlockwise(uint32_t rotateForMs); }; #endif //Motion_h \ No newline at end of file From 4165afd578f098450bed3b71407c58a50c8b1888 Mon Sep 17 00:00:00 2001 From: 99cardz Date: Mon, 8 Jan 2024 15:37:39 +0100 Subject: [PATCH 12/20] implement move method --- src/motion/Motion.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/motion/Motion.h b/src/motion/Motion.h index e0edb66..7348769 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -13,11 +13,15 @@ #define Motion_h #include +const int MOTOR_RIGHT_PIN = 11; +const int MOTOR_LEFT_PIN = 12; + class Motion{ protected: public: + Motion(); /** From 8fa5de4b12f8927e8e7589b2997bb3c3af2ef52f Mon Sep 17 00:00:00 2001 From: 99cardz Date: Mon, 8 Jan 2024 15:37:52 +0100 Subject: [PATCH 13/20] implement move method --- src/motion/Motion.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/motion/Motion.cpp diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp new file mode 100644 index 0000000..028aed3 --- /dev/null +++ b/src/motion/Motion.cpp @@ -0,0 +1,41 @@ +/** + * @file Motion.cpp + * @author Jonathan Schulze, Nick Hübenthal + * @brief Implementation of the Motion class. + * @version 0.1 + * @date 2023-12-13 + * + * @copyright Copyright (c) 2023 + * + */ + +#include "Motion.h" + +// Constructor +Motion::Motion() { + +} + +// Initialize the movement component. +void Motion::begin(void) { + +} + +// Move forward for a certain amount of time. +void Motion::move(uint32_t moveForMs) { + analogWrite(MOTOR_LEFT_PIN, 128); + analogWrite(MOTOR_RIGHT_PIN, 128); + vTaskDelay(moveForMs); + analogWrite(MOTOR_LEFT_PIN, 0); + analogWrite(MOTOR_RIGHT_PIN, 0); +} + +// Rotate clockwise for a certain amount of time. +void Motion::rotateClockwise(uint32_t rotateForMs) { + +} + +// Rotate anticlockwise for a certain amount of time. +void Motion::rotateAnticlockwise(uint32_t rotateForMs) { + +} From f2253a7cb5e940e4707d35706b26a66e7298cc0f Mon Sep 17 00:00:00 2001 From: 99cardz Date: Mon, 8 Jan 2024 15:44:36 +0100 Subject: [PATCH 14/20] added Arduino and vtask imports --- src/motion/Motion.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/motion/Motion.h b/src/motion/Motion.h index 7348769..eb1eccc 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -12,6 +12,9 @@ #ifndef Motion_h #define Motion_h #include +#include +#include +#include const int MOTOR_RIGHT_PIN = 11; const int MOTOR_LEFT_PIN = 12; From e42058bb82f6d111c284cd129f2253fccd052e14 Mon Sep 17 00:00:00 2001 From: 99cardz Date: Mon, 8 Jan 2024 16:26:56 +0100 Subject: [PATCH 15/20] experimenting with xTaskCreate --- src/Dezibot.cpp | 54 +------------------------------------------ src/motion/Motion.cpp | 12 ++++++---- 2 files changed, 9 insertions(+), 57 deletions(-) diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index 3285444..38eb327 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -26,57 +26,5 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define GPIO_LED 48 void Dezibot::begin(void) { - Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(3, GPIO_LED, NEO_GRB + NEO_KHZ800); - Wire.begin(1, 2); - if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { - Serial.println("SSD1306 allocation failed"); - for (;;); // Don't proceed, loop forever - } - - display.display(); - vTaskDelay(2000); - display.clearDisplay(); - vTaskDelay(2000); - - // Draw a single pixel in white - display.drawPixel(10, 10, SSD1306_WHITE); - - // Show the display buffer on the screen. You MUST call display() after - // drawing commands to make them visible on screen! - display.display(); - vTaskDelay(2000); - - Serial.begin(9600); - Serial.println("start"); - - - vTaskDelay(1000); - - while (1) { - /* Blink off (output low) */ - ledStrip.setPixelColor(1, ledStrip.Color(100, 100, 100)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - /* Blink on (output high) */ - ledStrip.setPixelColor(1, ledStrip.Color(0, 0, 0)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - int64_t time_us = (int64_t) tv_now.tv_sec * 1000000L + (int64_t) tv_now.tv_usec; - - - Serial.println(time_us); - - display.clearDisplay(); - - display.setTextSize(2); // Draw 2X-scale text - display.setTextColor(SSD1306_WHITE); - display.setCursor(10, 0); - display.println(F("scroll")); - display.display(); // Show initial text - vTaskDelay(1000); - - } + motion.begin(); } \ No newline at end of file diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp index 028aed3..d4c0113 100644 --- a/src/motion/Motion.cpp +++ b/src/motion/Motion.cpp @@ -20,16 +20,20 @@ Motion::Motion() { void Motion::begin(void) { } - -// Move forward for a certain amount of time. -void Motion::move(uint32_t moveForMs) { +void moveTask(void * moveForMs) { analogWrite(MOTOR_LEFT_PIN, 128); analogWrite(MOTOR_RIGHT_PIN, 128); - vTaskDelay(moveForMs); + vTaskDelay((uint32_t) moveForMs); analogWrite(MOTOR_LEFT_PIN, 0); analogWrite(MOTOR_RIGHT_PIN, 0); } +// Move forward for a certain amount of time. +void Motion::move(uint32_t moveForMs) { + xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL); +} + + // Rotate clockwise for a certain amount of time. void Motion::rotateClockwise(uint32_t rotateForMs) { From 3d4b62438ea8f2f7128dfe1f03ed602f557a0dfe Mon Sep 17 00:00:00 2001 From: 99cardz Date: Wed, 10 Jan 2024 12:48:28 +0100 Subject: [PATCH 16/20] added arduino-cli commands to upload and compile --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b2fb3b1..c0d6b18 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,10 @@ For instance, in `src/Dezibot.h`, to include `src/motion/Motion.h`, you should w * USB Mode: "Hardware CDC and JTAG" * Programmer: "Esptool" +Using `arduino-cli` to compile and upload: +`arduino-cli upload /Users/jo/Documents/Arduino/theSketch -p /dev/cu.usbmodem101 -b esp32:esp32:nora_w10` +`arduino-cli compile /Users/jo/Documents/Arduino/theSketch -p /dev/cu.usbmodem101 -b esp32:esp32:nora_w10` + #### Display It is important to specify the SDA and SCL ports by using `Wire.begin(SDA, SCL)`. From 5a731e5fa418d3c7304bf2da657c93c2d5d735bd Mon Sep 17 00:00:00 2001 From: 99cardz Date: Wed, 10 Jan 2024 13:57:03 +0100 Subject: [PATCH 17/20] vTask Testing --- src/motion/Motion.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp index d4c0113..049a75d 100644 --- a/src/motion/Motion.cpp +++ b/src/motion/Motion.cpp @@ -31,6 +31,11 @@ void moveTask(void * moveForMs) { // Move forward for a certain amount of time. void Motion::move(uint32_t moveForMs) { xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL); + // analogWrite(MOTOR_LEFT_PIN, 128); + // analogWrite(MOTOR_RIGHT_PIN, 128); + // vTaskDelay(moveForMs); + // analogWrite(MOTOR_LEFT_PIN, 0); + // analogWrite(MOTOR_RIGHT_PIN, 0); } From fb3b4211d5a6ddfd3a40bd1ec49686b909ee7a8f Mon Sep 17 00:00:00 2001 From: 99cardz Date: Wed, 10 Jan 2024 15:56:26 +0100 Subject: [PATCH 18/20] tasks working now --- src/motion/Motion.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp index 049a75d..5244d24 100644 --- a/src/motion/Motion.cpp +++ b/src/motion/Motion.cpp @@ -11,6 +11,10 @@ #include "Motion.h" +TaskHandle_t xMoveTaskHandle = NULL; +TaskHandle_t xClockwiseTaskHandle = NULL; +TaskHandle_t xAntiClockwiseTaskHandle = NULL; + // Constructor Motion::Motion() { @@ -20,31 +24,40 @@ Motion::Motion() { void Motion::begin(void) { } -void moveTask(void * moveForMs) { +void moveTask(void * args) { analogWrite(MOTOR_LEFT_PIN, 128); analogWrite(MOTOR_RIGHT_PIN, 128); - vTaskDelay((uint32_t) moveForMs); + vTaskDelay((uint32_t) args / portTICK_PERIOD_MS); analogWrite(MOTOR_LEFT_PIN, 0); analogWrite(MOTOR_RIGHT_PIN, 0); + vTaskDelete(xMoveTaskHandle); } // Move forward for a certain amount of time. void Motion::move(uint32_t moveForMs) { - xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL); - // analogWrite(MOTOR_LEFT_PIN, 128); - // analogWrite(MOTOR_RIGHT_PIN, 128); - // vTaskDelay(moveForMs); - // analogWrite(MOTOR_LEFT_PIN, 0); - // analogWrite(MOTOR_RIGHT_PIN, 0); + xTaskCreate(moveTask, "Move", 4096, (void*)moveForMs, 10, &xMoveTaskHandle); } +void leftMotorTask(void * args) { + analogWrite(MOTOR_LEFT_PIN, 128); + vTaskDelay((uint32_t) args / portTICK_PERIOD_MS); + analogWrite(MOTOR_LEFT_PIN, 0); + vTaskDelete(xClockwiseTaskHandle); +} // Rotate clockwise for a certain amount of time. void Motion::rotateClockwise(uint32_t rotateForMs) { + xTaskCreate(leftMotorTask, "LeftMotor", 4096, (void*)rotateForMs, 10, &xClockwiseTaskHandle); +} +void rightMotorTask(void * args) { + analogWrite(MOTOR_RIGHT_PIN, 128); + vTaskDelay((uint32_t) args / portTICK_PERIOD_MS); + analogWrite(MOTOR_RIGHT_PIN, 0); + vTaskDelete(xAntiClockwiseTaskHandle); } // Rotate anticlockwise for a certain amount of time. void Motion::rotateAnticlockwise(uint32_t rotateForMs) { - + xTaskCreate(rightMotorTask, "RightMotor", 4096, (void*)rotateForMs, 10, &xAntiClockwiseTaskHandle); } From b8474815c0b4a1a54622c5f8ea862672c822e778 Mon Sep 17 00:00:00 2001 From: 99cardz Date: Tue, 6 Feb 2024 13:33:56 +0100 Subject: [PATCH 19/20] add example sketch --- example/motion.ino | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 example/motion.ino diff --git a/example/motion.ino b/example/motion.ino new file mode 100644 index 0000000..2bdfd47 --- /dev/null +++ b/example/motion.ino @@ -0,0 +1,18 @@ +#include +Dezibot dezibot = Dezibot(); +void setup() { + dezibot.begin(); + Serial.begin(9600); +} +void loop() { + Serial.println("bla"); + dezibot.motion.move(1000); + dezibot.multiColorLight.setLed(BOTTOM, RED); + delay(2000); dezibot.motion.rotateAnticlockwise(1000); + dezibot.multiColorLight.setLed(BOTTOM, GREEN); + delay(2000); dezibot.motion.rotateClockwise(1000); + dezibot.multiColorLight.setLed(BOTTOM, BLUE); + delay(2000); + dezibot.multiColorLight.turnOffLed(); + delay(2000); +} \ No newline at end of file From 45977c95b9018e6741e751bbf6af7f306f6b2c32 Mon Sep 17 00:00:00 2001 From: 99cardz Date: Tue, 6 Feb 2024 13:34:23 +0100 Subject: [PATCH 20/20] formatting --- example/motion.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example/motion.ino b/example/motion.ino index 2bdfd47..e1f6d37 100644 --- a/example/motion.ino +++ b/example/motion.ino @@ -8,9 +8,11 @@ void loop() { Serial.println("bla"); dezibot.motion.move(1000); dezibot.multiColorLight.setLed(BOTTOM, RED); - delay(2000); dezibot.motion.rotateAnticlockwise(1000); + delay(2000); + dezibot.motion.rotateAnticlockwise(1000); dezibot.multiColorLight.setLed(BOTTOM, GREEN); - delay(2000); dezibot.motion.rotateClockwise(1000); + delay(2000); + dezibot.motion.rotateClockwise(1000); dezibot.multiColorLight.setLed(BOTTOM, BLUE); delay(2000); dezibot.multiColorLight.turnOffLed();