RCKit
DifferentialSetter.h
1 // DifferentialSetter.h
2 //
3 // Setter class cluster that controls 2 analog outputs based on 2 analog inputs so that a joystic
4 // can be used to control 2 motors like on a tank or bulldozer
5 /// \author Mike McCauley (mikem@airspayce.com)
6 ///
7 // Copyright (C) 2010 Mike McCauley
8 // $Id: DifferentialSetter.h,v 1.3 2018/09/17 23:09:57 mikem Exp mikem $
9 
10 #ifndef DifferentialSetter_h
11 #define DifferentialSetter_h
12 
13 #include "Setter.h"
14 #include <inttypes.h>
15 
16 /////////////////////////////////////////////////////////////////////
17 /// \class DifferentialSetter DifferentialSetter.h <DifferentialSetter.h>
18 /// \brief Setter class cluster that controls 2 analog outputs based on 2 analog inputs so that a joystic
19 /// can be used to control 2 motors like on a tank or bulldozer or concentric rotor helicopter.
20 /// inputA controls forwars/reverse and inputB controls left/right.
21 ///
22 /// A Differential is used to drive 2 motors in forward and reverse directions
23 /// in response to the inputs from 2 joysticks.
24 ///
25 /// It requires 2 HBridges as output:
26 /// one to drive the left motor forward/reverse and one to drive the right motor forward/reverse.
27 ///
28 /// It also requires 2 inputs,
29 /// one for the fore-aft and one for the left-right. The 2 outputs drive 2 reversible motors
30 /// that act like the motors on a tank
31 /// or bulldozer, allowing forward, reverse and turning under the control of an x-Y joystick.
32 ///
33 /// In general, the fore/aft input (inputA) is replicated on the 2 outputs, but if inputB varies
34 /// either side of 127, outputA is increased/decreased and outputB in decreased/increased.
35 /// The outputs are never permitted outside the range 0 - 255.
36 ///
37 /// The standard input (inputA) to this Setter controls the forward/reverse. The left/right controls come
38 /// through an instance of the DifferentialLRSetter class.
39 ///
40 /// Typically the outputs would be two HBridgeSetter instances to control a pair of motors
41 /// but could be ServoSetter, AccelStepperSpeedSetter
42 /// or AccelStepperPositionSetter or any other combination.
43 ///
44 class DifferentialSetter : public Setter
45 {
46 public:
47  /// \param[in] targetA The Setter to use for output A.
48  /// \param[in] targetB The Setter to use for output B.
49  DifferentialSetter(Setter* targetA, Setter* targetB);
50 
51  /// Set or change the output pin
52  /// \param[in] targetA The Setter to use for output A.
53  /// \param[in] targetB The Setter to use for output B.
54  void setTargets(Setter* targetA, Setter* targetB);
55 
56  /// Input the value to be used to set the 2 output Setters.
57  /// \param[in] value The fore/aft value.
58  virtual void input(int value);
59 
60  /// This is the B input, controlling left-right differential. It has to come from
61  /// an instance of DifferentialLRSetter.
62  /// \param[in] value The input value to set.
63  virtual void inputB(int value);
64 
65  /// Called when the source of input data is lost, and the Setter is required to fail in a safe way.
66  /// Calls the failsafes of targetA and targetB
67  virtual void failsafe();
68 
69 protected:
70  /// Internal function that computes the two output vlaues based on themost recent input values
71  void doOutput();
72 
73 private:
74  /// The B output Setter. targetA is the setter that is included in the Setter class
75  Setter* _targetB;
76  int _lastInputA;
77  int _lastInputB;
78 };
79 
80 /////////////////////////////////////////////////////////////////////
81 /// \class DifferentialLRSetter DifferentialSetter.h <DifferentialSetter.h>
82 /// \brief Setter class cluster that provides the left-right input to a DifferentialSetter
83 ///
84 /// Looks like a conventional; setter, but sets the B input of a DifferentialSetter
85 /// This is for setting the left-right inputs into a DifferentialSetter
87 {
88 public:
89  /// \param target The DifferentialSetter whose inputB is to be set by this Setter
91 
92  /// \param value The left/right value (inputB) to set in the target DifferentialSetter
93  virtual void input(int value);
94 };
95 
96 
97 #endif
DifferentialSetter::failsafe
virtual void failsafe()
Definition: DifferentialSetter.cpp:92
DifferentialLRSetter
Setter class cluster that provides the left-right input to a DifferentialSetter.
Definition: DifferentialSetter.h:86
Setter::input
virtual void input(int value)
This is where incoming values are set.
Definition: Setter.cpp:26
DifferentialSetter::doOutput
void doOutput()
Internal function that computes the two output vlaues based on themost recent input values.
Definition: DifferentialSetter.cpp:56
Setter::failsafe
virtual void failsafe()
Definition: Setter.cpp:33
DifferentialLRSetter::DifferentialLRSetter
DifferentialLRSetter(DifferentialSetter *target)
Definition: DifferentialSetter.cpp:15
DifferentialSetter
Setter class cluster that controls 2 analog outputs based on 2 analog inputs so that a joystic can be...
Definition: DifferentialSetter.h:44
Setter::_target
Setter * _target
This is the instance of Setter that will be given the transfotmed output value.
Definition: Setter.h:59
DifferentialSetter::DifferentialSetter
DifferentialSetter(Setter *targetA, Setter *targetB)
Definition: DifferentialSetter.cpp:29
DifferentialSetter::inputB
virtual void inputB(int value)
Definition: DifferentialSetter.cpp:49
Setter::setTarget
virtual void setTarget(Setter *target)
Definition: Setter.cpp:40
DifferentialSetter::setTargets
void setTargets(Setter *targetA, Setter *targetB)
Definition: DifferentialSetter.cpp:35
Setter
Virtual base class for classes that receive a value, maybe transform it and then do something with it...
Definition: Setter.h:25
DifferentialSetter::input
virtual void input(int value)
Definition: DifferentialSetter.cpp:42
DifferentialLRSetter::input
virtual void input(int value)
Definition: DifferentialSetter.cpp:20