
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
EixoController.cpp@0:7cedfb720712, 2017-06-07 (annotated)
- Committer:
- waspSalander
- Date:
- Wed Jun 07 13:31:02 2017 +0000
- Revision:
- 0:7cedfb720712
- Child:
- 1:ef18c260ce02
CNC_Controller (2 mechanical axis)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
waspSalander | 0:7cedfb720712 | 1 | #include "EixoController.h" |
waspSalander | 0:7cedfb720712 | 2 | |
waspSalander | 0:7cedfb720712 | 3 | |
waspSalander | 0:7cedfb720712 | 4 | EixoController::EixoController(float totalPathPulse, float totalPathCm, Stepp *motor, PinName pinOrigin, PinName pinEnd): swOrigin(pinOrigin), swEnd(pinEnd) { |
waspSalander | 0:7cedfb720712 | 5 | |
waspSalander | 0:7cedfb720712 | 6 | this->totalPathPulse = totalPathPulse; |
waspSalander | 0:7cedfb720712 | 7 | this->totalPathCm = totalPathCm; |
waspSalander | 0:7cedfb720712 | 8 | this->motor = motor; |
waspSalander | 0:7cedfb720712 | 9 | |
waspSalander | 0:7cedfb720712 | 10 | debug = new Debug(); |
waspSalander | 0:7cedfb720712 | 11 | } |
waspSalander | 0:7cedfb720712 | 12 | |
waspSalander | 0:7cedfb720712 | 13 | |
waspSalander | 0:7cedfb720712 | 14 | bool EixoController:: goToOrigem(DigitalIn swOrigem, int dirOrigem){ |
waspSalander | 0:7cedfb720712 | 15 | if(swOrigem == 1){ // já está na origem ? |
waspSalander | 0:7cedfb720712 | 16 | return true; |
waspSalander | 0:7cedfb720712 | 17 | } |
waspSalander | 0:7cedfb720712 | 18 | else{ // vá para a origem |
waspSalander | 0:7cedfb720712 | 19 | return motor->findLimits(50000, dirOrigem, swOrigem); |
waspSalander | 0:7cedfb720712 | 20 | } |
waspSalander | 0:7cedfb720712 | 21 | } |
waspSalander | 0:7cedfb720712 | 22 | |
waspSalander | 0:7cedfb720712 | 23 | void EixoController:: calibragem(int startDirection){ |
waspSalander | 0:7cedfb720712 | 24 | int teste1 = 0; |
waspSalander | 0:7cedfb720712 | 25 | int teste2 = 0; |
waspSalander | 0:7cedfb720712 | 26 | |
waspSalander | 0:7cedfb720712 | 27 | while (1){ // repita até calibragem correta |
waspSalander | 0:7cedfb720712 | 28 | teste1 = motor->step(totalPathPulse, startDirection); |
waspSalander | 0:7cedfb720712 | 29 | wait(0.2); |
waspSalander | 0:7cedfb720712 | 30 | teste2 = motor->step(totalPathPulse, !startDirection); |
waspSalander | 0:7cedfb720712 | 31 | |
waspSalander | 0:7cedfb720712 | 32 | if(teste1 == teste2){ |
waspSalander | 0:7cedfb720712 | 33 | // Passos iguais |
waspSalander | 0:7cedfb720712 | 34 | break; |
waspSalander | 0:7cedfb720712 | 35 | } |
waspSalander | 0:7cedfb720712 | 36 | else{ |
waspSalander | 0:7cedfb720712 | 37 | // Passos Diferentes |
waspSalander | 0:7cedfb720712 | 38 | break; |
waspSalander | 0:7cedfb720712 | 39 | } |
waspSalander | 0:7cedfb720712 | 40 | } |
waspSalander | 0:7cedfb720712 | 41 | |
waspSalander | 0:7cedfb720712 | 42 | } |
waspSalander | 0:7cedfb720712 | 43 | |
waspSalander | 0:7cedfb720712 | 44 | |
waspSalander | 0:7cedfb720712 | 45 | int EixoController::conversao(int posCm){ // 38cm == 30000 passos |
waspSalander | 0:7cedfb720712 | 46 | float pulses = (totalPathPulse*posCm)/totalPathCm; // regra de três |
waspSalander | 0:7cedfb720712 | 47 | return (int)pulses; |
waspSalander | 0:7cedfb720712 | 48 | } |
waspSalander | 0:7cedfb720712 | 49 | |
waspSalander | 0:7cedfb720712 | 50 | void EixoController:: goToPosition(int posCm, int dir){ |
waspSalander | 0:7cedfb720712 | 51 | |
waspSalander | 0:7cedfb720712 | 52 | int pulses = conversao(posCm); |
waspSalander | 0:7cedfb720712 | 53 | motor->step(pulses, dir); |
waspSalander | 0:7cedfb720712 | 54 | |
waspSalander | 0:7cedfb720712 | 55 | } |
waspSalander | 0:7cedfb720712 | 56 |