00001 // HBridgeSetter.h 00002 // 00003 // Setter class that outputs its value to a HBridge configured on 2 analog output pins 00004 /// \author Mike McCauley (mikem@open.com.au) 00005 /// 00006 // Copyright (C) 2010 Mike McCauley 00007 // $Id: HBridgeSetter.h,v 1.3 2010/06/28 00:56:10 mikem Exp $ 00008 00009 #ifndef HBridgeSetter_h 00010 #define HBridgeSetter_h 00011 00012 #include "Setter.h" 00013 #include <inttypes.h> 00014 00015 ///////////////////////////////////////////////////////////////////// 00016 /// \class HBridgeSetter HBridgeSetter.h <HBridgeSetter.h> 00017 /// \brief Setter class that outputs its value to a HBridge configured on 2 output Setter 00018 /// 00019 /// A HBridge is used to drive a motor in forward and reverse directions. It requires 2 Setters as output: 00020 /// one to drive the motor forwards and one to drive it in reverse. When driving forward the reverse 00021 /// output is 0 and vice versa. 00022 /// 00023 /// Typically the outputs would be AnalogSetters to control a motor through a pair of analog outputs, 00024 /// but could be ServoSetter, AccelStepperSpeedSetter 00025 /// or AccelStepperPositionSetter or any other combination. 00026 /// 00027 class HBridgeSetter : public Setter 00028 { 00029 public: 00030 /// \param[in] targetA The Setter to use for output A. 00031 /// \param[in] targetB The Setter to use for output B. 00032 HBridgeSetter(Setter* targetA, Setter* targetB); 00033 00034 /// Set or change the output pin 00035 /// \param[in] targetA The Setter to use for output A. 00036 /// \param[in] targetB The Setter to use for output B. 00037 void setTargets(Setter* targetA, Setter* targetB); 00038 00039 /// Input the value to be used to set the 2 output Setters. 00040 /// Input of 127 produces 0 on both outputs (stopped) 00041 /// Input of 128 to 255 translates to output Setter A from 0 to 256 00042 /// and output Setter B at 0 (forward). 00043 /// Input of 127 to 0 translates to output Setter B from 0 to 254 00044 /// and output Setter A at 0 (reverse). 00045 /// \param[in] value The input value to set. 00046 virtual void input(int value); 00047 00048 /// Called when the source of input data is lost, and the Setter is required to fail in a safe way. 00049 /// Calls the failsafes of targetA and targetB 00050 virtual void failsafe(); 00051 00052 protected: 00053 00054 private: 00055 /// The B output Setter. targetA is the setter that is included in the Setter class 00056 Setter* _targetB; 00057 }; 00058 00059 #endif g