mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-21 20:11:46 +02:00
Merge remote-tracking branch 'origin/feature/#5-motion' into feature/#16-find-a-friend
This commit is contained in:
commit
8cb33e3096
@ -137,6 +137,10 @@ For instance, in `src/Dezibot.h`, to include `src/motion/Motion.h`, you should w
|
||||
* Programmer: "Esptool"
|
||||
* USB CDC on Boot: Enabled
|
||||
|
||||
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)`.
|
||||
|
@ -1,13 +1,18 @@
|
||||
#include <Dezibot.h>
|
||||
|
||||
Dezibot dezibot = Dezibot();
|
||||
|
||||
const uint8_t MYFOO = 10;
|
||||
void setup() {
|
||||
dezibot.begin();
|
||||
dezibot.infraredLight.front.turnOn();
|
||||
dezibot.infraredLight.bottom.turnOn();
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
dezibot.multiColorLight.turnOff(ALL);
|
||||
delay(1000);
|
||||
}
|
||||
|
20
example/motion.ino
Normal file
20
example/motion.ino
Normal file
@ -0,0 +1,20 @@
|
||||
#include <Dezibot.h>
|
||||
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);
|
||||
}
|
@ -1,12 +1,24 @@
|
||||
//
|
||||
// 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"
|
||||
|
||||
Dezibot::Dezibot():multiColorLight(){
|
||||
|
||||
void Dezibot::begin(void) {
|
||||
infraredLight.begin();
|
||||
lightDetection.begin();
|
||||
}
|
||||
motion.begin();
|
||||
multiColorLight.begin();
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -23,6 +23,7 @@ class Dezibot {
|
||||
protected:
|
||||
|
||||
public:
|
||||
Dezibot();
|
||||
Motion motion;
|
||||
LightDetection lightDetection;
|
||||
ColorDetection colorDetection;
|
||||
|
63
src/motion/Motion.cpp
Normal file
63
src/motion/Motion.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @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"
|
||||
|
||||
TaskHandle_t xMoveTaskHandle = NULL;
|
||||
TaskHandle_t xClockwiseTaskHandle = NULL;
|
||||
TaskHandle_t xAntiClockwiseTaskHandle = NULL;
|
||||
|
||||
// Constructor
|
||||
Motion::Motion() {
|
||||
|
||||
}
|
||||
|
||||
// Initialize the movement component.
|
||||
void Motion::begin(void) {
|
||||
|
||||
}
|
||||
void moveTask(void * args) {
|
||||
analogWrite(MOTOR_LEFT_PIN, 128);
|
||||
analogWrite(MOTOR_RIGHT_PIN, 128);
|
||||
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", 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);
|
||||
}
|
@ -1,7 +1,55 @@
|
||||
/**
|
||||
* @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
|
||||
#include <stdint.h>
|
||||
#include <Arduino.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
const int MOTOR_RIGHT_PIN = 11;
|
||||
const int MOTOR_LEFT_PIN = 12;
|
||||
|
||||
|
||||
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(uint32_t moveForMs);
|
||||
|
||||
/**
|
||||
* @brief Rotate clockwise for a certain amount of time.
|
||||
* @param rotateForMs Representing the duration of rotating clockwise in milliseconds.
|
||||
*/
|
||||
void rotateClockwise(uint32_t rotateForMs);
|
||||
|
||||
/**
|
||||
* @brief Rotate anticlockwise for a certain amount of time.
|
||||
* @param rotateForMs Representing the duration of rotating anticlockwise in milliseconds.
|
||||
*/
|
||||
void rotateAnticlockwise(uint32_t rotateForMs);
|
||||
|
||||
};
|
||||
#endif //Motion_h
|
9
src/multiColorLight/ColorConstants.h
Normal file
9
src/multiColorLight/ColorConstants.h
Normal file
@ -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;
|
107
src/multiColorLight/MultiColorLight.cpp
Normal file
107
src/multiColorLight/MultiColorLight.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
#include "MultiColorLight.h"
|
||||
|
||||
MultiColorLight::MultiColorLight():rgbLeds(ledAmount,ledPin){
|
||||
|
||||
};
|
||||
|
||||
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(1,color);break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0,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<ledAmount; index++){
|
||||
MultiColorLight::setLed(index,color);
|
||||
}break;
|
||||
default:
|
||||
//TODO logging
|
||||
break;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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);
|
||||
vTaskDelay(interval);
|
||||
MultiColorLight::turnOffLed(leds);
|
||||
vTaskDelay(interval);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void MultiColorLight::turnOffLed(leds leds){
|
||||
switch (leds){
|
||||
case TOP_LEFT:
|
||||
MultiColorLight::setLed(1,0);break;
|
||||
case TOP_RIGHT:
|
||||
MultiColorLight::setLed(0,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:
|
||||
for (int index = 0; index<3; index++){
|
||||
MultiColorLight::setLed(index,0);
|
||||
}break;
|
||||
default:
|
||||
//TODO logging
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
uint32_t MultiColorLight::color(uint8_t r, uint8_t g, uint8_t b){
|
||||
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-70){
|
||||
green = maxBrightness-70;
|
||||
}
|
||||
if(blue > maxBrightness-50){
|
||||
blue = maxBrightness-50;
|
||||
}
|
||||
return MultiColorLight::color(red,green,blue);
|
||||
}
|
@ -1,6 +1,139 @@
|
||||
/**
|
||||
* @file MultiColorLight.h
|
||||
* @author Saskia Duebener, Hans Haupt
|
||||
* @brief This component controls the ability to show multicolored light, using the RGB-LEDs
|
||||
* @version 0.2
|
||||
* @date 2023-11-25
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
#ifndef MultiColorLight_h
|
||||
#define MultiColorLight_h
|
||||
class MultiColorLight{
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "ColorConstants.h"
|
||||
/**
|
||||
* @brief Describes combinations of leds on the Dezibot.
|
||||
* With the Robot in Front of you, when the robot drives away from you, the left LED is TOP_LEFT
|
||||
*
|
||||
*/
|
||||
enum leds{
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
BOTTOM,
|
||||
TOP,
|
||||
ALL
|
||||
};
|
||||
|
||||
class MultiColorLight{
|
||||
protected:
|
||||
static const uint16_t ledAmount = 3;
|
||||
static const int16_t ledPin = 48;
|
||||
static const uint8_t maxBrightness = 150;
|
||||
Adafruit_NeoPixel rgbLeds;
|
||||
public:
|
||||
|
||||
MultiColorLight();
|
||||
/**
|
||||
* @brief initialize the multicolor component
|
||||
*
|
||||
*/
|
||||
void begin(void);
|
||||
|
||||
/**
|
||||
* @brief Set the specified led to the passed color
|
||||
* @param index ranging from 0-2, 0: Right, 1: Left, 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 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
|
||||
*
|
||||
* @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 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
|
||||
*
|
||||
* @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 turnOffLed(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);
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user