RCKit
HBridgeSetter.h
1 // HBridgeSetter.h
2 //
3 // Setter class that outputs its value to a HBridge configured on 2 analog output pins
4 /// \author Mike McCauley (mikem@airspayce.com)
5 ///
6 // Copyright (C) 2010 Mike McCauley
7 // $Id: HBridgeSetter.h,v 1.4 2018/09/17 23:09:57 mikem Exp mikem $
8 
9 #ifndef HBridgeSetter_h
10 #define HBridgeSetter_h
11 
12 #include "Setter.h"
13 #include <inttypes.h>
14 
15 /////////////////////////////////////////////////////////////////////
16 /// \class HBridgeSetter HBridgeSetter.h <HBridgeSetter.h>
17 /// \brief Setter class that outputs its value to a HBridge configured on 2 output Setter
18 ///
19 /// A HBridge is used to drive a motor in forward and reverse directions. It requires 2 Setters as output:
20 /// one to drive the motor forwards and one to drive it in reverse. When driving forward the reverse
21 /// output is 0 and vice versa.
22 ///
23 /// Typically the outputs would be AnalogSetters to control a motor through a pair of analog outputs,
24 /// but could be ServoSetter, AccelStepperSpeedSetter
25 /// or AccelStepperPositionSetter or any other combination.
26 ///
27 class HBridgeSetter : public Setter
28 {
29 public:
30  /// \param[in] targetA The Setter to use for output A.
31  /// \param[in] targetB The Setter to use for output B.
32  HBridgeSetter(Setter* targetA, Setter* targetB);
33 
34  /// Set or change the output pin
35  /// \param[in] targetA The Setter to use for output A.
36  /// \param[in] targetB The Setter to use for output B.
37  void setTargets(Setter* targetA, Setter* targetB);
38 
39  /// Input the value to be used to set the 2 output Setters.
40  /// Input of 127 produces 0 on both outputs (stopped)
41  /// Input of 128 to 255 translates to output Setter A from 0 to 256
42  /// and output Setter B at 0 (forward).
43  /// Input of 127 to 0 translates to output Setter B from 0 to 254
44  /// and output Setter A at 0 (reverse).
45  /// \param[in] value The input value to set.
46  virtual void input(int value);
47 
48  /// Called when the source of input data is lost, and the Setter is required to fail in a safe way.
49  /// Calls the failsafes of targetA and targetB
50  virtual void failsafe();
51 
52 protected:
53 
54 private:
55  /// The B output Setter. targetA is the setter that is included in the Setter class
56  Setter* _targetB;
57 };
58 
59 #endif
Setter::input
virtual void input(int value)
This is where incoming values are set.
Definition: Setter.cpp:26
Setter::failsafe
virtual void failsafe()
Definition: Setter.cpp:33
HBridgeSetter::HBridgeSetter
HBridgeSetter(Setter *targetA, Setter *targetB)
Definition: HBridgeSetter.cpp:17
HBridgeSetter
Setter class that outputs its value to a HBridge configured on 2 output Setter.
Definition: HBridgeSetter.h:27
HBridgeSetter::input
virtual void input(int value)
Definition: HBridgeSetter.cpp:30
Setter::setTarget
virtual void setTarget(Setter *target)
Definition: Setter.cpp:40
HBridgeSetter::setTargets
void setTargets(Setter *targetA, Setter *targetB)
Definition: HBridgeSetter.cpp:23
HBridgeSetter::failsafe
virtual void failsafe()
Definition: HBridgeSetter.cpp:53
Setter
Virtual base class for classes that receive a value, maybe transform it and then do something with it...
Definition: Setter.h:25