2 Motores + Joystick
Dependencies: X_NUCLEO_IHM01A1 TextLCD
Fork of HelloWorld_IHM01A1_2Motors_mbedOS by
Revision 53:7c56b06e694e, committed 2018-05-21
- Comitter:
- leogrotti
- Date:
- Mon May 21 19:44:03 2018 +0000
- Parent:
- 52:7f80fc02710e
- Child:
- 54:175e4f3682e8
- Commit message:
- todos os eixos com fim de curso. IHM iniciada.
Changed in this revision
| TextLCD_copy.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD_copy.lib Mon May 21 19:44:03 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/50_135_507_38_Insper/code/TextLCD/#4e71ba6b0671
--- a/main.cpp Mon May 21 16:49:53 2018 +0000
+++ b/main.cpp Mon May 21 19:44:03 2018 +0000
@@ -50,6 +50,12 @@
#include <list>
+/* includes para os lcds */
+#include "TextLCD.h"
+/* definindo apertado e solto para lcd */
+#define apertado 0
+#define solto 1
+
/* Definitions ---------------------------------------------------------------*/
@@ -73,17 +79,34 @@
DigitalIn fim_curso_X (PD_2);
DigitalIn fim_curso_Y (PC_11);
+DigitalIn fim_curso_Z (PC_8);
Serial pc(USBTX, USBRX);
+
+/* LCD */
+I2C i2c_lcd(D14,D15); // sda, scl
+
+TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
+
+int menu=0;
+float xmenu=1.0, ymenu=2.0, zmenu=3.0;
+int inicial= 1;
+int pisca =0;
+float i=0.0;
+
+/* FIM LCD */
+
AnalogIn eixo_X(A2);
AnalogIn eixo_Y(A3);
AnalogIn eixo_ZU(A0);
AnalogIn eixo_ZD(A1);
-DigitalIn salva_pos (PC_1);
-DigitalIn vai_cami (PC_0);
+DigitalIn salva_pos (PC_1); //1
+DigitalIn vai_cami (PC_0); //2
+DigitalIn cancelar (PC_10); //3
+DigitalIn concluir (PC_12); //4
float x;
float y;
@@ -155,6 +178,18 @@
}
+ void salva_posicao(){
+ listaX[index] = motor2->get_position();
+ listaY[index] = motor1->get_position();
+ listaZ[index] = motor3->get_position();
+ for (int j=0; j<=index; j++) {
+ printf("posX%d %d: \r\n", j, listaX[j]);
+ printf("posY%d %d: \r\n", j, listaY[j]);
+ printf("posZ%d %d: \r\n", j, listaZ[j]);
+ }
+ index = index+1;
+ wait_ms(DELAY_2);
+ }
void vai_caminho_desejado (int listapontosX[10], int listapontosY[10], int listapontosZ[10], int index_local) {
int PYatual = motor1->get_position();
@@ -275,6 +310,17 @@
}
+ lcd.setBacklight(TextLCD::LightOn);
+ lcd.setCursor(TextLCD::CurOff_BlkOff);
+
+ lcd.cls();
+ lcd.setAddress(3,0);
+ lcd.printf("MENU PRINCIPAL");
+ lcd.setAddress(0,2);
+ lcd.printf("1-SALVAR PONTOS");
+ lcd.setAddress(0,3);
+ lcd.printf("2-INICIAR PROGRAMA");
+
while(true) {
count = count +1;
// Leitura analógica
@@ -295,31 +341,40 @@
// Movimentando eixo Z cima caso botão 1 apertado
- if (zu >0.7) {
+ if (zu >0.7 && !fim_curso_Z) {
motor3->run(StepperMotor::FWD);
- printf("Z UP \r\n\n");
+ segu_fim_curso = 1;
+ Dir_Z = 1;
+ wait_ms(DELAY_1);
+ }
+
+// Movimentando eixo Z baixo caso botão 2 apertado
+ else if (zd >0.7 && !fim_curso_Z) {
+ motor3->run(StepperMotor::BWD);
+ segu_fim_curso = 1;
+ Dir_Z = 0;
wait_ms(DELAY_1);
}
// Parando eixo Z caso botão 1 e 2 liberado
- if (zu< 0.7 && zd < 0.7){
+ else /*(zu< 0.7 && zd < 0.7 )*/{
motor3->hard_stop();
- printf("Z PARA \r\n\n");
wait_ms(DELAY_1);
- }
-
-// Movimentando eixo Z baixo caso botão 2 apertado
- if (zd >0.7) {
- motor3->run(StepperMotor::BWD);
- printf("Z DESCE \r\n\n");
- wait_ms(DELAY_1);
- }
-
- // Parando eixo Z caso botão 1 e 2 liberado
- if (zu< 0.7 && zd < 0.7){
- motor3->hard_stop();
- printf("Z PARA \r\n\n");
- wait_ms(DELAY_1);
+ if (fim_curso_Z && segu_fim_curso==1) {
+ printf("Fim de curso Z apertada \r\n");
+ if (Dir_Z == 1){
+ motor3->move(StepperMotor::BWD, 1000);
+ motor3->wait_while_active();
+ segu_fim_curso = 0;
+ wait_ms(DELAY_1);
+ }
+ if (Dir_Z == 0){
+ motor3->move(StepperMotor::FWD, 1000);
+ motor3->wait_while_active();
+ segu_fim_curso = 0;
+ wait_ms(DELAY_1);
+ }
+ }
}
@@ -361,7 +416,6 @@
}
// Movimentando eixo X duas direções com joystick
- //if (flagX1 == 0) {
// Movimentando eixo X fwd
if (w>0.80 && !fim_curso_X) {
motor2->run(StepperMotor::BWD);
@@ -397,25 +451,39 @@
}
}
}
-
- if (salva_pos) {
- listaX[index] = motor2->get_position();
- listaY[index] = motor1->get_position();
- listaZ[index] = motor3->get_position();
- for (int j=0; j<=index; j++) {
- printf("posX%d %d: \r\n", j, listaX[j]);
- printf("posY%d %d: \r\n", j, listaY[j]);
- printf("posZ%d %d: \r\n", j, listaZ[j]);
- }
- index = index+1;
- wait_ms(DELAY_2);
- }
-
+
if (vai_cami) {
vai_caminho_desejado(listaX, listaY, listaZ, index);
printf("Vai caminho pressionado %d \r\n", index);
wait_ms(DELAY_2);
}
+ if (salva_pos && menu == 0){
+ menu = 1;
+ lcd.cls();
+ lcd.setCursor(TextLCD::CurOff_BlkOff);
+ lcd.setAddress(0,0);
+ lcd.printf("1-SALVAR PONTO %i",menu);
+ lcd.setAddress(0,1);
+ lcd.printf("2-VOLTAR");
+ lcd.setAddress(0,2);
+ lcd.printf("3-CANCELAR ");
+ wait_ms(DELAY_2);
+ }
+
+
+ if (salva_pos && menu>0){
+ lcd.cls();
+ salva_posicao();
+ lcd.setCursor(TextLCD::CurOff_BlkOff);
+ lcd.setAddress(0,0);
+ lcd.printf("1-SALVAR PONTO %i",menu+1);
+ lcd.setAddress(0,1);
+ lcd.printf("2-VOLTAR");
+ lcd.setAddress(0,2);
+ lcd.printf("3-CANCELAR ");
+ menu=menu+1;
+ }
+
}
}
