feat: gestion GRBL STEPPER
This commit is contained in:
parent
0a43f65ce2
commit
caa5b0ceb7
22
lib/GRBL/include/GRBL.h
Normal file
22
lib/GRBL/include/GRBL.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef GRBL_H
|
||||||
|
#define GRBL_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Module_GRBL_13.2.h"
|
||||||
|
|
||||||
|
class iGRBL{
|
||||||
|
public:
|
||||||
|
virtual void init(int speed, double pas, int accel, String mode = "distance") = 0;
|
||||||
|
virtual void mouveForward(int mm = 5) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class GRBL : public iGRBL{
|
||||||
|
public:
|
||||||
|
GRBL(int grblAddr);
|
||||||
|
void init(int speed, double pas, int accel, String mode = "distance") override;
|
||||||
|
void mouveForward(int mm = 5) override;
|
||||||
|
private:
|
||||||
|
Module_GRBL* grbl;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
34
lib/GRBL/src/GRBL.cpp
Normal file
34
lib/GRBL/src/GRBL.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "../include/GRBL.h"
|
||||||
|
|
||||||
|
GRBL::GRBL(int grblAddr){
|
||||||
|
this->grbl = new Module_GRBL(grblAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GRBL::init(int speed, double pas, int accel, String mode){
|
||||||
|
char s[1024];
|
||||||
|
|
||||||
|
this->grbl->Init(&Wire);
|
||||||
|
this->grbl->setMode(mode);
|
||||||
|
|
||||||
|
sprintf(s,"$0=%f", pas); // step/mm
|
||||||
|
this->grbl->sendGcode(s);
|
||||||
|
Serial.println(s);
|
||||||
|
|
||||||
|
sprintf(s,"$4=%d", speed); // speed
|
||||||
|
this->grbl->sendGcode(s);
|
||||||
|
Serial.println(s);
|
||||||
|
|
||||||
|
sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2
|
||||||
|
this->grbl->sendGcode(s);
|
||||||
|
Serial.println(s);
|
||||||
|
|
||||||
|
sprintf(s,"$3=%d", 500); // puse/µsec
|
||||||
|
this->grbl->sendGcode(s);
|
||||||
|
Serial.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GRBL::mouveForward(int mm = 5){
|
||||||
|
char s[1024];
|
||||||
|
sprintf(s, "G1 X%d", mm);
|
||||||
|
this->grbl->sendGcode(s);
|
||||||
|
}
|
65
src/main.cpp
65
src/main.cpp
@ -12,13 +12,17 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <M5Stack.h>
|
#include <M5Stack.h>
|
||||||
#include "Module_GRBL_13.2.h"
|
//#include "Module_GRBL_13.2.h"
|
||||||
|
|
||||||
|
#include "GRBL.h"
|
||||||
|
|
||||||
|
|
||||||
#define STEPMOTOR_I2C_ADDR 0x70
|
#define STEPMOTOR_I2C_ADDR 0x70
|
||||||
// #define STEPMOTOR_I2C_ADDR 0x71
|
// #define STEPMOTOR_I2C_ADDR 0x71
|
||||||
|
|
||||||
Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR);
|
//Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief initialise le GRBL pour le stepper
|
* @brief initialise le GRBL pour le stepper
|
||||||
@ -28,30 +32,33 @@ Module_GRBL _GRBL = Module_GRBL(STEPMOTOR_I2C_ADDR);
|
|||||||
* @param accel vitesse d'acceleration du mptuer (mm/sec²)
|
* @param accel vitesse d'acceleration du mptuer (mm/sec²)
|
||||||
* @param mode mode de fonctionnement (defaut = distance) absolute
|
* @param mode mode de fonctionnement (defaut = distance) absolute
|
||||||
*/
|
*/
|
||||||
void init(int speed, double pas, int accel ,String mode = "distance"){
|
// void init(int speed, double pas, int accel ,String mode = "distance"){
|
||||||
char s[1024];
|
// char s[1024];
|
||||||
|
|
||||||
_GRBL.Init(&Wire);
|
// _GRBL.Init(&Wire);
|
||||||
_GRBL.setMode(mode);
|
// _GRBL.setMode(mode);
|
||||||
|
|
||||||
sprintf(s,"$0=%f", pas); // step/mm
|
// sprintf(s,"$0=%f", pas); // step/mm
|
||||||
_GRBL.sendGcode(s);
|
// _GRBL.sendGcode(s);
|
||||||
Serial.println(s);
|
// Serial.println(s);
|
||||||
|
|
||||||
sprintf(s,"$4=%d", speed); // speed
|
// sprintf(s,"$4=%d", speed); // speed
|
||||||
_GRBL.sendGcode(s);
|
// _GRBL.sendGcode(s);
|
||||||
Serial.println(s);
|
// Serial.println(s);
|
||||||
|
|
||||||
sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2
|
// sprintf(s,"$8=%d", accel); // acceleration, mm/sec^2
|
||||||
_GRBL.sendGcode(s);
|
// _GRBL.sendGcode(s);
|
||||||
Serial.println(s);
|
// Serial.println(s);
|
||||||
|
|
||||||
sprintf(s,"$3=%d", 500); // puse/µsec
|
// sprintf(s,"$3=%d", 500); // puse/µsec
|
||||||
_GRBL.sendGcode(s);
|
// _GRBL.sendGcode(s);
|
||||||
Serial.println(s);
|
// Serial.println(s);
|
||||||
}
|
// }
|
||||||
|
GRBL* grbl;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
grbl = new GRBL(STEPMOTOR_I2C_ADDR);
|
||||||
|
|
||||||
M5.begin();
|
M5.begin();
|
||||||
M5.Power.begin();
|
M5.Power.begin();
|
||||||
Wire.begin(21, 22);
|
Wire.begin(21, 22);
|
||||||
@ -66,28 +73,28 @@ void setup() {
|
|||||||
M5.Lcd.setCursor(50, 120);
|
M5.Lcd.setCursor(50, 120);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
M5.Lcd.println("Control Motor");
|
M5.Lcd.println("Control Motor");
|
||||||
init(STEPER_SPEED, STEPER_PAS, STEPER_ACC);
|
grbl->init(STEPER_SPEED, STEPER_PAS, STEPER_ACC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouveForward(int mm = 5){
|
// void mouveForward(int mm = 5){
|
||||||
char s[1024];
|
// char s[1024];
|
||||||
sprintf(s, "G1 X%d", mm);
|
// sprintf(s, "G1 X%d", mm);
|
||||||
_GRBL.sendGcode(s);
|
// _GRBL.sendGcode(s);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (M5.BtnA.wasPressed())
|
if (M5.BtnA.wasPressed())
|
||||||
{
|
{
|
||||||
Serial.print(_GRBL.readStatus());
|
// Serial.print(_GRBL.readStatus());
|
||||||
mouveForward(50);
|
grbl->mouveForward(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (M5.BtnB.wasPressed()) {
|
if (M5.BtnB.wasPressed()) {
|
||||||
mouveForward(50);
|
grbl->mouveForward(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (M5.BtnC.wasReleased()) {
|
if (M5.BtnC.wasReleased()) {
|
||||||
_GRBL.unLock();
|
// _GRBL.unLock();
|
||||||
}
|
}
|
||||||
M5.update();
|
M5.update();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user