Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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_Practice1 by
Diff: motor_drive.h
- Revision:
- 0:bf96e953cdb8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motor_drive.h Mon Jun 26 09:59:14 2017 +0000 @@ -0,0 +1,51 @@ +/* +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; +}; \ No newline at end of file