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.
Fork of Step_Motor by
Revision 5:d92004b211c9, committed 2018-06-02
- Comitter:
- pablolopez89
- Date:
- Sat Jun 02 16:34:11 2018 +0000
- Parent:
- 4:8581e6927b36
- Commit message:
- WIKI Robot Piccolo
Changed in this revision
Step_Motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
Step_Motor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8581e6927b36 -r d92004b211c9 Step_Motor.cpp --- a/Step_Motor.cpp Wed Apr 25 13:33:03 2018 +0000 +++ b/Step_Motor.cpp Sat Jun 02 16:34:11 2018 +0000 @@ -1,50 +1,47 @@ #include "Step_Motor.h" #include "mbed.h" -#include "General.h" - - Serial pc1(USBTX,USBRX); - - -stepmotor::stepmotor(PinName in1, PinName in2, PinName in3, PinName in4,PinName in5, PinName in6, PinName in7, PinName in8) : motor_out(in1,in2,in3,in4,in5,in6,in7,in8) { +stepmotor::stepmotor(PinName in1, PinName in2, PinName in3, PinName in4, PinName in5,PinName in6, PinName in7, PinName in8) : motor_out(in1,in2,in3,in4,in5,in6,in7,in8) { motor_out=0x0; nstep=0; - motorSpeed=1200; - nstep2=7; + nstep2=0; + motorSpeed=1500; + add=0; + } void stepmotor::move() { - switch(nstep2) { - case 0: ms2 = 0x1; break; // 0001 XXXX - case 1: ms2 = 0x3; break; // 0011 - case 2: ms2 = 0x2; break; // 0010 - case 3: ms2 = 0x6; break; // 0110 - case 4: ms2 = 0x4; break; // 0100 - case 5: ms2 = 0xC; break; // 1100 - case 6: ms2 = 0x8; break; // 1000 - case 7: ms2 = 0x9; break; // 1001 + case 0: add = 0x1; break; // 0001 + case 1: add = 0x3; break; // 0011 + case 2: add = 0x2; break; // 0010 + case 3: add = 0x6; break; // 0110 + case 4: add = 0x4; break; // 0100 + case 5: add = 0xC; break; // 1100 + case 6: add = 0x8; break; // 1000 + case 7: add = 0x9; break; // 1001 - default: ms2 = 0x0; break; // 0000 + default: add = 0x0; break; // 0000 } - + switch(nstep) { - case 0: motor_out = 0x10 + ms2; break; // 0001 XXXX - case 1: motor_out = 0x30 + ms2; break; // 0011 - case 2: motor_out = 0x20 + ms2; break; // 0010 - case 3: motor_out = 0x60 + ms2; break; // 0110 - case 4: motor_out = 0x40 + ms2; break; // 0100 - case 5: motor_out = 0xC0 + ms2; break; // 1100 - case 6: motor_out = 0x80 + ms2; break; // 1000 - case 7: motor_out = 0x90 + ms2; break; // 1001 + case 0: motor_out = 0x10 + add; break; // 0001 xxxx + case 1: motor_out = 0x30 + add; break; // 0011 xxxx + case 2: motor_out = 0x20 + add; break; // 0010 xxxx + case 3: motor_out = 0x60 + add; break; // 0110 xxxx + case 4: motor_out = 0x40 + add; break; // 0100 xxxx + case 5: motor_out = 0xC0 + add; break; // 1100 xxxx + case 6: motor_out = 0x80 + add; break; // 1000 xxxx + case 7: motor_out = 0x90 + add; break; // 1001 xxxx - default: motor_out = 0x00 + ms2; break; // 0000 + default: motor_out = 0x00 + add; break; // 0000 xxxx } + wait_us(motorSpeed); } @@ -57,29 +54,21 @@ } void stepmotor::step(uint32_t num_steps, uint8_t cw) { -// funcion para mover el motor N pasos CW o CCW -// num_steps número de paso que da el motor -// cw =True para dirección en sentido del reloj -// cw =False para dirección contraria de las manecillas del reloj - pc1.baud(9600); //programar los baudios - pc1.format(8,SerialBase::None,1); +//cw 0 si va a girar a la izquierda, 1 si gira a la derecha, 2 si sigue derecho, 3 retrocede uint32_t count=num_steps ; while(count){ - if (cw==DER) nstep++; nstep2++; - if (cw==IZQ) nstep--; nstep2--; - if (cw==UP) nstep++; nstep2--; - if (cw==DOWN) nstep--; nstep2++; + if (cw==1) {nstep++; nstep2--;} + if (cw==0) {nstep--; nstep2++;} + if (cw==2) {nstep++; nstep2++;} + if (cw==3) {nstep--; nstep2--;} if (nstep>7) nstep=0; if (nstep<0) nstep=7; - if (nstep2>7) nstep=0; - if (nstep2<0) nstep=7; + if (nstep2>7) nstep2=0; + if (nstep2<0) nstep2=7; move(); count--; } - if(cw==UP) pc1.printf("Avance \n"); - else if (cw==DOWN) pc1.printf("Retrocedi \n"); - else if (cw==IZQ) pc1.printf("Gire Izq \n"); - else if (cw==DER) pc1.printf("Gire Der \n"); + } \ No newline at end of file
diff -r 8581e6927b36 -r d92004b211c9 Step_Motor.h --- a/Step_Motor.h Wed Apr 25 13:33:03 2018 +0000 +++ b/Step_Motor.h Sat Jun 02 16:34:11 2018 +0000 @@ -3,22 +3,18 @@ #include "mbed.h" -#define NUME_PASOS 45629 -#define RADIO_R 50 - class stepmotor { public: - stepmotor(PinName in1, PinName in2, PinName in3, PinName in4,PinName in5, PinName in6, PinName in7, PinName in8); + stepmotor(PinName in1, PinName in2, PinName in3, PinName in4, PinName in5,PinName in6, PinName in7, PinName in8); void step(uint32_t num_steps,uint8_t cw); void set_speed(int speed); uint32_t get_speed(); private: BusOut motor_out; uint32_t motorSpeed; - int8_t nstep; - int8_t nstep2; - int8_t ms2; + int32_t nstep,nstep2; + uint8_t add; void move(); };