WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
DriverStationEnhancedIO.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef __DRIVER_STATION_ENHANCED_IO_H__
8 #define __DRIVER_STATION_ENHANCED_IO_H__
9 
10 #include "ErrorBase.h"
11 #include "NetworkCommunication/FRCComm.h"
12 #include <stack>
13 #include <vector>
14 #include <vxWorks.h>
15 
16 #define kAnalogInputResolution ((double)((1<<14)-1))
17 #define kAnalogInputReference 3.3
18 #define kAnalogOutputResolution ((double)((1<<8)-1))
19 #define kAnalogOutputReference 4.0
20 #define kAccelOffset 8300
21 #define kAccelScale 3300.0
22 #define kSupportedAPIVersion 1
23 
30 {
31  // Can only be constructed by the DriverStation class.
32  friend class DriverStation;
33 
34 #pragma pack(push,1)
35  // BEGIN: Definitions from the Cypress firmware
36  typedef struct
37  {
38  uint16_t digital;
39  uint16_t digital_oe;
40  uint16_t digital_pe;
41  uint16_t pwm_compare[4];
42  uint16_t pwm_period[2];
43  uint8_t dac[2];
44  uint8_t leds;
45  union
46  {
47  struct
48  {
49  // Bits are inverted from cypress fw because of big-endian!
50  uint8_t pwm_enable : 4;
51  uint8_t comparator_enable : 2;
52  uint8_t quad_index_enable : 2;
53  };
54  uint8_t enables;
55  };
56  uint8_t fixed_digital_out;
57  } output_t; //data to IO (23 bytes)
58 
59  typedef struct
60  {
61  uint8_t api_version;
62  uint8_t fw_version;
63  int16_t analog[8];
64  uint16_t digital;
65  int16_t accel[3];
66  int16_t quad[2];
67  uint8_t buttons;
68  uint8_t capsense_slider;
69  uint8_t capsense_proximity;
70  } input_t; //data from IO (33 bytes)
71  // END: Definitions from the Cypress firmware
72 
73  // Dynamic block definitions
74  typedef struct
75  {
76  uint8_t size; // Must be 25 (size remaining in the block not counting the size variable)
77  uint8_t id; // Must be 18
78  output_t data;
79  uint8_t flags;
80  } status_block_t;
81 
82  typedef struct
83  {
84  uint8_t size; // Must be 34
85  uint8_t id; // Must be 17
86  input_t data;
87  } control_block_t;
88 #pragma pack(pop)
89 
90  enum tBlockID
91  {
92  kInputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
93  kOutputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
94  };
95  enum tStatusFlags {kStatusValid = 0x01, kStatusConfigChanged = 0x02, kForceEnhancedMode = 0x04};
96 
97 public:
98  enum tDigitalConfig {kUnknown, kInputFloating, kInputPullUp, kInputPullDown, kOutput, kPWM, kAnalogComparator};
99  enum tAccelChannel {kAccelX = 0, kAccelY = 1, kAccelZ = 2};
100  enum tPWMPeriodChannels {kPWMChannels1and2, kPWMChannels3and4};
101 
102  double GetAcceleration(tAccelChannel channel);
103  double GetAnalogIn(uint32_t channel);
104  double GetAnalogInRatio(uint32_t channel);
105  double GetAnalogOut(uint32_t channel);
106  void SetAnalogOut(uint32_t channel, double value);
107  bool GetButton(uint32_t channel);
108  uint8_t GetButtons();
109  void SetLED(uint32_t channel, bool value);
110  void SetLEDs(uint8_t value);
111  bool GetDigital(uint32_t channel);
112  uint16_t GetDigitals();
113  void SetDigitalOutput(uint32_t channel, bool value);
114  tDigitalConfig GetDigitalConfig(uint32_t channel);
115  void SetDigitalConfig(uint32_t channel, tDigitalConfig config);
116  double GetPWMPeriod(tPWMPeriodChannels channels);
117  void SetPWMPeriod(tPWMPeriodChannels channels, double period);
118  bool GetFixedDigitalOutput(uint32_t channel);
119  void SetFixedDigitalOutput(uint32_t channel, bool value);
120  int16_t GetEncoder(uint32_t encoderNumber);
121  void ResetEncoder(uint32_t encoderNumber);
122  bool GetEncoderIndexEnable(uint32_t encoderNumber);
123  void SetEncoderIndexEnable(uint32_t encoderNumber, bool enable);
124  double GetTouchSlider();
125  double GetPWMOutput(uint32_t channel);
126  void SetPWMOutput(uint32_t channel, double value);
127  uint8_t GetFirmwareVersion();
128 
129 private:
131  virtual ~DriverStationEnhancedIO();
132  void UpdateData();
133  void MergeConfigIntoOutput(const status_block_t &dsOutputBlock, status_block_t &localCache);
134  bool IsConfigEqual(const status_block_t &dsOutputBlock, const status_block_t &localCache);
135 
136  // Usage Guidelines...
137  DISALLOW_COPY_AND_ASSIGN(DriverStationEnhancedIO);
138 
139  control_block_t m_inputData;
140  status_block_t m_outputData;
141  SEM_ID m_inputDataSemaphore;
142  SEM_ID m_outputDataSemaphore;
143  bool m_inputValid;
144  bool m_outputValid;
145  bool m_configChanged;
146  bool m_requestEnhancedEnable;
147  int16_t m_encoderOffsets[2];
148 };
149 
150 #endif
151 
void SetPWMOutput(uint32_t channel, double value)
Definition: DriverStationEnhancedIO.cpp:948
uint16_t GetDigitals()
Definition: DriverStationEnhancedIO.cpp:429
uint8_t GetButtons()
Definition: DriverStationEnhancedIO.cpp:335
double GetPWMOutput(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:922
uint8_t GetFirmwareVersion()
Definition: DriverStationEnhancedIO.cpp:983
tDigitalConfig GetDigitalConfig(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:494
void SetLEDs(uint8_t value)
Definition: DriverStationEnhancedIO.cpp:388
void SetFixedDigitalOutput(uint32_t channel, bool value)
Definition: DriverStationEnhancedIO.cpp:749
void SetDigitalOutput(uint32_t channel, bool value)
Definition: DriverStationEnhancedIO.cpp:447
bool GetFixedDigitalOutput(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:718
bool GetEncoderIndexEnable(uint32_t encoderNumber)
Definition: DriverStationEnhancedIO.cpp:851
double GetPWMPeriod(tPWMPeriodChannels channels)
Definition: DriverStationEnhancedIO.cpp:652
Definition: DriverStationEnhancedIO.h:29
void SetDigitalConfig(uint32_t channel, tDigitalConfig config)
Definition: DriverStationEnhancedIO.cpp:563
Definition: ErrorBase.h:37
void SetAnalogOut(uint32_t channel, double value)
Definition: DriverStationEnhancedIO.cpp:271
bool GetDigital(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:406
void SetLED(uint32_t channel, bool value)
Definition: DriverStationEnhancedIO.cpp:353
double GetAnalogOut(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:241
void SetPWMPeriod(tPWMPeriodChannels channels, double period)
Definition: DriverStationEnhancedIO.cpp:680
void SetEncoderIndexEnable(uint32_t encoderNumber, bool enable)
Definition: DriverStationEnhancedIO.cpp:882
double GetTouchSlider()
Definition: DriverStationEnhancedIO.cpp:901
double GetAnalogInRatio(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:208
void ResetEncoder(uint32_t encoderNumber)
Definition: DriverStationEnhancedIO.cpp:825
bool GetButton(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:312
double GetAcceleration(tAccelChannel channel)
Definition: DriverStationEnhancedIO.cpp:166
Definition: DriverStation.h:21
int16_t GetEncoder(uint32_t encoderNumber)
Definition: DriverStationEnhancedIO.cpp:793
double GetAnalogIn(uint32_t channel)
Definition: DriverStationEnhancedIO.cpp:196