rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
dc_motors.h
Go to the documentation of this file.
1/**
2 * @file dc_motors.h
3 *
4 * @date March 3, 2020
5 * @author Matthew Kennedy (c) 2020
6 */
7
8#pragma once
9
10#include "dc_motor.h"
11
12#include <cstddef>
13
14DcMotor* initDcMotor(const char *disPinMsg, const dc_io& io, size_t index, bool useTwoWires);
15DcMotor* initDcMotor(brain_pin_e coil_p, brain_pin_e coil_m, size_t index);
16
17// Manual control of motors for use by console commands
18void setDcMotorFrequency(size_t index, int hz);
19void setDcMotorDuty(size_t index, float duty);
20
21void showDcMotorInfo(int i);
22
23// Simple wrapper to use an OutputPin as "PWM" that can only do 0 or 1
24struct PwmWrapper : public IPwm {
26
28
29 void setSimplePwmDutyCycle(float dutyCycle) override {
30 m_pin.setValue(dutyCycle > 0.5f);
31 }
32};
33
35private:
40
44
47
48 bool isStarted = false;
49public:
50
52
53 void start(bool useTwoWires,
54 brain_pin_e pinEnable,
55 brain_pin_e pinDir1,
56 brain_pin_e pinDir2,
57 const char *disPinMsg,
58 brain_pin_e pinDisable,
59 bool isInverted,
60 Scheduler* executor,
61 int frequency);
62
64
69
70 const char *msg() {
71 return dcMotor.msg();
72 }
73
74 void stop() {
75 // todo: replace 'isStarted' with 'stop'
76 }
77};
78
const char * msg()
Definition dc_motors.h:70
void setFrequency(int frequency)
Definition dc_motors.h:65
OutputPin m_pinDir2
Definition dc_motors.h:38
void stop()
Definition dc_motors.h:74
void start(bool useTwoWires, brain_pin_e pinEnable, brain_pin_e pinDir1, brain_pin_e pinDir2, const char *disPinMsg, brain_pin_e pinDisable, bool isInverted, Scheduler *executor, int frequency)
Definition dc_motors.cpp:12
SimplePwm m_pwm2
Definition dc_motors.h:46
SimplePwm m_pwm1
Definition dc_motors.h:45
OutputPin m_pinEnable
Definition dc_motors.h:36
PwmWrapper wrappedDir1
Definition dc_motors.h:42
OutputPin m_disablePin
Definition dc_motors.h:39
OutputPin m_pinDir1
Definition dc_motors.h:37
bool isStarted
Definition dc_motors.h:48
PwmWrapper wrappedDir2
Definition dc_motors.h:43
PwmWrapper wrappedEnable
Definition dc_motors.h:41
TwoPinDcMotor dcMotor
Definition dc_motors.h:63
Brushed or brushless DC motor interface.
Definition dc_motor.h:20
const char * msg() const
Definition dc_motor.h:40
Single output pin reference and state.
Definition efi_output.h:49
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
void setFrequency(float frequency)
Represents a DC motor controller (H-bridge) with some combination of PWM and on/off control pins....
Definition dc_motor.h:56
DcMotor * initDcMotor(const char *disPinMsg, const dc_io &io, size_t index, bool useTwoWires)
Definition dc_motors.cpp:90
void setDcMotorFrequency(size_t index, int hz)
void showDcMotorInfo(int i)
void setDcMotorDuty(size_t index, float duty)
DcHardware * getPrimaryDCHardwareForLogging()
Definition dc_motors.cpp:86
static float frequency
Definition init_flex.cpp:21
brain_pin_e pin
Definition stm32_adc.cpp:15
PwmWrapper(OutputPin &pin)
Definition dc_motors.h:27
OutputPin & m_pin
Definition dc_motors.h:25
void setSimplePwmDutyCycle(float dutyCycle) override
Definition dc_motors.h:29
static float duty