This is a remote control tester, it uses a CNC, Ethernet Communication with a JAVAFX interface and a PLC in order to control some valves.

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of CNC_CONTROLLER by Lahis Almeida

Committer:
kevencastro7
Date:
Fri Dec 15 19:40:41 2017 +0000
Revision:
2:835c883d81b0
Parent:
1:ef18c260ce02
This is a remote control tester, it uses a CNC, Ethernet Communication with  a JAVAFX interface and a PLC in order to control some valves.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
waspSalander 0:7cedfb720712 1 #include "EixoController.h"
waspSalander 0:7cedfb720712 2
waspSalander 0:7cedfb720712 3
kevencastro7 2:835c883d81b0 4 EixoController::EixoController(float totalPathPulse, float totalPathCm, Stepp *motor,PCF8574 *pcf, int swOrigin, int swEnd){
kevencastro7 2:835c883d81b0 5 this->pcf = pcf;
waspSalander 0:7cedfb720712 6 this->totalPathPulse = totalPathPulse;
waspSalander 0:7cedfb720712 7 this->totalPathCm = totalPathCm;
waspSalander 0:7cedfb720712 8 this->motor = motor;
kevencastro7 2:835c883d81b0 9 this->swOrigin = swOrigin;
kevencastro7 2:835c883d81b0 10 this->swEnd = swEnd;
kevencastro7 2:835c883d81b0 11 debug = new Debug();
waspSalander 0:7cedfb720712 12 }
waspSalander 0:7cedfb720712 13
waspSalander 0:7cedfb720712 14
kevencastro7 2:835c883d81b0 15 bool EixoController:: goToOrigem(int dirOrigem){
kevencastro7 2:835c883d81b0 16 if(this->pcf->read(this->swOrigin) == 1){ // já está na origem ?
waspSalander 0:7cedfb720712 17 return true;
waspSalander 0:7cedfb720712 18 }
waspSalander 0:7cedfb720712 19 else{ // vá para a origem
kevencastro7 2:835c883d81b0 20 return motor->findLimits(30000, dirOrigem, this->pcf,this->swOrigin);
waspSalander 1:ef18c260ce02 21
waspSalander 0:7cedfb720712 22 }
waspSalander 0:7cedfb720712 23 }
waspSalander 0:7cedfb720712 24
waspSalander 0:7cedfb720712 25 void EixoController:: calibragem(int startDirection){
waspSalander 0:7cedfb720712 26 int teste1 = 0;
waspSalander 0:7cedfb720712 27 int teste2 = 0;
waspSalander 0:7cedfb720712 28
waspSalander 0:7cedfb720712 29 while (1){ // repita até calibragem correta
waspSalander 0:7cedfb720712 30 teste1 = motor->step(totalPathPulse, startDirection);
waspSalander 0:7cedfb720712 31 wait(0.2);
waspSalander 0:7cedfb720712 32 teste2 = motor->step(totalPathPulse, !startDirection);
waspSalander 0:7cedfb720712 33
waspSalander 0:7cedfb720712 34 if(teste1 == teste2){
waspSalander 0:7cedfb720712 35 // Passos iguais
waspSalander 0:7cedfb720712 36 break;
waspSalander 0:7cedfb720712 37 }
waspSalander 0:7cedfb720712 38 else{
waspSalander 0:7cedfb720712 39 // Passos Diferentes
waspSalander 0:7cedfb720712 40 break;
waspSalander 0:7cedfb720712 41 }
waspSalander 0:7cedfb720712 42 }
waspSalander 0:7cedfb720712 43
waspSalander 0:7cedfb720712 44 }
waspSalander 0:7cedfb720712 45
waspSalander 0:7cedfb720712 46
waspSalander 0:7cedfb720712 47 int EixoController::conversao(int posCm){ // 38cm == 30000 passos
waspSalander 0:7cedfb720712 48 float pulses = (totalPathPulse*posCm)/totalPathCm; // regra de três
waspSalander 0:7cedfb720712 49 return (int)pulses;
waspSalander 0:7cedfb720712 50 }
waspSalander 0:7cedfb720712 51
waspSalander 0:7cedfb720712 52 void EixoController:: goToPosition(int posCm, int dir){
waspSalander 0:7cedfb720712 53
waspSalander 1:ef18c260ce02 54 int pulses = conversao(posCm);
waspSalander 1:ef18c260ce02 55 motor->step(pulses, dir);
waspSalander 0:7cedfb720712 56 }
waspSalander 0:7cedfb720712 57