このプログラムはDcMotorDirectDrive libraryのサンプルプログラムです。 mabuchi motor (RF-300C-11440 ,DC3V,18mA,2200rpm)を3個制御します。 モータは正転、逆転を繰り返します。 This program is a sample program DcMotorDirectDrive library. mabuchi motor (RF-300C-11440, DC3V, 18mA, 2200rpm) contains three controls. Motor forward, Reverse rotation repeat. =video 動画 = {{http://www.youtube.com/watch?v=w-ipv5tC5m4}}

Dependencies:   mbed

Committer:
suupen
Date:
Mon Dec 05 12:13:07 2011 +0000
Revision:
0:36fd4dec9f15
V1.0   2011/12/06

Who changed what in which revision?

UserRevisionLine numberNew contents of line
suupen 0:36fd4dec9f15 1 //============================================
suupen 0:36fd4dec9f15 2 // DcMotorDirectDrive Library Example
suupen 0:36fd4dec9f15 3 //
suupen 0:36fd4dec9f15 4 // This program controls the motor 3.
suupen 0:36fd4dec9f15 5 // Repeat the forward and reverse motor.
suupen 0:36fd4dec9f15 6 // Continuously varies the rotational speed of the motor.
suupen 0:36fd4dec9f15 7 //
suupen 0:36fd4dec9f15 8 // <schematic>
suupen 0:36fd4dec9f15 9 //
suupen 0:36fd4dec9f15 10 // motor1,2,3 : mabuchi motor RF-300C-11440 DC3V 18mA 2200rpm)
suupen 0:36fd4dec9f15 11 // __
suupen 0:36fd4dec9f15 12 // p21(pwmOut) ---------| | motor1
suupen 0:36fd4dec9f15 13 // | |--
suupen 0:36fd4dec9f15 14 // p22(digitalOut) ---------|__|
suupen 0:36fd4dec9f15 15 //
suupen 0:36fd4dec9f15 16 // __
suupen 0:36fd4dec9f15 17 // p23(pwmOut) ---------| | motor2
suupen 0:36fd4dec9f15 18 // | |--
suupen 0:36fd4dec9f15 19 // p24(digitalOut) ---------|__|
suupen 0:36fd4dec9f15 20 //
suupen 0:36fd4dec9f15 21 // __
suupen 0:36fd4dec9f15 22 // p25(pwmOut) ---------| | motor3
suupen 0:36fd4dec9f15 23 // | |--
suupen 0:36fd4dec9f15 24 // p26(digitalOut) ---------|__|
suupen 0:36fd4dec9f15 25 //
suupen 0:36fd4dec9f15 26 //=============================================
suupen 0:36fd4dec9f15 27
suupen 0:36fd4dec9f15 28 #include "mbed.h"
suupen 0:36fd4dec9f15 29
suupen 0:36fd4dec9f15 30 #include "DcMotorDirectDrive.h"
suupen 0:36fd4dec9f15 31
suupen 0:36fd4dec9f15 32 // pwm pin
suupen 0:36fd4dec9f15 33 // |
suupen 0:36fd4dec9f15 34 // | reference pin
suupen 0:36fd4dec9f15 35 // | |
suupen 0:36fd4dec9f15 36 DcMotorDirectDrive motor1(p21, p22);
suupen 0:36fd4dec9f15 37 DcMotorDirectDrive motor2(p23, p24);
suupen 0:36fd4dec9f15 38 DcMotorDirectDrive motor3(p25, p26);
suupen 0:36fd4dec9f15 39
suupen 0:36fd4dec9f15 40
suupen 0:36fd4dec9f15 41 DigitalOut led1(LED1);
suupen 0:36fd4dec9f15 42 DigitalOut led4(LED4);
suupen 0:36fd4dec9f15 43
suupen 0:36fd4dec9f15 44 Timer timer; // data change timer
suupen 0:36fd4dec9f15 45
suupen 0:36fd4dec9f15 46 int main() {
suupen 0:36fd4dec9f15 47 float siji = 1.0f; // motor output (+1.0 -> ... -> +0.5 -> -1.0 -> ... -> -0.5 -> +1.0)
suupen 0:36fd4dec9f15 48 uint8_t fugo = 0; // 0 : normal rotation, 1 : reverse rotation
suupen 0:36fd4dec9f15 49
suupen 0:36fd4dec9f15 50
suupen 0:36fd4dec9f15 51 timer.start();
suupen 0:36fd4dec9f15 52
suupen 0:36fd4dec9f15 53 while(1) {
suupen 0:36fd4dec9f15 54 // After 100[ms] to start the process
suupen 0:36fd4dec9f15 55 if(timer.read_ms() >= 100){
suupen 0:36fd4dec9f15 56 timer.reset();
suupen 0:36fd4dec9f15 57
suupen 0:36fd4dec9f15 58 if(fugo == 0){
suupen 0:36fd4dec9f15 59 // Normal rotation
suupen 0:36fd4dec9f15 60 // siji = +1.0 -> +0.5
suupen 0:36fd4dec9f15 61 siji -= 0.005;
suupen 0:36fd4dec9f15 62 if(siji < 0.5f){
suupen 0:36fd4dec9f15 63 fugo = 1;
suupen 0:36fd4dec9f15 64 siji = -1.0f;
suupen 0:36fd4dec9f15 65 }
suupen 0:36fd4dec9f15 66 }
suupen 0:36fd4dec9f15 67 else{
suupen 0:36fd4dec9f15 68 // Reverse rotation
suupen 0:36fd4dec9f15 69 siji += 0.005;
suupen 0:36fd4dec9f15 70 if(siji > -0.5f){
suupen 0:36fd4dec9f15 71 fugo = 0;
suupen 0:36fd4dec9f15 72 siji = +1.0f;
suupen 0:36fd4dec9f15 73 }
suupen 0:36fd4dec9f15 74 }
suupen 0:36fd4dec9f15 75 // Outputs a control instruction to the motor
suupen 0:36fd4dec9f15 76 motor1.DcMotorDirectDrive_main(siji);
suupen 0:36fd4dec9f15 77 motor2.DcMotorDirectDrive_main(siji);
suupen 0:36fd4dec9f15 78 motor3.DcMotorDirectDrive_main(siji);
suupen 0:36fd4dec9f15 79
suupen 0:36fd4dec9f15 80 // rotation display
suupen 0:36fd4dec9f15 81 if(siji > 0.5){
suupen 0:36fd4dec9f15 82 // normal rotation
suupen 0:36fd4dec9f15 83 led1 = 1;
suupen 0:36fd4dec9f15 84 led4 = 0;
suupen 0:36fd4dec9f15 85 }
suupen 0:36fd4dec9f15 86 else{
suupen 0:36fd4dec9f15 87 // reverse rotation
suupen 0:36fd4dec9f15 88 led1 = 0;
suupen 0:36fd4dec9f15 89 led4 = 1;
suupen 0:36fd4dec9f15 90 }
suupen 0:36fd4dec9f15 91 }
suupen 0:36fd4dec9f15 92 }
suupen 0:36fd4dec9f15 93 }