Ravens Robotics FRC 2015
SmoothAxis.cpp
Go to the documentation of this file.
1 
9 #include <SmoothAxis.h>
10 #include <cmath> // std::abs
11 #include <algorithm> // std::min, std::max
12 
17  SmoothAxis::setEnabled(false); // Delegate initialization of private members
18 }
19 
24  // Auto-generated destructor stub
25 }
26 
30 void SmoothAxis::SetTarget( float newTarget ) {
31  // Ensure input is within range - peg at max.
32  newTarget = std::min(newTarget,(float) -1);
33  newTarget = std::max(newTarget,(float) +1);
34 
35  m_prevTarget = m_target; // Remember our previous target
36  m_target = newTarget; // Store new target
37 }
38 
48  // Check that smoothing is enabled, and that the target
49  // increment is outside our tolerance, before smoothing.
50  if (isEnabled() && std::abs(m_target - m_prevTarget) > kAccelVal) {
51  //bring the motor value closer to the joystick by 1%
53  }
54  return m_target;
55 }
56 
61  return m_enabled;
62 }
63 
67 void SmoothAxis::setEnabled(bool enabled) {
68  m_enabled = enabled;
69  // Anytime we change state, zero our targets to
70  // reset the smoothing algorithm.
71  // (Thanks for the tip, Jacob!)
72  m_prevTarget = m_target = 0.0;
73 }
bool isEnabled()
Definition: SmoothAxis.cpp:60
virtual ~SmoothAxis()
Definition: SmoothAxis.cpp:23
float m_target
Definition: SmoothAxis.h:63
float m_prevTarget
current & previous target settings for smoothing algo
Definition: SmoothAxis.h:63
bool m_enabled
=true if smoothing enabled
Definition: SmoothAxis.h:62
void setEnabled(bool enabled)
Definition: SmoothAxis.cpp:67
void SetTarget(float newTarget)
Definition: SmoothAxis.cpp:30
float GetValue()
Definition: SmoothAxis.cpp:47
Header file of helper class for Drive RobotComponents.
const float kAccelVal
Acceleration increment: approach target by 1%.
Definition: SmoothAxis.h:64