WPILib 2012
WPILibRoboticsLibraryforFRC
DriverStationEnhancedIO.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef __DRIVER_STATION_ENHANCED_IO_H__
00008 #define __DRIVER_STATION_ENHANCED_IO_H__
00009 
00010 #include "ErrorBase.h"
00011 #include "NetworkCommunication/FRCComm.h"
00012 #include <stack>
00013 #include <vector>
00014 #include <vxWorks.h>
00015 
00016 #define kAnalogInputResolution ((double)((1<<14)-1))
00017 #define kAnalogInputReference 3.3
00018 #define kAnalogOutputResolution ((double)((1<<8)-1))
00019 #define kAnalogOutputReference 4.0
00020 #define kAccelOffset 8300
00021 #define kAccelScale 3300.0
00022 #define kSupportedAPIVersion 1
00023 
00029 class DriverStationEnhancedIO : public ErrorBase
00030 {
00031         // Can only be constructed by the DriverStation class.
00032         friend class DriverStation;
00033 
00034 #pragma pack(push,1)
00035         // BEGIN: Definitions from the Cypress firmware
00036         typedef struct
00037         {
00038                 UINT16 digital;
00039                 UINT16 digital_oe;
00040                 UINT16 digital_pe;
00041                 UINT16 pwm_compare[4];
00042                 UINT16 pwm_period[2];
00043                 UINT8 dac[2];
00044                 UINT8 leds;
00045                 union
00046                 {
00047                         struct
00048                         {
00049                                 // Bits are inverted from cypress fw because of big-endian!
00050                                 UINT8 pwm_enable : 4;
00051                                 UINT8 comparator_enable : 2;
00052                                 UINT8 quad_index_enable : 2;
00053                         };
00054                         UINT8 enables;
00055                 };
00056                 UINT8 fixed_digital_out;
00057         } output_t;  //data to IO (23 bytes)
00058 
00059         typedef struct
00060         {
00061                 UINT8 api_version;
00062                 UINT8 fw_version;
00063                 INT16 analog[8];
00064                 UINT16 digital;
00065                 INT16 accel[3];
00066                 INT16 quad[2];
00067                 UINT8 buttons;
00068                 UINT8 capsense_slider;
00069                 UINT8 capsense_proximity;
00070         } input_t;      //data from IO (33 bytes)
00071         // END: Definitions from the Cypress firmware
00072 
00073         // Dynamic block definitions
00074         typedef struct
00075         {
00076                 UINT8 size; // Must be 25 (size remaining in the block not counting the size variable)
00077                 UINT8 id; // Must be 18
00078                 output_t data;
00079                 UINT8 flags;
00080         } status_block_t;
00081 
00082         typedef struct
00083         {
00084                 UINT8 size; // Must be 34
00085                 UINT8 id; // Must be 17
00086                 input_t data;
00087         } control_block_t;
00088 #pragma pack(pop)
00089 
00090         enum tBlockID
00091         {
00092                 kInputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
00093                 kOutputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
00094         };
00095         enum tStatusFlags {kStatusValid = 0x01, kStatusConfigChanged = 0x02, kForceEnhancedMode = 0x04};
00096 
00097 public:
00098         enum tDigitalConfig {kUnknown, kInputFloating, kInputPullUp, kInputPullDown, kOutput, kPWM, kAnalogComparator};
00099         enum tAccelChannel {kAccelX = 0, kAccelY = 1, kAccelZ = 2};
00100         enum tPWMPeriodChannels {kPWMChannels1and2, kPWMChannels3and4};
00101 
00102         double GetAcceleration(tAccelChannel channel);
00103         double GetAnalogIn(UINT32 channel);
00104         double GetAnalogInRatio(UINT32 channel);
00105         double GetAnalogOut(UINT32 channel);
00106         void SetAnalogOut(UINT32 channel, double value);
00107         bool GetButton(UINT32 channel);
00108         UINT8 GetButtons();
00109         void SetLED(UINT32 channel, bool value);
00110         void SetLEDs(UINT8 value);
00111         bool GetDigital(UINT32 channel);
00112         UINT16 GetDigitals();
00113         void SetDigitalOutput(UINT32 channel, bool value);
00114         tDigitalConfig GetDigitalConfig(UINT32 channel);
00115         void SetDigitalConfig(UINT32 channel, tDigitalConfig config);
00116         double GetPWMPeriod(tPWMPeriodChannels channels);
00117         void SetPWMPeriod(tPWMPeriodChannels channels, double period);
00118         bool GetFixedDigitalOutput(UINT32 channel);
00119         void SetFixedDigitalOutput(UINT32 channel, bool value);
00120         INT16 GetEncoder(UINT32 encoderNumber);
00121         void ResetEncoder(UINT32 encoderNumber);
00122         bool GetEncoderIndexEnable(UINT32 encoderNumber);
00123         void SetEncoderIndexEnable(UINT32 encoderNumber, bool enable);
00124         double GetTouchSlider();
00125         double GetPWMOutput(UINT32 channel);
00126         void SetPWMOutput(UINT32 channel, double value);
00127         UINT8 GetFirmwareVersion();
00128 
00129 private:
00130         DriverStationEnhancedIO();
00131         virtual ~DriverStationEnhancedIO();
00132         void UpdateData();
00133         void MergeConfigIntoOutput(const status_block_t &dsOutputBlock, status_block_t &localCache);
00134         bool IsConfigEqual(const status_block_t &dsOutputBlock, const status_block_t &localCache);
00135 
00136         // Usage Guidelines...
00137         DISALLOW_COPY_AND_ASSIGN(DriverStationEnhancedIO);
00138 
00139         control_block_t m_inputData;
00140         status_block_t m_outputData;
00141         SEM_ID m_inputDataSemaphore;
00142         SEM_ID m_outputDataSemaphore;
00143         bool m_inputValid;
00144         bool m_outputValid;
00145         bool m_configChanged;
00146         bool m_requestEnhancedEnable;
00147         INT16 m_encoderOffsets[2];
00148 };
00149 
00150 #endif
00151 
 All Classes Functions Variables