![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
my new gear...
actuator/Servomotor.cpp@2:e7b09385d197, 2022-03-27 (annotated)
- Committer:
- yootee
- Date:
- Sun Mar 27 04:39:16 2022 +0000
- Revision:
- 2:e7b09385d197
arrc?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yootee | 2:e7b09385d197 | 1 | #include<Servomotor.hpp> |
yootee | 2:e7b09385d197 | 2 | |
yootee | 2:e7b09385d197 | 3 | servo::servo(PinName signal,unsigned int range_degree,unsigned int pulse_cycle,unsigned int min_pulse,unsigned int max_pulse):signal_(signal),range_degree_(range_degree),pulse_cycle_(pulse_cycle),min_pulse_(min_pulse),max_pulse_(max_pulse) |
yootee | 2:e7b09385d197 | 4 | { |
yootee | 2:e7b09385d197 | 5 | now_angle_ = 0; |
yootee | 2:e7b09385d197 | 6 | pdp = (max_pulse - min_pulse)/range_degree; |
yootee | 2:e7b09385d197 | 7 | } |
yootee | 2:e7b09385d197 | 8 | |
yootee | 2:e7b09385d197 | 9 | void servo::Setangle(unsigned int tar_angle){ |
yootee | 2:e7b09385d197 | 10 | PwmOut servo(signal_); |
yootee | 2:e7b09385d197 | 11 | servo.period_us(pulse_cycle_); |
yootee | 2:e7b09385d197 | 12 | unsigned int tar_angle_ = (tar_angle > range_degree_ ? range_degree_ :tar_angle); |
yootee | 2:e7b09385d197 | 13 | pulsese = min_pulse_+pdp*tar_angle_; |
yootee | 2:e7b09385d197 | 14 | servo.pulsewidth_us(pulsese); |
yootee | 2:e7b09385d197 | 15 | now_angle_ = tar_angle; |
yootee | 2:e7b09385d197 | 16 | } |
yootee | 2:e7b09385d197 | 17 | |
yootee | 2:e7b09385d197 | 18 | void servo::Addangle(int tar_angle){ |
yootee | 2:e7b09385d197 | 19 | PwmOut servo(signal_); |
yootee | 2:e7b09385d197 | 20 | servo.period_us(pulse_cycle_); |
yootee | 2:e7b09385d197 | 21 | int tar_angle_ = now_angle_ + tar_angle; |
yootee | 2:e7b09385d197 | 22 | tar_angle_ = (tar_angle_ < 0 ? 0 : tar_angle_ > range_degree_ ? range_degree_ :tar_angle_); |
yootee | 2:e7b09385d197 | 23 | pulsese = min_pulse_+pdp*tar_angle_; |
yootee | 2:e7b09385d197 | 24 | servo.pulsewidth_us(pulsese); |
yootee | 2:e7b09385d197 | 25 | now_angle_ = tar_angle_; |
yootee | 2:e7b09385d197 | 26 | } |