RCKit
Main Page
Classes
Files
Examples
File List
File Members
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.2 2010/06/30 02:48:59 mikem Exp $
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
86
class
DifferentialLRSetter
:
public
Setter
87
{
88
public
:
89
/// \param target The DifferentialSetter whose inputB is to be set by this Setter
90
DifferentialLRSetter
(
DifferentialSetter
* target);
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
Generated by
1.8.1