diff --git a/README.md b/README.md index 944a862..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)`. @@ -169,4 +173,3 @@ void Dezibot::begin(void) { vTaskDelay(2000); } ``` - diff --git a/example/example.ino b/example/example.ino deleted file mode 100644 index bf5898c..0000000 --- a/example/example.ino +++ /dev/null @@ -1,20 +0,0 @@ -#include "Dezibot.h" -Dezibot dezibot; -void setup() { - - dezibot.begin(); - dezibot.motionDetection.begin(); - //dezibot.motionDetection.end(); - // put your setup code here, to run once: - Serial.begin(115200); -} - -void loop() { - // put your main code here, to run repeatedly: - - //Serial.println(dezibot.motionDetection.getTemperature()); - Serial.println(dezibot.motionDetection.getAcceleration().z); - //Serial.println(dezibot.motionDetection.getRotation().x); - Serial.println(dezibot.motionDetection.getWhoAmI()); - delay(5000); -} diff --git a/example/example/example.ino b/example/example/example.ino new file mode 100644 index 0000000..e376753 --- /dev/null +++ b/example/example/example.ino @@ -0,0 +1,19 @@ +#include + +Dezibot dezibot = Dezibot(); +const uint8_t MYFOO = 10; +void setup() { + dezibot.begin(); + +} + +void loop() { +dezibot.motion.move(); +delay(1000); +dezibot.motion.rotateAntiClockwise(); +delay(1000); +dezibot.motion.rotateClockwise(); +delay(1000); +dezibot.motion.stop(); +delay(1000); +} diff --git a/example/motion/motion.ino b/example/motion/motion.ino new file mode 100644 index 0000000..e1f6d37 --- /dev/null +++ b/example/motion/motion.ino @@ -0,0 +1,20 @@ +#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 diff --git a/example/plain.cpp b/example/plain.cpp deleted file mode 100644 index c8fad0c..0000000 --- a/example/plain.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Dezibot.h" - -int main(){ - return 0; -} \ No newline at end of file diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index cf2084e..dec15f1 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -16,5 +16,6 @@ Dezibot::Dezibot():multiColorLight(),motionDetection(){ }; void Dezibot::begin(void) { + motion.begin(); multiColorLight.begin(); }; diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp new file mode 100644 index 0000000..e26df10 --- /dev/null +++ b/src/motion/Motion.cpp @@ -0,0 +1,81 @@ +/** + * @file Motion.cpp + * @author Jonathan Schulze, Nick Hübenthal, Hans Haupt + * @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; + +// Initialize the movement component. +void Motion::begin(void) { + +}; +void Motion::moveTask(void * args) { + analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY); + analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY); + 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) { + if (moveForMs > 0){ + xTaskCreate(moveTask, "Move", 4096, (void*)moveForMs, 10, &xMoveTaskHandle); + } else{ + analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY); + analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY); + } +}; + +void Motion::leftMotorTask(void * args) { + analogWrite(MOTOR_LEFT_PIN, LEFT_MOTOR_DUTY); + analogWrite(MOTOR_RIGHT_PIN, 0); + 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) { + if (rotateForMs > 0){ + xTaskCreate(leftMotorTask, "LeftMotor", 4096, (void*)rotateForMs, 10, &xClockwiseTaskHandle); + } else { + analogWrite(MOTOR_LEFT_PIN,LEFT_MOTOR_DUTY); + analogWrite(MOTOR_RIGHT_PIN,0); + } +}; + +void Motion::rightMotorTask(void * args) { + analogWrite(MOTOR_RIGHT_PIN, RIGHT_MOTOR_DUTY); + analogWrite(MOTOR_LEFT_PIN,0); + 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) { + if(rotateForMs > 0){ + xTaskCreate(rightMotorTask, "RightMotor", 4096, (void*)rotateForMs, 10, &xAntiClockwiseTaskHandle); + } else { + analogWrite(MOTOR_RIGHT_PIN,RIGHT_MOTOR_DUTY); + analogWrite(MOTOR_LEFT_PIN,0); + } +}; + +void Motion::stop(void){ + analogWrite(MOTOR_LEFT_PIN,0); + analogWrite(MOTOR_RIGHT_PIN,0); +} + diff --git a/src/motion/Motion.h b/src/motion/Motion.h index 99cb603..6fa3f66 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -1,7 +1,64 @@ +/** + * @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 +#include +#include +#include class Motion{ +protected: + static const uint8_t RIGHT_MOTOR_DUTY = 128; + static const uint8_t LEFT_MOTOR_DUTY = 128; + static const int MOTOR_RIGHT_PIN = 11; + static const int MOTOR_LEFT_PIN = 12; + static void moveTask(void * args); + static void leftMotorTask(void * args); + static void rightMotorTask(void * args); + +public: + /** + * @brief Initialize the movement component. + * + */ + void begin(void); + + /** + * @brief Move forward for a certain amount of time. + * Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop(). + * @param moveForMs Representing the duration of forward moving in milliseconds. + */ + static void move(uint32_t moveForMs=0); + + /** + * @brief Rotate clockwise for a certain amount of time. + * Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop(). + * @param rotateForMs Representing the duration of rotating clockwise in milliseconds. + */ + static void rotateClockwise(uint32_t rotateForMs=0); + + /** + * @brief Rotate anticlockwise for a certain amount of time. + * Call with moveForMs 0 will start movement, that must be stopped explicit by call to stop(). + * @param rotateForMs Representing the duration of rotating anticlockwise in milliseconds. + */ + static void rotateAntiClockwise(uint32_t rotateForMs=0); + + /** + * @brief stops any current movement, no matter if timebased or endless + * + */ + static void stop(void); }; #endif //Motion_h \ No newline at end of file