Added one task
Dependencies: mbed
Robot/src/motor.cpp@0:fb4269aa5fb4, 2017-05-26 (annotated)
- Committer:
- PicYusuke
- Date:
- Fri May 26 03:51:19 2017 +0000
- Revision:
- 0:fb4269aa5fb4
hoge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PicYusuke | 0:fb4269aa5fb4 | 1 | #include "motor.h" |
PicYusuke | 0:fb4269aa5fb4 | 2 | |
PicYusuke | 0:fb4269aa5fb4 | 3 | float v_bat = 11.3f; //モータ用電源電圧 |
PicYusuke | 0:fb4269aa5fb4 | 4 | |
PicYusuke | 0:fb4269aa5fb4 | 5 | /*-----使用するPWMモジュール-----*/ |
PicYusuke | 0:fb4269aa5fb4 | 6 | PwmOut *motor_L = &pwm2; |
PicYusuke | 0:fb4269aa5fb4 | 7 | PwmOut *motor_R = &pwm1; |
PicYusuke | 0:fb4269aa5fb4 | 8 | PwmOut *motor_lift = &pwm3; |
PicYusuke | 0:fb4269aa5fb4 | 9 | /*----------------------------*/ |
PicYusuke | 0:fb4269aa5fb4 | 10 | |
PicYusuke | 0:fb4269aa5fb4 | 11 | /*--------回転方向制御I/O--------*/ |
PicYusuke | 0:fb4269aa5fb4 | 12 | DigitalOut ml_dir(PB_3); //left motor |
PicYusuke | 0:fb4269aa5fb4 | 13 | DigitalOut mr_dir(PB_4); //right motor |
PicYusuke | 0:fb4269aa5fb4 | 14 | DigitalOut me_dir(PB_10); //lift motor (elevation) |
PicYusuke | 0:fb4269aa5fb4 | 15 | /*-----------------------------*/ |
PicYusuke | 0:fb4269aa5fb4 | 16 | |
PicYusuke | 0:fb4269aa5fb4 | 17 | void Put_Vm_L(float v) |
PicYusuke | 0:fb4269aa5fb4 | 18 | { |
PicYusuke | 0:fb4269aa5fb4 | 19 | if(v < 0.0f) |
PicYusuke | 0:fb4269aa5fb4 | 20 | { |
PicYusuke | 0:fb4269aa5fb4 | 21 | ml_dir = 1; |
PicYusuke | 0:fb4269aa5fb4 | 22 | (*motor_L).write(-v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 23 | } |
PicYusuke | 0:fb4269aa5fb4 | 24 | else |
PicYusuke | 0:fb4269aa5fb4 | 25 | { |
PicYusuke | 0:fb4269aa5fb4 | 26 | ml_dir = 0; |
PicYusuke | 0:fb4269aa5fb4 | 27 | (*motor_L).write(v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 28 | } |
PicYusuke | 0:fb4269aa5fb4 | 29 | } |
PicYusuke | 0:fb4269aa5fb4 | 30 | |
PicYusuke | 0:fb4269aa5fb4 | 31 | void Put_Vm_R(float v) |
PicYusuke | 0:fb4269aa5fb4 | 32 | { |
PicYusuke | 0:fb4269aa5fb4 | 33 | if(v < 0.0f) |
PicYusuke | 0:fb4269aa5fb4 | 34 | { |
PicYusuke | 0:fb4269aa5fb4 | 35 | mr_dir = 1; |
PicYusuke | 0:fb4269aa5fb4 | 36 | (*motor_R).write(-v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 37 | } |
PicYusuke | 0:fb4269aa5fb4 | 38 | else |
PicYusuke | 0:fb4269aa5fb4 | 39 | { |
PicYusuke | 0:fb4269aa5fb4 | 40 | mr_dir = 0; |
PicYusuke | 0:fb4269aa5fb4 | 41 | (*motor_R).write(v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 42 | } |
PicYusuke | 0:fb4269aa5fb4 | 43 | } |
PicYusuke | 0:fb4269aa5fb4 | 44 | |
PicYusuke | 0:fb4269aa5fb4 | 45 | void Put_Vm_Lift(float v) |
PicYusuke | 0:fb4269aa5fb4 | 46 | { |
PicYusuke | 0:fb4269aa5fb4 | 47 | if(v > 0.0f) |
PicYusuke | 0:fb4269aa5fb4 | 48 | { |
PicYusuke | 0:fb4269aa5fb4 | 49 | me_dir = 1; |
PicYusuke | 0:fb4269aa5fb4 | 50 | (*motor_lift).write(v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 51 | } |
PicYusuke | 0:fb4269aa5fb4 | 52 | else |
PicYusuke | 0:fb4269aa5fb4 | 53 | { |
PicYusuke | 0:fb4269aa5fb4 | 54 | me_dir = 0; |
PicYusuke | 0:fb4269aa5fb4 | 55 | (*motor_lift).write(-v / v_bat); |
PicYusuke | 0:fb4269aa5fb4 | 56 | } |
PicYusuke | 0:fb4269aa5fb4 | 57 | } |