CMake Changes

This is the changes made by Patrick Plenefisch converting the native
code to use CMake and the CMake Maven Plugin, as opposed to the
native Maven plugin. This is to allow for compatibility with newer
versions of the GCC toolchain. All the cpp sources were moved from
maven style directories to cpp style directories for CMake.

Change-Id: I67f5e3608948f37c83b0990d232105a3784f8593
This commit is contained in:
Brad Miller
2014-03-24 16:13:08 -04:00
parent 33134bef1d
commit 69d9ad70ab
804 changed files with 586 additions and 9377 deletions

View File

@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __ADXL345_I2C_h__
#define __ADXL345_I2C_h__
#include "SensorBase.h"
class I2C;
/**
* ADXL345 Accelerometer on I2C.
*
* This class alows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
* This class assumes the default (not alternate) sensor address of 0x3A (8-bit address).
*/
class ADXL345_I2C : public SensorBase
{
protected:
static const uint8_t kAddress = 0x3A;
static const uint8_t kPowerCtlRegister = 0x2D;
static const uint8_t kDataFormatRegister = 0x31;
static const uint8_t kDataRegister = 0x32;
static constexpr double kGsPerLSB = 0.00390625;
enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04};
enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20,
kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04};
public:
enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03};
enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04};
struct AllAxes
{
double XAxis;
double YAxis;
double ZAxis;
};
public:
explicit ADXL345_I2C(uint8_t moduleNumber, DataFormat_Range range=kRange_2G);
virtual ~ADXL345_I2C();
virtual double GetAcceleration(Axes axis);
virtual AllAxes GetAccelerations();
protected:
I2C* m_i2c;
};
#endif

View File

@@ -0,0 +1,67 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __ADXL345_SPI_h__
#define __ADXL345_SPI_h__
#include "SensorBase.h"
class DigitalInput;
class DigitalOutput;
class SPI;
/**
* ADXL345 Accelerometer on SPI.
*
* This class alows access to an Analog Devices ADXL345 3-axis accelerometer via SPI.
* This class assumes the sensor is wired in 4-wire SPI mode.
*/
class ADXL345_SPI : public SensorBase
{
protected:
static const uint8_t kPowerCtlRegister = 0x2D;
static const uint8_t kDataFormatRegister = 0x31;
static const uint8_t kDataRegister = 0x32;
static constexpr double kGsPerLSB = 0.00390625;
enum SPIAddressFields {kAddress_Read=0x80, kAddress_MultiByte=0x40};
enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04};
enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20,
kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04};
public:
enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03};
enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04};
struct AllAxes
{
double XAxis;
double YAxis;
double ZAxis;
};
public:
ADXL345_SPI(DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso,
DigitalOutput &cs, DataFormat_Range range=kRange_2G);
ADXL345_SPI(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso,
DigitalOutput *cs, DataFormat_Range range=kRange_2G);
ADXL345_SPI(uint8_t moduleNumber, uint32_t clk, uint32_t mosi, uint32_t miso, uint32_t cs,
DataFormat_Range range=kRange_2G);
virtual ~ADXL345_SPI();
virtual double GetAcceleration(Axes axis);
virtual AllAxes GetAccelerations();
protected:
void Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso,
DigitalOutput *cs, DataFormat_Range range);
DigitalOutput *m_clk;
DigitalOutput *m_mosi;
DigitalInput *m_miso;
DigitalOutput *m_cs;
SPI* m_spi;
};
#endif

View File

