LRT13  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
DrivetrainData.h
1 #ifndef DRIVETRAIN_DATA_H
2 #define DRIVETRAIN_DATA_H
3 
4 #include "ComponentData.h"
5 #include <semLib.h>
6 
7 
8 class DriveEncoders;
9 
10 namespace data
11 {
16 namespace drivetrain
17 {
18  enum ControlMode
19  {
20  POSITION_CONTROL, VELOCITY_CONTROL, OPEN_LOOP
21  };
22 
23  enum ForwardOrTurn
24  {
25  FORWARD = 0, TURN = 1
26  };
27 
28  enum Side
29  {
30  LEFT = 2, RIGHT = 3
31  };
32 
33  class DrivetrainData
34  {
35  public:
36  DrivetrainData();
37  ~DrivetrainData();
38 
39  ControlMode getControlMode(ForwardOrTurn axis);
40 
41  void setOpenLoopOutput(ForwardOrTurn axis, double setpoint);
42  void setVelocitySetpoint(ForwardOrTurn axis, double setpoint);
43 
44  void setRelativePositionSetpoint(ForwardOrTurn axis, double setpoint,
45  double maxSpeed, bool fromLastSetpoint = false);
46  void setMaxPositionControlSpeed(ForwardOrTurn axis, double maxSpeed);
47 
48  void setControlMode(ForwardOrTurn axis, ControlMode control);
49 
50  void setZeroHeading();
51  void zeroLastPositionSetpoint(ForwardOrTurn axis);
52 
53  SEM_ID createPositionOperationSemaphore(ForwardOrTurn axis, double errorThreshold);
54 
55  bool isDesiredPositionOperationComplete(ForwardOrTurn axis,
56  double errorThreshold);
57 
58  double getOpenLoopOutput(ForwardOrTurn axis);
59  double getVelocitySetpoint(ForwardOrTurn axis);
60  double getRelativePositionSetpoint(ForwardOrTurn axis);
61  double getAbsolutePositionSetpoint(ForwardOrTurn axis);
62  double getPositionControlMaxSpeed(ForwardOrTurn axis);
63  bool isPositionSetpointChanged(ForwardOrTurn axis);
64  void setPositionSetpointChanged(ForwardOrTurn axis, bool changed);
65  double getPositionControlStartingPosition(ForwardOrTurn axis);
66 
67  float getCurrentHeading();
68 
69  void serviceOperationSemaphores();
70  void cleanWaitForSem(SEM_ID sem);
71  bool cleanWaitForSem(SEM_ID sem, double timeout);
72 
73  void DebugPrintPosition(ForwardOrTurn axis);
74  double getCurrentPos(ForwardOrTurn axis);
75 
76  void syncArc();
77  bool syncingArc();
78 
79  void overrideForwardCurrentLimit(float limit);
80  void overrideReverseCurrentLimit(float limit);
81  float getForwardCurrentLimit();
82  float getReverseCurrentLimit();
83  bool shouldOverrideForwardCurrentLimit();
84  bool shouldOverrideReverseCurrentLimit();
85 
86  private:
87 
88  DriveEncoders *m_driveEncoders;
89  ControlMode m_controlModes[2];
90  double m_desiredOpenLoopOutputs[2];
91  double m_desiredRates[2];
92  double m_positionSetpoints[2];
93  double m_maxSpeeds[2];
94  double m_positionStart[2];
95  float m_zeroHeading;
96  bool m_positionSetpointChanged[2];
97  bool m_syncArc;
98  bool m_overrideCurrentLimitForward;
99  bool m_overrideCurrentLimitReverse;
100  float m_currentLimitForward;
101  float m_currentLimitReverse;
102 
103  typedef struct drivetrainOpSem
104  {
105  SEM_ID sem;
106  ForwardOrTurn axis;
107  double errorThreshold;
108  };
109  list<drivetrainOpSem> operationSems;
110  };
111 }
112 }
113 
114 #endif