miki sumito
/
four_wheel_omni
四輪オムニの足回りを動かすプログラム
motor/motor.cpp@1:cb4a6d5c77c8, 2022-10-08 (annotated)
- Committer:
- m_smt
- Date:
- Sat Oct 08 11:14:39 2022 +0000
- Revision:
- 1:cb4a6d5c77c8
- Parent:
- 0:39c2bb18192b
move four wheel omni
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m_smt | 0:39c2bb18192b | 1 | #include "motor.hpp" |
m_smt | 0:39c2bb18192b | 2 | |
m_smt | 0:39c2bb18192b | 3 | Motor::Motor(PinName pin_a,PinName pin_b) : motor1(pin_a),motor2(pin_b) |
m_smt | 0:39c2bb18192b | 4 | { |
m_smt | 0:39c2bb18192b | 5 | motor1.period_us(2048); |
m_smt | 0:39c2bb18192b | 6 | motor2.period_us(2048); |
m_smt | 0:39c2bb18192b | 7 | } |
m_smt | 0:39c2bb18192b | 8 | |
m_smt | 0:39c2bb18192b | 9 | void Motor::revolution(double pwm) |
m_smt | 0:39c2bb18192b | 10 | { |
m_smt | 0:39c2bb18192b | 11 | if(pwm == 0.0) |
m_smt | 0:39c2bb18192b | 12 | { |
m_smt | 0:39c2bb18192b | 13 | motor1 = 0.0; |
m_smt | 0:39c2bb18192b | 14 | motor2 = 0.0; |
m_smt | 0:39c2bb18192b | 15 | } |
m_smt | 0:39c2bb18192b | 16 | else if(pwm > 0.0) |
m_smt | 0:39c2bb18192b | 17 | { |
m_smt | 0:39c2bb18192b | 18 | motor1 = pwm; |
m_smt | 0:39c2bb18192b | 19 | motor2 = 0.0; |
m_smt | 0:39c2bb18192b | 20 | } |
m_smt | 0:39c2bb18192b | 21 | else if(pwm < 0.0) |
m_smt | 0:39c2bb18192b | 22 | { |
m_smt | 0:39c2bb18192b | 23 | motor1 = 0.0; |
m_smt | 0:39c2bb18192b | 24 | motor2 = -pwm; |
m_smt | 0:39c2bb18192b | 25 | } |
m_smt | 0:39c2bb18192b | 26 | } |
m_smt | 0:39c2bb18192b | 27 | |
m_smt | 0:39c2bb18192b | 28 | void Motor::reset() |
m_smt | 0:39c2bb18192b | 29 | { |
m_smt | 0:39c2bb18192b | 30 | motor1 = 0.0; |
m_smt | 0:39c2bb18192b | 31 | motor2 = 0.0; |
m_smt | 0:39c2bb18192b | 32 | } |