@@ -0,0 +1,51 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ACCELEROMETER_H_
#define ACCELEROMETER_H_
#include "AnalogChannel.h"
#include "SensorBase.h"
#include "PIDSource.h"
#include "LiveWindow/LiveWindowSendable.h"
/**
* Handle operation of the accelerometer.
* The accelerometer reads acceleration directly through the sensor. Many sensors have
* multiple axis and can be treated as multiple devices. Each is calibrated by finding
* the center value over a period of time.
*/
class Accelerometer : public SensorBase, public PIDSource, public LiveWindowSendable {
public:
explicit Accelerometer(uint32_t channel);
Accelerometer(uint8_t moduleNumber, uint32_t channel);
explicit Accelerometer(AnalogChannel *channel);
virtual ~Accelerometer();
float GetAcceleration();
void SetSensitivity(float sensitivity);
void SetZero(float zero);
double PIDGet();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitAccelerometer();
AnalogChannel *m_analogChannel;
float m_voltsPerG;
float m_zeroGVoltage;
bool m_allocatedChannel;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,87 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_CHANNEL_H_
#define ANALOG_CHANNEL_H_
#include "HAL/HAL.h"
#include "SensorBase.h"
#include "PIDSource.h"
#include "LiveWindow/LiveWindowSendable.h"
class AnalogModule;
/**
* Analog channel class.
*
* Each analog channel is read from hardware as a 12-bit number representing -10V to 10V.
*
* Connected to each analog channel is an averaging and oversampling engine. This engine accumulates
* the specified ( by SetAverageBits() and SetOversampleBits() ) number of samples before returning a new
* value. This is not a sliding window average. The only difference between the oversampled samples and
* the averaged samples is that the oversampled samples are simply accumulated effectively increasing the
* resolution, while the averaged samples are divided by the number of samples to retain the resolution,
* but get more stable values.
*/
class AnalogChannel : public SensorBase, public PIDSource, public LiveWindowSendable
{
public:
static const uint8_t kAccumulatorModuleNumber = 1;
static const uint32_t kAccumulatorNumChannels = 2;
static const uint32_t kAccumulatorChannels[kAccumulatorNumChannels];
AnalogChannel(uint8_t moduleNumber, uint32_t channel);
explicit AnalogChannel(uint32_t channel);
virtual ~AnalogChannel();
AnalogModule *GetModule();
int16_t GetValue();
int32_t GetAverageValue();
float GetVoltage();
float GetAverageVoltage();
uint8_t GetModuleNumber();
uint32_t GetChannel();
void SetAverageBits(uint32_t bits);
uint32_t GetAverageBits();
void SetOversampleBits(uint32_t bits);
uint32_t GetOversampleBits();
uint32_t GetLSBWeight();
int32_t GetOffset();
bool IsAccumulatorChannel();
void InitAccumulator();
void SetAccumulatorInitialValue(int64_t value);
void ResetAccumulator();
void SetAccumulatorCenter(int32_t center);
void SetAccumulatorDeadband(int32_t deadband);
int64_t GetAccumulatorValue();
uint32_t GetAccumulatorCount();
void GetAccumulatorOutput(int64_t *value, uint32_t *count);
double PIDGet();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitChannel(uint8_t moduleNumber, uint32_t channel);
uint32_t m_channel, m_module;
void* m_port;
int64_t m_accumulatorOffset;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,56 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_MODULE_H_
#define ANALOG_MODULE_H_
#include "HAL/HAL.h"
#include "Module.h"
/**
* Analog Module class.
* Each module can independently sample its channels at a configurable rate.
* There is a 64-bit hardware accumulator associated with channel 1 on each module.
* The accumulator is attached to the output of the oversample and average engine so that the center
* value can be specified in higher resolution resulting in less error.
*/
class AnalogModule: public Module
{
friend class Module;
public:
static const long kTimebase = 40000000; ///< 40 MHz clock
static const long kDefaultOversampleBits = 0;
static const long kDefaultAverageBits = 7;
static const uint32_t kAnalogChannels = 8;
static constexpr float kDefaultSampleRate = 50000.0;
void SetSampleRate(float samplesPerSecond);
float GetSampleRate();
void SetAverageBits(uint32_t channel, uint32_t bits);
uint32_t GetAverageBits(uint32_t channel);
void SetOversampleBits(uint32_t channel, uint32_t bits);
uint32_t GetOversampleBits(uint32_t channel);
int16_t GetValue(uint32_t channel);
int32_t GetAverageValue(uint32_t channel);
float GetAverageVoltage(uint32_t channel);
float GetVoltage(uint32_t channel);
uint32_t GetLSBWeight(uint32_t channel);
int32_t GetOffset(uint32_t channel);
int32_t VoltsToValue(int32_t channel, float voltage);
static AnalogModule* GetInstance(uint8_t moduleNumber);
protected:
explicit AnalogModule(uint8_t moduleNumber);
virtual ~AnalogModule();
private:
uint8_t m_moduleNumber;
void* m_ports[kAnalogChannels];
};
#endif

View File

@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_TRIGGER_H_
#define ANALOG_TRIGGER_H_
#include "HAL/HAL.h"
#include "AnalogTriggerOutput.h"
#include "SensorBase.h"
class AnalogChannel;
class AnalogModule;
class AnalogTrigger: public SensorBase
{
friend class AnalogTriggerOutput;
public:
AnalogTrigger(uint8_t moduleNumber, uint32_t channel);
explicit AnalogTrigger(uint32_t channel);
explicit AnalogTrigger(AnalogChannel *channel);
virtual ~AnalogTrigger();
void SetLimitsVoltage(float lower, float upper);
void SetLimitsRaw(int32_t lower, int32_t upper);
void SetAveraged(bool useAveragedValue);
void SetFiltered(bool useFilteredValue);
uint32_t GetIndex();
bool GetInWindow();
bool GetTriggerState();
AnalogTriggerOutput *CreateOutput(AnalogTriggerType type);
private:
void InitTrigger(uint8_t moduleNumber, uint32_t channel);
uint8_t m_index;
void* m_trigger;
};
#endif

View File

@@ -0,0 +1,64 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ANALOG_TRIGGER_OUTPUT_H_
#define ANALOG_TRIGGER_OUTPUT_H_
#include "DigitalSource.h"
class AnalogTrigger;
/**
* Class to represent a specific output from an analog trigger.
* This class is used to get the current output value and also as a DigitalSource
* to provide routing of an output to digital subsystems on the FPGA such as
* Counter, Encoder, and Interrupt.
*
* The TriggerState output indicates the primary output value of the trigger. If the analog
* signal is less than the lower limit, the output is false. If the analog value is greater
* than the upper limit, then the output is true. If the analog value is in between, then
* the trigger output state maintains its most recent value.
*
* The InWindow output indicates whether or not the analog signal is inside the range defined
* by the limits.
*
* The RisingPulse and FallingPulse outputs detect an instantaneous transition from above the
* upper limit to below the lower limit, and vise versa. These pulses represent a rollover
* condition of a sensor and can be routed to an up / down couter or to interrupts. Because
* the outputs generate a pulse, they cannot be read directly. To help ensure that a rollover
* condition is not missed, there is an average rejection filter available that operates on the
* upper 8 bits of a 12 bit number and selects the nearest outlyer of 3 samples. This will reject
* a sample that is (due to averaging or sampling) errantly between the two limits. This filter
* will fail if more than one sample in a row is errantly in between the two limits. You may see
* this problem if attempting to use this feature with a mechanical rollover sensor, such as a
* 360 degree no-stop potentiometer without signal conditioning, because the rollover transition
* is not sharp / clean enough. Using the averaging engine may help with this, but rotational speeds of
* the sensor will then be limited.
*/
class AnalogTriggerOutput: public DigitalSource
{
friend class AnalogTrigger;
public:
virtual ~AnalogTriggerOutput();
bool Get();
// DigitalSource interface
virtual uint32_t GetChannelForRouting();
virtual uint32_t GetModuleForRouting();
virtual bool GetAnalogTriggerForRouting();
virtual void RequestInterrupts(InterruptHandlerFunction handler, void *param=NULL); ///< Asynchronus handler version.
virtual void RequestInterrupts(); ///< Synchronus Wait version.
protected:
AnalogTriggerOutput(AnalogTrigger *trigger, AnalogTriggerType outputType);
private:
AnalogTrigger *m_trigger;
AnalogTriggerType m_outputType;
};
#endif

21
wpilibc/include/Base.h Normal file
View File

@@ -0,0 +1,21 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef _BASE_H
#define _BASE_H
// If don't have C++11, define constexpr as const for WindRiver
#if __cplusplus < 201103L
#define constexpr const
#endif
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __ANALOG_IO_BUTTON_H__
#define __ANALOG_IO_BUTTON_H__
#include "Buttons/Button.h"
class AnalogIOButton : public Trigger
{
public:
static const double kThreshold;
AnalogIOButton(int port);
virtual ~AnalogIOButton() {}
virtual bool Get();
private:
int m_port;
};
#endif

View File

@@ -0,0 +1,35 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include "Buttons/Trigger.h"
#include "Commands/Command.h"
/**
* This class provides an easy way to link commands to OI inputs.
*
* It is very easy to link a button to a command. For instance, you could
* link the trigger button of a joystick to a "score" command.
*
* This class represents a subclass of Trigger that is specifically aimed at
* buttons on an operator interface as a common use case of the more generalized
* Trigger objects. This is a simple wrapper around Trigger with the method names
* renamed to fit the Button object use.
*
* @author brad
*/
class Button : public Trigger {
public:
virtual void WhenPressed(Command *command);
virtual void WhileHeld(Command *command);
virtual void WhenReleased(Command *command);
virtual void CancelWhenPressed(Command *command);
virtual void ToggleWhenPressed(Command *command);
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __BUTTON_SCHEDULER_H__
#define __BUTTON_SCHEDULER_H__
class Trigger;
class Command;
class ButtonScheduler
{
public:
ButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ButtonScheduler() {}
virtual void Execute() = 0;
void Start();
protected:
bool m_pressedLast;
Trigger *m_button;
Command *m_command;
};
#endif

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __CANCEL_BUTTON_SCHEDULER_H__
#define __CANCEL_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class CancelButtonScheduler : public ButtonScheduler
{
public:
CancelButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~CancelButtonScheduler() {}
virtual void Execute();
private:
bool pressedLast;
};
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DIGITAL_IO_BUTTON_H__
#define __DIGITAL_IO_BUTTON_H__
#include "Buttons/Button.h"
class DigitalIOButton: public Button
{
public:
static const bool kActiveState;
DigitalIOButton(int port);
virtual ~DigitalIOButton() {}
virtual bool Get();
private:
int m_port;
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __HELD_BUTTON_SCHEDULER_H__
#define __HELD_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class HeldButtonScheduler : public ButtonScheduler
{
public:
HeldButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~HeldButtonScheduler() {}
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __INTERNAL_BUTTON_H__
#define __INTERNAL_BUTTON_H__
#include "Buttons/Button.h"
class InternalButton : public Button
{
public:
InternalButton();
InternalButton(bool inverted);
virtual ~InternalButton() {}
void SetInverted(bool inverted);
void SetPressed(bool pressed);
virtual bool Get();
private:
bool m_pressed;
bool m_inverted;
};
#endif

View File

@@ -0,0 +1,26 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __JOYSTICK_BUTTON_H__
#define __JOYSTICK_BUTTON_H__
#include "GenericHID.h"
#include "Buttons/Button.h"
class JoystickButton : public Button
{
public:
JoystickButton(GenericHID *joystick, int buttonNumber);
virtual ~JoystickButton() {}
virtual bool Get();
private:
GenericHID *m_joystick;
int m_buttonNumber;
};
#endif

View File

@@ -0,0 +1,28 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __NETWORK_BUTTON_H__
#define __NETWORK_BUTTON_H__
#include "Buttons/Button.h"
#include <string>
class NetworkButton : public Button
{
public:
NetworkButton(const char *tableName, const char *field);
NetworkButton(ITable* table, const char *field);
virtual ~NetworkButton() {}
virtual bool Get();
private:
ITable* m_netTable;
std::string m_field;
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PRESSED_BUTTON_SCHEDULER_H__
#define __PRESSED_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class PressedButtonScheduler : public ButtonScheduler
{
public:
PressedButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~PressedButtonScheduler() {}
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __RELEASED_BUTTON_SCHEDULER_H__
#define __RELEASED_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class ReleasedButtonScheduler : public ButtonScheduler
{
public:
ReleasedButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ReleasedButtonScheduler() {}
virtual void Execute();
};
#endif

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __TOGGLE_BUTTON_SCHEDULER_H__
#define __TOGGLE_BUTTON_SCHEDULER_H__
#include "Buttons/ButtonScheduler.h"
class Trigger;
class Command;
class ToggleButtonScheduler : public ButtonScheduler
{
public:
ToggleButtonScheduler(bool last, Trigger *button, Command *orders);
virtual ~ToggleButtonScheduler() {}
virtual void Execute();
private:
bool pressedLast;
};
#endif

View File

@@ -0,0 +1,49 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __TRIGGER_H__
#define __TRIGGER_H__
#include "SmartDashboard/Sendable.h"
class Command;
/**
* This class provides an easy way to link commands to inputs.
*
* It is very easy to link a polled input to a command. For instance, you could
* link the trigger button of a joystick to a "score" command or an encoder reaching
* a particular value.
*
* It is encouraged that teams write a subclass of Trigger if they want to have
* something unusual (for instance, if they want to react to the user holding
* a button while the robot is reading a certain sensor input). For this, they
* only have to write the {@link Trigger#Get()} method to get the full functionality
* of the Trigger class.
*
* @author Brad Miller, Joe Grinstead
*/
class Trigger : public Sendable
{
public:
Trigger();
virtual ~Trigger() {}
bool Grab();
virtual bool Get() = 0;
void WhenActive(Command *command);
void WhileActive(Command *command);
void WhenInactive(Command *command);
void CancelWhenActive(Command *command);
void ToggleWhenActive(Command *command);
virtual void InitTable(ITable* table);
virtual ITable* GetTable();
virtual std::string GetSmartDashboardType();
protected:
ITable* m_table;
};
#endif

View File

@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2009. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
// JaguarCANDriver.h
//
// Defines the API for building a CAN Interface Plugin to support
// PWM-cable-free CAN motor control on FRC robots. This allows you
// to connect any CAN interface to the secure Jaguar CAN driver.
//
#ifndef __JaguarCANDriver_h__
#define __JaguarCANDriver_h__
#include "HAL/HAL.h"
#ifdef __cplusplus
extern "C"
{
#endif
void FRC_NetworkCommunication_JaguarCANDriver_sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t *status);
void FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, uint32_t timeoutMs, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif // __JaguarCANDriver_h__

View File

@@ -0,0 +1,428 @@
//*****************************************************************************
//
// can_proto.h - Definitions for the CAN protocol used to communicate with the
// BDC motor controller.
//
// Copyright (c) 2008 Texas Instruments Incorporated. All rights reserved.
// TI Information - Selective Disclosure
//
//*****************************************************************************
#ifndef __CAN_PROTO_H__
#define __CAN_PROTO_H__
//*****************************************************************************
//
// The masks of the fields that are used in the message identifier.
//
//*****************************************************************************
#define CAN_MSGID_FULL_M 0x1fffffff
#define CAN_MSGID_DEVNO_M 0x0000003f
#define CAN_MSGID_API_M 0x0000ffc0
#define CAN_MSGID_MFR_M 0x00ff0000
#define CAN_MSGID_DTYPE_M 0x1f000000
#define CAN_MSGID_DEVNO_S 0
#define CAN_MSGID_API_S 6
#define CAN_MSGID_MFR_S 16
#define CAN_MSGID_DTYPE_S 24
//*****************************************************************************
//
// The Reserved device number values in the Message Id.
//
//*****************************************************************************
#define CAN_MSGID_DEVNO_BCAST 0x00000000
//*****************************************************************************
//
// The Reserved system control API numbers in the Message Id.
//
//*****************************************************************************
#define CAN_MSGID_API_SYSHALT 0x00000000
#define CAN_MSGID_API_SYSRST 0x00000040
#define CAN_MSGID_API_DEVASSIGN 0x00000080
#define CAN_MSGID_API_DEVQUERY 0x000000c0
#define CAN_MSGID_API_HEARTBEAT 0x00000140
#define CAN_MSGID_API_SYNC 0x00000180
#define CAN_MSGID_API_UPDATE 0x000001c0
#define CAN_MSGID_API_FIRMVER 0x00000200
#define CAN_MSGID_API_ENUMERATE 0x00000240
#define CAN_MSGID_API_SYSRESUME 0x00000280
//*****************************************************************************
//
// The 32 bit values associated with the CAN_MSGID_API_STATUS request.
//
//*****************************************************************************
#define CAN_STATUS_CODE_M 0x0000ffff
#define CAN_STATUS_MFG_M 0x00ff0000
#define CAN_STATUS_DTYPE_M 0x1f000000
#define CAN_STATUS_CODE_S 0
#define CAN_STATUS_MFG_S 16
#define CAN_STATUS_DTYPE_S 24
//*****************************************************************************
//
// The Reserved manufacturer identifiers in the Message Id.
//
//*****************************************************************************
#define CAN_MSGID_MFR_NI 0x00010000
#define CAN_MSGID_MFR_LM 0x00020000
#define CAN_MSGID_MFR_DEKA 0x00030000
//*****************************************************************************
//
// The Reserved device type identifiers in the Message Id.
//
//*****************************************************************************
#define CAN_MSGID_DTYPE_BCAST 0x00000000
#define CAN_MSGID_DTYPE_ROBOT 0x01000000
#define CAN_MSGID_DTYPE_MOTOR 0x02000000
#define CAN_MSGID_DTYPE_RELAY 0x03000000
#define CAN_MSGID_DTYPE_GYRO 0x04000000
#define CAN_MSGID_DTYPE_ACCEL 0x05000000
#define CAN_MSGID_DTYPE_USONIC 0x06000000
#define CAN_MSGID_DTYPE_GEART 0x07000000
#define CAN_MSGID_DTYPE_UPDATE 0x1f000000
//*****************************************************************************
//
// LM Motor Control API Classes API Class and ID masks.
//
//*****************************************************************************
#define CAN_MSGID_API_CLASS_M 0x0000fc00
#define CAN_MSGID_API_ID_M 0x000003c0
//*****************************************************************************
//
// LM Motor Control API Classes in the Message Id for non-broadcast.
// These are the upper 6 bits of the API field, the lower 4 bits determine
// the APIId.
//
//*****************************************************************************
#define CAN_API_MC_VOLTAGE 0x00000000
#define CAN_API_MC_SPD 0x00000400
#define CAN_API_MC_VCOMP 0x00000800
#define CAN_API_MC_POS 0x00000c00
#define CAN_API_MC_ICTRL 0x00001000
#define CAN_API_MC_STATUS 0x00001400
#define CAN_API_MC_PSTAT 0x00001800
#define CAN_API_MC_CFG 0x00001c00
#define CAN_API_MC_ACK 0x00002000
//*****************************************************************************
//
// The Stellaris Motor Class Control Voltage API definitions.
//
//*****************************************************************************
#define LM_API_VOLT (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_VOLTAGE)
#define LM_API_VOLT_EN (LM_API_VOLT | (0 << CAN_MSGID_API_S))
#define LM_API_VOLT_DIS (LM_API_VOLT | (1 << CAN_MSGID_API_S))
#define LM_API_VOLT_SET (LM_API_VOLT | (2 << CAN_MSGID_API_S))
#define LM_API_VOLT_SET_RAMP (LM_API_VOLT | (3 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_VOLT_T_EN (LM_API_VOLT | (4 << CAN_MSGID_API_S))
#define LM_API_VOLT_T_SET (LM_API_VOLT | (5 << CAN_MSGID_API_S))
#define LM_API_VOLT_T_SET_NO_ACK \
(LM_API_VOLT | (7 << CAN_MSGID_API_S))
//##### FIRST END #####
#define LM_API_VOLT_SET_NO_ACK (LM_API_VOLT | (8 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris Motor Class Control API definitions for LM_API_VOLT_SET_RAMP.
//
//*****************************************************************************
#define LM_API_VOLT_RAMP_DIS 0
//*****************************************************************************
//
// The Stellaris Motor Class Control API definitions for CAN_MSGID_API_SYNC.
//
//*****************************************************************************
#define LM_API_SYNC_PEND_NOW 0
//*****************************************************************************
//
// The Stellaris Motor Class Speed Control API definitions.
//
//*****************************************************************************
#define LM_API_SPD (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_SPD)
#define LM_API_SPD_EN (LM_API_SPD | (0 << CAN_MSGID_API_S))
#define LM_API_SPD_DIS (LM_API_SPD | (1 << CAN_MSGID_API_S))
#define LM_API_SPD_SET (LM_API_SPD | (2 << CAN_MSGID_API_S))
#define LM_API_SPD_PC (LM_API_SPD | (3 << CAN_MSGID_API_S))
#define LM_API_SPD_IC (LM_API_SPD | (4 << CAN_MSGID_API_S))
#define LM_API_SPD_DC (LM_API_SPD | (5 << CAN_MSGID_API_S))
#define LM_API_SPD_REF (LM_API_SPD | (6 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_SPD_T_EN (LM_API_SPD | (7 << CAN_MSGID_API_S))
#define LM_API_SPD_T_SET (LM_API_SPD | (8 << CAN_MSGID_API_S))
#define LM_API_SPD_T_SET_NO_ACK (LM_API_SPD | (10 << CAN_MSGID_API_S))
//##### FIRST END #####
#define LM_API_SPD_SET_NO_ACK (LM_API_SPD | (11 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris Motor Control Voltage Compensation Control API definitions.
//
//*****************************************************************************
#define LM_API_VCOMP (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_VCOMP)
#define LM_API_VCOMP_EN (LM_API_VCOMP | (0 << CAN_MSGID_API_S))
#define LM_API_VCOMP_DIS (LM_API_VCOMP | (1 << CAN_MSGID_API_S))
#define LM_API_VCOMP_SET (LM_API_VCOMP | (2 << CAN_MSGID_API_S))
#define LM_API_VCOMP_IN_RAMP (LM_API_VCOMP | (3 << CAN_MSGID_API_S))
#define LM_API_VCOMP_COMP_RAMP (LM_API_VCOMP | (4 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_VCOMP_T_EN (LM_API_VCOMP | (5 << CAN_MSGID_API_S))
#define LM_API_VCOMP_T_SET (LM_API_VCOMP | (6 << CAN_MSGID_API_S))
#define LM_API_VCOMP_T_SET_NO_ACK \
(LM_API_VCOMP | (8 << CAN_MSGID_API_S))
//##### FIRST END #####
#define LM_API_VCOMP_SET_NO_ACK (LM_API_VCOMP | (9 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris Motor Class Position Control API definitions.
//
//*****************************************************************************
#define LM_API_POS (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_POS)
#define LM_API_POS_EN (LM_API_POS | (0 << CAN_MSGID_API_S))
#define LM_API_POS_DIS (LM_API_POS | (1 << CAN_MSGID_API_S))
#define LM_API_POS_SET (LM_API_POS | (2 << CAN_MSGID_API_S))
#define LM_API_POS_PC (LM_API_POS | (3 << CAN_MSGID_API_S))
#define LM_API_POS_IC (LM_API_POS | (4 << CAN_MSGID_API_S))
#define LM_API_POS_DC (LM_API_POS | (5 << CAN_MSGID_API_S))
#define LM_API_POS_REF (LM_API_POS | (6 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_POS_T_EN (LM_API_POS | (7 << CAN_MSGID_API_S))
#define LM_API_POS_T_SET (LM_API_POS | (8 << CAN_MSGID_API_S))
#define LM_API_POS_T_SET_NO_ACK (LM_API_POS | (10 << CAN_MSGID_API_S))
//##### FIRST END #####
#define LM_API_POS_SET_NO_ACK (LM_API_POS | (11 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris Motor Class Current Control API definitions.
//
//*****************************************************************************
#define LM_API_ICTRL (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_ICTRL)
#define LM_API_ICTRL_EN (LM_API_ICTRL | (0 << CAN_MSGID_API_S))
#define LM_API_ICTRL_DIS (LM_API_ICTRL | (1 << CAN_MSGID_API_S))
#define LM_API_ICTRL_SET (LM_API_ICTRL | (2 << CAN_MSGID_API_S))
#define LM_API_ICTRL_PC (LM_API_ICTRL | (3 << CAN_MSGID_API_S))
#define LM_API_ICTRL_IC (LM_API_ICTRL | (4 << CAN_MSGID_API_S))
#define LM_API_ICTRL_DC (LM_API_ICTRL | (5 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_ICTRL_T_EN (LM_API_ICTRL | (6 << CAN_MSGID_API_S))
#define LM_API_ICTRL_T_SET (LM_API_ICTRL | (7 << CAN_MSGID_API_S))
#define LM_API_ICTRL_T_SET_NO_ACK \
(LM_API_ICTRL | (9 << CAN_MSGID_API_S))
//##### FIRST END #####
#define LM_API_ICTRL_SET_NO_ACK (LM_API_ICTRL | (10 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris Motor Class Firmware Update API definitions.
//
//*****************************************************************************
#define LM_API_UPD (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_UPDATE)
#define LM_API_UPD_PING (LM_API_UPD | (0 << CAN_MSGID_API_S))
#define LM_API_UPD_DOWNLOAD (LM_API_UPD | (1 << CAN_MSGID_API_S))
#define LM_API_UPD_SEND_DATA (LM_API_UPD | (2 << CAN_MSGID_API_S))
#define LM_API_UPD_RESET (LM_API_UPD | (3 << CAN_MSGID_API_S))
#define LM_API_UPD_ACK (LM_API_UPD | (4 << CAN_MSGID_API_S))
#define LM_API_HWVER (LM_API_UPD | (5 << CAN_MSGID_API_S))
#define LM_API_UPD_REQUEST (LM_API_UPD | (6 << CAN_MSGID_API_S))
//##### FIRST BEGIN #####
#define LM_API_UNTRUST_EN (LM_API_UPD | (11 << CAN_MSGID_API_S))
#define LM_API_TRUST_EN (LM_API_UPD | (12 << CAN_MSGID_API_S))
#define LM_API_TRUST_HEARTBEAT (LM_API_UPD | (13 << CAN_MSGID_API_S))
//##### FIRST END #####
//*****************************************************************************
//
// The Stellaris Motor Class Status API definitions.
//
//*****************************************************************************
#define LM_API_STATUS (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_STATUS)
#define LM_API_STATUS_VOLTOUT (LM_API_STATUS | (0 << CAN_MSGID_API_S))
#define LM_API_STATUS_VOLTBUS (LM_API_STATUS | (1 << CAN_MSGID_API_S))
#define LM_API_STATUS_CURRENT (LM_API_STATUS | (2 << CAN_MSGID_API_S))
#define LM_API_STATUS_TEMP (LM_API_STATUS | (3 << CAN_MSGID_API_S))
#define LM_API_STATUS_POS (LM_API_STATUS | (4 << CAN_MSGID_API_S))
#define LM_API_STATUS_SPD (LM_API_STATUS | (5 << CAN_MSGID_API_S))
#define LM_API_STATUS_LIMIT (LM_API_STATUS | (6 << CAN_MSGID_API_S))
#define LM_API_STATUS_FAULT (LM_API_STATUS | (7 << CAN_MSGID_API_S))
#define LM_API_STATUS_POWER (LM_API_STATUS | (8 << CAN_MSGID_API_S))
#define LM_API_STATUS_CMODE (LM_API_STATUS | (9 << CAN_MSGID_API_S))
#define LM_API_STATUS_VOUT (LM_API_STATUS | (10 << CAN_MSGID_API_S))
#define LM_API_STATUS_STKY_FLT (LM_API_STATUS | (11 << CAN_MSGID_API_S))
#define LM_API_STATUS_FLT_COUNT (LM_API_STATUS | (12 << CAN_MSGID_API_S))
//*****************************************************************************
//
// These definitions are used with the byte that is returned from
// the status request for LM_API_STATUS_LIMIT.
//
//*****************************************************************************
#define LM_STATUS_LIMIT_FWD 0x01
#define LM_STATUS_LIMIT_REV 0x02
#define LM_STATUS_LIMIT_SFWD 0x04
#define LM_STATUS_LIMIT_SREV 0x08
#define LM_STATUS_LIMIT_STKY_FWD \
0x10
#define LM_STATUS_LIMIT_STKY_REV \
0x20
#define LM_STATUS_LIMIT_STKY_SFWD \
0x40
#define LM_STATUS_LIMIT_STKY_SREV \
0x80
//*****************************************************************************
//
// LM Motor Control status codes returned due to the CAN_STATUS_CODE_M field.
//
//*****************************************************************************
#define LM_STATUS_FAULT_ILIMIT 0x01
#define LM_STATUS_FAULT_TLIMIT 0x02
#define LM_STATUS_FAULT_VLIMIT 0x04
//*****************************************************************************
//
// The Stellaris Motor Class Configuration API definitions.
//
//*****************************************************************************
#define LM_API_CFG (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_CFG)
#define LM_API_CFG_NUM_BRUSHES (LM_API_CFG | (0 << CAN_MSGID_API_S))
#define LM_API_CFG_ENC_LINES (LM_API_CFG | (1 << CAN_MSGID_API_S))
#define LM_API_CFG_POT_TURNS (LM_API_CFG | (2 << CAN_MSGID_API_S))
#define LM_API_CFG_BRAKE_COAST (LM_API_CFG | (3 << CAN_MSGID_API_S))
#define LM_API_CFG_LIMIT_MODE (LM_API_CFG | (4 << CAN_MSGID_API_S))
#define LM_API_CFG_LIMIT_FWD (LM_API_CFG | (5 << CAN_MSGID_API_S))
#define LM_API_CFG_LIMIT_REV (LM_API_CFG | (6 << CAN_MSGID_API_S))
#define LM_API_CFG_MAX_VOUT (LM_API_CFG | (7 << CAN_MSGID_API_S))
#define LM_API_CFG_FAULT_TIME (LM_API_CFG | (8 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The Stellaris ACK API definition.
//
//*****************************************************************************
#define LM_API_ACK (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_ACK)
//*****************************************************************************
//
// The 8 bit values that can be returned by a call to LM_API_STATUS_HWVER.
//
//*****************************************************************************
#define LM_HWVER_UNKNOWN 0x00
#define LM_HWVER_JAG_1_0 0x01
#define LM_HWVER_JAG_2_0 0x02
//*****************************************************************************
//
// The 8 bit values that can be returned by a call to LM_API_STATUS_CMODE.
//
//*****************************************************************************
#define LM_STATUS_CMODE_VOLT 0x00
#define LM_STATUS_CMODE_CURRENT 0x01
#define LM_STATUS_CMODE_SPEED 0x02
#define LM_STATUS_CMODE_POS 0x03
#define LM_STATUS_CMODE_VCOMP 0x04
//*****************************************************************************
//
// The values that can specified as the position or speed reference. Not all
// values are valid for each reference; if an invalid reference is set, then
// none will be selected.
//
//*****************************************************************************
#define LM_REF_ENCODER 0x00
#define LM_REF_POT 0x01
#define LM_REF_INV_ENCODER 0x02
#define LM_REF_QUAD_ENCODER 0x03
#define LM_REF_NONE 0xff
//*****************************************************************************
//
// The flags that are used to indicate the currently active fault sources.
//
//*****************************************************************************
#define LM_FAULT_CURRENT 0x01
#define LM_FAULT_TEMP 0x02
#define LM_FAULT_VBUS 0x04
#define LM_FAULT_GATE_DRIVE 0x08
#define LM_FAULT_COMM 0x10
//*****************************************************************************
//
// The Stellaris Motor Class Periodic Status API definitions.
//
//*****************************************************************************
#define LM_API_PSTAT (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_PSTAT)
#define LM_API_PSTAT_PER_EN_S0 (LM_API_PSTAT | (0 << CAN_MSGID_API_S))
#define LM_API_PSTAT_PER_EN_S1 (LM_API_PSTAT | (1 << CAN_MSGID_API_S))
#define LM_API_PSTAT_PER_EN_S2 (LM_API_PSTAT | (2 << CAN_MSGID_API_S))
#define LM_API_PSTAT_PER_EN_S3 (LM_API_PSTAT | (3 << CAN_MSGID_API_S))
#define LM_API_PSTAT_CFG_S0 (LM_API_PSTAT | (4 << CAN_MSGID_API_S))
#define LM_API_PSTAT_CFG_S1 (LM_API_PSTAT | (5 << CAN_MSGID_API_S))
#define LM_API_PSTAT_CFG_S2 (LM_API_PSTAT | (6 << CAN_MSGID_API_S))
#define LM_API_PSTAT_CFG_S3 (LM_API_PSTAT | (7 << CAN_MSGID_API_S))
#define LM_API_PSTAT_DATA_S0 (LM_API_PSTAT | (8 << CAN_MSGID_API_S))
#define LM_API_PSTAT_DATA_S1 (LM_API_PSTAT | (9 << CAN_MSGID_API_S))
#define LM_API_PSTAT_DATA_S2 (LM_API_PSTAT | (10 << CAN_MSGID_API_S))
#define LM_API_PSTAT_DATA_S3 (LM_API_PSTAT | (11 << CAN_MSGID_API_S))
//*****************************************************************************
//
// The values that can be used to configure the data the Periodic Status
// Message bytes. Bytes of a multi-byte data values are encoded as
// little-endian, therefore B0 is the least significant byte.
//
//*****************************************************************************
#define LM_PSTAT_END 0
#define LM_PSTAT_VOLTOUT_B0 1
#define LM_PSTAT_VOLTOUT_B1 2
#define LM_PSTAT_VOLTBUS_B0 3
#define LM_PSTAT_VOLTBUS_B1 4
#define LM_PSTAT_CURRENT_B0 5
#define LM_PSTAT_CURRENT_B1 6
#define LM_PSTAT_TEMP_B0 7
#define LM_PSTAT_TEMP_B1 8
#define LM_PSTAT_POS_B0 9
#define LM_PSTAT_POS_B1 10
#define LM_PSTAT_POS_B2 11
#define LM_PSTAT_POS_B3 12
#define LM_PSTAT_SPD_B0 13
#define LM_PSTAT_SPD_B1 14
#define LM_PSTAT_SPD_B2 15
#define LM_PSTAT_SPD_B3 16
#define LM_PSTAT_LIMIT_NCLR 17
#define LM_PSTAT_LIMIT_CLR 18
#define LM_PSTAT_FAULT 19
#define LM_PSTAT_STKY_FLT_NCLR 20
#define LM_PSTAT_STKY_FLT_CLR 21
#define LM_PSTAT_VOUT_B0 22
#define LM_PSTAT_VOUT_B1 23
#define LM_PSTAT_FLT_COUNT_CURRENT \
24
#define LM_PSTAT_FLT_COUNT_TEMP 25
#define LM_PSTAT_FLT_COUNT_VOLTBUS \
26
#define LM_PSTAT_FLT_COUNT_GATE 27
#define LM_PSTAT_FLT_COUNT_COMM 28
#define LM_PSTAT_CANSTS 29
#define LM_PSTAT_CANERR_B0 30
#define LM_PSTAT_CANERR_B1 31
#endif // __CAN_PROTO_H__

136
wpilibc/include/CANJaguar.h Normal file
View File

@@ -0,0 +1,136 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2009. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef CANJAGUAR_H
#define CANJAGUAR_H
#include "ErrorBase.h"
#include "MotorSafety.h"
#include "MotorSafetyHelper.h"
#include "PIDOutput.h"
#include "SpeedController.h"
#include "HAL/Semaphore.h"
#include "HAL/HAL.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITable.h"
/**
* Luminary Micro Jaguar Speed Control
*/
class CANJaguar : public MotorSafety,
public SpeedController,
public ErrorBase,
public LiveWindowSendable,
public ITableListener
{
public:
// The internal PID control loop in the Jaguar runs at 1kHz.
static const int32_t kControllerRate = 1000;
static constexpr double kApproxBusVoltage = 12.0;
typedef enum {kPercentVbus, kCurrent, kSpeed, kPosition, kVoltage} ControlMode;
typedef enum {kCurrentFault = 1, kTemperatureFault = 2, kBusVoltageFault = 4, kGateDriverFault = 8} Faults;
typedef enum {kForwardLimit = 1, kReverseLimit = 2} Limits;
typedef enum {kPosRef_QuadEncoder = 0, kPosRef_Potentiometer = 1, kPosRef_None = 0xFF} PositionReference;
typedef enum {kSpeedRef_Encoder = 0, kSpeedRef_InvEncoder = 2, kSpeedRef_QuadEncoder = 3, kSpeedRef_None = 0xFF} SpeedReference;
typedef enum {kNeutralMode_Jumper = 0, kNeutralMode_Brake = 1, kNeutralMode_Coast = 2} NeutralMode;
typedef enum {kLimitMode_SwitchInputsOnly = 0, kLimitMode_SoftPositionLimits = 1} LimitMode;
explicit CANJaguar(uint8_t deviceNumber, ControlMode controlMode = kPercentVbus);
virtual ~CANJaguar();
// SpeedController interface
virtual float Get();
virtual void Set(float value, uint8_t syncGroup=0);
virtual void Disable();
// PIDOutput interface
virtual void PIDWrite(float output);
// Other Accessors
void SetSpeedReference(SpeedReference reference);
SpeedReference GetSpeedReference();
void SetPositionReference(PositionReference reference);
PositionReference GetPositionReference();
void SetPID(double p, double i, double d);
double GetP();
double GetI();
double GetD();
void EnableControl(double encoderInitialPosition = 0.0);
void DisableControl();
void ChangeControlMode(ControlMode controlMode);
ControlMode GetControlMode();
float GetBusVoltage();
float GetOutputVoltage();
float GetOutputCurrent();
float GetTemperature();
double GetPosition();
double GetSpeed();
bool GetForwardLimitOK();
bool GetReverseLimitOK();
uint16_t GetFaults();
bool GetPowerCycled();
void SetVoltageRampRate(double rampRate);
virtual uint32_t GetFirmwareVersion();
uint8_t GetHardwareVersion();
void ConfigNeutralMode(NeutralMode mode);
void ConfigEncoderCodesPerRev(uint16_t codesPerRev);
void ConfigPotentiometerTurns(uint16_t turns);
void ConfigSoftPositionLimits(double forwardLimitPosition, double reverseLimitPosition);
void DisableSoftPositionLimits();
void ConfigMaxOutputVoltage(double voltage);
void ConfigFaultTime(float faultTime);
static void UpdateSyncGroup(uint8_t syncGroup);
void SetExpiration(float timeout);
float GetExpiration();
bool IsAlive();
void StopMotor();
bool IsSafetyEnabled();
void SetSafetyEnabled(bool enabled);
void GetDescription(char *desc);
protected:
uint8_t packPercentage(uint8_t *buffer, double value);
uint8_t packFXP8_8(uint8_t *buffer, double value);
uint8_t packFXP16_16(uint8_t *buffer, double value);
uint8_t packint16_t(uint8_t *buffer, int16_t value);
uint8_t packint32_t(uint8_t *buffer, int32_t value);
double unpackPercentage(uint8_t *buffer);
double unpackFXP8_8(uint8_t *buffer);
double unpackFXP16_16(uint8_t *buffer);
int16_t unpackint16_t(uint8_t *buffer);
int32_t unpackint32_t(uint8_t *buffer);
virtual void setTransaction(uint32_t messageID, const uint8_t *data, uint8_t dataSize);
virtual void getTransaction(uint32_t messageID, uint8_t *data, uint8_t *dataSize);
static int32_t sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize);
static int32_t receiveMessage(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, float timeout = 0.02);
uint8_t m_deviceNumber;
ControlMode m_controlMode;
MUTEX_ID m_transactionSemaphore;
double m_maxOutputVoltage;
MotorSafetyHelper *m_safetyHelper;
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
ITable *m_table;
private:
void InitCANJaguar();
};
#endif

View File

@@ -0,0 +1,164 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_H__
#define __COMMAND_H__
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include <set>
#include <string>
class CommandGroup;
class Subsystem;
/**
* The Command class is at the very core of the entire command framework.
* Every command can be started with a call to {@link Command#Start() Start()}.
* Once a command is started it will call {@link Command#Initialize() Initialize()}, and then
* will repeatedly call {@link Command#Execute() Execute()} until the {@link Command#IsFinished() IsFinished()}
* returns true. Once it does, {@link Command#End() End()} will be called.
*
* <p>However, if at any point while it is running {@link Command#Cancel() Cancel()} is called, then
* the command will be stopped and {@link Command#Interrupted() Interrupted()} will be called.</p>
*
* <p>If a command uses a {@link Subsystem}, then it should specify that it does so by
* calling the {@link Command#Requires(Subsystem) Requires(...)} method
* in its constructor. Note that a Command may have multiple requirements, and
* {@link Command#Requires(Subsystem) Requires(...)} should be
* called for each one.</p>
*
* <p>If a command is running and a new command with shared requirements is started,
* then one of two things will happen. If the active command is interruptible,
* then {@link Command#Cancel() Cancel()} will be called and the command will be removed
* to make way for the new one. If the active command is not interruptible, the
* other one will not even be started, and the active one will continue functioning.</p>
*
* @see CommandGroup
* @see Subsystem
*/
class Command : public ErrorBase, public NamedSendable, public ITableListener
{
friend class CommandGroup;
friend class Scheduler;
public:
Command();
Command(const char *name);
Command(double timeout);
Command(const char *name, double timeout);
virtual ~Command();
double TimeSinceInitialized();
void Requires(Subsystem *s);
bool IsCanceled();
void Start();
bool Run();
void Cancel();
bool IsRunning();
bool IsInterruptible();
void SetInterruptible(bool interruptible);
bool DoesRequire(Subsystem *subsystem);
typedef std::set<Subsystem *> SubsystemSet;
SubsystemSet GetRequirements();
CommandGroup *GetGroup();
void SetRunWhenDisabled(bool run);
bool WillRunWhenDisabled();
int GetID();
protected:
void SetTimeout(double timeout);
bool IsTimedOut();
bool AssertUnlocked(const char *message);
void SetParent(CommandGroup *parent);
/**
* The initialize method is called the first time this Command is run after
* being started.
*/
virtual void Initialize() = 0;
/**
* The execute method is called repeatedly until this Command either finishes
* or is canceled.
*/
virtual void Execute() = 0;
/**
* Returns whether this command is finished.
* If it is, then the command will be removed
* and {@link Command#end() end()} will be called.
*
* <p>It may be useful for a team to reference the {@link Command#isTimedOut() isTimedOut()} method
* for time-sensitive commands.</p>
* @return whether this command is finished.
* @see Command#isTimedOut() isTimedOut()
*/
virtual bool IsFinished() = 0;
/**
* Called when the command ended peacefully. This is where you may want
* to wrap up loose ends, like shutting off a motor that was being used
* in the command.
*/
virtual void End() = 0;
/**
* Called when the command ends because somebody called {@link Command#cancel() cancel()}
* or another command shared the same requirements as this one, and booted
* it out.
*
* <p>This is where you may want
* to wrap up loose ends, like shutting off a motor that was being used
* in the command.</p>
*
* <p>Generally, it is useful to simply call the {@link Command#end() end()} method
* within this method</p>
*/
virtual void Interrupted() = 0;
virtual void _Initialize();
virtual void _Interrupted();
virtual void _Execute();
virtual void _End();
virtual void _Cancel();
private:
void InitCommand(const char *name, double timeout);
void LockChanges();
/*synchronized*/ void Removed();
void StartRunning();
void StartTiming();
/** The name of this command */
std::string m_name;
/** The time since this command was initialized */
double m_startTime;
/** The time (in seconds) before this command "times out" (or -1 if no timeout) */
double m_timeout;
/** Whether or not this command has been initialized */
bool m_initialized;
/** The requirements (or null if no requirements) */
SubsystemSet m_requirements;
/** Whether or not it is running */
bool m_running;
/** Whether or not it is interruptible*/
bool m_interruptible;
/** Whether or not it has been canceled */
bool m_canceled;
/** Whether or not it has been locked */
bool m_locked;
/** Whether this command should run when the robot is disabled */
bool m_runWhenDisabled;
/** The {@link CommandGroup} this is in */
CommandGroup *m_parent;
int m_commandID;
static int m_commandCounter;
public:
virtual std::string GetName();
virtual void InitTable(ITable* table);
virtual ITable* GetTable();
virtual std::string GetSmartDashboardType();
virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
protected:
ITable* m_table;
};
#endif

View File

@@ -0,0 +1,71 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_GROUP_H__
#define __COMMAND_GROUP_H__
#include "Commands/Command.h"
#include "Commands/CommandGroupEntry.h"
#include <list>
#include <vector>
/**
* A {@link CommandGroup} is a list of commands which are executed in sequence.
*
* <p>Commands in a {@link CommandGroup} are added using the {@link CommandGroup#AddSequential(Command) AddSequential(...)} method
* and are called sequentially.
* {@link CommandGroup CommandGroups} are themselves {@link Command Commands}
* and can be given to other {@link CommandGroup CommandGroups}.</p>
*
* <p>{@link CommandGroup CommandGroups} will carry all of the requirements of their {@link Command subcommands}. Additional
* requirements can be specified by calling {@link CommandGroup#Requires(Subsystem) Requires(...)}
* normally in the constructor.</P>
*
* <p>CommandGroups can also execute commands in parallel, simply by adding them
* using {@link CommandGroup#AddParallel(Command) AddParallel(...)}.</p>
*
* @see Command
* @see Subsystem
*/
class CommandGroup : public Command
{
public:
CommandGroup();
CommandGroup(const char *name);
virtual ~CommandGroup();
void AddSequential(Command *command);
void AddSequential(Command *command, double timeout);
void AddParallel(Command *command);
void AddParallel(Command *command, double timeout);
bool IsInterruptible();
int GetSize();
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
virtual void _Initialize();
virtual void _Interrupted();
virtual void _Execute();
virtual void _End();
private:
void CancelConflicts(Command *command);
typedef std::vector<CommandGroupEntry> CommandVector;
/** The commands in this group (stored in entries) */
CommandVector m_commands;
typedef std::list<CommandGroupEntry> CommandList;
/** The active children in this group (stored in entries) */
CommandList m_children;
/** The current command, -1 signifies that none have been run */
int m_currentCommandIndex;
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __COMMAND_GROUP_ENTRY_H__
#define __COMMAND_GROUP_ENTRY_H__
class Command;
class CommandGroupEntry
{
public:
typedef enum {kSequence_InSequence, kSequence_BranchPeer, kSequence_BranchChild} Sequence;
CommandGroupEntry();
CommandGroupEntry(Command *command, Sequence state);
CommandGroupEntry(Command *command, Sequence state, double timeout);
bool IsTimedOut();
double m_timeout;
Command *m_command;
Sequence m_state;
};
#endif

View File

@@ -0,0 +1,56 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PID_COMMAND_H__
#define __PID_COMMAND_H__
#include "Commands/Command.h"
#include "PIDSource.h"
#include "PIDOutput.h"
class PIDController;
class PIDCommand : public Command, public PIDOutput, public PIDSource
{
public:
PIDCommand(const char *name, double p, double i, double d);
PIDCommand(const char *name, double p, double i, double d, double period);
PIDCommand(const char *name, double p, double i, double d, double f, double perioid);
PIDCommand(double p, double i, double d);
PIDCommand(double p, double i, double d, double period);
PIDCommand(double p, double i, double d, double f, double period);
virtual ~PIDCommand();
void SetSetpointRelative(double deltaSetpoint);
// PIDOutput interface
virtual void PIDWrite(float output);
// PIDSource interface
virtual double PIDGet();
protected:
PIDController *GetPIDController();
virtual void _Initialize();
virtual void _Interrupted();
virtual void _End();
void SetSetpoint(double setpoint);
double GetSetpoint();
double GetPosition();
virtual double ReturnPIDInput() = 0;
virtual void UsePIDOutput(double output) = 0;
private:
/** The internal {@link PIDController} */
PIDController *m_controller;
public:
virtual void InitTable(ITable* table);
virtual std::string GetSmartDashboardType();
};
#endif

View File

@@ -0,0 +1,70 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PID_SUBSYSTEM_H__
#define __PID_SUBSYSTEM_H__
#include "Commands/Subsystem.h"
#include "PIDController.h"
#include "PIDSource.h"
#include "PIDOutput.h"
/**
* This class is designed to handle the case where there is a {@link Subsystem}
* which uses a single {@link PIDController} almost constantly (for instance,
* an elevator which attempts to stay at a constant height).
*
* <p>It provides some convenience methods to run an internal {@link PIDController}.
* It also allows access to the internal {@link PIDController} in order to give total control
* to the programmer.</p>
*
*/
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource
{
public:
PIDSubsystem(const char *name, double p, double i, double d);
PIDSubsystem(const char *name, double p, double i, double d, double f);
PIDSubsystem(const char *name, double p, double i, double d, double f, double period);
PIDSubsystem(double p, double i, double d);
PIDSubsystem(double p, double i, double d, double f);
PIDSubsystem(double p, double i, double d, double f, double period);
virtual ~PIDSubsystem();
void Enable();
void Disable();
// PIDOutput interface
virtual void PIDWrite(float output);
// PIDSource interface
virtual double PIDGet();
void SetSetpoint(double setpoint);
void SetSetpointRelative(double deltaSetpoint);
void SetInputRange(float minimumInput, float maximumInput);
double GetSetpoint();
double GetPosition();
virtual void SetAbsoluteTolerance(float absValue);
virtual void SetPercentTolerance(float percent);
virtual bool OnTarget();
protected:
PIDController *GetPIDController();
virtual double ReturnPIDInput() = 0;
virtual void UsePIDOutput(double output) = 0;
private:
/** The internal {@link PIDController} */
PIDController *m_controller;
public:
virtual void InitTable(ITable* table);
virtual std::string GetSmartDashboardType();
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PRINT_COMMAND_H__
#define __PRINT_COMMAND_H__
#include "Commands/Command.h"
#include <string>
class PrintCommand : public Command
{
public:
PrintCommand(const char *message);
virtual ~PrintCommand() {}
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
std::string m_message;
};
#endif

View File

@@ -0,0 +1,71 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SCHEDULER_H__
#define __SCHEDULER_H__
#include "Commands/Command.h"
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include "networktables/NetworkTable.h"
#include "networktables2/type/NumberArray.h"
#include "networktables2/type/StringArray.h"
#include "SmartDashboard/SmartDashboard.h"
#include "HAL/Semaphore.h"
#include <list>
#include <map>
#include <set>
#include <vector>
class ButtonScheduler;
class Subsystem;
class Scheduler : public ErrorBase, public NamedSendable
{
public:
static Scheduler *GetInstance();
void AddCommand(Command* command);
void AddButton(ButtonScheduler* button);
void RegisterSubsystem(Subsystem *subsystem);
void Run();
void Remove(Command *command);
void RemoveAll();
void SetEnabled(bool enabled);
void UpdateTable();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
std::string GetName();
std::string GetType();
private:
Scheduler();
virtual ~Scheduler();
void ProcessCommandAddition(Command *command);
static Scheduler *_instance;
Command::SubsystemSet m_subsystems;
MUTEX_ID m_buttonsLock;
typedef std::vector<ButtonScheduler *> ButtonVector;
ButtonVector m_buttons;
typedef std::vector<Command *> CommandVector;
MUTEX_ID m_additionsLock;
CommandVector m_additions;
typedef std::set<Command *> CommandSet;
CommandSet m_commands;
bool m_adding;
bool m_enabled;
StringArray *commands;
NumberArray *ids;
NumberArray *toCancel;
ITable *m_table;
bool m_runningCommandsChanged;
};
#endif

View File

@@ -0,0 +1,29 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __START_COMMAND_H__
#define __START_COMMAND_H__
#include "Commands/Command.h"
class StartCommand : public Command
{
public:
StartCommand(Command *commandToStart);
virtual ~StartCommand() {}
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
Command *m_commandToFork;
};
#endif

View File

@@ -0,0 +1,48 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SUBSYSTEM_H__
#define __SUBSYSTEM_H__
#include "ErrorBase.h"
#include "SmartDashboard/NamedSendable.h"
#include <string>
class Command;
class Subsystem : public ErrorBase, public NamedSendable
{
friend class Scheduler;
public:
Subsystem(const char *name);
virtual ~Subsystem() {}
void SetDefaultCommand(Command *command);
Command *GetDefaultCommand();
void SetCurrentCommand(Command *command);
Command *GetCurrentCommand();
virtual void InitDefaultCommand();
private:
void ConfirmCommand();
Command *m_currentCommand;
bool m_currentCommandChanged;
Command *m_defaultCommand;
std::string m_name;
bool m_initializedDefaultCommand;
public:
virtual std::string GetName();
virtual void InitTable(ITable* table);
virtual ITable* GetTable();
virtual std::string GetSmartDashboardType();
protected:
ITable* m_table;
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_COMMAND_H__
#define __WAIT_COMMAND_H__
#include "Commands/Command.h"
class WaitCommand : public Command
{
public:
WaitCommand(double timeout);
WaitCommand(const char *name, double timeout);
virtual ~WaitCommand() {}
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
};
#endif

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_FOR_CHILDREN_H__
#define __WAIT_FOR_CHILDREN_H__
#include "Commands/Command.h"
class WaitForChildren : public Command
{
public:
WaitForChildren(double timeout);
WaitForChildren(const char *name, double timeout);
virtual ~WaitForChildren() {}
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
};
#endif

View File

@@ -0,0 +1,30 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __WAIT_UNTIL_COMMAND_H__
#define __WAIT_UNTIL_COMMAND_H__
#include "Commands/Command.h"
class WaitUntilCommand : public Command
{
public:
WaitUntilCommand(double time);
WaitUntilCommand(const char *name, double time);
virtual ~WaitUntilCommand() {}
protected:
virtual void Initialize();
virtual void Execute();
virtual bool IsFinished();
virtual void End();
virtual void Interrupted();
private:
double m_time;
};
#endif

View File

@@ -0,0 +1,60 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef COMPRESSOR_H_
#define COMPRESSOR_H_
#define COMPRESSOR_PRIORITY 90
#include "SensorBase.h"
#include "Relay.h"
#include "Task.h"
#include "LiveWindow/LiveWindowSendable.h"
class DigitalInput;
/**
* Compressor object.
* The Compressor object is designed to handle the operation of the compressor, pressure sensor and
* relay for a FIRST robot pneumatics system. The Compressor object starts a task which runs in the
* backround and periodically polls the pressure sensor and operates the relay that controls the
* compressor.
*/
class Compressor: public SensorBase, public LiveWindowSendable
{
public:
Compressor(uint32_t pressureSwitchChannel, uint32_t compressorRelayChannel);
Compressor(uint8_t pressureSwitchModuleNumber, uint32_t pressureSwitchChannel,
uint8_t compresssorRelayModuleNumber, uint32_t compressorRelayChannel);
~Compressor();
void Start();
void Stop();
bool Enabled();
uint32_t GetPressureSwitchValue();
void SetRelayValue(Relay::Value relayValue);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitCompressor(uint8_t pressureSwitchModuleNumber, uint32_t pressureSwitchChannel,
uint8_t compresssorRelayModuleNumber, uint32_t compressorRelayChannel);
DigitalInput *m_pressureSwitch;
Relay *m_relay;
bool m_enabled;
Task m_task;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,35 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include "HAL/HAL.h"
/**
* Interface for Controllers
* Common interface for controllers. Controllers run control loops, the most common
* are PID controllers and their variants, but this includes anything that is controlling
* an actuator in a separate thread.
*/
class Controller
{
public:
virtual ~Controller() {};
/**
* Allows the control loop to run
*/
virtual void Enable() = 0;
/**
* Stops the control loop from running until explicitly re-enabled by calling enable()
*/
virtual void Disable() = 0;
};
#endif

97
wpilibc/include/Counter.h Normal file
View File

@@ -0,0 +1,97 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef CPPCOUNTER_H_
#define CPPCOUNTER_H_
#include "HAL/HAL.h"
#include "AnalogTriggerOutput.h"
#include "CounterBase.h"
#include "SensorBase.h"
#include "LiveWindow/LiveWindowSendable.h"
/**
* Class for counting the number of ticks on a digital input channel.
* This is a general purpose class for counting repetitive events. It can return the number
* of counts, the period of the most recent cycle, and detect when the signal being counted
* has stopped by supplying a maximum cycle time.
*/
class Counter : public SensorBase, public CounterBase, public LiveWindowSendable
{
public:
/* typedef enum {kTwoPulse=0, kSemiperiod=1, kPulseLength=2, kExternalDirection=3} Mode; */
Counter();
explicit Counter(uint32_t channel);
Counter(uint8_t moduleNumber, uint32_t channel);
explicit Counter(DigitalSource *source);
explicit Counter(DigitalSource &source);
explicit Counter(AnalogTrigger *trigger);
explicit Counter(AnalogTrigger &trigger);
Counter(EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted);
virtual ~Counter();
void SetUpSource(uint32_t channel);
void SetUpSource(uint8_t moduleNumber, uint32_t channel);
void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType);
void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerType triggerType);
void SetUpSource(DigitalSource *source);
void SetUpSource(DigitalSource &source);
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
void ClearUpSource();
void SetDownSource(uint32_t channel);
void SetDownSource(uint8_t moduleNumber, uint32_t channel);
void SetDownSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType);
void SetDownSource(AnalogTrigger &analogTrigger, AnalogTriggerType triggerType);
void SetDownSource(DigitalSource *source);
void SetDownSource(DigitalSource &source);
void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
void ClearDownSource();
void SetUpDownCounterMode();
void SetExternalDirectionMode();
void SetSemiPeriodMode(bool highSemiPeriod);
void SetPulseLengthMode(float threshold);
void SetReverseDirection(bool reverseDirection);
// CounterBase interface
void Start();
int32_t Get();
void Reset();
void Stop();
double GetPeriod();
void SetMaxPeriod(double maxPeriod);
void SetUpdateWhenEmpty(bool enabled);
bool GetStopped();
bool GetDirection();
void SetSamplesToAverage(int samplesToAverage);
int GetSamplesToAverage();
uint32_t GetIndex() {return m_index;}
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
virtual std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
protected:
DigitalSource *m_upSource; ///< What makes the counter count up.
DigitalSource *m_downSource; ///< What makes the counter count down.
void* m_counter; ///< The FPGA counter object.
private:
void InitCounter(Mode mode = kTwoPulse);
bool m_allocatedUpSource; ///< Was the upSource allocated locally?
bool m_allocatedDownSource; ///< Was the downSource allocated locally?
uint32_t m_index; ///< The index of this counter.
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef CPPCOUNTER_BASE_H_
#define CPPCOUNTER_BASE_H_
/**
* Interface for counting the number of ticks on a digital input channel.
* Encoders, Gear tooth sensors, and counters should all subclass this so it can be used to
* build more advanced classes for control and driving.
*/
class CounterBase
{
public:
typedef enum {k1X, k2X, k4X} EncodingType;
virtual ~CounterBase() {}
virtual void Start() = 0;
virtual int32_t Get() = 0;
virtual void Reset() = 0;
virtual void Stop() = 0;
virtual double GetPeriod() = 0;
virtual void SetMaxPeriod(double maxPeriod) = 0;
virtual bool GetStopped() = 0;
virtual bool GetDirection() = 0;
};
#endif

View File

@@ -0,0 +1,76 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DASHBOARD_H__
#define __DASHBOARD_H__
#include "DashboardBase.h"
//#include "NetworkCommunication/FRCComm.h"
#include <stack>
#include <vector>
#include "HAL/HAL.h"
#include "HAL/Semaphore.h"
/**
* Pack data into the "user data" field that gets sent to the dashboard laptop
* via the driver station.
*/
class Dashboard : public DashboardBase
{
public:
explicit Dashboard(MUTEX_ID statusDataSemaphore);
virtual ~Dashboard();
enum Type {kI8, kI16, kI32, kU8, kU16, kU32, kFloat, kDouble, kBoolean, kString, kOther};
enum ComplexType {kArray, kCluster};
void AddI8(int8_t value);
void AddI16(int16_t value);
void AddI32(int32_t value);
void AddU8(uint8_t value);
void AddU16(uint16_t value);
void AddU32(uint32_t value);
void AddFloat(float value);
void AddDouble(double value);
void AddBoolean(bool value);
void AddString(char* value);
void AddString(char* value, int32_t length);
void AddArray();
void FinalizeArray();
void AddCluster();
void FinalizeCluster();
void Printf(const char *writeFmt, ...);
int32_t Finalize();
void GetStatusBuffer(char** userStatusData, int32_t* userStatusDataSize);
void Flush() {}
private:
static const int32_t kMaxDashboardDataSize = HAL_USER_STATUS_DATA_SIZE - sizeof(uint32_t) * 3 - sizeof(uint8_t); // 13 bytes needed for 3 size parameters and the sequence number
// Usage Guidelines...
DISALLOW_COPY_AND_ASSIGN(Dashboard);
bool ValidateAdd(int32_t size);
void AddedElement(Type type);
bool IsArrayRoot();
char *m_userStatusData;
int32_t m_userStatusDataSize;
char *m_localBuffer;
char *m_localPrintBuffer;
char *m_packPtr;
std::vector<Type> m_expectedArrayElementType;
std::vector<int32_t> m_arrayElementCount;
std::vector<int32_t*> m_arraySizePtr;
std::stack<ComplexType> m_complexTypeStack;
MUTEX_ID m_printSemaphore;
MUTEX_ID m_statusDataSemaphore;
};
#endif

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DASHBOARDBASE_H__
#define __DASHBOARDBASE_H__
#include "HAL/HAL.h"
#include "ErrorBase.h"
class DashboardBase : public ErrorBase {
public:
virtual void GetStatusBuffer(char** userStatusData, int32_t* userStatusDataSize) = 0;
virtual void Flush() = 0;
virtual ~DashboardBase() {}
protected:
DashboardBase() {}
private:
DISALLOW_COPY_AND_ASSIGN(DashboardBase);
};
#endif

View File

@@ -0,0 +1,57 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef DIGITAL_INPUT_H_
#define DIGITAL_INPUT_H_
class DigitalModule;
#include "DigitalSource.h"
#include "LiveWindow/LiveWindowSendable.h"
/**
* Class to read a digital input.
* This class will read digital inputs and return the current value on the channel. Other devices
* such as encoders, gear tooth sensors, etc. that are implemented elsewhere will automatically
* allocate digital inputs and outputs as required. This class is only for devices like switches
* etc. that aren't implemented anywhere else.
*/
class DigitalInput : public DigitalSource, public LiveWindowSendable {
public:
explicit DigitalInput(uint32_t channel);
DigitalInput(uint8_t moduleNumber, uint32_t channel);
virtual ~DigitalInput();
uint32_t Get();
uint32_t GetChannel();
// Digital Source Interface
virtual uint32_t GetChannelForRouting();
virtual uint32_t GetModuleForRouting();
virtual bool GetAnalogTriggerForRouting();
// Interruptable Interface
virtual void RequestInterrupts(InterruptHandlerFunction handler, void *param=NULL); ///< Asynchronus handler version.
virtual void RequestInterrupts(); ///< Synchronus Wait version.
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitDigitalInput(uint8_t moduleNumber, uint32_t channel);
uint32_t m_channel;
DigitalModule *m_module;
bool m_lastValue;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,67 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef DIGITAL_MODULE_H_
#define DIGITAL_MODULE_H_
#include "HAL/HAL.h"
#include "Module.h"
class I2C;
const uint32_t kExpectedLoopTiming = 260;
class DigitalModule: public Module
{
friend class I2C;
friend class Module;
protected:
explicit DigitalModule(uint8_t moduleNumber);
virtual ~DigitalModule();
public:
void SetPWM(uint32_t channel, unsigned short value);
unsigned short GetPWM(uint32_t channel);
void SetPWMPeriodScale(uint32_t channel, uint32_t squelchMask);
void SetRelayForward(uint32_t channel, bool on);
void SetRelayReverse(uint32_t channel, bool on);
bool GetRelayForward(uint32_t channel);
uint8_t GetRelayForward();
bool GetRelayReverse(uint32_t channel);
uint8_t GetRelayReverse();
bool AllocateDIO(uint32_t channel, bool input);
void FreeDIO(uint32_t channel);
void SetDIO(uint32_t channel, short value);
bool GetDIO(uint32_t channel);
uint16_t GetDIO();
bool GetDIODirection(uint32_t channel);
uint16_t GetDIODirection();
void Pulse(uint32_t channel, float pulseLength);
bool IsPulsing(uint32_t channel);
bool IsPulsing();
uint32_t AllocateDO_PWM();
void FreeDO_PWM(uint32_t pwmGenerator);
void SetDO_PWMRate(float rate);
void SetDO_PWMDutyCycle(uint32_t pwmGenerator, float dutyCycle);
void SetDO_PWMOutputChannel(uint32_t pwmGenerator, uint32_t channel);
uint16_t GetLoopTiming();
I2C* GetI2C(uint32_t address);
static DigitalModule* GetInstance(uint8_t moduleNumber);
static uint8_t RemapDigitalChannel(uint32_t channel) { return 15 - channel; }; // TODO: Need channel validation
static uint8_t UnmapDigitalChannel(uint32_t channel) { return 15 - channel; }; // TODO: Need channel validation
private:
uint8_t m_module;
void* m_digital_ports[kDigitalChannels];
void* m_relay_ports[kRelayChannels];
void* m_pwm_ports[kPwmChannels];
};
#endif

View File

@@ -0,0 +1,63 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef DIGITAL_OUTPUT_H_
#define DIGITAL_OUTPUT_H_
#include "DigitalSource.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITableListener.h"
class DigitalModule;
/**
* Class to write to digital outputs.
* Write values to the digital output channels. Other devices implemented elsewhere will allocate
* channels automatically so for those devices it shouldn't be done here.
*/
class DigitalOutput : public DigitalSource, public ITableListener, public LiveWindowSendable
{
public:
explicit DigitalOutput(uint32_t channel);
DigitalOutput(uint8_t moduleNumber, uint32_t channel);
virtual ~DigitalOutput();
void Set(uint32_t value);
uint32_t GetChannel();
void Pulse(float length);
bool IsPulsing();
void SetPWMRate(float rate);
void EnablePWM(float initialDutyCycle);
void DisablePWM();
void UpdateDutyCycle(float dutyCycle);
// Digital Source Interface
virtual uint32_t GetChannelForRouting();
virtual uint32_t GetModuleForRouting();
virtual bool GetAnalogTriggerForRouting();
virtual void RequestInterrupts(InterruptHandlerFunction handler, void *param);
virtual void RequestInterrupts();
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitDigitalOutput(uint8_t moduleNumber, uint32_t channel);
uint32_t m_channel;
uint32_t m_pwmGenerator;
DigitalModule *m_module;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,31 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef DIGITAL_SOURCE_H
#define DIGITAL_SOURCE_H
#include "InterruptableSensorBase.h"
/**
* DigitalSource Interface.
* The DigitalSource represents all the possible inputs for a counter or a quadrature encoder. The source may be
* either a digital input or an analog input. If the caller just provides a channel, then a digital input will be
* constructed and freed when finished for the source. The source can either be a digital input or analog trigger
* but not both.
*/
class DigitalSource: public InterruptableSensorBase
{
public:
virtual ~DigitalSource();
virtual uint32_t GetChannelForRouting() = 0;
virtual uint32_t GetModuleForRouting() = 0;
virtual bool GetAnalogTriggerForRouting() = 0;
virtual void RequestInterrupts(InterruptHandlerFunction handler, void *param) = 0;
virtual void RequestInterrupts() = 0;
};
#endif

View File

@@ -0,0 +1,51 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef DOUBLE_SOLENOID_H_
#define DOUBLE_SOLENOID_H_
#include "SolenoidBase.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITableListener.h"
/**
* DoubleSolenoid class for running 2 channels of high voltage Digital Output
* (9472 module).
*
* The DoubleSolenoid class is typically used for pneumatics solenoids that
* have two positions controlled by two separate channels.
*/
class DoubleSolenoid : public SolenoidBase, public LiveWindowSendable, public ITableListener {
public:
typedef enum {kOff, kForward, kReverse} Value;
explicit DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel);
DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel, uint32_t reverseChannel);
virtual ~DoubleSolenoid();
virtual void Set(Value value);
virtual Value Get();
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
virtual void InitSolenoid();
uint32_t m_forwardChannel; ///< The forward channel on the module to control.
uint32_t m_reverseChannel; ///< The reverse channel on the module to control.
uint8_t m_forwardMask; ///< The mask for the forward channel.
uint8_t m_reverseMask; ///< The mask for the reverse channel.
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,133 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DRIVER_STATION_H__
#define __DRIVER_STATION_H__
#include "Dashboard.h"
#include "DriverStationEnhancedIO.h"
#include "SensorBase.h"
#include "Task.h"
struct HALCommonControlData;
class AnalogChannel;
/**
* Provide access to the network communication data to / from the Driver Station.
*/
class DriverStation : public SensorBase
{
public:
enum Alliance {kRed, kBlue, kInvalid};
virtual ~DriverStation();
static DriverStation *GetInstance();
static const uint32_t kBatteryModuleNumber = 1;
static const uint32_t kBatteryChannel = 8;
static const uint32_t kJoystickPorts = 4;
static const uint32_t kJoystickAxes = 6;
float GetStickAxis(uint32_t stick, uint32_t axis);
short GetStickButtons(uint32_t stick);
float GetAnalogIn(uint32_t channel);
bool GetDigitalIn(uint32_t channel);
void SetDigitalOut(uint32_t channel, bool value);
bool GetDigitalOut(uint32_t channel);
bool IsEnabled();
bool IsDisabled();
bool IsAutonomous();
bool IsOperatorControl();
bool IsTest();
bool IsNewControlData();
bool IsFMSAttached();
uint32_t GetPacketNumber();
Alliance GetAlliance();
uint32_t GetLocation();
void WaitForData();
double GetMatchTime();
float GetBatteryVoltage();
uint16_t GetTeamNumber();
// Get the default dashboard packers. These instances stay around even after
// a call to SetHigh|LowPriorityDashboardPackerToUse() changes which packer
// is in use. You can restore the default high priority packer by calling
// SetHighPriorityDashboardPackerToUse(&GetHighPriorityDashboardPacker()).
Dashboard& GetHighPriorityDashboardPacker() { return m_dashboardHigh; }
Dashboard& GetLowPriorityDashboardPacker() { return m_dashboardLow; }
// Get/set the dashboard packers to use. This can sideline or restore the
// default packers. Initializing SmartDashboard changes the high priority
// packer in use so beware that the default packer will then be idle. These
// methods support any kind of DashboardBase, e.g. a Dashboard or a
// SmartDashboard.
DashboardBase* GetHighPriorityDashboardPackerInUse() { return m_dashboardInUseHigh; }
DashboardBase* GetLowPriorityDashboardPackerInUse() { return m_dashboardInUseLow; }
void SetHighPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseHigh = db; }
void SetLowPriorityDashboardPackerToUse(DashboardBase* db) { m_dashboardInUseLow = db; }
DriverStationEnhancedIO& GetEnhancedIO() { return m_enhancedIO; }
void IncrementUpdateNumber() { m_updateNumber++; }
MUTEX_ID GetUserStatusDataSem() { return m_statusDataSemaphore; }
/** Only to be used to tell the Driver Station what code you claim to be executing
* for diagnostic purposes only
* @param entering If true, starting disabled code; if false, leaving disabled code */
void InDisabled(bool entering) {m_userInDisabled=entering;}
/** Only to be used to tell the Driver Station what code you claim to be executing
* for diagnostic purposes only
* @param entering If true, starting autonomous code; if false, leaving autonomous code */
void InAutonomous(bool entering) {m_userInAutonomous=entering;}
/** Only to be used to tell the Driver Station what code you claim to be executing
* for diagnostic purposes only
* @param entering If true, starting teleop code; if false, leaving teleop code */
void InOperatorControl(bool entering) {m_userInTeleop=entering;}
/** Only to be used to tell the Driver Station what code you claim to be executing
* for diagnostic purposes only
* @param entering If true, starting test code; if false, leaving test code */
void InTest(bool entering) {m_userInTest=entering;}
protected:
DriverStation();
void GetData();
void SetData();
private:
static void InitTask(DriverStation *ds);
static DriverStation *m_instance;
static uint8_t m_updateNumber;
///< TODO: Get rid of this and use the semaphore signaling
static constexpr float kUpdatePeriod = 0.02;
void Run();
struct HALCommonControlData *m_controlData;
uint8_t m_digitalOut;
AnalogChannel *m_batteryChannel;
MUTEX_ID m_statusDataSemaphore;
Task m_task;
Dashboard m_dashboardHigh; // the default dashboard packers
Dashboard m_dashboardLow;
DashboardBase* m_dashboardInUseHigh; // the current dashboard packers in use
DashboardBase* m_dashboardInUseLow;
SEMAPHORE_ID m_newControlData;
MUTEX_ID m_packetDataAvailableSem;
DriverStationEnhancedIO m_enhancedIO;
MULTIWAIT_ID m_waitForDataSem;
double m_approxMatchTimeOffset;
bool m_userInDisabled;
bool m_userInAutonomous;
bool m_userInTeleop;
bool m_userInTest;
};
#endif

View File

@@ -0,0 +1,153 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DRIVER_STATION_ENHANCED_IO_H__
#define __DRIVER_STATION_ENHANCED_IO_H__
#include "ErrorBase.h"
//#include "NetworkCommunication/FRCComm.h"
#include <stack>
#include <vector>
#include "HAL/HAL.h"
#include "HAL/Semaphore.h"
#define kAnalogInputResolution ((double)((1<<14)-1))
#define kAnalogInputReference 3.3
#define kAnalogOutputResolution ((double)((1<<8)-1))
#define kAnalogOutputReference 4.0
#define kAccelOffset 8300
#define kAccelScale 3300.0
#define kSupportedAPIVersion 1
/**
* Interact with the more complete I/O available from the
* newest driver station. Get a reference to an object
* of this type by calling GetEnhancedIO() on the DriverStation object.
*/
class DriverStationEnhancedIO : public ErrorBase
{
// Can only be constructed by the DriverStation class.
friend class DriverStation;
#pragma pack(push,1)
// BEGIN: Definitions from the Cypress firmware
typedef struct
{
uint16_t digital;
uint16_t digital_oe;
uint16_t digital_pe;
uint16_t pwm_compare[4];
uint16_t pwm_period[2];
uint8_t dac[2];
uint8_t leds;
union
{
struct
{
// Bits are inverted from cypress fw because of big-endian!
uint8_t pwm_enable : 4;
uint8_t comparator_enable : 2;
uint8_t quad_index_enable : 2;
};
uint8_t enables;
};
uint8_t fixed_digital_out;
} output_t; //data to IO (23 bytes)
typedef struct
{
uint8_t api_version;
uint8_t fw_version;
int16_t analog[8];
uint16_t digital;
int16_t accel[3];
int16_t quad[2];
uint8_t buttons;
uint8_t capsense_slider;
uint8_t capsense_proximity;
} input_t; //data from IO (33 bytes)
// END: Definitions from the Cypress firmware
// Dynamic block definitions
typedef struct
{
uint8_t size; // Must be 25 (size remaining in the block not counting the size variable)
uint8_t id; // Must be 18
output_t data;
uint8_t flags;
} status_block_t;
typedef struct
{
uint8_t size; // Must be 34
uint8_t id; // Must be 17
input_t data;
} control_block_t;
#pragma pack(pop)
enum tBlockID
{
kInputBlockID = HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
kOutputBlockID = HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
};
enum tStatusFlags {kStatusValid = 0x01, kStatusConfigChanged = 0x02, kForceEnhancedMode = 0x04};
public:
enum tDigitalConfig {kUnknown, kInputFloating, kInputPullUp, kInputPullDown, kOutput, kPWM, kAnalogComparator};
enum tAccelChannel {kAccelX = 0, kAccelY = 1, kAccelZ = 2};
enum tPWMPeriodChannels {kPWMChannels1and2, kPWMChannels3and4};
double GetAcceleration(tAccelChannel channel);
double GetAnalogIn(uint32_t channel);
double GetAnalogInRatio(uint32_t channel);
double GetAnalogOut(uint32_t channel);
void SetAnalogOut(uint32_t channel, double value);
bool GetButton(uint32_t channel);
uint8_t GetButtons();
void SetLED(uint32_t channel, bool value);
void SetLEDs(uint8_t value);
bool GetDigital(uint32_t channel);
uint16_t GetDigitals();
void SetDigitalOutput(uint32_t channel, bool value);
tDigitalConfig GetDigitalConfig(uint32_t channel);
void SetDigitalConfig(uint32_t channel, tDigitalConfig config);
double GetPWMPeriod(tPWMPeriodChannels channels);
void SetPWMPeriod(tPWMPeriodChannels channels, double period);
bool GetFixedDigitalOutput(uint32_t channel);
void SetFixedDigitalOutput(uint32_t channel, bool value);
int16_t GetEncoder(uint32_t encoderNumber);
void ResetEncoder(uint32_t encoderNumber);
bool GetEncoderIndexEnable(uint32_t encoderNumber);
void SetEncoderIndexEnable(uint32_t encoderNumber, bool enable);
double GetTouchSlider();
double GetPWMOutput(uint32_t channel);
void SetPWMOutput(uint32_t channel, double value);
uint8_t GetFirmwareVersion();
private:
DriverStationEnhancedIO();
virtual ~DriverStationEnhancedIO();
void UpdateData();
void MergeConfigIntoOutput(const status_block_t &dsOutputBlock, status_block_t &localCache);
bool IsConfigEqual(const status_block_t &dsOutputBlock, const status_block_t &localCache);
// Usage Guidelines...
DISALLOW_COPY_AND_ASSIGN(DriverStationEnhancedIO);
control_block_t m_inputData;
status_block_t m_outputData;
MUTEX_ID m_inputDataSemaphore;
MUTEX_ID m_outputDataSemaphore;
bool m_inputValid;
bool m_outputValid;
bool m_configChanged;
bool m_requestEnhancedEnable;
int16_t m_encoderOffsets[2];
};
#endif

View File

@@ -0,0 +1,54 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __DRIVER_STATION_LCD_H__
#define __DRIVER_STATION_LCD_H__
#include "SensorBase.h"
#include "HAL/Semaphore.h"
#include <stdarg.h>
/**
* Provide access to "LCD" on the Driver Station.
* This is the Messages box on the DS Operation tab.
*
* Buffer the printed data locally and then send it
* when UpdateLCD is called.
*/
class DriverStationLCD : public SensorBase
{
public:
static const uint32_t kSyncTimeout_ms = 20;
static const uint16_t kFullDisplayTextCommand = 0x9FFF;
static const int32_t kLineLength = 21;
static const int32_t kNumLines = 6;
enum Line {kMain_Line6=0, kUser_Line1=0, kUser_Line2=1, kUser_Line3=2, kUser_Line4=3, kUser_Line5=4, kUser_Line6=5};
virtual ~DriverStationLCD();
static DriverStationLCD *GetInstance();
void UpdateLCD();
void Printf(Line line, int32_t startingColumn, const char *writeFmt, ...);
void VPrintf(Line line, int32_t startingColumn, const char *writeFmt, va_list args);
void PrintfLine(Line line, const char *writeFmt, ...);
void VPrintfLine(Line line, const char *writeFmt, va_list args);
void Clear();
protected:
DriverStationLCD();
private:
static void InitTask(DriverStationLCD *ds);
static DriverStationLCD *m_instance;
DISALLOW_COPY_AND_ASSIGN(DriverStationLCD);
char *m_textBuffer;
MUTEX_ID m_textBufferSemaphore;
};
#endif

83
wpilibc/include/Encoder.h Normal file
View File

@@ -0,0 +1,83 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef QUAD_ENCODER_H_
#define QUAD_ENCODER_H_
#include "HAL/HAL.h"
#include "CounterBase.h"
#include "SensorBase.h"
#include "Counter.h"
#include "PIDSource.h"
#include "LiveWindow/LiveWindowSendable.h"
class DigitalSource;
/**
* Class to read quad encoders.
* Quadrature encoders are devices that count shaft rotation and can sense direction. The output of
* the QuadEncoder class is an integer that can count either up or down, and can go negative for
* reverse direction counting. When creating QuadEncoders, a direction is supplied that changes the
* sense of the output to make code more readable if the encoder is mounted such that forward movement
* generates negative values. Quadrature encoders have two digital outputs, an A Channel and a B Channel
* that are out of phase with each other to allow the FPGA to do direction sensing.
*/
class Encoder: public SensorBase, public CounterBase, public PIDSource, public LiveWindowSendable
{
public:
Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection=false, EncodingType encodingType = k4X);
Encoder(uint8_t aModuleNumber, uint32_t aChannel, uint8_t bModuleNumber, uint32_t _bChannel, bool reverseDirection=false, EncodingType encodingType = k4X);
Encoder(DigitalSource *aSource, DigitalSource *bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
Encoder(DigitalSource &aSource, DigitalSource &bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
virtual ~Encoder();
// CounterBase interface
void Start();
int32_t Get();
int32_t GetRaw();
void Reset();
void Stop();
double GetPeriod();
void SetMaxPeriod(double maxPeriod);
bool GetStopped();
bool GetDirection();
double GetDistance();
double GetRate();
void SetMinRate(double minRate);
void SetDistancePerPulse(double distancePerPulse);
void SetReverseDirection(bool reverseDirection);
void SetSamplesToAverage(int samplesToAverage);
int GetSamplesToAverage();
void SetPIDSourceParameter(PIDSourceParameter pidSource);
double PIDGet();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitEncoder(bool _reverseDirection, EncodingType encodingType);
double DecodingScaleFactor();
DigitalSource *m_aSource; // the A phase of the quad encoder
DigitalSource *m_bSource; // the B phase of the quad encoder
bool m_allocatedASource; // was the A source allocated locally?
bool m_allocatedBSource; // was the B source allocated locally?
void* m_encoder;
double m_distancePerPulse; // distance of travel for each encoder tick
Counter *m_counter; // Counter object for 1x and 2x encoding
EncodingType m_encodingType; // Encoding type
PIDSourceParameter m_pidSource;// Encoder parameter that sources a PID controller
ITable *m_table;
};
#endif

58
wpilibc/include/Error.h Normal file
View File

@@ -0,0 +1,58 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef _ERROR_H
#define _ERROR_H
#include "Base.h"
#include <string>
#include "HAL/HAL.h"
// Forward declarations
class ErrorBase;
/**
* Error object represents a library error.
*/
class Error
{
public:
typedef int32_t Code;
Error();
~Error();
void Clone(Error &error);
Code GetCode() const;
const char *GetMessage() const;
const char *GetFilename() const;
const char *GetFunction() const;
uint32_t GetLineNumber() const;
const ErrorBase* GetOriginatingObject() const;
double GetTime() const;
void Clear();
void Set(Code code, const char* contextMessage, const char* filename,
const char *function, uint32_t lineNumber, const ErrorBase* originatingObject);
static void EnableStackTrace(bool enable) { m_stackTraceEnabled=enable; }
static void EnableSuspendOnError(bool enable) { m_suspendOnErrorEnabled=enable; }
private:
void Report();
Code m_code;
std::string m_message;
std::string m_filename;
std::string m_function;
uint32_t m_lineNumber;
const ErrorBase* m_originatingObject;
double m_timestamp;
static bool m_stackTraceEnabled;
static bool m_suspendOnErrorEnabled;
DISALLOW_COPY_AND_ASSIGN(Error);
};
#endif

View File

@@ -0,0 +1,69 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef _ERROR_BASE_H
#define _ERROR_BASE_H
#include "Base.h"
#include "Error.h"
#include "HAL/Semaphore.h"
#include "HAL/HAL.h"
#define wpi_setErrnoErrorWithContext(context) (this->SetErrnoError((context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrnoError() (wpi_setErrnoErrorWithContext(""))
#define wpi_setImaqErrorWithContext(code, context) (this->SetImaqError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setErrorWithContext(code, context) (this->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setError(code) (wpi_setErrorWithContext(code, ""))
#define wpi_setStaticErrorWithContext(object, code, context) (object->SetError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setStaticError(object, code) (wpi_setStaticErrorWithContext(object, code, ""))
#define wpi_setGlobalErrorWithContext(code, context) (ErrorBase::SetGlobalError((code), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setGlobalError(code) (wpi_setGlobalErrorWithContext(code, ""))
#define wpi_setWPIErrorWithContext(error, context) (this->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setWPIError(error) (wpi_setWPIErrorWithContext(error, ""))
#define wpi_setStaticWPIErrorWithContext(object, error, context) (object->SetWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setStaticWPIError(object, error) (wpi_setStaticWPIErrorWithContext(object, error, ""))
#define wpi_setGlobalWPIErrorWithContext(error, context) (ErrorBase::SetGlobalWPIError((wpi_error_s_##error), (context), __FILE__, __FUNCTION__, __LINE__))
#define wpi_setGlobalWPIError(error) (wpi_setGlobalWPIErrorWithContext(error, ""))
/**
* Base class for most objects.
* ErrorBase is the base class for most objects since it holds the generated error
* for that object. In addition, there is a single instance of a global error object
*/
class ErrorBase
{
//TODO: Consider initializing instance variables and cleanup in destructor
public:
virtual ~ErrorBase();
virtual Error& GetError();
virtual const Error& GetError() const;
virtual void SetErrnoError(const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const;
virtual void SetImaqError(int success, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const;
virtual void SetError(Error::Code code, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const;
virtual void SetWPIError(const char *errorMessage, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber) const;
virtual void CloneError(ErrorBase *rhs) const;
virtual void ClearError() const;
virtual bool StatusIsFatal() const;
static void SetGlobalError(Error::Code code, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber);
static void SetGlobalWPIError(const char *errorMessage, const char *contextMessage,
const char* filename, const char* function, uint32_t lineNumber);
static Error& GetGlobalError();
protected:
mutable Error m_error;
// TODO: Replace globalError with a global list of all errors.
static MUTEX_ID _globalErrorMutex;
static Error _globalError;
ErrorBase();
private:
DISALLOW_COPY_AND_ASSIGN(ErrorBase);
};
#endif

View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef GEAR_TOOTH_H_
#define GEAR_TOOTH_H_
#include "Counter.h"
/**
* Alias for counter class.
* Implement the gear tooth sensor supplied by FIRST. Currently there is no reverse sensing on
* the gear tooth sensor, but in future versions we might implement the necessary timing in the
* FPGA to sense direction.
*/
class GearTooth : public Counter
{
public:
/// 55 uSec for threshold
static constexpr double kGearToothThreshold = 55e-6;
GearTooth(uint32_t channel, bool directionSensitive = false);
GearTooth(uint8_t moduleNumber, uint32_t channel, bool directionSensitive = false);
GearTooth(DigitalSource *source, bool directionSensitive = false);
GearTooth(DigitalSource &source, bool directionSensitive = false);
virtual ~GearTooth();
void EnableDirectionSensing(bool directionSensitive);
virtual std::string GetSmartDashboardType();
};
#endif

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef GENERIC_HID_H
#define GENERIC_HID_H
#include "HAL/HAL.h"
/** GenericHID Interface
*/
class GenericHID
{
public:
typedef enum {
kLeftHand = 0,
kRightHand = 1
} JoystickHand;
virtual ~GenericHID() {}
virtual float GetX(JoystickHand hand = kRightHand) = 0;
virtual float GetY(JoystickHand hand = kRightHand) = 0;
virtual float GetZ() = 0;
virtual float GetTwist() = 0;
virtual float GetThrottle() = 0;
virtual float GetRawAxis(uint32_t axis) = 0;
virtual bool GetTrigger(JoystickHand hand = kRightHand) = 0;
virtual bool GetTop(JoystickHand hand = kRightHand) = 0;
virtual bool GetBumper(JoystickHand hand = kRightHand) = 0;
virtual bool GetRawButton(uint32_t button) = 0;
};
#endif

69
wpilibc/include/Gyro.h Normal file
View File

@@ -0,0 +1,69 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef GYRO_H_
#define GYRO_H_
#include "SensorBase.h"
#include "PIDSource.h"
#include "LiveWindow/LiveWindowSendable.h"
class AnalogChannel;
class AnalogModule;
/**
* Use a rate gyro to return the robots heading relative to a starting position.
* The Gyro class tracks the robots heading based on the starting position. As the robot
* rotates the new heading is computed by integrating the rate of rotation returned
* by the sensor. When the class is instantiated, it does a short calibration routine
* where it samples the gyro while at rest to determine the default offset. This is
* subtracted from each sample to determine the heading. This gyro class must be used
* with a channel that is assigned one of the Analog accumulators from the FPGA. See
* AnalogChannel for the current accumulator assignments.
*/
class Gyro : public SensorBase, public PIDSource, public LiveWindowSendable
{
public:
static const uint32_t kOversampleBits = 10;
static const uint32_t kAverageBits = 0;
static constexpr float kSamplesPerSecond = 50.0;
static constexpr float kCalibrationSampleTime = 5.0;
static constexpr float kDefaultVoltsPerDegreePerSecond = 0.007;
Gyro(uint8_t moduleNumber, uint32_t channel);
explicit Gyro(uint32_t channel);
explicit Gyro(AnalogChannel *channel);
explicit Gyro(AnalogChannel &channel);
virtual ~Gyro();
virtual float GetAngle();
virtual double GetRate();
void SetSensitivity(float voltsPerDegreePerSecond);
void SetPIDSourceParameter(PIDSourceParameter pidSource);
virtual void Reset();
// PIDSource interface
double PIDGet();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitGyro();
AnalogChannel *m_analog;
float m_voltsPerDegreePerSecond;
float m_offset;
bool m_channelAllocated;
uint32_t m_center;
PIDSourceParameter m_pidSource;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,78 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __HiTechnicColorSensor_h__
#define __HiTechnicColorSensor_h__
#include "SensorBase.h"
#include "LiveWindow/LiveWindowSendable.h"
class I2C;
/**
* HiTechnic NXT Color Sensor.
*
* This class allows access to a HiTechnic NXT Color Sensor on an I2C bus.
* These sensors do not allow changing addresses so you cannot have more
* than one on a single bus.
*
* Details on the sensor can be found here:
* http://www.hitechnic.com/index.html?lang=en-us&target=d17.html
*
*/
class HiTechnicColorSensor : public SensorBase
{
public:
enum tColorMode {kActive = 0, kPassive = 1, kRaw = 3};
typedef struct{
uint16_t red;
uint16_t blue;
uint16_t green;
}RGB;
explicit HiTechnicColorSensor(uint8_t moduleNumber);
virtual ~HiTechnicColorSensor();
uint8_t GetColor();
uint8_t GetRed();
uint8_t GetGreen();
uint8_t GetBlue();
RGB GetRGB();
uint16_t GetRawRed();
uint16_t GetRawGreen();
uint16_t GetRawBlue();
RGB GetRawRGB();
void SetMode(tColorMode mode);
//LiveWindowSendable interface
virtual std::string GetType();
virtual void InitTable(ITable *subtable);
virtual void UpdateTable();
virtual ITable* GetTable();
virtual void StartLiveWindowMode();
virtual void StopLiveWindowMode();
private:
static const uint8_t kAddress = 0x02;
static const uint8_t kManufacturerBaseRegister = 0x08;
static const uint8_t kManufacturerSize = 0x08;
static const uint8_t kSensorTypeBaseRegister = 0x10;
static const uint8_t kSensorTypeSize = 0x08;
static const uint8_t kModeRegister = 0x41;
static const uint8_t kColorRegister = 0x42;
static const uint8_t kRedRegister = 0x43;
static const uint8_t kGreenRegister = 0x44;
static const uint8_t kBlueRegister = 0x45;
static const uint8_t kRawRedRegister = 0x43;
static const uint8_t kRawGreenRegister = 0x45;
static const uint8_t kRawBlueRegister = 0x47;
int m_mode;
I2C* m_i2c;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,55 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __HiTechnicCompass_h__
#define __HiTechnicCompass_h__
#include "SensorBase.h"
#include "LiveWindow/LiveWindowSendable.h"
class I2C;
/**
* HiTechnic NXT Compass.
*
* This class alows access to a HiTechnic NXT Compass on an I2C bus.
* These sensors to not allow changing addresses so you cannot have more
* than one on a single bus.
*
* Details on the sensor can be found here:
* http://www.hitechnic.com/index.html?lang=en-us&target=d17.html
*
* @todo Implement a calibration method for the sensor.
*/
class HiTechnicCompass : public SensorBase, public LiveWindowSendable
{
public:
explicit HiTechnicCompass(uint8_t moduleNumber);
virtual ~HiTechnicCompass();
float GetAngle();
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
static const uint8_t kAddress = 0x02;
static const uint8_t kManufacturerBaseRegister = 0x08;
static const uint8_t kManufacturerSize = 0x08;
static const uint8_t kSensorTypeBaseRegister = 0x10;
static const uint8_t kSensorTypeSize = 0x08;
static const uint8_t kHeadingRegister = 0x44;
I2C* m_i2c;
ITable *m_table;
};
#endif

48
wpilibc/include/I2C.h Normal file
View File

@@ -0,0 +1,48 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef I2C_H
#define I2C_H
#include "SensorBase.h"
#include "HAL/Semaphore.h"
class DigitalModule;
/**
* I2C bus interface class.
*
* This class is intended to be used by sensor (and other I2C device) drivers.
* It probably should not be used directly.
*
* It is constructed by calling DigitalModule::GetI2C() on a DigitalModule object.
*/
class I2C : SensorBase
{
friend class DigitalModule;
public:
virtual ~I2C();
bool Transaction(uint8_t *dataToSend, uint8_t sendSize, uint8_t *dataReceived, uint8_t receiveSize);
bool AddressOnly();
bool Write(uint8_t registerAddress, uint8_t data);
bool Read(uint8_t registerAddress, uint8_t count, uint8_t *data);
void Broadcast(uint8_t registerAddress, uint8_t data);
void SetCompatibilityMode(bool enable);
bool VerifySensor(uint8_t registerAddress, uint8_t count, const uint8_t *expected);
private:
static MUTEX_ID m_semaphore;
static uint32_t m_objCount;
I2C(DigitalModule *module, uint8_t deviceAddress);
DigitalModule *m_module;
uint8_t m_deviceAddress;
bool m_compatibilityMode;
};
#endif

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef INTERRUPTABLE_SENSORBASE_H_
#define INTERRUPTABLE_SENSORBASE_H_
#include "HAL/HAL.h"
#include "SensorBase.h"
class InterruptableSensorBase : public SensorBase
{
public:
InterruptableSensorBase();
virtual ~InterruptableSensorBase();
virtual void RequestInterrupts(InterruptHandlerFunction handler, void *param) = 0; ///< Asynchronus handler version.
virtual void RequestInterrupts() = 0; ///< Synchronus Wait version.
virtual void CancelInterrupts(); ///< Free up the underlying chipobject functions.
virtual void WaitForInterrupt(float timeout); ///< Synchronus version.
virtual void EnableInterrupts(); ///< Enable interrupts - after finishing setup.
virtual void DisableInterrupts(); ///< Disable, but don't deallocate.
virtual double ReadInterruptTimestamp(); ///< Return the timestamp for the interrupt that occurred.
protected:
void* m_interrupt;
uint32_t m_interruptIndex;
void AllocateInterrupts(bool watcher);
};
#endif

View File

@@ -0,0 +1,83 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ROBOT_ITERATIVE_H_
#define ROBOT_ITERATIVE_H_
#include "Timer.h"
#include "RobotBase.h"
/**
* IterativeRobot implements a specific type of Robot Program framework, extending the RobotBase class.
*
* The IterativeRobot class is intended to be subclassed by a user creating a robot program.
*
* This class is intended to implement the "old style" default code, by providing
* the following functions which are called by the main loop, StartCompetition(), at the appropriate times:
*
* RobotInit() -- provide for initialization at robot power-on
*
* Init() functions -- each of the following functions is called once when the
* appropriate mode is entered:
* - DisabledInit() -- called only when first disabled
* - AutonomousInit() -- called each and every time autonomous is entered from another mode
* - TeleopInit() -- called each and every time teleop is entered from another mode
* - TestInit() -- called each and every time test is entered from another mode
*
* Periodic() functions -- each of these functions is called iteratively at the
* appropriate periodic rate (aka the "slow loop"). The default period of
* the iterative robot is synced to the driver station control packets,
* giving a periodic frequency of about 50Hz (50 times per second).
* - DisabledPeriodic()
* - AutonomousPeriodic()
* - TeleopPeriodic()
* - TestPeriodic()
*
*/
class IterativeRobot : public RobotBase {
public:
/*
* The default period for the periodic function calls (seconds)
* Setting the period to 0.0 will cause the periodic functions to follow
* the Driver Station packet rate of about 50Hz.
*/
static constexpr double kDefaultPeriod = 0.0;
virtual void StartCompetition();
virtual void RobotInit();
virtual void DisabledInit();
virtual void AutonomousInit();
virtual void TeleopInit();
virtual void TestInit();
virtual void DisabledPeriodic();
virtual void AutonomousPeriodic();
virtual void TeleopPeriodic();
virtual void TestPeriodic();
void SetPeriod(double period);
double GetPeriod();
double GetLoopsPerSec();
protected:
virtual ~IterativeRobot();
IterativeRobot();
private:
bool NextPeriodReady();
bool m_disabledInitialized;
bool m_autonomousInitialized;
bool m_teleopInitialized;
bool m_testInitialized;
double m_period;
Timer m_mainLoopTimer;
};
#endif

34
wpilibc/include/Jaguar.h Normal file
View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef JAGUAR_H
#define JAGUAR_H
#include "SafePWM.h"
#include "SpeedController.h"
#include "PIDOutput.h"
/**
* Luminary Micro Jaguar Speed Control
*/
class Jaguar : public SafePWM, public SpeedController
{
public:
explicit Jaguar(uint32_t channel);
Jaguar(uint8_t moduleNumber, uint32_t channel);
virtual ~Jaguar();
virtual void Set(float value, uint8_t syncGroup=0);
virtual float Get();
virtual void Disable();
virtual void PIDWrite(float output);
private:
void InitJaguar();
};
#endif

View File

@@ -0,0 +1,77 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef JOYSTICK_H_
#define JOYSTICK_H_
#include "GenericHID.h"
#include "ErrorBase.h"
class DriverStation;
/**
* Handle input from standard Joysticks connected to the Driver Station.
* This class handles standard input that comes from the Driver Station. Each time a value is requested
* the most recent value is returned. There is a single class instance for each joystick and the mapping
* of ports to hardware buttons depends on the code in the driver station.
*/
class Joystick : public GenericHID, public ErrorBase
{
public:
static const uint32_t kDefaultXAxis = 1;
static const uint32_t kDefaultYAxis = 2;
static const uint32_t kDefaultZAxis = 3;
static const uint32_t kDefaultTwistAxis = 4;
static const uint32_t kDefaultThrottleAxis = 3;
typedef enum
{
kXAxis, kYAxis, kZAxis, kTwistAxis, kThrottleAxis, kNumAxisTypes
} AxisType;
static const uint32_t kDefaultTriggerButton = 1;
static const uint32_t kDefaultTopButton = 2;
typedef enum
{
kTriggerButton, kTopButton, kNumButtonTypes
} ButtonType;
explicit Joystick(uint32_t port);
Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes);
virtual ~Joystick();
uint32_t GetAxisChannel(AxisType axis);
void SetAxisChannel(AxisType axis, uint32_t channel);
virtual float GetX(JoystickHand hand = kRightHand);
virtual float GetY(JoystickHand hand = kRightHand);
virtual float GetZ();
virtual float GetTwist();
virtual float GetThrottle();
virtual float GetAxis(AxisType axis);
float GetRawAxis(uint32_t axis);
virtual bool GetTrigger(JoystickHand hand = kRightHand);
virtual bool GetTop(JoystickHand hand = kRightHand);
virtual bool GetBumper(JoystickHand hand = kRightHand);
virtual bool GetButton(ButtonType button);
bool GetRawButton(uint32_t button);
static Joystick* GetStickForPort(uint32_t port);
virtual float GetMagnitude();
virtual float GetDirectionRadians();
virtual float GetDirectionDegrees();
private:
DISALLOW_COPY_AND_ASSIGN(Joystick);
void InitJoystick(uint32_t numAxisTypes, uint32_t numButtonTypes);
DriverStation *m_ds;
uint32_t m_port;
uint32_t *m_axes;
uint32_t *m_buttons;
};
#endif

73
wpilibc/include/Kinect.h Normal file
View File

@@ -0,0 +1,73 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __KINECT_H__
#define __KINECT_H__
#include "SensorBase.h"
#include "Skeleton.h"
#include "HAL/Semaphore.h"
#define kNumSkeletons 1
/**
* Handles raw data input from the FRC Kinect Server
* when used with a Kinect device connected to the Driver Station.
* Each time a value is requested the most recent value is returned.
* See Getting Started with Microsoft Kinect for FRC and the Kinect
* for Windows SDK API reference for more information
*/
class Kinect : public SensorBase
{
public:
typedef enum {kNotTracked, kPositionOnly, kTracked} SkeletonTrackingState;
typedef enum {kClippedRight = 1, kClippedLeft = 2, kClippedTop = 4, kClippedBottom = 8} SkeletonQuality;
typedef struct
{
float x;
float y;
float z;
float w;
} Point4;
int GetNumberOfPlayers();
Point4 GetFloorClipPlane();
Point4 GetGravityNormal();
Skeleton GetSkeleton(int skeletonIndex = 1);
Point4 GetPosition(int skeletonIndex = 1);
uint32_t GetQuality(int skeletonIndex = 1);
SkeletonTrackingState GetTrackingState(int skeletonIndex = 1);
static Kinect *GetInstance();
private:
Kinect();
~Kinect();
void UpdateData();
DISALLOW_COPY_AND_ASSIGN(Kinect);
uint32_t m_recentPacketNumber;
MUTEX_ID m_dataLock;
int m_numberOfPlayers;
Point4 m_floorClipPlane;
Point4 m_gravityNormal;
Point4 m_position[kNumSkeletons];
uint32_t m_quality[kNumSkeletons];
SkeletonTrackingState m_trackingState[kNumSkeletons];
Skeleton m_skeletons[kNumSkeletons];
// TODO: Include structs for this data format (would be clearer than 100 magic numbers)
char m_rawHeader[46];
char m_rawSkeletonExtra[42];
char m_rawSkeleton[242];
static Kinect *_instance;
};
#endif

View File

@@ -0,0 +1,61 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __KINECT_STICK_H__
#define __KINECT_STICK_H__
#include "ErrorBase.h"
#include "GenericHID.h"
/**
* Handles input from the Joystick data sent by the FRC Kinect Server
* when used with a Kinect device connected to the Driver Station.
* Each time a value is requested the most recent value is returned.
* Default gestures embedded in the FRC Kinect Server are described
* in the document Getting Started with Microsoft Kinect for FRC.
*/
class KinectStick : public GenericHID, public ErrorBase
{
public:
explicit KinectStick(int id);
virtual float GetX(JoystickHand hand = kRightHand);
virtual float GetY(JoystickHand hand = kRightHand);
virtual float GetZ();
virtual float GetTwist();
virtual float GetThrottle();
virtual float GetRawAxis(uint32_t axis);
virtual bool GetTrigger(JoystickHand hand = kRightHand);
virtual bool GetTop(JoystickHand hand = kRightHand);
virtual bool GetBumper(JoystickHand hand = kRightHand);
virtual bool GetRawButton(uint32_t button);
private:
void GetData();
float ConvertRawToFloat(int8_t charValue);
typedef union
{
struct
{
uint8_t size;
uint8_t id;
struct
{
unsigned char axis[6];
unsigned short buttons;
} rawSticks[2];
} formatted;
char data[18];
} KinectStickData;
int m_id;
static uint32_t _recentPacketNumber;
static KinectStickData _sticks;
};
#endif

View File

@@ -0,0 +1,67 @@
#ifndef _LIVE_WINDOW_H
#define _LIVE_WINDOW_H
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITable.h"
#include "Commands/Scheduler.h"
#include <vector>
#include <map>
struct LiveWindowComponent
{
std::string subsystem;
std::string name;
bool isSensor;
LiveWindowComponent()
{}//WTF?
LiveWindowComponent(std::string subsystem, std::string name, bool isSensor)
{
this->subsystem = subsystem;
this->name = name;
this->isSensor = isSensor;
}
};
/**
* The LiveWindow class is the public interface for putting sensors and actuators
* on the LiveWindow.
*
* @author Brad Miller
*/
class LiveWindow {
public:
static LiveWindow * GetInstance();
void Run();
void AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component);
void AddActuator(const char *subsystem, const char *name, LiveWindowSendable *component);
void AddSensor(std::string type, int module, int channel, LiveWindowSendable *component);
void AddActuator(std::string type, int module, int channel, LiveWindowSendable *component);
bool IsEnabled() { return m_enabled; }
void SetEnabled(bool enabled);
protected:
LiveWindow();
virtual ~LiveWindow();
private:
void UpdateValues();
void Initialize();
void InitializeLiveWindowComponents();
std::vector<LiveWindowSendable *> m_sensors;
std::map<LiveWindowSendable *, LiveWindowComponent> m_components;
static LiveWindow *m_instance;
ITable *m_liveWindowTable;
ITable *m_statusTable;
Scheduler *m_scheduler;
bool m_enabled;
bool m_firstTime;
};
#endif

View File

@@ -0,0 +1,40 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) Patrick Plenefisch 2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef LIVEWINDOWSENDABLE_H_
#define LIVEWINDOWSENDABLE_H_
#include "SmartDashboard/Sendable.h"
/**
* Live Window Sendable is a special type of object sendable to the live window.
*
* @author Patrick Plenefisch
*/
class LiveWindowSendable: public Sendable
{
public:
/**
* Update the table for this sendable object with the latest
* values.
*/
virtual void UpdateTable() = 0;
/**
* Start having this sendable object automatically respond to
* value changes reflect the value on the table.
*/
virtual void StartLiveWindowMode() = 0;
/**
* Stop having this sendable object automatically respond to value
* changes.
*/
virtual void StopLiveWindowMode() = 0;
};
#endif /* LIVEWINDOWSENDABLE_H_ */

View File

@@ -0,0 +1,12 @@
#ifndef _LIVE_WINDOW_STATUS_LISTENER_H
#define _LIVE_WINDOW_STATUS_LISTENER_H
#include "tables/ITable.h"
#include "tables/ITableListener.h"
class LiveWindowStatusListener : public ITableListener {
public:
virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
};
#endif

34
wpilibc/include/Module.h Normal file
View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef MODULE_H_
#define MODULE_H_
#include "SensorBase.h"
#include "NetworkCommunication/LoadOut.h"
#define kMaxModules (nLoadOut::kModuleType_Solenoid * kMaxModuleNumber + (kMaxModuleNumber - 1))
class Module: public SensorBase
{
public:
nLoadOut::tModuleType GetType() {return m_moduleType;}
uint8_t GetNumber() {return m_moduleNumber;}
static Module *GetModule(nLoadOut::tModuleType type, uint8_t number);
protected:
explicit Module(nLoadOut::tModuleType type, uint8_t number);
virtual ~Module();
nLoadOut::tModuleType m_moduleType; ///< The type of module represented.
uint8_t m_moduleNumber; ///< The module index within the module type.
private:
static uint8_t ToIndex(nLoadOut::tModuleType type, uint8_t number);
static Module* m_modules[kMaxModules];
};
#endif

View File

@@ -0,0 +1,23 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef _MOTOR_SAFETY_
#define _MOTOR_SAFETY_
#define DEFAULT_SAFETY_EXPIRATION 0.1
class MotorSafety {
public:
virtual void SetExpiration(float timeout) = 0;
virtual float GetExpiration() = 0;
virtual bool IsAlive() = 0;
virtual void StopMotor() = 0;
virtual void SetSafetyEnabled(bool enabled) = 0;
virtual bool IsSafetyEnabled() = 0;
virtual void GetDescription(char *desc) = 0;
};
#endif

View File

@@ -0,0 +1,39 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __MOTOR_SAFETY_HELPER__
#define __MOTOR_SAFETY_HELPER__
#include "ErrorBase.h"
#include "HAL/cpp/Synchronized.h"
class MotorSafety;
class MotorSafetyHelper : public ErrorBase
{
public:
MotorSafetyHelper(MotorSafety *safeObject);
~MotorSafetyHelper();
void Feed();
void SetExpiration(float expirationTime);
float GetExpiration();
bool IsAlive();
void Check();
void SetSafetyEnabled(bool enabled);
bool IsSafetyEnabled();
static void CheckMotors();
private:
double m_expiration; // the expiration time for this object
bool m_enabled; // true if motor safety is enabled for this motor
double m_stopTime; // the FPGA clock value when this motor has expired
ReentrantSemaphore m_syncMutex; // protect accesses to the state for this object
MotorSafety *m_safeObject; // the object that is using the helper
MotorSafetyHelper *m_nextHelper; // next object in the list of MotorSafetyHelpers
static MotorSafetyHelper *m_headHelper; // the head of the list of MotorSafetyHelper objects
static ReentrantSemaphore m_listMutex; // protect accesses to the list of helpers
};
#endif

View File

@@ -0,0 +1,19 @@
#ifndef __AICalibration_h__
#define __AICalibration_h__
#include "HAL/HAL.h"
#ifdef __cplusplus
extern "C"
{
#endif
uint32_t FRC_NetworkCommunication_nAICalibration_getLSBWeight(const uint32_t aiSystemIndex, const uint32_t channel, int32_t *status);
int32_t FRC_NetworkCommunication_nAICalibration_getOffset(const uint32_t aiSystemIndex, const uint32_t channel, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif // __AICalibration_h__

View File

@@ -0,0 +1,193 @@
/*************************************************************
* NOTICE
*
* These are the only externally exposed functions to the
* NetworkCommunication library
*
* This is an implementation of FRC Spec for Comm Protocol
* Revision 4.5, June 30, 2008
*
* Copyright (c) National Instruments 2008. All Rights Reserved.
*
*************************************************************/
#ifndef __FRC_COMM_H__
#define __FRC_COMM_H__
#ifdef SIMULATION
#include <vxWorks_compat.h>
#define EXPORT_FUNC __declspec(dllexport) __cdecl
#else
#if defined(__vxworks)
#include <vxWorks.h>
#define EXPORT_FUNC
#else
#include <stdint.h>
#include <pthread.h>
#define EXPORT_FUNC
#endif
#endif
// Commandeer some bytes at the end for advanced I/O feedback.
#define IO_CONFIG_DATA_SIZE 32
#define SYS_STATUS_DATA_SIZE 44
#define USER_STATUS_DATA_SIZE (984 - IO_CONFIG_DATA_SIZE - SYS_STATUS_DATA_SIZE)
#define USER_DS_LCD_DATA_SIZE 128
struct FRCCommonControlData{
uint16_t packetIndex;
union {
uint8_t control;
#ifndef __vxworks
struct {
uint8_t checkVersions :1;
uint8_t test :1;
uint8_t resync : 1;
uint8_t fmsAttached:1;
uint8_t autonomous : 1;
uint8_t enabled : 1;
uint8_t notEStop : 1;
uint8_t reset : 1;
};
#else
struct {
uint8_t reset : 1;
uint8_t notEStop : 1;
uint8_t enabled : 1;
uint8_t autonomous : 1;
uint8_t fmsAttached:1;
uint8_t resync : 1;
uint8_t test :1;
uint8_t checkVersions :1;
};
#endif
};
uint8_t dsDigitalIn;
uint16_t teamID;
char dsID_Alliance;
char dsID_Position;
union {
int8_t stick0Axes[6];
struct {
int8_t stick0Axis1;
int8_t stick0Axis2;
int8_t stick0Axis3;
int8_t stick0Axis4;
int8_t stick0Axis5;
int8_t stick0Axis6;
};
};
uint16_t stick0Buttons; // Left-most 4 bits are unused
union {
int8_t stick1Axes[6];
struct {
int8_t stick1Axis1;
int8_t stick1Axis2;
int8_t stick1Axis3;
int8_t stick1Axis4;
int8_t stick1Axis5;
int8_t stick1Axis6;
};
};
uint16_t stick1Buttons; // Left-most 4 bits are unused
union {
int8_t stick2Axes[6];
struct {
int8_t stick2Axis1;
int8_t stick2Axis2;
int8_t stick2Axis3;
int8_t stick2Axis4;
int8_t stick2Axis5;
int8_t stick2Axis6;
};
};
uint16_t stick2Buttons; // Left-most 4 bits are unused
union {
int8_t stick3Axes[6];
struct {
int8_t stick3Axis1;
int8_t stick3Axis2;
int8_t stick3Axis3;
int8_t stick3Axis4;
int8_t stick3Axis5;
int8_t stick3Axis6;
};
};
uint16_t stick3Buttons; // Left-most 4 bits are unused
//Analog inputs are 10 bit right-justified
uint16_t analog1;
uint16_t analog2;
uint16_t analog3;
uint16_t analog4;
uint64_t cRIOChecksum;
uint32_t FPGAChecksum0;
uint32_t FPGAChecksum1;
uint32_t FPGAChecksum2;
uint32_t FPGAChecksum3;
char versionData[8];
};
#define kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input 17
#define kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output 18
#define kFRC_NetworkCommunication_DynamicType_Kinect_Header 19
#define kFRC_NetworkCommunication_DynamicType_Kinect_Extra1 20
#define kFRC_NetworkCommunication_DynamicType_Kinect_Vertices1 21
#define kFRC_NetworkCommunication_DynamicType_Kinect_Extra2 22
#define kFRC_NetworkCommunication_DynamicType_Kinect_Vertices2 23
#define kFRC_NetworkCommunication_DynamicType_Kinect_Joystick 24
#define kFRC_NetworkCommunication_DynamicType_Kinect_Custom 25
extern "C" {
#ifndef SIMULATION
void EXPORT_FUNC getFPGAHardwareVersion(uint16_t *fpgaVersion, uint32_t *fpgaRevision);
#endif
int EXPORT_FUNC getCommonControlData(FRCCommonControlData *data, int wait_ms);
int EXPORT_FUNC getRecentCommonControlData(FRCCommonControlData *commonData, int wait_ms);
int EXPORT_FUNC getRecentStatusData(uint8_t *batteryInt, uint8_t *batteryDec, uint8_t *dsDigitalOut, int wait_ms);
int EXPORT_FUNC getDynamicControlData(uint8_t type, char *dynamicData, int32_t maxLength, int wait_ms);
int EXPORT_FUNC setStatusData(float battery, uint8_t dsDigitalOut, uint8_t updateNumber,
const char *userDataHigh, int userDataHighLength,
const char *userDataLow, int userDataLowLength, int wait_ms);
int EXPORT_FUNC setStatusDataFloatAsInt(int battery, uint8_t dsDigitalOut, uint8_t updateNumber,
const char *userDataHigh, int userDataHighLength,
const char *userDataLow, int userDataLowLength, int wait_ms);
int EXPORT_FUNC setErrorData(const char *errors, int errorsLength, int wait_ms);
int EXPORT_FUNC setUserDsLcdData(const char *userDsLcdData, int userDsLcdDataLength, int wait_ms);
int EXPORT_FUNC overrideIOConfig(const char *ioConfig, int wait_ms);
#ifdef SIMULATION
void EXPORT_FUNC setNewDataSem(HANDLE);
#else
# if defined (__vxworks)
void EXPORT_FUNC setNewDataSem(SEM_ID);
void EXPORT_FUNC setResyncSem(SEM_ID);
# else
void EXPORT_FUNC setNewDataSem(pthread_mutex_t *);
void EXPORT_FUNC setResyncSem(pthread_mutex_t *);
# endif
void EXPORT_FUNC signalResyncActionDone(void);
#endif
// this uint32_t is really a LVRefNum
void EXPORT_FUNC setNewDataOccurRef(uint32_t refnum);
#ifndef SIMULATION
void EXPORT_FUNC setResyncOccurRef(uint32_t refnum);
#endif
void EXPORT_FUNC FRC_NetworkCommunication_getVersionString(char *version);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramStarting(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramDisabled(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramAutonomous(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTeleop(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTest(void);
};
#endif

View File

@@ -0,0 +1,39 @@
#ifndef __LoadOut_h__
#define __LoadOut_h__
#define kMaxModuleNumber 2
namespace nLoadOut
{
typedef enum {
kModuleType_Unknown = 0x00,
kModuleType_Analog = 0x01,
kModuleType_Digital = 0x02,
kModuleType_Solenoid = 0x03,
} tModuleType;
bool getModulePresence(tModuleType moduleType, uint8_t moduleNumber);
typedef enum {
kTargetClass_Unknown = 0x00,
kTargetClass_FRC1 = 0x10,
kTargetClass_FRC2 = 0x20,
kTargetClass_FRC2_Analog = kTargetClass_FRC2 | kModuleType_Analog,
kTargetClass_FRC2_Digital = kTargetClass_FRC2 | kModuleType_Digital,
kTargetClass_FRC2_Solenoid = kTargetClass_FRC2 | kModuleType_Solenoid,
kTargetClass_FamilyMask = 0xF0,
kTargetClass_ModuleMask = 0x0F,
} tTargetClass;
tTargetClass getTargetClass();
}
#ifdef __cplusplus
extern "C" {
#endif
uint32_t FRC_NetworkCommunication_nLoadOut_getModulePresence(uint32_t moduleType, uint8_t moduleNumber);
uint32_t FRC_NetworkCommunication_nLoadOut_getTargetClass();
#ifdef __cplusplus
}
#endif
#endif // __LoadOut_h__

View File

@@ -0,0 +1,135 @@
#ifndef __UsageReporting_h__
#define __UsageReporting_h__
#ifdef SIMULATION
#include <vxWorks_compat.h>
#define EXPORT_FUNC __declspec(dllexport) __cdecl
#else
#include "HAL/HAL.h"
#define EXPORT_FUNC
#endif
#define kUsageReporting_version 1
namespace nUsageReporting
{
typedef enum
{
kResourceType_Controller,
kResourceType_Module,
kResourceType_Language,
kResourceType_CANPlugin,
kResourceType_Accelerometer,
kResourceType_ADXL345,
kResourceType_AnalogChannel,
kResourceType_AnalogTrigger,
kResourceType_AnalogTriggerOutput,
kResourceType_CANJaguar,
kResourceType_Compressor,
kResourceType_Counter,
kResourceType_Dashboard,
kResourceType_DigitalInput,
kResourceType_DigitalOutput,
kResourceType_DriverStationCIO,
kResourceType_DriverStationEIO,
kResourceType_DriverStationLCD,
kResourceType_Encoder,
kResourceType_GearTooth,
kResourceType_Gyro,
kResourceType_I2C,
kResourceType_Framework,
kResourceType_Jaguar,
kResourceType_Joystick,
kResourceType_Kinect,
kResourceType_KinectStick,
kResourceType_PIDController,
kResourceType_Preferences,
kResourceType_PWM,
kResourceType_Relay,
kResourceType_RobotDrive,
kResourceType_SerialPort,
kResourceType_Servo,
kResourceType_Solenoid,
kResourceType_SPI,
kResourceType_Task,
kResourceType_Ultrasonic,
kResourceType_Victor,
kResourceType_Button,
kResourceType_Command,
kResourceType_AxisCamera,
kResourceType_PCVideoServer,
kResourceType_SmartDashboard,
kResourceType_Talon,
kResourceType_HiTechnicColorSensor,
kResourceType_HiTechnicAccel,
kResourceType_HiTechnicCompass,
kResourceType_SRF08,
} tResourceType;
typedef enum
{
kLanguage_LabVIEW = 1,
kLanguage_CPlusPlus = 2,
kLanguage_Java = 3,
kLanguage_Python = 4,
kCANPlugin_BlackJagBridge = 1,
kCANPlugin_2CAN = 2,
kFramework_Iterative = 1,
kFramework_Simple = 2,
kRobotDrive_ArcadeStandard = 1,
kRobotDrive_ArcadeButtonSpin = 2,
kRobotDrive_ArcadeRatioCurve = 3,
kRobotDrive_Tank = 4,
kRobotDrive_MecanumPolar = 5,
kRobotDrive_MecanumCartesian = 6,
kDriverStationCIO_Analog = 1,
kDriverStationCIO_DigitalIn = 2,
kDriverStationCIO_DigitalOut = 3,
kDriverStationEIO_Acceleration = 1,
kDriverStationEIO_AnalogIn = 2,
kDriverStationEIO_AnalogOut = 3,
kDriverStationEIO_Button = 4,
kDriverStationEIO_LED = 5,
kDriverStationEIO_DigitalIn = 6,
kDriverStationEIO_DigitalOut = 7,
kDriverStationEIO_FixedDigitalOut = 8,
kDriverStationEIO_PWM = 9,
kDriverStationEIO_Encoder = 10,
kDriverStationEIO_TouchSlider = 11,
kADXL345_SPI = 1,
kADXL345_I2C = 2,
kCommand_Scheduler = 1,
kSmartDashboard_Instance = 1,
} tInstances;
/**
* Report the usage of a resource of interest.
*
* @param resource one of the values in the tResourceType above (max value 51).
* @param instanceNumber an index that identifies the resource instance.
* @param context an optional additional context number for some cases (such as module number). Set to 0 to omit.
* @param feature a string to be included describing features in use on a specific resource. Setting the same resource more than once allows you to change the feature string.
*/
uint32_t EXPORT_FUNC report(tResourceType resource, uint8_t instanceNumber, uint8_t context = 0, const char *feature = NULL);
}
#ifdef __cplusplus
extern "C" {
#endif
uint32_t EXPORT_FUNC FRC_NetworkCommunication_nUsageReporting_report(uint8_t resource, uint8_t instanceNumber, uint8_t context, const char *feature);
#ifdef __cplusplus
}
#endif
#endif // __UsageReporting_h__

View File

@@ -0,0 +1,21 @@
#ifndef __SYM_MODULE_LINK_H__
#define __SYM_MODULE_LINK_H__
#include "HAL/HAL.h"
#ifdef __cplusplus
extern "C" {
#endif
extern STATUS moduleNameFindBySymbolName
(
const char * symbol, /* symbol name to look for */
char * module /* where to return module name */
);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef NOTIFIER_H
#define NOTIFIER_H
#include "HAL/HAL.h"
#include "ErrorBase.h"
#include "HAL/cpp/Synchronized.h"
typedef void (*TimerEventHandler)(void *param);
class Notifier : public ErrorBase
{
public:
Notifier(TimerEventHandler handler, void *param = NULL);
virtual ~Notifier();
void StartSingle(double delay);
void StartPeriodic(double period);
void Stop();
private:
static Notifier *timerQueueHead;
static ReentrantSemaphore queueSemaphore;
static void* m_notifier;
static int refcount;
static void ProcessQueue(uint32_t mask, void *params); // process the timer queue on a timer event
static void UpdateAlarm(); // update the FPGA alarm since the queue has changed
void InsertInQueue(bool reschedule); // insert this Notifier in the timer queue
void DeleteFromQueue(); // delete this Notifier from the timer queue
TimerEventHandler m_handler; // address of the handler
void *m_param; // a parameter to pass to the handler
double m_period; // the relative time (either periodic or single)
double m_expirationTime; // absolute expiration time for the current event
Notifier *m_nextEvent; // next Nofifier event
bool m_periodic; // true if this is a periodic event
bool m_queued; // indicates if this entry is queued
SEMAPHORE_ID m_handlerSemaphore; // held by interrupt manager task while handler call is in progress
DISALLOW_COPY_AND_ASSIGN(Notifier);
};
#endif

View File

@@ -0,0 +1,109 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef PIDCONTROLLER_H_
#define PIDCONTROLLER_H_
#include "Base.h"
#include "HAL/Semaphore.h"
#include "Controller.h"
#include "LiveWindow/LiveWindow.h"
class PIDOutput;
class PIDSource;
class Notifier;
/**
* Class implements a PID Control Loop.
*
* Creates a separate thread which reads the given PIDSource and takes
* care of the integral calculations, as well as writing the given
* PIDOutput
*/
class PIDController : public LiveWindowSendable, public Controller, public ITableListener
{
public:
PIDController(float p, float i, float d,
PIDSource *source, PIDOutput *output,
float period = 0.05);
PIDController(float p, float i, float d, float f,
PIDSource *source, PIDOutput *output,
float period = 0.05);
virtual ~PIDController();
virtual float Get();
virtual void SetContinuous(bool continuous = true);
virtual void SetInputRange(float minimumInput, float maximumInput);
virtual void SetOutputRange(float mimimumOutput, float maximumOutput);
virtual void SetPID(float p, float i, float d);
virtual void SetPID(float p, float i, float d, float f);
virtual float GetP();
virtual float GetI();
virtual float GetD();
virtual float GetF();
virtual void SetSetpoint(float setpoint);
virtual float GetSetpoint();
virtual float GetError();
virtual void SetTolerance(float percent);
virtual void SetAbsoluteTolerance(float absValue);
virtual void SetPercentTolerance(float percentValue);
virtual bool OnTarget();
virtual void Enable();
virtual void Disable();
virtual bool IsEnabled();
virtual void Reset();
virtual void InitTable(ITable* table);
private:
float m_P; // factor for "proportional" control
float m_I; // factor for "integral" control
float m_D; // factor for "derivative" control
float m_F; // factor for "feed forward" control
float m_maximumOutput; // |maximum output|
float m_minimumOutput; // |minimum output|
float m_maximumInput; // maximum input - limit setpoint to this
float m_minimumInput; // minimum input - limit setpoint to this
bool m_continuous; // do the endpoints wrap around? eg. Absolute encoder
bool m_enabled; //is the pid controller enabled
float m_prevError; // the prior sensor input (used to compute velocity)
double m_totalError; //the sum of the errors for use in the integral calc
enum {kAbsoluteTolerance, kPercentTolerance, kNoTolerance} m_toleranceType;
float m_tolerance; //the percetage or absolute error that is considered on target
float m_setpoint;
float m_error;
float m_result;
float m_period;
MUTEX_ID m_semaphore;
PIDSource *m_pidInput;
PIDOutput *m_pidOutput;
Notifier *m_controlLoop;
void Initialize(float p, float i, float d, float f,
PIDSource *source, PIDOutput *output,
float period = 0.05);
static void CallCalculate(void *controller);
virtual ITable* GetTable();
virtual std::string GetSmartDashboardType();
virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
virtual void UpdateTable();
virtual void StartLiveWindowMode();
virtual void StopLiveWindowMode();
protected:
ITable* m_table;
void Calculate();
DISALLOW_COPY_AND_ASSIGN(PIDController);
};
#endif

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef PID_OUTPUT_H
#define PID_OUTPUT_H
#include "Base.h"
/**
* PIDOutput interface is a generic output for the PID class.
* PWMs use this class.
* Users implement this interface to allow for a PIDController to
* read directly from the inputs
*/
class PIDOutput
{
public:
virtual void PIDWrite(float output) = 0;
};
#endif

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef PID_SOURCE_H
#define PID_SOURCE_H
/**
* PIDSource interface is a generic sensor source for the PID class.
* All sensors that can be used with the PID class will implement the PIDSource that
* returns a standard value that will be used in the PID code.
*/
class PIDSource
{
public:
typedef enum {kDistance, kRate, kAngle} PIDSourceParameter;
virtual double PIDGet() = 0;
};
#endif

114
wpilibc/include/PWM.h Normal file
View File

@@ -0,0 +1,114 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef PWM_H_
#define PWM_H_
#include "SensorBase.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITableListener.h"
class DigitalModule;
/**
* Class implements the PWM generation in the FPGA.
*
* The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They are mapped
* to the hardware dependent values, in this case 0-255 for the FPGA.
* Changes are immediately sent to the FPGA, and the update occurs at the next
* FPGA cycle. There is no delay.
*
* As of revision 0.1.10 of the FPGA, the FPGA interprets the 0-255 values as follows:
* - 255 = full "forward"
* - 254 to 129 = linear scaling from "full forward" to "center"
* - 128 = center value
* - 127 to 2 = linear scaling from "center" to "full reverse"
* - 1 = full "reverse"
* - 0 = disabled (i.e. PWM output is held low)
*/
class PWM : public SensorBase, public ITableListener, public LiveWindowSendable
{
friend class DigitalModule;
public:
typedef enum {kPeriodMultiplier_1X = 1, kPeriodMultiplier_2X = 2, kPeriodMultiplier_4X = 4} PeriodMultiplier;
explicit PWM(uint32_t channel);
PWM(uint8_t moduleNumber, uint32_t channel);
virtual ~PWM();
virtual void SetRaw(unsigned short value);
virtual unsigned short GetRaw();
void SetPeriodMultiplier(PeriodMultiplier mult);
void EnableDeadbandElimination(bool eliminateDeadband);
void SetBounds(int32_t max, int32_t deadbandMax, int32_t center, int32_t deadbandMin, int32_t min);
void SetBounds(double max, double deadbandMax, double center, double deadbandMin, double min);
uint32_t GetChannel() {return m_channel;}
uint32_t GetModuleNumber();
protected:
/**
* kDefaultPwmPeriod is in ms
*
* - 20ms periods (50 Hz) are the "safest" setting in that this works for all devices
* - 20ms periods seem to be desirable for Vex Motors
* - 20ms periods are the specified period for HS-322HD servos, but work reliably down
* to 10.0 ms; starting at about 8.5ms, the servo sometimes hums and get hot;
* by 5.0ms the hum is nearly continuous
* - 10ms periods work well for Victor 884
* - 5ms periods allows higher update rates for Luminary Micro Jaguar speed controllers.
* Due to the shipping firmware on the Jaguar, we can't run the update period less
* than 5.05 ms.
*
* kDefaultPwmPeriod is the 1x period (5.05 ms). In hardware, the period scaling is implemented as an
* output squelch to get longer periods for old devices.
*/
static constexpr float kDefaultPwmPeriod = 5.05;
/**
* kDefaultPwmCenter is the PWM range center in ms
*/
static constexpr float kDefaultPwmCenter = 1.5;
/**
* kDefaultPWMStepsDown is the number of PWM steps below the centerpoint
*/
static const int32_t kDefaultPwmStepsDown = 1000;
static const int32_t kPwmDisabled = 0;
virtual void SetPosition(float pos);
virtual float GetPosition();
virtual void SetSpeed(float speed);
virtual float GetSpeed();
bool m_eliminateDeadband;
int32_t m_maxPwm;
int32_t m_deadbandMaxPwm;
int32_t m_centerPwm;
int32_t m_deadbandMinPwm;
int32_t m_minPwm;
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
ITable *m_table;
private:
void InitPWM(uint8_t moduleNumber, uint32_t channel);
uint32_t m_channel;
DigitalModule *m_module;
int32_t GetMaxPositivePwm() { return m_maxPwm; };
int32_t GetMinPositivePwm() { return m_eliminateDeadband ? m_deadbandMaxPwm : m_centerPwm + 1; };
int32_t GetCenterPwm() { return m_centerPwm; };
int32_t GetMaxNegativePwm() { return m_eliminateDeadband ? m_deadbandMinPwm : m_centerPwm - 1; };
int32_t GetMinNegativePwm() { return m_minPwm; };
int32_t GetPositiveScaleFactor() {return GetMaxPositivePwm() - GetMinPositivePwm();} ///< The scale for positive speeds.
int32_t GetNegativeScaleFactor() {return GetMaxNegativePwm() - GetMinNegativePwm();} ///< The scale for negative speeds.
int32_t GetFullRangeScaleFactor() {return GetMaxPositivePwm() - GetMinNegativePwm();} ///< The scale for positions.
};
#endif

View File

@@ -0,0 +1,94 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __PREFERENCES_H__
#define __PREFERENCES_H__
#include "ErrorBase.h"
#include "Task.h"
#include <map>
#include "HAL/Semaphore.h"
#include <string>
#include <vector>
#include "tables/ITableListener.h"
#include "networktables/NetworkTable.h"
/**
* The preferences class provides a relatively simple way to save important values to
* the cRIO to access the next time the cRIO is booted.
*
* <p>This class loads and saves from a file
* inside the cRIO. The user can not access the file directly, but may modify values at specific
* fields which will then be saved to the file when {@link Preferences#Save() Save()} is called.</p>
*
* <p>This class is thread safe.</p>
*
* <p>This will also interact with {@link NetworkTable} by creating a table called "Preferences" with all the
* key-value pairs. To save using {@link NetworkTable}, simply set the boolean at position "~S A V E~" to true.
* Also, if the value of any variable is " in the {@link NetworkTable}, then that represents non-existence in the
* {@link Preferences} table</p>
*/
class Preferences : public ErrorBase, public ITableListener
{
public:
static Preferences *GetInstance();
std::vector<std::string> GetKeys();
std::string GetString(const char *key, const char *defaultValue = "");
int GetString(const char *key, char *value, int valueSize, const char *defaultValue = "");
int GetInt(const char *key, int defaultValue = 0);
double GetDouble(const char *key, double defaultValue = 0.0);
float GetFloat(const char *key, float defaultValue = 0.0);
bool GetBoolean(const char *key, bool defaultValue = false);
int64_t GetLong(const char *key, int64_t defaultValue = 0);
void PutString(const char *key, const char *value);
void PutInt(const char *key, int value);
void PutDouble(const char *key, double value);
void PutFloat(const char *key, float value);
void PutBoolean(const char *key, bool value);
void PutLong(const char *key, int64_t value);
void Save();
bool ContainsKey(const char *key);
void Remove(const char *key);
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
protected:
Preferences();
virtual ~Preferences();
private:
std::string Get(const char *key);
void Put(const char *key, std::string value);
void ReadTaskRun();
void WriteTaskRun();
static int InitReadTask(Preferences *obj) {obj->ReadTaskRun();return 0;}
static int InitWriteTask(Preferences *obj) {obj->WriteTaskRun();return 0;}
static Preferences *_instance;
/** The semaphore for accessing the file */
MUTEX_ID m_fileLock;
/** The semaphore for beginning reads and writes to the file */
SEMAPHORE_ID m_fileOpStarted;
/** The semaphore for reading from the table */
MUTEX_ID m_tableLock;
typedef std::map<std::string, std::string> StringMap;
/** The actual values (String->String) */
StringMap m_values;
/** The keys in the order they were read from the file */
std::vector<std::string> m_keys;
/** The comments that were in the file sorted by which key they appeared over (String->Comment) */
StringMap m_comments;
/** The comment at the end of the file */
std::string m_endComment;
Task m_readTask;
Task m_writeTask;
};
#endif

56
wpilibc/include/Relay.h Normal file
View File

@@ -0,0 +1,56 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef RELAY_H_
#define RELAY_H_
#include "SensorBase.h"
#include "tables/ITableListener.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITable.h"
class DigitalModule;
/**
* Class for Spike style relay outputs.
* Relays are intended to be connected to spikes or similar relays. The relay channels controls
* a pair of pins that are either both off, one on, the other on, or both on. This translates into
* two spike outputs at 0v, one at 12v and one at 0v, one at 0v and the other at 12v, or two
* spike outputs at 12V. This allows off, full forward, or full reverse control of motors without
* variable speed. It also allows the two channels (forward and reverse) to be used independently
* for something that does not care about voltage polatiry (like a solenoid).
*/
class Relay : public SensorBase, public ITableListener, public LiveWindowSendable {
public:
typedef enum {kOff, kOn, kForward, kReverse} Value;
typedef enum {kBothDirections, kForwardOnly, kReverseOnly} Direction;
Relay(uint32_t channel, Direction direction = kBothDirections);
Relay(uint8_t moduleNumber, uint32_t channel, Direction direction = kBothDirections);
virtual ~Relay();
void Set(Value value);
Value Get();
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
ITable *m_table;
private:
void InitRelay(uint8_t moduleNumber);
uint32_t m_channel;
Direction m_direction;
DigitalModule *m_module;
};
#endif

View File

@@ -0,0 +1,44 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef RESOURCE_H_
#define RESOURCE_H_
#include "ErrorBase.h"
#include "HAL/cpp/Synchronized.h"
#include "HAL/HAL.h"
/**
* The Resource class is a convenient way to track allocated resources.
* It tracks them as indicies in the range [0 .. elements - 1].
* E.g. the library uses this to track hardware channel allocation.
*
* The Resource class does not allocate the hardware channels or other
* resources; it just tracks which indices were marked in use by
* Allocate and not yet freed by Free.
*/
class Resource : public ErrorBase
{
public:
virtual ~Resource();
static void CreateResourceObject(Resource **r, uint32_t elements);
uint32_t Allocate(const char *resourceDesc);
uint32_t Allocate(uint32_t index, const char *resourceDesc);
void Free(uint32_t index);
private:
explicit Resource(uint32_t size);
bool *m_isAllocated;
ReentrantSemaphore m_allocateLock;
uint32_t m_size;
static ReentrantSemaphore m_createLock;
DISALLOW_COPY_AND_ASSIGN(Resource);
};
#endif

View File

@@ -0,0 +1,79 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ROBOT_H_
#define ROBOT_H_
#include "Base.h"
#include "Task.h"
class DriverStation;
#ifdef __vxworks
#define START_ROBOT_CLASS(_ClassName_) \
RobotBase *FRC_userClassFactory() \
{ \
cout << "Instantiating " #_ClassName_ "...\n";\
RobotBase* rb= new _ClassName_();\
cout << "...Instantiated " #_ClassName_ "\n";\
return rb;\
} \
extern "C" { \
int32_t FRC_UserProgram_StartupLibraryInit() \
{ \
RobotBase::startRobotTask((FUNCPTR)FRC_userClassFactory); \
return 0; \
} \
}
#else
#define START_ROBOT_CLASS(_ClassName_) \
int main() \
{ \
HALNetworkCommunicationReserve(); \
RobotBase* robot = new _ClassName_(); \
robot->StartCompetition(); \
return 0; \
}
#endif
/**
* Implement a Robot Program framework.
* The RobotBase class is intended to be subclassed by a user creating a robot program.
* Overridden Autonomous() and OperatorControl() methods are called at the appropriate time
* as the match proceeds. In the current implementation, the Autonomous code will run to
* completion before the OperatorControl code could start. In the future the Autonomous code
* might be spawned as a task, then killed at the end of the Autonomous period.
*/
class RobotBase {
friend class RobotDeleter;
public:
static RobotBase &getInstance();
static void setInstance(RobotBase* robot);
bool IsEnabled();
bool IsDisabled();
bool IsAutonomous();
bool IsOperatorControl();
bool IsTest();
bool IsNewDataAvailable();
static void startRobotTask(FUNCPTR factory);
static void robotTask(FUNCPTR factory, Task *task);
virtual void StartCompetition() = 0;
protected:
virtual ~RobotBase();
RobotBase();
Task *m_task;
DriverStation *m_ds;
private:
static RobotBase *m_instance;
DISALLOW_COPY_AND_ASSIGN(RobotBase);
};
#endif

View File

@@ -0,0 +1,108 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef ROBOTDRIVE_H_
#define ROBOTDRIVE_H_
#include "ErrorBase.h"
#include <stdlib.h>
#include "HAL/HAL.h"
#include "MotorSafety.h"
#include "MotorSafetyHelper.h"
class SpeedController;
class GenericHID;
/**
* Utility class for handling Robot drive based on a definition of the motor configuration.
* The robot drive class handles basic driving for a robot. Currently, 2 and 4 motor standard
* drive trains are supported. In the future other drive types like swerve and meccanum might
* be implemented. Motor channel numbers are passed supplied on creation of the class. Those are
* used for either the Drive function (intended for hand created drive code, such as autonomous)
* or with the Tank/Arcade functions intended to be used for Operator Control driving.
*/
class RobotDrive: public MotorSafety, public ErrorBase
{
public:
typedef enum
{
kFrontLeftMotor = 0,
kFrontRightMotor = 1,
kRearLeftMotor = 2,
kRearRightMotor = 3
} MotorType;
RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel);
RobotDrive(uint32_t frontLeftMotorChannel, uint32_t rearLeftMotorChannel,
uint32_t frontRightMotorChannel, uint32_t rearRightMotorChannel);
RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor);
RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor);
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
SpeedController *frontRightMotor, SpeedController *rearRightMotor);
RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
SpeedController &frontRightMotor, SpeedController &rearRightMotor);
virtual ~RobotDrive();
void Drive(float outputMagnitude, float curve);
void TankDrive(GenericHID *leftStick, GenericHID *rightStick, bool squaredInputs = true);
void TankDrive(GenericHID &leftStick, GenericHID &rightStick, bool squaredInputs = true);
void TankDrive(GenericHID *leftStick, uint32_t leftAxis, GenericHID *rightStick, uint32_t rightAxis, bool squaredInputs = true);
void TankDrive(GenericHID &leftStick, uint32_t leftAxis, GenericHID &rightStick, uint32_t rightAxis, bool squaredInputs = true);
void TankDrive(float leftValue, float rightValue, bool squaredInputs = true);
void ArcadeDrive(GenericHID *stick, bool squaredInputs = true);
void ArcadeDrive(GenericHID &stick, bool squaredInputs = true);
void ArcadeDrive(GenericHID *moveStick, uint32_t moveChannel, GenericHID *rotateStick, uint32_t rotateChannel, bool squaredInputs = true);
void ArcadeDrive(GenericHID &moveStick, uint32_t moveChannel, GenericHID &rotateStick, uint32_t rotateChannel, bool squaredInputs = true);
void ArcadeDrive(float moveValue, float rotateValue, bool squaredInputs = true);
void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle = 0.0);
void MecanumDrive_Polar(float magnitude, float direction, float rotation);
void HolonomicDrive(float magnitude, float direction, float rotation);
virtual void SetLeftRightMotorOutputs(float leftOutput, float rightOutput);
void SetInvertedMotor(MotorType motor, bool isInverted);
void SetSensitivity(float sensitivity);
void SetMaxOutput(double maxOutput);
void SetExpiration(float timeout);
float GetExpiration();
bool IsAlive();
void StopMotor();
bool IsSafetyEnabled();
void SetSafetyEnabled(bool enabled);
void GetDescription(char *desc);
protected:
void InitRobotDrive();
float Limit(float num);
void Normalize(double *wheelSpeeds);
void RotateVector(double &x, double &y, double angle);
static const int32_t kMaxNumberOfMotors = 4;
int32_t m_invertedMotors[kMaxNumberOfMotors];
float m_sensitivity;
double m_maxOutput;
bool m_deleteSpeedControllers;
SpeedController *m_frontLeftMotor;
SpeedController *m_frontRightMotor;
SpeedController *m_rearLeftMotor;
SpeedController *m_rearRightMotor;
MotorSafetyHelper *m_safetyHelper;
private:
int32_t GetNumMotors()
{
int motors = 0;
if (m_frontLeftMotor) motors++;
if (m_frontRightMotor) motors++;
if (m_rearLeftMotor) motors++;
if (m_rearRightMotor) motors++;
return motors;
}
DISALLOW_COPY_AND_ASSIGN(RobotDrive);
};
#endif

76
wpilibc/include/SPI.h Normal file
View File

@@ -0,0 +1,76 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SPI_H__
#define __SPI_H__
#include "HAL/HAL.h"
#include "SensorBase.h"
class DigitalOutput;
class DigitalInput;
/**
* SPI bus interface class.
*
* This class is intended to be used by sensor (and other SPI device) drivers.
* It probably should not be used directly.
*
* The FPGA only supports a single SPI interface.
*/
class SPI : public SensorBase
{
public:
SPI(DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso);
SPI(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso);
SPI(DigitalOutput &clk, DigitalOutput &mosi);
SPI(DigitalOutput *clk, DigitalOutput *mosi);
SPI(DigitalOutput &clk, DigitalInput &miso);
SPI(DigitalOutput *clk, DigitalInput *miso);
virtual ~SPI();
void SetBitsPerWord(uint32_t bits);
uint32_t GetBitsPerWord();
void SetClockRate(double hz);
void SetMSBFirst();
void SetLSBFirst();
void SetSampleDataOnFalling();
void SetSampleDataOnRising();
void SetSlaveSelect(DigitalOutput *ss, tFrameMode mode=kChipSelect, bool activeLow=false);
void SetSlaveSelect(DigitalOutput &ss, tFrameMode mode=kChipSelect, bool activeLow=false);
DigitalOutput *GetSlaveSelect(tFrameMode *mode=NULL, bool *activeLow=NULL);
void SetClockActiveLow();
void SetClockActiveHigh();
virtual void ApplyConfig();
virtual uint16_t GetOutputFIFOAvailable();
virtual uint16_t GetNumReceived();
virtual bool IsDone();
bool HadReceiveOverflow();
virtual void Write(uint32_t data);
virtual uint32_t Read(bool initiate = false);
virtual void Reset();
virtual void ClearReceivedData();
protected:
void* m_spi;
DigitalOutput *m_ss;
private:
void Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso);
DISALLOW_COPY_AND_ASSIGN(SPI);
};
#endif

43
wpilibc/include/SafePWM.h Normal file
View File

@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SAFE_PWM__
#define __SAFE_PWM__
#include "MotorSafety.h"
#include "PWM.h"
class MotorSafetyHelper;
/**
* A safe version of the PWM class.
* It is safe because it implements the MotorSafety interface that provides timeouts
* in the event that the motor value is not updated before the expiration time.
* This delegates the actual work to a MotorSafetyHelper object that is used for all
* objects that implement MotorSafety.
*/
class SafePWM: public PWM, public MotorSafety
{
public:
explicit SafePWM(uint32_t channel);
SafePWM(uint8_t moduleNumber, uint32_t channel);
~SafePWM();
void SetExpiration(float timeout);
float GetExpiration();
bool IsAlive();
void StopMotor();
bool IsSafetyEnabled();
void SetSafetyEnabled(bool enabled);
void GetDescription(char *desc);
virtual void SetSpeed(float speed);
private:
void InitSafePWM();
MotorSafetyHelper *m_safetyHelper;
};
#endif

View File

@@ -0,0 +1,57 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SENSORBASE_H_
#define SENSORBASE_H_
#include "ErrorBase.h"
#include <stdio.h>
#include "Base.h"
/**
* Base class for all sensors.
* Stores most recent status information as well as containing utility functions for checking
* channels and error processing.
*/
class SensorBase: public ErrorBase {
public:
SensorBase();
virtual ~SensorBase();
static void DeleteSingletons();
static uint32_t GetDefaultAnalogModule() { return 1; }
static uint32_t GetDefaultDigitalModule() { return 1; }
static uint32_t GetDefaultSolenoidModule() { return 1; }
static bool CheckAnalogModule(uint8_t moduleNumber);
static bool CheckDigitalModule(uint8_t moduleNumber);
static bool CheckPWMModule(uint8_t moduleNumber);
static bool CheckRelayModule(uint8_t moduleNumber);
static bool CheckSolenoidModule(uint8_t moduleNumber);
static bool CheckDigitalChannel(uint32_t channel);
static bool CheckRelayChannel(uint32_t channel);
static bool CheckPWMChannel(uint32_t channel);
static bool CheckAnalogChannel(uint32_t channel);
static bool CheckSolenoidChannel(uint32_t channel);
static const uint32_t kDigitalChannels = 14;
static const uint32_t kAnalogChannels = 8;
static const uint32_t kAnalogModules = 2;
static const uint32_t kDigitalModules = 2;
static const uint32_t kSolenoidChannels = 8;
static const uint32_t kSolenoidModules = 2;
static const uint32_t kPwmChannels = 10;
static const uint32_t kRelayChannels = 8;
static const uint32_t kChassisSlots = 8;
protected:
void AddToSingletonList();
private:
DISALLOW_COPY_AND_ASSIGN(SensorBase);
static SensorBase *m_singletonList;
SensorBase *m_nextSingleton;
};
#endif

View File

@@ -0,0 +1,61 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SerialPort_h__
#define __SerialPort_h__
#include "ErrorBase.h"
#include "HAL/HAL.h"
/**
* Driver for the RS-232 serial port on the cRIO.
*
* The current implementation uses the VISA formatted I/O mode. This means that
* all traffic goes through the fomatted buffers. This allows the intermingled
* use of Printf(), Scanf(), and the raw buffer accessors Read() and Write().
*
* More information can be found in the NI-VISA User Manual here:
* http://www.ni.com/pdf/manuals/370423a.pdf
* and the NI-VISA Programmer's Reference Manual here:
* http://www.ni.com/pdf/manuals/370132c.pdf
*/
class SerialPort : public ErrorBase
{
public:
typedef enum {kParity_None=0, kParity_Odd=1, kParity_Even=2, kParity_Mark=3, kParity_Space=4} Parity;
typedef enum {kStopBits_One=10, kStopBits_OnePointFive=15, kStopBits_Two=20} StopBits;
typedef enum {kFlowControl_None=0, kFlowControl_XonXoff=1, kFlowControl_RtsCts=2, kFlowControl_DtrDsr=4} FlowControl;
typedef enum {kFlushOnAccess=1, kFlushWhenFull=2} WriteBufferMode;
SerialPort(uint32_t baudRate, uint8_t dataBits = 8, Parity parity = kParity_None, StopBits stopBits = kStopBits_One);
~SerialPort();
void SetFlowControl(FlowControl flowControl);
void EnableTermination(char terminator = '\n');
void DisableTermination();
int32_t GetBytesReceived();
void Printf(const char *writeFmt, ...);
void Scanf(const char *readFmt, ...);
uint32_t Read(char *buffer, int32_t count);
uint32_t Write(const char *buffer, int32_t count);
void SetTimeout(float timeout);
void SetReadBufferSize(uint32_t size);
void SetWriteBufferSize(uint32_t size);
void SetWriteBufferMode(WriteBufferMode mode);
void Flush();
void Reset();
/*
* Do not call me!
*/
//void _internalHandler(uint32_t port, uint32_t eventType, uint32_t event);
private:
uint32_t m_resourceManagerHandle;
uint32_t m_portHandle;
bool m_consoleModeEnabled;
DISALLOW_COPY_AND_ASSIGN(SerialPort);
};
#endif

52
wpilibc/include/Servo.h Normal file
View File

@@ -0,0 +1,52 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SERVO_H
#define SERVO_H
#include "SafePWM.h"
#include "SpeedController.h"
/**
* Standard hobby style servo.
*
* The range parameters default to the appropriate values for the Hitec HS-322HD servo provided
* in the FIRST Kit of Parts in 2008.
*/
class Servo : public SafePWM
{
public:
explicit Servo(uint32_t channel);
Servo(uint8_t moduleNumber, uint32_t channel);
virtual ~Servo();
void Set(float value);
void SetOffline();
float Get();
void SetAngle(float angle);
float GetAngle();
static float GetMaxAngle() { return kMaxServoAngle; };
static float GetMinAngle() { return kMinServoAngle; };
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
ITable *m_table;
private:
void InitServo();
float GetServoAngleRange() {return kMaxServoAngle - kMinServoAngle;}
static constexpr float kMaxServoAngle = 170.0;
static constexpr float kMinServoAngle = 0.0;
};
#endif

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SIMPLE_ROBOT_H
#define SIMPLE_ROBOT_H
#include "RobotBase.h"
/**
* @todo If this is going to last until release, it needs a better name.
*/
class SimpleRobot: public RobotBase
{
public:
SimpleRobot();
virtual ~SimpleRobot() {}
virtual void RobotInit();
virtual void Disabled();
virtual void Autonomous();
virtual void OperatorControl();
virtual void Test();
virtual void RobotMain();
void StartCompetition();
private:
bool m_robotMainOverridden;
};
#endif

View File

@@ -0,0 +1,81 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SKELETON_H__
#define __SKELETON_H__
/**
* Represents Skeleton data from a Kinect device connected to the
* Driver Station. See Getting Started with Microsoft Kinect for
* FRC and the Kinect for Windows SDK API reference for more information
*/
class Skeleton
{
friend class Kinect;
public:
typedef enum
{
HipCenter = 0,
Spine = 1,
ShoulderCenter = 2,
Head = 3,
ShoulderLeft = 4,
ElbowLeft = 5,
WristLeft = 6,
HandLeft = 7,
ShoulderRight = 8,
ElbowRight = 9,
WristRight = 10,
HandRight = 11,
HipLeft = 12,
KneeLeft = 13,
AnkleLeft = 14,
FootLeft = 15,
HipRight = 16,
KneeRight = 17,
AnkleRight = 18,
FootRight = 19,
JointCount = 20
} JointTypes;
typedef enum {kNotTracked, kInferred, kTracked} JointTrackingState;
typedef struct
{
float x;
float y;
float z;
JointTrackingState trackingState;
} Joint;
Joint GetHandRight() { return m_joints[HandRight]; }
Joint GetHandLeft() { return m_joints[HandLeft]; }
Joint GetWristRight() { return m_joints[WristRight]; }
Joint GetWristLeft() { return m_joints[WristLeft]; }
Joint GetElbowLeft() { return m_joints[ElbowLeft]; }
Joint GetElbowRight() { return m_joints[ElbowRight]; }
Joint GetShoulderLeft() { return m_joints[ShoulderLeft]; }
Joint GetShoulderRight() { return m_joints[ShoulderRight]; }
Joint GetShoulderCenter() { return m_joints[ShoulderCenter]; }
Joint GetHead() { return m_joints[Head]; }
Joint GetSpine() { return m_joints[Spine]; }
Joint GetHipCenter() { return m_joints[HipCenter]; }
Joint GetHipRight() { return m_joints[HipRight]; }
Joint GetHipLeft() { return m_joints[HipLeft]; }
Joint GetKneeLeft() { return m_joints[KneeLeft]; }
Joint GetKneeRight() { return m_joints[KneeRight]; }
Joint GetAnkleLeft() { return m_joints[AnkleLeft]; }
Joint GetAnkleRight() { return m_joints[AnkleRight]; }
Joint GetFootLeft() { return m_joints[FootLeft]; }
Joint GetFootRight() { return m_joints[FootRight]; }
Joint GetJointValue(JointTypes index) { return m_joints[index]; }
private:
Joint m_joints[20];
};
#endif

View File

@@ -0,0 +1,29 @@
/*
* NamedSendable.h
*
* Created on: Oct 19, 2012
* Author: Mitchell Wills
*/
#ifndef NAMEDSENDABLE_H_
#define NAMEDSENDABLE_H_
#include <string>
#include "SmartDashboard/Sendable.h"
/**
* The interface for sendable objects that gives the sendable a default name in the Smart Dashboard
*
*/
class NamedSendable : public Sendable
{
public:
/**
* @return the name of the subtable of SmartDashboard that the Sendable object will use
*/
virtual std::string GetName() = 0;
};
#endif /* NAMEDSENDABLE_H_ */

View File

@@ -0,0 +1,33 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SMART_DASHBOARD_DATA__
#define __SMART_DASHBOARD_DATA__
#include <string>
#include "tables/ITable.h"
class Sendable
{
public:
/**
* Initializes a table for this sendable object.
* @param subtable The table to put the values in.
*/
virtual void InitTable(ITable* subtable) = 0;
/**
* @return the table that is currently associated with the sendable
*/
virtual ITable* GetTable() = 0;
/**
* @return the string representation of the named data type that will be used by the smart dashboard for this sendable
*/
virtual std::string GetSmartDashboardType() = 0;
};
#endif

View File

@@ -0,0 +1,47 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SENDABLE_CHOOSER_H__
#define __SENDABLE_CHOOSER_H__
#include "SmartDashboard/Sendable.h"
#include "tables/ITable.h"
#include <map>
#include <string>
/**
* The {@link SendableChooser} class is a useful tool for presenting a selection of options
* to the {@link SmartDashboard}.
*
* <p>For instance, you may wish to be able to select between multiple autonomous modes.
* You can do this by putting every possible {@link Command} you want to run as an autonomous into
* a {@link SendableChooser} and then put it into the {@link SmartDashboard} to have a list of options
* appear on the laptop. Once autonomous starts, simply ask the {@link SendableChooser} what the selected
* value is.</p>
*
* @see SmartDashboard
*/
class SendableChooser : public Sendable
{
public:
SendableChooser();
virtual ~SendableChooser() {};
void AddObject(const char *name, void *object);
void AddDefault(const char *name, void *object);
void *GetSelected();
virtual void InitTable(ITable* subtable);
virtual ITable* GetTable();
virtual std::string GetSmartDashboardType();
private:
std::string m_defaultChoice;
std::map<std::string, void *> m_choices;
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,55 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2011. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef __SMART_DASHBOARD_H__
#define __SMART_DASHBOARD_H__
#include "SensorBase.h"
#include <map>
#include <string>
#include "SmartDashboard/Sendable.h"
#include "SmartDashboard/NamedSendable.h"
#include "tables/ITable.h"
class SmartDashboard : public SensorBase
{
public:
static void init();
static void PutData(std::string key, Sendable *data);
static void PutData(NamedSendable *value);
//static Sendable* GetData(std::string keyName);
static void PutBoolean(std::string keyName, bool value);
static bool GetBoolean(std::string keyName);
static void PutNumber(std::string keyName, double value);
static double GetNumber(std::string keyName);
static void PutString(std::string keyName, std::string value);
static int GetString(std::string keyName, char *value, unsigned int valueLen);
static std::string GetString(std::string keyName);
static void PutValue(std::string keyName, ComplexData& value);
static void RetrieveValue(std::string keyName, ComplexData& value);
private:
SmartDashboard();
virtual ~SmartDashboard();
DISALLOW_COPY_AND_ASSIGN(SmartDashboard);
/** The {@link NetworkTable} used by {@link SmartDashboard} */
static ITable* m_table;
/**
* A map linking tables in the SmartDashboard to the {@link SmartDashboardData} objects
* they came from.
*/
static std::map<ITable *, Sendable *> m_tablesToData;
};
#endif

View File

@@ -0,0 +1,46 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SOLENOID_H_
#define SOLENOID_H_
#include "SolenoidBase.h"
#include "LiveWindow/LiveWindowSendable.h"
#include "tables/ITableListener.h"
/**
* Solenoid class for running high voltage Digital Output (9472 module).
*
* The Solenoid class is typically used for pneumatics solenoids, but could be used
* for any device within the current spec of the 9472 module.
*/
class Solenoid : public SolenoidBase, public LiveWindowSendable, public ITableListener {
public:
explicit Solenoid(uint32_t channel);
Solenoid(uint8_t moduleNumber, uint32_t channel);
virtual ~Solenoid();
virtual void Set(bool on);
virtual bool Get();
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
void UpdateTable();
void StartLiveWindowMode();
void StopLiveWindowMode();
std::string GetSmartDashboardType();
void InitTable(ITable *subTable);
ITable * GetTable();
private:
void InitSolenoid();
uint32_t m_channel; ///< The channel on the module to control.
ITable *m_table;
};
#endif

View File

@@ -0,0 +1,36 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SOLENOID_BASE_H_
#define SOLENOID_BASE_H_
#include "Resource.h"
#include "SensorBase.h"
#include "HAL/HAL.h"
#include "HAL/cpp/Synchronized.h"
/**
* SolenoidBase class is the common base class for the Solenoid and
* DoubleSolenoid classes.
*/
class SolenoidBase : public SensorBase {
public:
virtual ~SolenoidBase();
uint8_t GetAll();
protected:
explicit SolenoidBase(uint8_t moduleNumber);
void Set(uint8_t value, uint8_t mask);
virtual void InitSolenoid() = 0;
uint32_t m_moduleNumber; ///< Slot number where the module is plugged into the chassis.
static Resource *m_allocated;
private:
void* m_ports[kSolenoidChannels];
};
#endif

View File

@@ -0,0 +1,40 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#ifndef SPEED_CONTROLLER_H
#define SPEED_CONTROLLER_H
#include "HAL/HAL.h"
#include "PIDOutput.h"
/**
* Interface for speed controlling devices.
*/
class SpeedController : public PIDOutput
{
public:
virtual ~SpeedController() {};
/**
* Common interface for setting the speed of a speed controller.
*
* @param speed The speed to set. Value should be between -1.0 and 1.0.
* @param syncGroup The update group to add this Set() to, pending UpdateSyncGroup(). If 0, update immediately.
*/
virtual void Set(float speed, uint8_t syncGroup=0) = 0;
/**
* Common interface for getting the current set speed of a speed controller.
*
* @return The current set speed. Value is between -1.0 and 1.0.
*/
virtual float Get() = 0;
/**
* Common interface for disabling a motor.
*/
virtual void Disable() = 0;
};
#endif

Some files were not shown because too many files have changed in this diff Show More