モータを回すよ
motor.cpp@0:a773f39e5d7a, 2022-02-02 (annotated)
- Committer:
- m2130
- Date:
- Wed Feb 02 11:25:12 2022 +0000
- Revision:
- 0:a773f39e5d7a
moving motors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m2130 | 0:a773f39e5d7a | 1 | #include "motor.hpp" |
m2130 | 0:a773f39e5d7a | 2 | |
m2130 | 0:a773f39e5d7a | 3 | Motor::Motor(PinName MP, PinName MM): mp(MP), mm(MM){ |
m2130 | 0:a773f39e5d7a | 4 | mp.period_us(2048); |
m2130 | 0:a773f39e5d7a | 5 | mm.period_us(2048); |
m2130 | 0:a773f39e5d7a | 6 | } |
m2130 | 0:a773f39e5d7a | 7 | |
m2130 | 0:a773f39e5d7a | 8 | void Motor::out(double pwm){ |
m2130 | 0:a773f39e5d7a | 9 | if(pwm > 0.0){ |
m2130 | 0:a773f39e5d7a | 10 | mp = pwm > 0.5 ? 0.5 : pwm; |
m2130 | 0:a773f39e5d7a | 11 | mm = 0.0; |
m2130 | 0:a773f39e5d7a | 12 | } |
m2130 | 0:a773f39e5d7a | 13 | else if(pwm == 0){ |
m2130 | 0:a773f39e5d7a | 14 | mp = 0.0; |
m2130 | 0:a773f39e5d7a | 15 | mm = 0.0; |
m2130 | 0:a773f39e5d7a | 16 | } |
m2130 | 0:a773f39e5d7a | 17 | else{ |
m2130 | 0:a773f39e5d7a | 18 | mp = 0.0; |
m2130 | 0:a773f39e5d7a | 19 | mm = -pwm > 0.5 ? 0.5 : -pwm; |
m2130 | 0:a773f39e5d7a | 20 | } |
m2130 | 0:a773f39e5d7a | 21 | } |