![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a
src/Drivers/vnh.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 VNH.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 defoinition for the VNH Bridge Driver |
alexpirciu | 1:ceee5a608e7c | 8 | * functionality. |
alexpirciu | 1:ceee5a608e7c | 9 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 10 | */ |
alexpirciu | 1:ceee5a608e7c | 11 | |
alexpirciu | 1:ceee5a608e7c | 12 | #include <Drivers/vnh.hpp> |
alexpirciu | 1:ceee5a608e7c | 13 | |
alexpirciu | 1:ceee5a608e7c | 14 | |
alexpirciu | 1:ceee5a608e7c | 15 | namespace drivers{ |
alexpirciu | 1:ceee5a608e7c | 16 | |
alexpirciu | 1:ceee5a608e7c | 17 | |
alexpirciu | 1:ceee5a608e7c | 18 | |
alexpirciu | 1:ceee5a608e7c | 19 | /** @brief VNH class constructor |
alexpirciu | 1:ceee5a608e7c | 20 | * |
alexpirciu | 1:ceee5a608e7c | 21 | * Constructor method |
alexpirciu | 1:ceee5a608e7c | 22 | * |
alexpirciu | 1:ceee5a608e7c | 23 | * @param _pwm PWM pin |
alexpirciu | 1:ceee5a608e7c | 24 | * @param _ina pin A |
alexpirciu | 1:ceee5a608e7c | 25 | * @param _inb pin B |
alexpirciu | 1:ceee5a608e7c | 26 | * @param _current current analog pin |
alexpirciu | 1:ceee5a608e7c | 27 | */ |
alexpirciu | 1:ceee5a608e7c | 28 | VNH::VNH(PinName _pwm, PinName _ina, PinName _inb, PinName _current) |
alexpirciu | 1:ceee5a608e7c | 29 | :pwm(_pwm) |
alexpirciu | 1:ceee5a608e7c | 30 | ,ina(_ina) |
alexpirciu | 1:ceee5a608e7c | 31 | ,inb(_inb) |
alexpirciu | 1:ceee5a608e7c | 32 | ,current(_current) |
alexpirciu | 1:ceee5a608e7c | 33 | { |
alexpirciu | 1:ceee5a608e7c | 34 | pwm.period_us(200); |
alexpirciu | 1:ceee5a608e7c | 35 | increment = 0.01; |
alexpirciu | 1:ceee5a608e7c | 36 | current_speed = 0; |
alexpirciu | 1:ceee5a608e7c | 37 | } |
alexpirciu | 1:ceee5a608e7c | 38 | |
alexpirciu | 1:ceee5a608e7c | 39 | /** @brief VNH class destructor |
alexpirciu | 1:ceee5a608e7c | 40 | * |
alexpirciu | 1:ceee5a608e7c | 41 | * Destructor method |
alexpirciu | 1:ceee5a608e7c | 42 | * |
alexpirciu | 1:ceee5a608e7c | 43 | * |
alexpirciu | 1:ceee5a608e7c | 44 | */ |
alexpirciu | 1:ceee5a608e7c | 45 | VNH::~VNH() |
alexpirciu | 1:ceee5a608e7c | 46 | { |
alexpirciu | 1:ceee5a608e7c | 47 | } |
alexpirciu | 1:ceee5a608e7c | 48 | |
alexpirciu | 1:ceee5a608e7c | 49 | /** @brief Start method |
alexpirciu | 1:ceee5a608e7c | 50 | * |
alexpirciu | 1:ceee5a608e7c | 51 | * |
alexpirciu | 1:ceee5a608e7c | 52 | * |
alexpirciu | 1:ceee5a608e7c | 53 | */ |
alexpirciu | 1:ceee5a608e7c | 54 | void VNH::Start(void) |
alexpirciu | 1:ceee5a608e7c | 55 | { |
alexpirciu | 1:ceee5a608e7c | 56 | ina = !inb; |
alexpirciu | 1:ceee5a608e7c | 57 | pwm.write(0); |
alexpirciu | 1:ceee5a608e7c | 58 | } |
alexpirciu | 1:ceee5a608e7c | 59 | |
alexpirciu | 1:ceee5a608e7c | 60 | /** @brief Stop method |
alexpirciu | 1:ceee5a608e7c | 61 | * |
alexpirciu | 1:ceee5a608e7c | 62 | * |
alexpirciu | 1:ceee5a608e7c | 63 | * |
alexpirciu | 1:ceee5a608e7c | 64 | */ |
alexpirciu | 1:ceee5a608e7c | 65 | void VNH::Stop(void) |
alexpirciu | 1:ceee5a608e7c | 66 | { |
alexpirciu | 1:ceee5a608e7c | 67 | ina = inb; |
alexpirciu | 1:ceee5a608e7c | 68 | } |
alexpirciu | 1:ceee5a608e7c | 69 | |
alexpirciu | 1:ceee5a608e7c | 70 | /** @brief Run method |
alexpirciu | 1:ceee5a608e7c | 71 | * |
alexpirciu | 1:ceee5a608e7c | 72 | * @param speed speed value |
alexpirciu | 1:ceee5a608e7c | 73 | * |
alexpirciu | 1:ceee5a608e7c | 74 | */ |
alexpirciu | 1:ceee5a608e7c | 75 | void VNH::Run(float speed) |
alexpirciu | 1:ceee5a608e7c | 76 | { |
alexpirciu | 1:ceee5a608e7c | 77 | Go(speed); |
alexpirciu | 1:ceee5a608e7c | 78 | } |
alexpirciu | 1:ceee5a608e7c | 79 | |
alexpirciu | 1:ceee5a608e7c | 80 | /** @brief Get current method |
alexpirciu | 1:ceee5a608e7c | 81 | * |
alexpirciu | 1:ceee5a608e7c | 82 | * |
alexpirciu | 1:ceee5a608e7c | 83 | * \return Current value |
alexpirciu | 1:ceee5a608e7c | 84 | */ |
alexpirciu | 1:ceee5a608e7c | 85 | float VNH::GetCurrent(void) |
alexpirciu | 1:ceee5a608e7c | 86 | { |
alexpirciu | 1:ceee5a608e7c | 87 | return (current.read()) * 5 / 0.14; |
alexpirciu | 1:ceee5a608e7c | 88 | } |
alexpirciu | 1:ceee5a608e7c | 89 | |
alexpirciu | 1:ceee5a608e7c | 90 | /** @brief Go method |
alexpirciu | 1:ceee5a608e7c | 91 | * |
alexpirciu | 1:ceee5a608e7c | 92 | * @param speed speed value |
alexpirciu | 1:ceee5a608e7c | 93 | * |
alexpirciu | 1:ceee5a608e7c | 94 | */ |
alexpirciu | 1:ceee5a608e7c | 95 | void VNH::Go(float speed) |
alexpirciu | 1:ceee5a608e7c | 96 | { |
alexpirciu | 1:ceee5a608e7c | 97 | //pwm.write(abs(speed)); |
alexpirciu | 1:ceee5a608e7c | 98 | if (speed < 0) |
alexpirciu | 1:ceee5a608e7c | 99 | { |
alexpirciu | 1:ceee5a608e7c | 100 | ina = 0; |
alexpirciu | 1:ceee5a608e7c | 101 | inb = 1; |
alexpirciu | 1:ceee5a608e7c | 102 | } |
alexpirciu | 1:ceee5a608e7c | 103 | else |
alexpirciu | 1:ceee5a608e7c | 104 | { |
alexpirciu | 1:ceee5a608e7c | 105 | ina = 1; |
alexpirciu | 1:ceee5a608e7c | 106 | inb = 0; |
alexpirciu | 1:ceee5a608e7c | 107 | } |
alexpirciu | 1:ceee5a608e7c | 108 | pwm =std::abs(speed); |
alexpirciu | 1:ceee5a608e7c | 109 | } |
alexpirciu | 1:ceee5a608e7c | 110 | |
alexpirciu | 1:ceee5a608e7c | 111 | /** @brief Inverse method |
alexpirciu | 1:ceee5a608e7c | 112 | * |
alexpirciu | 1:ceee5a608e7c | 113 | * @param f_speed speed value |
alexpirciu | 1:ceee5a608e7c | 114 | * |
alexpirciu | 1:ceee5a608e7c | 115 | */ |
alexpirciu | 1:ceee5a608e7c | 116 | void VNH::Inverse(float f_speed) |
alexpirciu | 1:ceee5a608e7c | 117 | { |
alexpirciu | 1:ceee5a608e7c | 118 | ina=!ina; |
alexpirciu | 1:ceee5a608e7c | 119 | inb=!inb; |
alexpirciu | 1:ceee5a608e7c | 120 | pwm =std::abs(f_speed); |
alexpirciu | 1:ceee5a608e7c | 121 | } |
alexpirciu | 1:ceee5a608e7c | 122 | |
alexpirciu | 1:ceee5a608e7c | 123 | /** @brief Brake method |
alexpirciu | 1:ceee5a608e7c | 124 | * |
alexpirciu | 1:ceee5a608e7c | 125 | * |
alexpirciu | 1:ceee5a608e7c | 126 | * |
alexpirciu | 1:ceee5a608e7c | 127 | */ |
alexpirciu | 1:ceee5a608e7c | 128 | void VNH::Brake() |
alexpirciu | 1:ceee5a608e7c | 129 | { |
alexpirciu | 1:ceee5a608e7c | 130 | ina.write(0); |
alexpirciu | 1:ceee5a608e7c | 131 | inb.write(0); |
alexpirciu | 1:ceee5a608e7c | 132 | pwm.write(100.0); |
alexpirciu | 1:ceee5a608e7c | 133 | } |
alexpirciu | 1:ceee5a608e7c | 134 | |
alexpirciu | 1:ceee5a608e7c | 135 | }; // namespace drivers |