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.
Dependencies: mbed
Diff: JOG_EIXO_Z.cpp
- Revision:
- 13:9ee128577854
- Parent:
- 12:f9ac40fa3540
- Child:
- 14:2b72dd426da1
diff -r f9ac40fa3540 -r 9ee128577854 JOG_EIXO_Z.cpp
--- a/JOG_EIXO_Z.cpp Fri May 14 18:20:36 2021 +0000
+++ b/JOG_EIXO_Z.cpp Fri May 14 18:34:18 2021 +0000
@@ -1,100 +1,54 @@
#include "mbed.h"
-// Dorinha
+
Serial pc (USBTX, USBRX);
-AnalogIn eixo_Z(A2);
+AnalogIn eixo_Z(A0);
InterruptIn posicao_salva(PA_8);
+InterruptIn botao_emergencia(PB_10);
-BusOut motor_y(PA_11, PB_12, PB_11, PB_2);
BusOut motor_z(PB_1, PB_15, PB_14, PB_13);
-double frequencia; //Hz
-double velocidade = 4; //RPM
double tempo; //Segundos
int i;
-int X, Y, Z;
-int pegaX, pegaY, pegaZ;
+int Z;
+int pegaZ;
int posicao_salva_estado, botao_emergencia_estado;
void rotina_posicao_salva(void);
void rotina_emergencia(void);
-
+void rotida_velocidade_eixo_Z(void);
int main()
{
- motor_x = 0x00;
- motor_y = 0x00;
+
+ pc.baud(115200);
motor_z = 0x00;
- pc.baud(115200);
posicao_salva.rise(&rotina_posicao_salva);
botao_emergencia.rise(&rotina_emergencia);
- frequencia = (2048*velocidade)/60;
- tempo = (1/frequencia);
while(1) {
- X = eixo_X.read_u16();
- Y = eixo_Y.read_u16();
Z = eixo_Z.read_u16();
posicao_salva_estado = posicao_salva.read();
botao_emergencia_estado = botao_emergencia.read();
-
- pc.printf("X=%4d, Y=%4d, Z=%4d, PegaX=%4d, PegaY=%4d, PegaZ=%4d, Posicao_salva_estado=%d, Botao_emergencia_estado=%d \r\n", X, Y, Z, pegaX, pegaY, pegaZ, posicao_salva_estado, botao_emergencia_estado);
-
- if(31000 <= X & X <= 35000) {
-
- motor_x = 0x00;
- } else {
- if (X > 31000) {
- for(i = 0; i < 4; i++) {
- motor_x = 1 << i;
- wait(tempo);
- }
- }
-
- if(X<35000) {
- for(i = 3; i > -1; i--) {
- motor_x = 1 << i;
- wait(tempo);
- }
- }
- }
+ rotida_velocidade_eixo_Z();
+ pc.printf("Z=%4d, PegaZ=%4d, Posicao_salva_estado=%d, Botao_emergencia_estado=%d \r\n", Z, pegaZ, posicao_salva_estado, botao_emergencia_estado);
- if(31000 <= Y & Y <= 35000) {
-
- motor_y = 0x00;
- }
-
- else {
- if (Y > 31000) {
- for(i = 0; i < 4; i++) {
- motor_y = 1 << i;
- wait(tempo);
- }
- }
-
- if(Y < 35000) {
- for(i = 3; i > -1; i--) {
- motor_y = 1 << i;
- wait(tempo);
- }
- }
- }
-
- if(31000 <= X & X <= 35000) {
+ if(31000 <= Z & Z <= 35000) {
motor_z = 0x00;
+
} else {
- if (X > 31000) {
+ if (Z > 31000) {
for(i = 0; i < 4; i++) {
motor_z = 1 << i;
wait(tempo);
}
}
- if(X<35000) {
+ if(Z < 35000) {
for(i = 3; i > -1; i--) {
motor_z = 1 << i;
wait(tempo);
@@ -108,28 +62,19 @@
void rotina_posicao_salva()
{
- if(posicao_salva_estado == 0) {
- pegaX = X;
- pegaY = Y;
- pegaZ = Z;
-
- } else {
-
- pegaX = 0;
- pegaY = 0;
- pegaZ = 0;
-
- }
+ if(posicao_salva_estado == 0)pegaZ = Z;
+ else pegaZ = 0;
}
void rotina_emergencia()
{
- if(botao_emergencia_estado == 0) {
- // botao retentivo pressionado
- motor_x = 0x00;
- motor_y = 0x00;
- motor_z = 0x00;
+
+ if(botao_emergencia_estado == 0) motor_z = 0x00;
+}
- }
+void rotida_velocidade_eixo_Z()
+{
+
+ tempo = (Z/65535)*(1/512);
}
\ No newline at end of file