program 1 driver
Dependencies: mbed motorController2
Diff: main.cpp
- Revision:
- 1:3370c513ff5c
- Parent:
- 0:1d2060237094
- Child:
- 2:50b081df251a
--- a/main.cpp Mon Oct 31 17:49:32 2016 +0000 +++ b/main.cpp Sun Dec 04 15:43:34 2016 +0000 @@ -1,4 +1,6 @@ #include "mbed.h" +#include "AccelStepper.h" +#include "math.h" // // By BalB @@ -8,14 +10,29 @@ AnalogIn top_right(A1); // Analog InPut AnalogIn bot_left(A2); // Analog InPut AnalogIn bot_right(A3); // Analog InPut +AccelStepper stepper1(1 , PA_10, PB_3); //(mode DRIVER, pin1, pin2) STEPPER DE DENTRO DE LA MAQUINA (STEPS DE 1.8) +AccelStepper stepper2(1 , PB_5, PB_4); //(mode DRIVER, pin1, pin2) STEPPER DE FUERA (EL QUE TIENE ENGRANAJES Y STEPS DE 0.6) +const float stp1 = 1.8; +const float stp2 =0.6; +const int range1 = 32; +const int range2 = 32; +const float micro_steps1 = 1/(stp1/range1);//sale que hara 18 steps +const float micro_steps2 = 1/(stp2/range2);//saln que hara 53 steps + DigitalOut myled(LED1); // Digital OutPut Serial pc(SERIAL_TX, SERIAL_RX); // Default USART is: 8N1 NO FlowControl + + // Variables -------------------------------------------------------------- -uint16_t meas = 0; -float_t Result_V = 0; -float_t MinStepRes = 0; +uint16_t measTL = 0; +uint16_t measTR = 0; +uint16_t measBL = 0; +uint16_t measBR = 0; +int i=0; +char choice; + //DigitalOut led(LED1); @@ -29,8 +46,25 @@ int main() { pc.printf("\n\r\n\rSTART program\n\r"); + stepper1.setSpeed(50); + stepper1.setAcceleration(5000); + stepper1.setCurrentPosition(0); + stepper2.setSpeed(50); + stepper2.setAcceleration(5000); + stepper2.setCurrentPosition(0); while(1) - { + { + if(i==0) + { + pc.printf("Que vols fer, anar seguent grau?? (1)...Retrocedir ?? (2)"); + while(!pc.readable()); + choice=pc.getc(); + pc.printf("char= %d" ,choice-48); + pc.printf(" ha leido"); + stepper2.moveTo(rint(-60*micro_steps2));//moveTo Sets target position + stepper2.runToPosition();//Gives the order to go to that target position + wait_ms(1500); + } // Read the analog input value measTL = top_left.read_u16(); measTR = top_right.read_u16(); @@ -40,26 +74,7 @@ // Display the result via Virtual COM pc.printf("TOP_LEFT == %d || TOP_RIGHT == %d || BOT_LEFT == %d || BOT_RIGHT == %d ", measTL, measTR , measBL, measBR); - wait(0.8); // 800 ms + wait_ms(800); // 800 ms } } - -/*int main() { - float meas; - - printf("\nAnalogIn example\n"); - - while(1) { - meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) - meas = meas * 3300; // Change the value to be in the 0 to 3300 range - printf("measure = %.0f mV\n", meas); - if (meas > 2000) { // If the value is greater than 2V then switch the LED on - led = 1; - } - else { - led = 0; - } - wait(0.2); // 200 ms - } -}*/