![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sampleProgram
Dependencies: QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo
Fork of 17robo_fuzi by
motor_drive.h@0:bf96e953cdb8, 2017-06-26 (annotated)
- Committer:
- echo_piyo
- Date:
- Mon Jun 26 09:59:14 2017 +0000
- Revision:
- 0:bf96e953cdb8
????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
echo_piyo | 0:bf96e953cdb8 | 1 | /* |
echo_piyo | 0:bf96e953cdb8 | 2 | MotorDrive Name(cw, ccw, pwm); |
echo_piyo | 0:bf96e953cdb8 | 3 | |
echo_piyo | 0:bf96e953cdb8 | 4 | setup(Frequency, DutyLimit) |
echo_piyo | 0:bf96e953cdb8 | 5 | MotorDrive関数のセットアップ |
echo_piyo | 0:bf96e953cdb8 | 6 | pwm周波数,pwmの最高値を決める |
echo_piyo | 0:bf96e953cdb8 | 7 | |
echo_piyo | 0:bf96e953cdb8 | 8 | output(duty) |
echo_piyo | 0:bf96e953cdb8 | 9 | dutyを出力する |
echo_piyo | 0:bf96e953cdb8 | 10 | */ |
echo_piyo | 0:bf96e953cdb8 | 11 | |
echo_piyo | 0:bf96e953cdb8 | 12 | class MotorDrive |
echo_piyo | 0:bf96e953cdb8 | 13 | { |
echo_piyo | 0:bf96e953cdb8 | 14 | public : |
echo_piyo | 0:bf96e953cdb8 | 15 | MotorDrive (PinName Cw, PinName Ccw, PinName Pwm) : cw(Cw), ccw(Ccw), pwm(Pwm) { |
echo_piyo | 0:bf96e953cdb8 | 16 | cw = 0; |
echo_piyo | 0:bf96e953cdb8 | 17 | ccw = 0; |
echo_piyo | 0:bf96e953cdb8 | 18 | pwm = 0; |
echo_piyo | 0:bf96e953cdb8 | 19 | } |
echo_piyo | 0:bf96e953cdb8 | 20 | |
echo_piyo | 0:bf96e953cdb8 | 21 | void setup(float Frequency, float Dutylimit) { |
echo_piyo | 0:bf96e953cdb8 | 22 | float Period = 1 / Frequency; |
echo_piyo | 0:bf96e953cdb8 | 23 | pwm.period(Period); |
echo_piyo | 0:bf96e953cdb8 | 24 | limit = Dutylimit; |
echo_piyo | 0:bf96e953cdb8 | 25 | } |
echo_piyo | 0:bf96e953cdb8 | 26 | |
echo_piyo | 0:bf96e953cdb8 | 27 | void output(float duty) { |
echo_piyo | 0:bf96e953cdb8 | 28 | if (duty > 0) { |
echo_piyo | 0:bf96e953cdb8 | 29 | ccw = 0; |
echo_piyo | 0:bf96e953cdb8 | 30 | cw = 1; |
echo_piyo | 0:bf96e953cdb8 | 31 | if (duty > limit) { |
echo_piyo | 0:bf96e953cdb8 | 32 | duty = limit; |
echo_piyo | 0:bf96e953cdb8 | 33 | } |
echo_piyo | 0:bf96e953cdb8 | 34 | } else { |
echo_piyo | 0:bf96e953cdb8 | 35 | cw = 0; |
echo_piyo | 0:bf96e953cdb8 | 36 | ccw = 1; |
echo_piyo | 0:bf96e953cdb8 | 37 | if (duty < -limit) { |
echo_piyo | 0:bf96e953cdb8 | 38 | duty = -limit; |
echo_piyo | 0:bf96e953cdb8 | 39 | } |
echo_piyo | 0:bf96e953cdb8 | 40 | } |
echo_piyo | 0:bf96e953cdb8 | 41 | |
echo_piyo | 0:bf96e953cdb8 | 42 | pwm = fabs(duty); |
echo_piyo | 0:bf96e953cdb8 | 43 | } |
echo_piyo | 0:bf96e953cdb8 | 44 | |
echo_piyo | 0:bf96e953cdb8 | 45 | private : |
echo_piyo | 0:bf96e953cdb8 | 46 | DigitalOut cw; |
echo_piyo | 0:bf96e953cdb8 | 47 | DigitalOut ccw; |
echo_piyo | 0:bf96e953cdb8 | 48 | PwmOut pwm; |
echo_piyo | 0:bf96e953cdb8 | 49 | |
echo_piyo | 0:bf96e953cdb8 | 50 | float limit; |
echo_piyo | 0:bf96e953cdb8 | 51 | }; |