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.
ESCON_motor.cpp
00001 /* 00002 * @author Jinhyuk Yoon 00003 * 00004 * Designed to control ESCON via NUCELO-F767ZI 00005 */ 00006 00007 #include "ESCON_motor.h" 00008 00009 ESCON_motor::ESCON_motor(PinName enable_out_pin, 00010 PinName dir_out_pin, 00011 PinName pwm_out_pin, 00012 double duty_cycle_, 00013 double motor_time_const) : enable_(enable_out_pin), 00014 dir_(dir_out_pin), 00015 pwm_(pwm_out_pin){ 00016 00017 duty_cycle = duty_cycle_; 00018 period = 1 / (5 * 1000 / (2 * PI * motor_time_const) ) ; 00019 /* 00020 * Calcuate maximum period based on cutoff frequency for motor actuation. 00021 * Motor time constant's unit is millesecond(ms). 00022 * Source: https://electronics.stackexchange.com/questions/242293/is-there-an-ideal-pwm-frequency-for-dc-brush-motors 00023 */ 00024 } 00025 00026 void ESCON_motor::enable(void) { enable_ = 1;} 00027 00028 void ESCON_motor::disable(void) { enable_ = 0; } 00029 00030 void ESCON_motor::CW(void) { dir_ = 0; } 00031 00032 void ESCON_motor::CCW(void) { dir_ = 1; } 00033 00034 void ESCON_motor::pwm(void) { 00035 pwm_.period(period); 00036 pwm_.pulsewidth(duty_cycle * period); 00037 } 00038 00039 void ESCON_motor::pwmDutyCycleChange(double duty_cycle_) { 00040 duty_cycle = duty_cycle_; 00041 pwm_.period(period); 00042 pwm_.pulsewidth(duty_cycle * period); 00043 }
Generated on Mon Aug 22 2022 05:43:00 by
1.7.2