00001 // DifferentialSetter.h 00002 // 00003 // Setter class cluster that controls 2 analog outputs based on 2 analog inputs so that a joystic 00004 // can be used to control 2 motors like on a tank or bulldozer 00005 /// \author Mike McCauley (mikem@open.com.au) 00006 /// 00007 // Copyright (C) 2010 Mike McCauley 00008 // $Id: DifferentialSetter.h,v 1.2 2010/06/30 02:48:59 mikem Exp mikem $ 00009 00010 #ifndef DifferentialSetter_h 00011 #define DifferentialSetter_h 00012 00013 #include "Setter.h" 00014 #include <inttypes.h> 00015 00016 ///////////////////////////////////////////////////////////////////// 00017 /// \class DifferentialSetter DifferentialSetter.h <DifferentialSetter.h> 00018 /// \brief Setter class cluster that controls 2 analog outputs based on 2 analog inputs so that a joystic 00019 /// can be used to control 2 motors like on a tank or bulldozer or concentric rotor helicopter. 00020 /// inputA controls forwars/reverse and inputB controls left/right. 00021 /// 00022 /// A Differential is used to drive 2 motors in forward and reverse directions 00023 /// in response to the inputs from 2 joysticks. 00024 /// 00025 /// It requires 2 HBridges as output: 00026 /// one to drive the left motor forward/reverse and one to drive the right motor forward/reverse. 00027 /// 00028 /// It also requires 2 inputs, 00029 /// one for the fore-aft and one for the left-right. The 2 outputs drive 2 reversible motors 00030 /// that act like the motors on a tank 00031 /// or bulldozer, allowing forward, reverse and turning under the control of an x-Y joystick. 00032 /// 00033 /// In general, the fore/aft input (inputA) is replicated on the 2 outputs, but if inputB varies 00034 /// either side of 127, outputA is increased/decreased and outputB in decreased/increased. 00035 /// The outputs are never permitted outside the range 0 - 255. 00036 /// 00037 /// The standard input (inputA) to this Setter controls the forward/reverse. The left/right controls come 00038 /// through an instance of the DifferentialLRSetter class. 00039 /// 00040 /// Typically the outputs would be two HBridgeSetter instances to control a pair of motors 00041 /// but could be ServoSetter, AccelStepperSpeedSetter 00042 /// or AccelStepperPositionSetter or any other combination. 00043 /// 00044 class DifferentialSetter : public Setter 00045 { 00046 public: 00047 /// \param[in] targetA The Setter to use for output A. 00048 /// \param[in] targetB The Setter to use for output B. 00049 DifferentialSetter(Setter* targetA, Setter* targetB); 00050 00051 /// Set or change the output pin 00052 /// \param[in] targetA The Setter to use for output A. 00053 /// \param[in] targetB The Setter to use for output B. 00054 void setTargets(Setter* targetA, Setter* targetB); 00055 00056 /// Input the value to be used to set the 2 output Setters. 00057 /// \param[in] value The fore/aft value. 00058 virtual void input(int value); 00059 00060 /// This is the B input, controlling left-right differential. It has to come from 00061 /// an instance of DifferentialLRSetter. 00062 /// \param[in] value The input value to set. 00063 virtual void inputB(int value); 00064 00065 /// Called when the source of input data is lost, and the Setter is required to fail in a safe way. 00066 /// Calls the failsafes of targetA and targetB 00067 virtual void failsafe(); 00068 00069 protected: 00070 /// Internal function that computes the two output vlaues based on themost recent input values 00071 void doOutput(); 00072 00073 private: 00074 /// The B output Setter. targetA is the setter that is included in the Setter class 00075 Setter* _targetB; 00076 int _lastInputA; 00077 int _lastInputB; 00078 }; 00079 00080 ///////////////////////////////////////////////////////////////////// 00081 /// \class DifferentialLRSetter DifferentialSetter.h <DifferentialSetter.h> 00082 /// \brief Setter class cluster that provides the left-right input to a DifferentialSetter 00083 /// 00084 /// Looks like a conventional; setter, but sets the B input of a DifferentialSetter 00085 /// This is for setting the left-right inputs into a DifferentialSetter 00086 class DifferentialLRSetter : public Setter 00087 { 00088 public: 00089 /// \param target The DifferentialSetter whose inputB is to be set by this Setter 00090 DifferentialLRSetter(DifferentialSetter* target); 00091 00092 /// \param value The left/right value (inputB) to set in the target DifferentialSetter 00093 virtual void input(int value); 00094 }; 00095 00096 00097 #endif