This Project has codes that may cnc controller possible. My cnc has 2 mechanical axis. I am monitoring through switches the axis limits. For this i use the library rtos. Enjoy.
Diff: EixoController.cpp
- Revision:
- 0:7cedfb720712
- Child:
- 1:ef18c260ce02
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EixoController.cpp Wed Jun 07 13:31:02 2017 +0000 @@ -0,0 +1,56 @@ +#include "EixoController.h" + + +EixoController::EixoController(float totalPathPulse, float totalPathCm, Stepp *motor, PinName pinOrigin, PinName pinEnd): swOrigin(pinOrigin), swEnd(pinEnd) { + + this->totalPathPulse = totalPathPulse; + this->totalPathCm = totalPathCm; + this->motor = motor; + + debug = new Debug(); +} + + +bool EixoController:: goToOrigem(DigitalIn swOrigem, int dirOrigem){ + if(swOrigem == 1){ // já está na origem ? + return true; + } + else{ // vá para a origem + return motor->findLimits(50000, dirOrigem, swOrigem); + } +} + +void EixoController:: calibragem(int startDirection){ + int teste1 = 0; + int teste2 = 0; + + while (1){ // repita até calibragem correta + teste1 = motor->step(totalPathPulse, startDirection); + wait(0.2); + teste2 = motor->step(totalPathPulse, !startDirection); + + if(teste1 == teste2){ + // Passos iguais + break; + } + else{ + // Passos Diferentes + break; + } + } + +} + + +int EixoController::conversao(int posCm){ // 38cm == 30000 passos + float pulses = (totalPathPulse*posCm)/totalPathCm; // regra de três + return (int)pulses; +} + +void EixoController:: goToPosition(int posCm, int dir){ + + int pulses = conversao(posCm); + motor->step(pulses, dir); + +} +