feature/servo_motor_component #17

Merged
Mathis merged 13 commits from feature/servo_motor_component into develop 2024-01-19 15:46:01 +00:00
7 changed files with 113 additions and 4 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"new": "cpp"
}
}

View File

@ -27,3 +27,8 @@ build_flags =
; nfc addr
-D NFC_ADDR=0x28
;;; Servo config ;;;
;;;;;;;;;;;;;;;;;;;;;;
-D RIGHT_POS=18
-D MIDDLE_POS=32
-D LEFT_POS=52

View File

@ -4,6 +4,7 @@
#include "Arduino.h"
#include "DolibarrClient.h"
#include <M5Stack.h>
#include "ServoMotorComponent.h"
class Program {
public:
@ -18,6 +19,7 @@ public:
void loop();
private:
DolibarrClient *client;
ServoMotorComponent *servo;
};
#endif

View File

@ -0,0 +1,59 @@
#include "ServoMotorComponent.h"
/////////////////////////////////////////////////////////////////////////////////////
// Functions for setting up the ServoMotor
/////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
* Prepares the ServoMotor.
*/
ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod, float step) {
this->PIN = PIN;
this->myservo.attach(PIN);
this->desiredposition = Position::MIDDLE;
this->currentPosition = MIDDLE_POS;

???

???
this->lastUpTime = millis();
this->updatePeriod = updatePeriod;
this->step = step;
this->myservo.write(this->PIN, this->currentPosition);

Nom des variables pas claire

Nom des variables pas claire
}
/**
* Set the desired position
* @desiredPosition: Give desired position
*/
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
switch (desiredPosition) {
case Position::LEFT:
this->desiredposition = LEFT_POS;
break;
case Position::MIDDLE:
this->desiredposition = MIDDLE_POS;
break;
case Position::RIGHT:
this->desiredposition = RIGHT_POS;
break;
default:
break;
}
}

Limite faire en sorte de pouvoir configurer le pas dans le constructeur (avec une valeur par défaut)
en double ou float

Limite faire en sorte de pouvoir configurer le pas dans le constructeur (avec une valeur par défaut) en double ou float
/**
* Write a new servoMotor position when it's necessary
*/
void ServoMotorComponent::refresh() {
Clement marked this conversation as resolved Outdated

typo ctrl C

typo ctrl C
if (this->desiredposition == this->currentPosition
|| millis() - this->lastUpTime <= this->updatePeriod) return;
if (this->currentPosition > this->desiredposition) {
this->currentPosition -= this->step;
Mathis marked this conversation as resolved Outdated

pas besoins car déja fait dans constructeur

pas besoins car déja fait dans constructeur
}
if (this->currentPosition < this->desiredposition) {
this->currentPosition += this->step;
}
this->lastUpTime = millis();
this->myservo.write(this->PIN, this->currentPosition);
}

View File

@ -0,0 +1,33 @@
#ifndef SERVOMOTOT_COMPONENT_H
#define SERVOMOTOT_COMPONENT_H
#include <Servo.h>
enum Position {
LEFT,
MIDDLE,
RIGHT
};
class ServoMotorComponent
Mathis marked this conversation as resolved Outdated

il n'y a pas d'interface

il n'y a pas d'interface
{
public:
ServoMotorComponent(int PIN, unsigned long updatePeriod, float step = 1);
void setDesiredPosition(Position desiredPosition);

tu peut viré le destructeur

tu peut viré le destructeur
void refresh();

met des commentaire doxygen sur tes fonction

met des commentaire doxygen sur tes fonction
private:
int PIN;
float currentPosition;
float desiredposition;
Servo myservo;
unsigned long lastUpTime;
unsigned long updatePeriod;
float step;
};
#endif //SERVOMOTOT_COMPONENT_H

View File

@ -55,6 +55,7 @@ lib_deps =
m5stack/M5Stack@^0.4.5 ; M5 Lib
m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD
m5stack/Module_GRBL_13.2@^0.0.3 ; M5 Lib pour Stepper (GRBL)
dlloydev/ESP32 ESP32S2 AnalogWrite ; Lib pour le Servo Motor
; example:
; erropix/ESP32 AnalogWrite@0.2

View File

@ -1,6 +1,7 @@
#include "Program.h"
#include "Arduino.h"
Review

vire tes changement dans Program.CPP avant de push

vire tes changement dans Program.CPP avant de push
#include "DolibarrClient.h"
#include "ServoMotorComponent.h"
int initialize_wifi(WifiConfig wifi) {
WiFiClass::mode(WIFI_STA); //Optional
@ -17,13 +18,16 @@ int initialize_wifi(WifiConfig wifi) {
Program::Program() {
Serial.begin(MONITOR_SPEED);
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
initialize_wifi(wifi_c);
this->client = new DolibarrClient(dolibarr);
this->servo = new ServoMotorComponent(2, 1, 0.1);
//struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
//struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
//initialize_wifi(wifi_c);
//this->client = new DolibarrClient(dolibarr);
}
void Program::loop() {
this->servo->refresh();
this->servo->setDesiredPosition(Position::LEFT);
}