feature/servo_motor_component #17
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"new": "cpp"
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
|
59
lib/ServoMotorComponent/src/ServoMotorComponent.cpp
Normal file
59
lib/ServoMotorComponent/src/ServoMotorComponent.cpp
Normal 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);
|
||||
Clement
commented
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;
|
||||
}
|
||||
}
|
||||
|
||||
Clement
commented
Limite faire en sorte de pouvoir configurer le pas dans le constructeur (avec une valeur par défaut) 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
Clement
commented
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
Clement
commented
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);
|
||||
}
|
33
lib/ServoMotorComponent/src/ServoMotorComponent.h
Normal file
33
lib/ServoMotorComponent/src/ServoMotorComponent.h
Normal 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
Clement
commented
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);
|
||||
Clement
commented
tu peut viré le destructeur tu peut viré le destructeur
|
||||
void refresh();
|
||||
|
||||
Clement
commented
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
|
@ -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
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "Program.h"
|
||||
#include "Arduino.h"
|
||||
Clement
commented
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user
???