RCKit
Main Page
Classes
Files
Examples
File List
File Members
MotorControllerSetter.h
1
// MotorControllerSetter.h
2
//
3
// Setter class that outputs its value to a MotorController configured on 1 digital and one analog output pins
4
/// \author Mike McCauley (mikem@airspayce.com)
5
///
6
// Copyright (C) 2010 Mike McCauley
7
// $Id: MotorControllerSetter.h,v 1.1 2012/08/25 06:18:13 mikem Exp $
8
9
#ifndef MotorControllerSetter_h
10
#define MotorControllerSetter_h
11
12
#include "Setter.h"
13
#include <inttypes.h>
14
15
/////////////////////////////////////////////////////////////////////
16
/// \class MotorControllerSetter MotorControllerSetter.h <MotorControllerSetter.h>
17
/// \brief Setter class that outputs its value to a MotorController configured on 1 digital and one analog output pins
18
///
19
/// A MotorController is used to drive a motor in forward and reverse directions. It requires 2 Setters as output:
20
/// one to specify the direction, and one to specify the speed.
21
///
22
/// Inputs 0 to 127 set direction to 0 (reverse) and speed to 254 to 0 respectively
23
/// Inputs 128 to 255 set direction to 1 (forward) and speed to 0 to 256 respectively
24
/// This means than an input of 0 will produce full speed reverse, and input of 127 will produce stop and
25
/// 255 will produce full speed forward. Truth table:
26
/// input A B
27
/// 0 0 254
28
/// 100 0 54
29
/// 127 255 0
30
/// 128 255 2
31
/// 203 255 146
32
/// 255 255 256
33
///
34
/// This is compatible with many motor controllers, such as the Arduino Motor Shield (L298N) (SKU:DRI0009) and many others
35
///
36
/// Typically the outputs would be a DigitalSetter and an AnalogSetter to control a motor through a digital (direction)
37
/// and an analog (PWM speed) outputs
38
///
39
class
MotorControllerSetter
:
public
Setter
40
{
41
public
:
42
/// \param[in] targetA The Setter to use for direction, typically a DigitalSetter.
43
/// \param[in] targetB The Setter to use for speed, typically an AnalogSetter.
44
MotorControllerSetter
(
Setter
* targetA,
Setter
* targetB);
45
46
/// Set or change the output pin
47
/// \param[in] targetA The Setter to use for output A.
48
/// \param[in] targetB The Setter to use for output B.
49
void
setTargets
(
Setter
* targetA,
Setter
* targetB);
50
51
/// Input the value to be used to set the 2 output Setters.
52
/// Input of 127 produces 255 on A and 0 on B (forward but stopped)
53
/// Input of 128 to 255 translates to output Setter A to 256 (forward)
54
/// and output Setter B at 0 to 254 (full speed).
55
/// Input of 127 to 0 translates to output Setter A to 0 (reverse)
56
/// and output Setter B at 0 to 254 (full speed).
57
/// \param[in] value The input value to set.
58
virtual
void
input
(
int
value);
59
60
/// Called when the source of input data is lost, and the Setter is required to fail in a safe way.
61
/// Calls the failsafes of targetA and targetB
62
virtual
void
failsafe
();
63
64
protected
:
65
66
private
:
67
/// The B output Setter. targetA is the setter that is included in the Setter class
68
Setter
* _targetB;
69
};
70
71
#endif
Generated by
1.8.1