program 1 driver
Dependencies: mbed motorController2
main.cpp
- Committer:
- BalB
- Date:
- 2016-12-04
- Revision:
- 1:3370c513ff5c
- Parent:
- 0:1d2060237094
- Child:
- 2:50b081df251a
File content as of revision 1:3370c513ff5c:
#include "mbed.h" #include "AccelStepper.h" #include "math.h" // // By BalB // #include "mbed.h" AnalogIn top_left(A0); // Analog InPut 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 measTL = 0; uint16_t measTR = 0; uint16_t measBL = 0; uint16_t measBR = 0; int i=0; char choice; //DigitalOut led(LED1); // ATTENTION // The two value below, must be changed in according to the Vcc and ADC // resolution float_t Valim = 3300; // This is the supplay voltage of ADC (or MCU) float_t ADCres = 4096; // This is the ADC resolution that in this case si 12Bit // All NUCLEO boards use an ADC with 12bit resolution 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(); measBL = bot_left.read_u16(); measBR = bot_right.read_u16(); // 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_ms(800); // 800 ms } }