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.
Diff: main.cpp
- Revision:
- 9:d771a576e4fc
- Parent:
- 8:de64672c240f
- Child:
- 10:cd868ca9997c
--- a/main.cpp Fri May 04 12:41:56 2018 +0000
+++ b/main.cpp Fri May 04 15:57:10 2018 +0000
@@ -1,5 +1,8 @@
#include "mbed.h"
+// Classes ---------------------------------------------------------------------------------
+Timer debounce;
+
// MACHINE SETUP ---------------------------------------------------------------------------
// drivers output signal
@@ -14,18 +17,18 @@
// hardware input signal
// end-of-stroke sensors
-DigitalIn endX1(D5);
-DigitalIn endX2(D10);
+InterruptIn endX1(D5);
+InterruptIn endX2(D13);
// IHM for development
-AnalogIn joyX(A1);
-AnalogIn joyY(A0);
+AnalogIn joyX(A0);
+AnalogIn joyY(A1);
DigitalIn zUp(D7);
DigitalIn zDwn(D6);
// variables definition
-int modeStatus = 1;
+int modeStatus = 0;
float valX;
float valY;
@@ -40,6 +43,16 @@
int y_dir;
int z_dir;
+int x_plus = 1;
+int x_minus = 0;
+int y_plus = 1;
+int y_minus = 0;
+int z_plus = 1;
+int z_minus = 0;
+
+int x_limit_min = 0;
+int x_limit_max = 0;
+
float ppsMax = 600.0;
int totalX = 0;
@@ -48,6 +61,9 @@
float X = 0;
float Y = 0;
+int endX1Status;
+int endX2Status;
+
// machine parameters
float xPitch = 3.0;
float yPitch = 3.0;
@@ -57,9 +73,16 @@
float steps_by_rotation = motor_steps_by_rotation/step_mode;
// prototype functions
+void setupPins();
void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step);
float distance(int steps, float pitch);
+void endX1Int_press(void);
+void endX1Int_release(void);
+
+void endX2Int_press(void);
+void endX2Int_release(void);
+
// MAIN PROGRAM ----------------------------------------------------------------
int contador = 0;
@@ -67,6 +90,12 @@
int main(){
printf("Starting...\r\n");
+ endX1.fall(&endX1Int_press);
+ endX1.rise(&endX1Int_release);
+
+ endX2.fall(&endX2Int_press);
+ endX2.rise(&endX2Int_release);
+
if(modeStatus){
//Código de JOG
printf("JOG Selected\n");
@@ -78,15 +107,15 @@
valZDwn = zDwn;
if(valX > 0.7){
- if(!x_dir){
- x_dir = 1;
+ if(x_dir != x_minus){
+ x_dir = x_minus;
}
activeX = 1;
totalX-=1;
}
else if(valX < 0.3){
- if(x_dir){
- x_dir = 0;
+ if(x_dir != x_plus){
+ x_dir = x_plus;
}
activeX = 1;
totalX+=1;
@@ -98,15 +127,15 @@
//----------------------------------------------------------------------
if(valY > 0.7){
- if(!y_dir){
- y_dir = 1;
+ if(y_dir != y_plus){
+ y_dir = y_plus;
}
activeY = 1;
totalY+=1;
}
else if(valY < 0.3){
- if(y_dir){
- y_dir = 0;
+ if(y_dir != y_minus){
+ y_dir = y_minus;
}
activeY = 1;
totalY-=1;
@@ -118,15 +147,15 @@
//----------------------------------------------------------------------
if(!valZUp && valZDwn){
- if(z_dir){
- z_dir = 0;
+ if(z_dir != z_minus){
+ z_dir = z_minus;
//totalZ-=1;
}
activeZ = 1;
}
else if(!valZDwn && valZUp){
- if(!z_dir){
- z_dir = 1;
+ if(z_dir != z_plus){
+ z_dir = z_plus;
//totalZ+=1;
}
activeZ = 1;
@@ -153,12 +182,59 @@
}
else {
- //Código de execução fora do JOG
- }
-
+ printf("X\n\r");
+ move(ppsMax, x_plus, y_plus, z_plus, 1600, 0, 0);
+ move(ppsMax, x_minus, y_plus, z_plus, 1600, 0, 0);
+
+ wait(2);
+
+ printf("Y\n\r");
+ move(ppsMax, x_plus, y_plus, z_plus, 0, 1600, 0);
+ move(ppsMax, x_minus, y_minus, z_plus, 0, 1600, 0);
+
+ wait(2);
+
+ printf("Z\n\r");
+ move(ppsMax, x_plus, y_plus, z_plus, 0, 0, 600);
+ move(ppsMax, x_minus, y_minus, z_minus, 0, 0, 600);
+
+ printf("Finished");
+ }
+}
+
+// FUNCTIONS ----------------------------------------------------------------
+void setupPins(){
+ //endX1.mode(PullUp);
+ //endX2.mode(PullUp);
}
-// FUNCTIONS ----------------------------------------------------------------
+void endX1Int_press(void){
+ //if(debounce.read_ms() > 50)
+ printf("X1 - press\n\r");
+ x_limit_min = 1;
+ //debounce.reset();
+}
+
+void endX1Int_release(void){
+ //if(debounce.read_ms() > 50)
+ printf("X1 - release\n\r");
+ x_limit_min = 0;
+ //debounce.reset();
+}
+
+void endX2Int_press(void){
+ //if(debounce.read_ms() > 50)
+ printf("X2 - press\n\r");
+ x_limit_max = 1;
+ //debounce.reset();
+}
+
+void endX2Int_release(void){
+ //if(debounce.read_ms() > 50)
+ printf("X2 - release\n\r");
+ x_limit_max = 0;
+ //debounce.reset();
+}
void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step){
float time = 1.0/pps/2.0;