rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
dc_motor.h
Go to the documentation of this file.
1/**
2 * @file dc_motor.h
3 *
4 * ETB user documentation at https://github.com/rusefi/rusefi/wiki/HOWTO_electronic_throttle_body
5 *
6 *
7 * @date Dec 22, 2018
8 * @author Matthew Kennedy, (c) 2018
9 */
10
11#pragma once
12
13/**
14 * @brief Brushed or brushless DC motor interface
15 *
16 * Represents a DC motor (brushed or brushless) that provides simple
17 * torque/power/current/duty cycle control, but not accurate absolute position control.
18 */
20{
21public:
22 /**
23 * @brief Sets the motor duty cycle.
24 * @param duty +1.0f represents full power forward, and -1.0f represents full power backward.
25 * @return True if any fault was detected driving the motor, and false if successful.
26 */
27 virtual bool set(float duty) = 0;
28
29 /**
30 * @brief Get the current motor duty cycle.
31 * @return The current duty cycle setting. +1.0f represents full power forward, and -1.0f represents full power backward.
32 */
33 virtual float get() const = 0;
34
35 virtual void disable(const char *msg) = 0;
36 virtual void enable() = 0;
37
38 virtual bool isOpenDirection() const = 0;
39
40 const char* msg() const {
41 return m_msg;
42 }
43
44protected:
45 const char* m_msg = nullptr;
46};
47
48struct IPwm;
49class OutputPin;
50
51/**
52 * @brief Represents a DC motor controller (H-bridge) with some combination of PWM and on/off control pins.
53 * 2024: what does 'TwoPin' class name mean? is that just a historic artifact?
54 */
55class TwoPinDcMotor : public DcMotor
56{
57public:
58 enum class ControlType
59 {
60 /**
61 * For example TLE7209 - two control wires:
62 * PWM on both wires - one to open, another to close
63 */
65 /**
66 * The control/enable pin is used for PWM and disable, and the two direction pins are used
67 * to set the polarity of each half of the H bridge. setting {dir1,dir2} = 10 should,
68 * turn the motor one direction (positive duty), and = 01 should turn the other way (negative
69 * duty).
70 *
71 * For example VNH2SP30 - three control wires:
72 * PWM on 'enable' PIN, two binary pins for direction
73 *
74 * TLE9201 with two wire control also uses this mode
75 * PWM on one pin, open/close using one binary direction pin, second direction pin unused
76 */
78 };
79
80private:
81 IPwm* m_enable = nullptr;
82 IPwm* m_dir1 = nullptr;
83 IPwm* m_dir2 = nullptr;
85 float m_value = 0;
86 bool m_isInverted = false;
87
89public:
90 /**
91 * @param enable IPwm driver for enable pin, for PWM speed control.
92 * @param dir1 Enable 1 or direction 1 pin. Gets set high to rotate forward.
93 * @param dir2 Enable 2 or direction 2 pin. Gets set high to rotate backward.
94 */
96
97 void configure(IPwm& enable, IPwm& dir1, IPwm& dir2, bool isInverted);
98
99 virtual bool set(float duty) override;
100 float get() const override;
101 bool isOpenDirection() const override;
102
103 void enable() override;
104 void disable(const char *msg) override;
105
106 void setType(ControlType type) { m_type = type; }
107};
Brushed or brushless DC motor interface.
Definition dc_motor.h:20
const char * msg() const
Definition dc_motor.h:40
virtual bool set(float duty)=0
Sets the motor duty cycle.
virtual float get() const =0
Get the current motor duty cycle.
virtual void enable()=0
const char * m_msg
Definition dc_motor.h:45
virtual bool isOpenDirection() const =0
virtual void disable(const char *msg)=0
Single output pin reference and state.
Definition efi_output.h:49
Represents a DC motor controller (H-bridge) with some combination of PWM and on/off control pins....
Definition dc_motor.h:56
IPwm * m_dir1
Definition dc_motor.h:82
OutputPin *const m_disable
Definition dc_motor.h:84
bool m_isInverted
Definition dc_motor.h:86
float get() const override
Get the current motor duty cycle.
Definition dc_motor.cpp:48
void setType(ControlType type)
Definition dc_motor.h:106
void disable(const char *msg) override
Definition dc_motor.cpp:34
void configure(IPwm &enable, IPwm &dir1, IPwm &dir2, bool isInverted)
Definition dc_motor.cpp:19
IPwm * m_dir2
Definition dc_motor.h:83
ControlType m_type
Definition dc_motor.h:88
IPwm * m_enable
Definition dc_motor.h:81
virtual bool set(float duty) override
Definition dc_motor.cpp:55
float m_value
Definition dc_motor.h:85
void enable() override
Definition dc_motor.cpp:26
bool isOpenDirection() const override
Definition dc_motor.cpp:44
static float duty