倒立振子ロボットで使用してるユニポーラのステッピングモータの駆動テストプログラムです。

Dependencies:   mbed

Committer:
bant62
Date:
Sat Jul 07 09:12:06 2012 +0000
Revision:
0:5253455d51ec

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bant62 0:5253455d51ec 1 #include "mbed.h"
bant62 0:5253455d51ec 2 #include "StepperMotor.h"
bant62 0:5253455d51ec 3
bant62 0:5253455d51ec 4 BusOut myleds(LED1, LED2, LED3, LED4);
bant62 0:5253455d51ec 5
bant62 0:5253455d51ec 6 Serial pc(USBTX, USBRX);
bant62 0:5253455d51ec 7
bant62 0:5253455d51ec 8 DigitalOut ae_fxma108(p29);
bant62 0:5253455d51ec 9
bant62 0:5253455d51ec 10 DigitalIn pb(p19);
bant62 0:5253455d51ec 11 DigitalIn pw(p20);
bant62 0:5253455d51ec 12
bant62 0:5253455d51ec 13 const char Welcome_Message[] =
bant62 0:5253455d51ec 14 "\r\nHello mbed World!\r\n"
bant62 0:5253455d51ec 15 "Expand your creativity and enjoy making.\r\n\r\n"
bant62 0:5253455d51ec 16 "Stepper Motor Test Mode.\r\n\r\n";
bant62 0:5253455d51ec 17
bant62 0:5253455d51ec 18
bant62 0:5253455d51ec 19 StepperMotor r_motor(p28,p27,p26,p25);
bant62 0:5253455d51ec 20 StepperMotor l_motor(p24,p23,p22,p21);
bant62 0:5253455d51ec 21
bant62 0:5253455d51ec 22 int main() {
bant62 0:5253455d51ec 23 pc.printf(Welcome_Message);
bant62 0:5253455d51ec 24
bant62 0:5253455d51ec 25 int old_pb=0;
bant62 0:5253455d51ec 26 int new_pb;
bant62 0:5253455d51ec 27 int old_pw=0;
bant62 0:5253455d51ec 28 int new_pw;
bant62 0:5253455d51ec 29 static int speed = 0;
bant62 0:5253455d51ec 30
bant62 0:5253455d51ec 31 pb.mode(PullUp);
bant62 0:5253455d51ec 32 pw.mode(PullUp);
bant62 0:5253455d51ec 33
bant62 0:5253455d51ec 34 ae_fxma108 = 0;
bant62 0:5253455d51ec 35
bant62 0:5253455d51ec 36 r_motor.SetSpeed(speed,CLOCK_WISE);
bant62 0:5253455d51ec 37 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE);
bant62 0:5253455d51ec 38
bant62 0:5253455d51ec 39 r_motor.PulseEnable();
bant62 0:5253455d51ec 40 l_motor.PulseEnable();
bant62 0:5253455d51ec 41
bant62 0:5253455d51ec 42 while(1) {
bant62 0:5253455d51ec 43 new_pb = pb;
bant62 0:5253455d51ec 44 if ((new_pb==0) && (old_pb==1)) {
bant62 0:5253455d51ec 45 if (speed == 0) continue;
bant62 0:5253455d51ec 46 speed--;
bant62 0:5253455d51ec 47 pc.printf("speed: %d\r\n",speed);
bant62 0:5253455d51ec 48 r_motor.SetSpeed(speed,CLOCK_WISE);
bant62 0:5253455d51ec 49 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE);
bant62 0:5253455d51ec 50 }
bant62 0:5253455d51ec 51 old_pb = new_pb;
bant62 0:5253455d51ec 52
bant62 0:5253455d51ec 53
bant62 0:5253455d51ec 54 new_pw = pw;
bant62 0:5253455d51ec 55 if ((new_pw==0) && (old_pw==1)) {
bant62 0:5253455d51ec 56 if (speed == 10) continue;
bant62 0:5253455d51ec 57 speed++;
bant62 0:5253455d51ec 58
bant62 0:5253455d51ec 59 pc.printf("speed: %d\r\n",speed);
bant62 0:5253455d51ec 60 r_motor.SetSpeed(speed,CLOCK_WISE);
bant62 0:5253455d51ec 61 l_motor.SetSpeed(speed,ANTI_CLOCK_WISE);
bant62 0:5253455d51ec 62 }
bant62 0:5253455d51ec 63 old_pw = new_pw;
bant62 0:5253455d51ec 64
bant62 0:5253455d51ec 65 myleds = speed;
bant62 0:5253455d51ec 66 }
bant62 0:5253455d51ec 67 }