Projeto Mecatrônico - 2020 - G3 / Mbed 2 deprecated Pipetagem

Dependencies:   mbed Pipetagem_automatica

Committer:
terhorst
Date:
Mon Jun 29 15:07:42 2020 +0000
Revision:
2:bce78210ffb1
Parent:
1:3dbb9b66b990
Iteracao comentada do projeto final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terhorst 1:3dbb9b66b990 1 #include "mbed.h"
terhorst 1:3dbb9b66b990 2
terhorst 2:bce78210ffb1 3 //Declaração das portas utilizadas
terhorst 1:3dbb9b66b990 4 AnalogIn XAxis(PA_0);
terhorst 1:3dbb9b66b990 5 AnalogIn YAxis(PA_1);
terhorst 2:bce78210ffb1 6 InterruptIn Parada(PC_9);
terhorst 2:bce78210ffb1 7 InterruptIn Reset(PB_2);
terhorst 1:3dbb9b66b990 8 InterruptIn butao(PC_13);
terhorst 1:3dbb9b66b990 9 DigitalIn ZAxis_UP(PA_8);
terhorst 1:3dbb9b66b990 10 DigitalIn ZAxis_DOWN(PB_10);
terhorst 1:3dbb9b66b990 11 DigitalOut Fase_M1_A(PB_12);
terhorst 1:3dbb9b66b990 12 DigitalOut Fase_M1_B(PB_15);
terhorst 1:3dbb9b66b990 13 DigitalOut Fase_M1_C(PB_14);
terhorst 1:3dbb9b66b990 14 DigitalOut Fase_M1_D(PB_13);
terhorst 1:3dbb9b66b990 15 DigitalOut Fase_M2_A(PC_12);
terhorst 1:3dbb9b66b990 16 DigitalOut Fase_M2_B(PA_13);
terhorst 1:3dbb9b66b990 17 DigitalOut Fase_M2_C(PA_14);
terhorst 1:3dbb9b66b990 18 DigitalOut Fase_M2_D(PA_15);
terhorst 1:3dbb9b66b990 19 DigitalOut Fase_M3_A(PA_12);
terhorst 1:3dbb9b66b990 20 DigitalOut Fase_M3_B(PC_5);
terhorst 1:3dbb9b66b990 21 DigitalOut Fase_M3_C(PC_6);
terhorst 1:3dbb9b66b990 22 DigitalOut Fase_M3_D(PC_8);
terhorst 1:3dbb9b66b990 23 DigitalOut Emergencia(PB_9);
terhorst 1:3dbb9b66b990 24 Timer debounce;
terhorst 1:3dbb9b66b990 25
terhorst 2:bce78210ffb1 26 //Declaração das funções a serem chamadas posteriormente
terhorst 1:3dbb9b66b990 27 void Botao_Emergencia(void);
terhorst 1:3dbb9b66b990 28 void PAROU(void);
terhorst 2:bce78210ffb1 29 void reset(void);
terhorst 1:3dbb9b66b990 30
terhorst 2:bce78210ffb1 31 //Declaração das variáveis utilizadas no decorrer do programa
terhorst 2:bce78210ffb1 32 float tempo = 0.01;
terhorst 1:3dbb9b66b990 33 int ZUP = ZAxis_UP;
terhorst 1:3dbb9b66b990 34 int ZDOWN = ZAxis_DOWN;
terhorst 1:3dbb9b66b990 35 int limite1 = 0;
terhorst 1:3dbb9b66b990 36 int limite2 = 0;
terhorst 1:3dbb9b66b990 37 int limite3 = 0;
terhorst 1:3dbb9b66b990 38 int limite4 = 0;
terhorst 1:3dbb9b66b990 39 int limite5 = 0;
terhorst 1:3dbb9b66b990 40 int limite6 = 0;
terhorst 1:3dbb9b66b990 41 int PosicaoUsuario[] = {0,0,0};
terhorst 1:3dbb9b66b990 42 int estado = 1;
terhorst 1:3dbb9b66b990 43
terhorst 2:bce78210ffb1 44 //Função de acionamento do motor do eixo Z para subir a pipeta
terhorst 1:3dbb9b66b990 45 void SubindoZ() {
terhorst 1:3dbb9b66b990 46 if (debounce.read_ms()>200) {
terhorst 1:3dbb9b66b990 47 Fase_M3_D = 1;
terhorst 1:3dbb9b66b990 48 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 49 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 50 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 51 wait(tempo);
terhorst 1:3dbb9b66b990 52 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 53 Fase_M3_C = 1;
terhorst 1:3dbb9b66b990 54 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 55 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 56 wait(tempo);
terhorst 1:3dbb9b66b990 57 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 58 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 59 Fase_M3_B = 1;
terhorst 1:3dbb9b66b990 60 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 61 wait(tempo);
terhorst 1:3dbb9b66b990 62 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 63 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 64 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 65 Fase_M3_A = 1;
terhorst 1:3dbb9b66b990 66 wait(tempo);
terhorst 1:3dbb9b66b990 67 limite1 = limite1 + 1;
terhorst 1:3dbb9b66b990 68 if (limite1 == 50) {
terhorst 2:bce78210ffb1 69 PosicaoUsuario[2] = PosicaoUsuario[2] - 5; //Incremento da posição conforme passo do motor
terhorst 1:3dbb9b66b990 70 }
terhorst 1:3dbb9b66b990 71 }
terhorst 1:3dbb9b66b990 72 }
terhorst 1:3dbb9b66b990 73
terhorst 2:bce78210ffb1 74 //Função de acionamento do motor do eixo Z para descer a pipeta
terhorst 1:3dbb9b66b990 75 void DescendoZ() {
terhorst 1:3dbb9b66b990 76 if (debounce.read_ms()>200) {
terhorst 1:3dbb9b66b990 77 Fase_M3_A = 1;
terhorst 1:3dbb9b66b990 78 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 79 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 80 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 81 wait(tempo);
terhorst 1:3dbb9b66b990 82 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 83 Fase_M3_B = 1;
terhorst 1:3dbb9b66b990 84 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 85 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 86 wait(tempo);
terhorst 1:3dbb9b66b990 87 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 88 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 89 Fase_M3_C = 1;
terhorst 1:3dbb9b66b990 90 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 91 wait(tempo);
terhorst 1:3dbb9b66b990 92 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 93 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 94 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 95 Fase_M3_D = 1;
terhorst 1:3dbb9b66b990 96 wait(tempo);
terhorst 1:3dbb9b66b990 97 limite2 = limite2 + 1;
terhorst 1:3dbb9b66b990 98 if (limite2 == 50) {
terhorst 2:bce78210ffb1 99 PosicaoUsuario[2] = PosicaoUsuario[2] + 5; //Incremento da posição conforme passo do motor
terhorst 1:3dbb9b66b990 100 }
terhorst 1:3dbb9b66b990 101 }
terhorst 1:3dbb9b66b990 102 }
terhorst 1:3dbb9b66b990 103
terhorst 2:bce78210ffb1 104 //Função principal do programa, onde as demais funções são chamadas
terhorst 1:3dbb9b66b990 105 void joystick(){
terhorst 2:bce78210ffb1 106
terhorst 2:bce78210ffb1 107 //Declaração de algumas variáveis para funcionamento da função
terhorst 1:3dbb9b66b990 108 int X,Y;
terhorst 1:3dbb9b66b990 109 Emergencia = 0;
terhorst 1:3dbb9b66b990 110 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 111 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 112 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 113 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 114 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 115 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 116 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 117 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 118 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 119 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 120 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 121 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 122
terhorst 2:bce78210ffb1 123 //Inicio do debounce
terhorst 1:3dbb9b66b990 124 debounce.start();
terhorst 2:bce78210ffb1 125
terhorst 2:bce78210ffb1 126 //Declaração dos botões necessários para o bom funcionamento do programa
terhorst 1:3dbb9b66b990 127 butao.rise(&Botao_Emergencia);
terhorst 2:bce78210ffb1 128 Parada.rise(&PAROU);
terhorst 1:3dbb9b66b990 129
terhorst 2:bce78210ffb1 130 while (estado == 1) { //Inicio do loop do código principal
terhorst 1:3dbb9b66b990 131
terhorst 2:bce78210ffb1 132 //Leitura dos eixos do joystick
terhorst 1:3dbb9b66b990 133 X = XAxis.read() * 1000;
terhorst 1:3dbb9b66b990 134 Y = YAxis.read() * 1000;
terhorst 1:3dbb9b66b990 135
terhorst 1:3dbb9b66b990 136 if (ZAxis_UP != 0 && ZAxis_DOWN == 0) { // Quando o botão UP estiver pressionado e o botão DOWN não - Suba a pipeta - inverte o sentido de rotação do motor
terhorst 1:3dbb9b66b990 137 SubindoZ();
terhorst 1:3dbb9b66b990 138 }
terhorst 1:3dbb9b66b990 139
terhorst 1:3dbb9b66b990 140 else if (ZAxis_DOWN != 0 && ZAxis_UP == 0 ) { // Quando o botão DOWN estiver pressionado e o botão UP não - Desce a pipeta - sentido normal de rotação do motor
terhorst 1:3dbb9b66b990 141 DescendoZ();
terhorst 1:3dbb9b66b990 142 }
terhorst 1:3dbb9b66b990 143
terhorst 1:3dbb9b66b990 144 if (100<X<900) { //delimitando range de atuação do joystick
terhorst 1:3dbb9b66b990 145 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 146 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 147 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 148 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 149 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 150 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 151 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 152 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 153 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 154 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 155 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 156 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 157 }
terhorst 1:3dbb9b66b990 158
terhorst 1:3dbb9b66b990 159 if (100<Y<900) { //delimitando range de atuação do joystick
terhorst 1:3dbb9b66b990 160 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 161 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 162 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 163 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 164 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 165 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 166 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 167 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 168 Fase_M3_A = 0;
terhorst 1:3dbb9b66b990 169 Fase_M3_B = 0;
terhorst 1:3dbb9b66b990 170 Fase_M3_C = 0;
terhorst 1:3dbb9b66b990 171 Fase_M3_D = 0;
terhorst 1:3dbb9b66b990 172 }
terhorst 1:3dbb9b66b990 173
terhorst 1:3dbb9b66b990 174 if (X<100) { //seta esquerda - Inverte o sentido de rotação
terhorst 1:3dbb9b66b990 175
terhorst 1:3dbb9b66b990 176 Fase_M1_D = 1;
terhorst 1:3dbb9b66b990 177 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 178 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 179 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 180 wait(tempo);
terhorst 1:3dbb9b66b990 181 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 182 Fase_M1_C = 1;
terhorst 1:3dbb9b66b990 183 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 184 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 185 wait(tempo);
terhorst 1:3dbb9b66b990 186 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 187 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 188 Fase_M1_B = 1;
terhorst 1:3dbb9b66b990 189 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 190 wait(tempo);
terhorst 1:3dbb9b66b990 191 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 192 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 193 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 194 Fase_M1_A = 1;
terhorst 1:3dbb9b66b990 195 wait(tempo);
terhorst 1:3dbb9b66b990 196 limite3 = limite3 + 1;
terhorst 1:3dbb9b66b990 197 if (limite3 == 50) {
terhorst 2:bce78210ffb1 198 PosicaoUsuario[0] = PosicaoUsuario[0] - 5; //Incremento do valor posição com base no passo do motor
terhorst 1:3dbb9b66b990 199 }
terhorst 1:3dbb9b66b990 200 }
terhorst 1:3dbb9b66b990 201
terhorst 1:3dbb9b66b990 202 else if (X>900) { // seta direita - sentido normal de rotação
terhorst 1:3dbb9b66b990 203
terhorst 1:3dbb9b66b990 204 Fase_M1_A = 1;
terhorst 1:3dbb9b66b990 205 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 206 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 207 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 208 wait(tempo);
terhorst 1:3dbb9b66b990 209 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 210 Fase_M1_B = 1;
terhorst 1:3dbb9b66b990 211 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 212 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 213 wait(tempo);
terhorst 1:3dbb9b66b990 214 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 215 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 216 Fase_M1_C = 1;
terhorst 1:3dbb9b66b990 217 Fase_M1_D = 0;
terhorst 1:3dbb9b66b990 218 wait(tempo);
terhorst 1:3dbb9b66b990 219 Fase_M1_A = 0;
terhorst 1:3dbb9b66b990 220 Fase_M1_B = 0;
terhorst 1:3dbb9b66b990 221 Fase_M1_C = 0;
terhorst 1:3dbb9b66b990 222 Fase_M1_D = 1;
terhorst 1:3dbb9b66b990 223 wait(tempo);
terhorst 1:3dbb9b66b990 224 limite4 = limite4 + 1;
terhorst 1:3dbb9b66b990 225 if (limite4 == 50) {
terhorst 2:bce78210ffb1 226 PosicaoUsuario[0] = PosicaoUsuario[0] + 5; //Incremento do valor posição com base no passo do motor
terhorst 1:3dbb9b66b990 227 }
terhorst 1:3dbb9b66b990 228 }
terhorst 1:3dbb9b66b990 229
terhorst 1:3dbb9b66b990 230 else if (Y<100) { //seta pra baixo - Inverte o sentido de rotação
terhorst 1:3dbb9b66b990 231
terhorst 1:3dbb9b66b990 232 Fase_M2_D = 1;
terhorst 1:3dbb9b66b990 233 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 234 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 235 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 236 wait(tempo);
terhorst 1:3dbb9b66b990 237 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 238 Fase_M2_C = 1;
terhorst 1:3dbb9b66b990 239 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 240 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 241 wait(tempo);
terhorst 1:3dbb9b66b990 242 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 243 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 244 Fase_M2_B = 1;
terhorst 1:3dbb9b66b990 245 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 246 wait(tempo);
terhorst 1:3dbb9b66b990 247 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 248 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 249 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 250 Fase_M2_A = 1;
terhorst 1:3dbb9b66b990 251 wait(tempo);
terhorst 1:3dbb9b66b990 252 limite5 = limite5 + 1;
terhorst 1:3dbb9b66b990 253 if (limite5 == 50) {
terhorst 2:bce78210ffb1 254 PosicaoUsuario[1] = PosicaoUsuario[1] - 5; //Incremento do valor posição com base no passo do motor
terhorst 1:3dbb9b66b990 255 }
terhorst 1:3dbb9b66b990 256 }
terhorst 1:3dbb9b66b990 257
terhorst 1:3dbb9b66b990 258 else if (Y>900) { //seta pra cima - Sentido normal de rotação
terhorst 1:3dbb9b66b990 259
terhorst 1:3dbb9b66b990 260 Fase_M2_A = 1;
terhorst 1:3dbb9b66b990 261 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 262 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 263 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 264 wait(tempo);
terhorst 1:3dbb9b66b990 265 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 266 Fase_M2_B = 1;
terhorst 1:3dbb9b66b990 267 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 268 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 269 wait(tempo);
terhorst 1:3dbb9b66b990 270 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 271 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 272 Fase_M2_C = 1;
terhorst 1:3dbb9b66b990 273 Fase_M2_D = 0;
terhorst 1:3dbb9b66b990 274 wait(tempo);
terhorst 1:3dbb9b66b990 275 Fase_M2_A = 0;
terhorst 1:3dbb9b66b990 276 Fase_M2_B = 0;
terhorst 1:3dbb9b66b990 277 Fase_M2_C = 0;
terhorst 1:3dbb9b66b990 278 Fase_M2_D = 1;
terhorst 1:3dbb9b66b990 279 wait(tempo);
terhorst 1:3dbb9b66b990 280 limite6 = limite6 + 1;
terhorst 1:3dbb9b66b990 281 if (limite6 == 50) {
terhorst 2:bce78210ffb1 282 PosicaoUsuario[1] = PosicaoUsuario[1] + 5; //Incremento do valor posição com base no passo do motor
terhorst 1:3dbb9b66b990 283 }
terhorst 1:3dbb9b66b990 284 }
terhorst 1:3dbb9b66b990 285 }
terhorst 1:3dbb9b66b990 286 }
terhorst 1:3dbb9b66b990 287
terhorst 2:bce78210ffb1 288 //Função de ativação do botão de emergência
terhorst 1:3dbb9b66b990 289 void Botao_Emergencia() {
terhorst 1:3dbb9b66b990 290 if (debounce.read_ms()>200) {
terhorst 2:bce78210ffb1 291 Emergencia = 1; //Ao atualizar esta variável desligamos o módulo relê, impossibilitando a execução de qualquer movimento por parte do usuário
terhorst 1:3dbb9b66b990 292 debounce.reset();
terhorst 1:3dbb9b66b990 293 }
terhorst 2:bce78210ffb1 294 Reset.rise(reset);
terhorst 1:3dbb9b66b990 295 }
terhorst 1:3dbb9b66b990 296
terhorst 2:bce78210ffb1 297 //Função para saída do loop da função do joystick
terhorst 2:bce78210ffb1 298 void PAROU() {
terhorst 2:bce78210ffb1 299 estado = 0; //Atualiza o valor da variável "estado" de forma a sair do while
terhorst 2:bce78210ffb1 300 }
terhorst 1:3dbb9b66b990 301
terhorst 2:bce78210ffb1 302 void reset() { //Função de reset para saída do estado de emergência iniciado ao se ativar o botão de emergência
terhorst 2:bce78210ffb1 303 Emergencia = 0; //Atualização do valor da variável Emergência para que ele retorne a atividade que estava executando
terhorst 2:bce78210ffb1 304 }