Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
EixoController.cpp
00001 #include "EixoController.h" 00002 00003 00004 EixoController::EixoController(float totalPathPulse, float totalPathCm, Stepp *motor, PinName pinOrigin, PinName pinEnd): swOrigin(pinOrigin), swEnd(pinEnd) { 00005 00006 this->totalPathPulse = totalPathPulse; 00007 this->totalPathCm = totalPathCm; 00008 this->motor = motor; 00009 00010 debug = new Debug(); 00011 } 00012 00013 00014 bool EixoController:: goToOrigem(DigitalIn swOrigem, int dirOrigem){ 00015 if(swOrigem == 1){ // já está na origem ? 00016 return true; 00017 } 00018 else{ // vá para a origem 00019 return motor->findLimits(30000, dirOrigem, swOrigem); 00020 00021 } 00022 } 00023 00024 void EixoController:: calibragem(int startDirection){ 00025 int teste1 = 0; 00026 int teste2 = 0; 00027 00028 while (1){ // repita até calibragem correta 00029 teste1 = motor->step(totalPathPulse, startDirection); 00030 wait(0.2); 00031 teste2 = motor->step(totalPathPulse, !startDirection); 00032 00033 if(teste1 == teste2){ 00034 // Passos iguais 00035 break; 00036 } 00037 else{ 00038 // Passos Diferentes 00039 break; 00040 } 00041 } 00042 00043 } 00044 00045 00046 int EixoController::conversao(int posCm){ // 38cm == 30000 passos 00047 float pulses = (totalPathPulse*posCm)/totalPathCm; // regra de três 00048 return (int)pulses; 00049 } 00050 00051 void EixoController:: goToPosition(int posCm, int dir){ 00052 00053 int pulses = conversao(posCm); 00054 motor->step(pulses, dir); 00055 } 00056
Generated on Sun Jul 24 2022 20:01:40 by
1.7.2