![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a
src/Drivers/servo.cpp@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | /** |
alexpirciu | 1:ceee5a608e7c | 2 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 3 | * @file SERVO.cpp |
alexpirciu | 1:ceee5a608e7c | 4 | * @author RBRO/PJ-IU |
alexpirciu | 1:ceee5a608e7c | 5 | * @version V1.0.0 |
alexpirciu | 1:ceee5a608e7c | 6 | * @date day-month-2017 |
alexpirciu | 1:ceee5a608e7c | 7 | * @brief This file contains the class definition for the steering SERVO |
alexpirciu | 1:ceee5a608e7c | 8 | * functionality. |
alexpirciu | 1:ceee5a608e7c | 9 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 10 | */ |
alexpirciu | 1:ceee5a608e7c | 11 | |
alexpirciu | 1:ceee5a608e7c | 12 | #include <Drivers/servo.hpp> |
alexpirciu | 1:ceee5a608e7c | 13 | |
alexpirciu | 1:ceee5a608e7c | 14 | |
alexpirciu | 1:ceee5a608e7c | 15 | namespace drivers{ |
alexpirciu | 1:ceee5a608e7c | 16 | /** @brief SERVO class constructor |
alexpirciu | 1:ceee5a608e7c | 17 | * |
alexpirciu | 1:ceee5a608e7c | 18 | * Constructor method |
alexpirciu | 1:ceee5a608e7c | 19 | * |
alexpirciu | 1:ceee5a608e7c | 20 | * @param _pwm pin connected to servo input |
alexpirciu | 1:ceee5a608e7c | 21 | */ |
alexpirciu | 1:ceee5a608e7c | 22 | SERVO::SERVO(PinName _pwm) |
alexpirciu | 1:ceee5a608e7c | 23 | :pwm(_pwm) |
alexpirciu | 1:ceee5a608e7c | 24 | { |
alexpirciu | 1:ceee5a608e7c | 25 | pwm.period_ms(20); |
alexpirciu | 1:ceee5a608e7c | 26 | // pwm.write(0.075); |
alexpirciu | 1:ceee5a608e7c | 27 | pwm.write(0.07525); |
alexpirciu | 1:ceee5a608e7c | 28 | }; |
alexpirciu | 1:ceee5a608e7c | 29 | |
alexpirciu | 1:ceee5a608e7c | 30 | /** @brief SERVO class destructor |
alexpirciu | 1:ceee5a608e7c | 31 | * |
alexpirciu | 1:ceee5a608e7c | 32 | * Destructor method |
alexpirciu | 1:ceee5a608e7c | 33 | * |
alexpirciu | 1:ceee5a608e7c | 34 | * |
alexpirciu | 1:ceee5a608e7c | 35 | */ |
alexpirciu | 1:ceee5a608e7c | 36 | SERVO::~SERVO() |
alexpirciu | 1:ceee5a608e7c | 37 | { |
alexpirciu | 1:ceee5a608e7c | 38 | }; |
alexpirciu | 1:ceee5a608e7c | 39 | |
alexpirciu | 1:ceee5a608e7c | 40 | /** @brief Set angle method |
alexpirciu | 1:ceee5a608e7c | 41 | * |
alexpirciu | 1:ceee5a608e7c | 42 | * @param angle angle |
alexpirciu | 1:ceee5a608e7c | 43 | */ |
alexpirciu | 1:ceee5a608e7c | 44 | void SERVO::SetAngle(float angle) |
alexpirciu | 1:ceee5a608e7c | 45 | { |
alexpirciu | 1:ceee5a608e7c | 46 | pwm.write(conversion(angle)); |
alexpirciu | 1:ceee5a608e7c | 47 | }; |
alexpirciu | 1:ceee5a608e7c | 48 | |
alexpirciu | 1:ceee5a608e7c | 49 | /** @brief Conversion method |
alexpirciu | 1:ceee5a608e7c | 50 | * |
alexpirciu | 1:ceee5a608e7c | 51 | * @param angle angle |
alexpirciu | 1:ceee5a608e7c | 52 | * \return duty cycle |
alexpirciu | 1:ceee5a608e7c | 53 | */ |
alexpirciu | 1:ceee5a608e7c | 54 | float SERVO::conversion(float angle) |
alexpirciu | 1:ceee5a608e7c | 55 | { |
alexpirciu | 1:ceee5a608e7c | 56 | //rc-servo-4519 |
alexpirciu | 1:ceee5a608e7c | 57 | //return (0.0010321101 * angle + 0.0725); |
alexpirciu | 1:ceee5a608e7c | 58 | //fs-5106B |
alexpirciu | 1:ceee5a608e7c | 59 | // return (0.035 +0.0272+ (angle + 25.f) / 1953.135); |
alexpirciu | 1:ceee5a608e7c | 60 | //RS2 MG/BB |
alexpirciu | 1:ceee5a608e7c | 61 | return (0.0009505 * angle + 0.07525); |
alexpirciu | 1:ceee5a608e7c | 62 | }; |
alexpirciu | 1:ceee5a608e7c | 63 | }; // namespace drivers |