![](/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
- Committer:
- echo_piyo
- Date:
- 2017-06-26
- Revision:
- 0:bf96e953cdb8
File content as of revision 0:bf96e953cdb8:
/* MotorDrive Name(cw, ccw, pwm); setup(Frequency, DutyLimit) MotorDrive関数のセットアップ pwm周波数,pwmの最高値を決める output(duty) dutyを出力する */ class MotorDrive { public : MotorDrive (PinName Cw, PinName Ccw, PinName Pwm) : cw(Cw), ccw(Ccw), pwm(Pwm) { cw = 0; ccw = 0; pwm = 0; } void setup(float Frequency, float Dutylimit) { float Period = 1 / Frequency; pwm.period(Period); limit = Dutylimit; } void output(float duty) { if (duty > 0) { ccw = 0; cw = 1; if (duty > limit) { duty = limit; } } else { cw = 0; ccw = 1; if (duty < -limit) { duty = -limit; } } pwm = fabs(duty); } private : DigitalOut cw; DigitalOut ccw; PwmOut pwm; float limit; };