grupo 3 - pipfox projeto mecatronico 2021

Dependencies:   mbed TouchScreen_kbv_mbed MCUFRIEND_kbv_R299 GLUE_STUFF_kbv ADA_GFX_kbv_R1107

Committer:
stephanie_liu
Date:
Tue Jun 01 14:33:34 2021 +0000
Revision:
5:fa6ff327713c
Grupo 3 - PipFox - Codigo desenvolvimento

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stephanie_liu 5:fa6ff327713c 1 // --------------------------- SETUP ------------------------------------------
stephanie_liu 5:fa6ff327713c 2 #pragma once
stephanie_liu 5:fa6ff327713c 3
stephanie_liu 5:fa6ff327713c 4 //----------------------- incluindo bibliotecas -----------------------
stephanie_liu 5:fa6ff327713c 5 #include "mbed.h"
stephanie_liu 5:fa6ff327713c 6 #include "Arduino.h"
stephanie_liu 5:fa6ff327713c 7 //#include "MCUFRIEND_kbv.h"
stephanie_liu 5:fa6ff327713c 8
stephanie_liu 5:fa6ff327713c 9 //----------------------- Configuracao do display -----------------------
stephanie_liu 5:fa6ff327713c 10 ////MCUFRIEND_kbv tft;
stephanie_liu 5:fa6ff327713c 11 //uint8_t Orientation = 1;
stephanie_liu 5:fa6ff327713c 12 //#define BLACK 0x0000
stephanie_liu 5:fa6ff327713c 13 //#define BLUE 0x001F
stephanie_liu 5:fa6ff327713c 14 //#define RED 0xF800
stephanie_liu 5:fa6ff327713c 15 //#define GREEN 0x07E0
stephanie_liu 5:fa6ff327713c 16 //#define CYAN 0x07FF
stephanie_liu 5:fa6ff327713c 17 //#define MAGENTA 0xF81F
stephanie_liu 5:fa6ff327713c 18 //#define YELLOW 0xFFE0
stephanie_liu 5:fa6ff327713c 19 //#define WHITE 0xFFFF
stephanie_liu 5:fa6ff327713c 20
stephanie_liu 5:fa6ff327713c 21 // !!!CALIBRAR!!! - Joystick
stephanie_liu 5:fa6ff327713c 22 #define Xmax 65000 // X Joystick
stephanie_liu 5:fa6ff327713c 23 #define Xmin 0 // X Joystick
stephanie_liu 5:fa6ff327713c 24 #define CXmin 31000 // Centro Joystick X
stephanie_liu 5:fa6ff327713c 25 #define CXmax 33500 // Centro Joystick X
stephanie_liu 5:fa6ff327713c 26 #define CYmin 31000 // Centro Joystick Y
stephanie_liu 5:fa6ff327713c 27 #define CYmax 34500 // Centro Joystick Y
stephanie_liu 5:fa6ff327713c 28 #define Ymax 65000 // Y Joystick
stephanie_liu 5:fa6ff327713c 29 #define Ymin 0 // Y Joystick
stephanie_liu 5:fa6ff327713c 30
stephanie_liu 5:fa6ff327713c 31 //----------------------- Monitor serial -----------------------
stephanie_liu 5:fa6ff327713c 32 //Serial pc(USBTX, USBRX);
stephanie_liu 5:fa6ff327713c 33
stephanie_liu 5:fa6ff327713c 34 //----------------------- Definição das portas dos motores -----------------------
stephanie_liu 5:fa6ff327713c 35 BusOut motor_x(PC_4, PB_13, PB_14, PB_1);
stephanie_liu 5:fa6ff327713c 36 BusOut motor_y(PB_2, PB_11, PB_12, PA_11);
stephanie_liu 5:fa6ff327713c 37 BusOut motor_z(PA_12, PC_5, PC_6, PC_8);
stephanie_liu 5:fa6ff327713c 38 BusOut motores[3] = {motor_x, motor_y, motor_z};
stephanie_liu 5:fa6ff327713c 39 //----------------------- Declaração das portas dos leds -----------------------
stephanie_liu 5:fa6ff327713c 40 DigitalOut led_vermelho(PD_2);
stephanie_liu 5:fa6ff327713c 41 DigitalOut led_verde(PC_11);
stephanie_liu 5:fa6ff327713c 42 DigitalOut led_amarelo(PC_10);
stephanie_liu 5:fa6ff327713c 43 DigitalOut led_azul(PC_12);
stephanie_liu 5:fa6ff327713c 44
stephanie_liu 5:fa6ff327713c 45 //----------------------- Botoes -----------------------
stephanie_liu 5:fa6ff327713c 46 InterruptIn bot_emerg(PC_13); // Botão de emergência
stephanie_liu 5:fa6ff327713c 47 DigitalIn endstops(PA_15);
stephanie_liu 5:fa6ff327713c 48 DigitalIn enter(PB_15);
stephanie_liu 5:fa6ff327713c 49 DigitalIn z1(PA_13); // movimentacao em Z+
stephanie_liu 5:fa6ff327713c 50 DigitalIn z2(PC_15); // movimentacao em Z-
stephanie_liu 5:fa6ff327713c 51
stephanie_liu 5:fa6ff327713c 52 //----------------------- Declaração das portas do Joystick (x e y) -----------------------
stephanie_liu 5:fa6ff327713c 53 AnalogIn Ax(PC_3);
stephanie_liu 5:fa6ff327713c 54 AnalogIn Ay(PC_2);
stephanie_liu 5:fa6ff327713c 55
stephanie_liu 5:fa6ff327713c 56 // ----------------------- variaveis relacionadas ao motor e o joystick -----------------------
stephanie_liu 5:fa6ff327713c 57 int x, y, vx, vy, vz;
stephanie_liu 5:fa6ff327713c 58
stephanie_liu 5:fa6ff327713c 59 //----------------------- variaveis variaveis responsaveis pela logica -----------------------
stephanie_liu 5:fa6ff327713c 60 bool determinar_ponto = true; // 1 -> ponto de coleta; 0 -> ponto de solta
stephanie_liu 5:fa6ff327713c 61 bool print_valor_pos = true;
stephanie_liu 5:fa6ff327713c 62 bool tipo_de_movimento = false; // 0 atual para coleta ou 1 de pega para solta
stephanie_liu 5:fa6ff327713c 63 bool rotina_principal = false; // 1 para rotina principal e 0 para outras rotinas
stephanie_liu 5:fa6ff327713c 64
stephanie_liu 5:fa6ff327713c 65 struct PontoSolta {
stephanie_liu 5:fa6ff327713c 66 int coord[3];
stephanie_liu 5:fa6ff327713c 67 int volume_desejado;
stephanie_liu 5:fa6ff327713c 68 int volume_atual;
stephanie_liu 5:fa6ff327713c 69 };
stephanie_liu 5:fa6ff327713c 70
stephanie_liu 5:fa6ff327713c 71 struct Controlador {
stephanie_liu 5:fa6ff327713c 72 bool ref_feito[3];
stephanie_liu 5:fa6ff327713c 73 bool enable; // 0 -> emergencia; -> 1 funcionamento normal; 2-> fim do processo
stephanie_liu 5:fa6ff327713c 74 volatile bool emergencia;
stephanie_liu 5:fa6ff327713c 75 int soltas;
stephanie_liu 5:fa6ff327713c 76 int max_coord[3];
stephanie_liu 5:fa6ff327713c 77 int min_coord[3];
stephanie_liu 5:fa6ff327713c 78 // arrays
stephanie_liu 5:fa6ff327713c 79 PontoSolta solta[9];
stephanie_liu 5:fa6ff327713c 80 int coleta[3];
stephanie_liu 5:fa6ff327713c 81 int atual[3];
stephanie_liu 5:fa6ff327713c 82 int distancia_coleta_atual[3];
stephanie_liu 5:fa6ff327713c 83 int distancia_solta_coleta[3];
stephanie_liu 5:fa6ff327713c 84 int step[3];
stephanie_liu 5:fa6ff327713c 85 int step_rev[3]; // passo/rev motor x,y,z
stephanie_liu 5:fa6ff327713c 86 int passo[3]; // passo x, y, z (FUSO)
stephanie_liu 5:fa6ff327713c 87 int tempo;
stephanie_liu 5:fa6ff327713c 88 int destino[3];
stephanie_liu 5:fa6ff327713c 89
stephanie_liu 5:fa6ff327713c 90 // --------------------- Rotina emergencia, display ---------------------------
stephanie_liu 5:fa6ff327713c 91 void variavel_default(void);
stephanie_liu 5:fa6ff327713c 92 void emerg(void);
stephanie_liu 5:fa6ff327713c 93 void display(void);
stephanie_liu 5:fa6ff327713c 94 void eixo_refere(void);
stephanie_liu 5:fa6ff327713c 95 void motor_joystick(int, int, bool, bool);
stephanie_liu 5:fa6ff327713c 96 void ponto_coleta(void);
stephanie_liu 5:fa6ff327713c 97 void ponto_solta(int);
stephanie_liu 5:fa6ff327713c 98 void ir_ponto(int destino[3]);
stephanie_liu 5:fa6ff327713c 99 void coletar(void);
stephanie_liu 5:fa6ff327713c 100 void soltar(void);
stephanie_liu 5:fa6ff327713c 101 };
stephanie_liu 5:fa6ff327713c 102
stephanie_liu 5:fa6ff327713c 103 // ----------------------- declaracao de funcoes -----------------------
stephanie_liu 5:fa6ff327713c 104 void aciona_motor(int, bool, BusOut &);
stephanie_liu 5:fa6ff327713c 105 void desliga_motor(BusOut &);
stephanie_liu 5:fa6ff327713c 106