mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Renamed folders for consistency, using sim/athena/shared schema (#27)
Rename the following folders: hal/lib/Athena -> hal/lib/athena hal/lib/Desktop -> hal/lib/sim hal/lib/Shared -> hal/lib/shared wpilibc/Athena -> wpilibc/athena wpilibc/simulation -> wpilibc/sim Windows users may need to run gradlew clean after updating.
This commit is contained in:
committed by
Peter Johnson
parent
54092378e9
commit
e71f454b9d
51
wpilibc/sim/include/AnalogGyro.h
Normal file
51
wpilibc/sim/include/AnalogGyro.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GyroBase.h"
|
||||
#include "simulation/SimGyro.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class AnalogInput;
|
||||
class AnalogModule;
|
||||
|
||||
/**
|
||||
* Use a rate gyro to return the robots heading relative to a starting position.
|
||||
*
|
||||
* The AnalogGyro 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 AnalogInput for
|
||||
* the current accumulator assignments.
|
||||
*/
|
||||
class AnalogGyro : public GyroBase {
|
||||
public:
|
||||
static const uint32_t kOversampleBits;
|
||||
static const uint32_t kAverageBits;
|
||||
static const float kSamplesPerSecond;
|
||||
static const float kCalibrationSampleTime;
|
||||
static const float kDefaultVoltsPerDegreePerSecond;
|
||||
|
||||
explicit AnalogGyro(uint32_t channel);
|
||||
virtual ~AnalogGyro() = default;
|
||||
float GetAngle() const;
|
||||
void Calibrate() override;
|
||||
double GetRate() const;
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
void InitAnalogGyro(int channel);
|
||||
|
||||
SimGyro* impl;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
60
wpilibc/sim/include/AnalogInput.h
Normal file
60
wpilibc/sim/include/AnalogInput.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimFloatInput.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Analog input class.
|
||||
*
|
||||
* 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 AnalogInput : 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];
|
||||
|
||||
explicit AnalogInput(uint32_t channel);
|
||||
virtual ~AnalogInput() = default;
|
||||
|
||||
float GetVoltage() const;
|
||||
float GetAverageVoltage() const;
|
||||
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
double PIDGet() override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
SimFloatInput* m_impl;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
95
wpilibc/sim/include/AnalogPotentiometer.h
Normal file
95
wpilibc/sim/include/AnalogPotentiometer.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class for reading analog potentiometers. Analog potentiometers read
|
||||
* in an analog voltage that corresponds to a position. Usually the
|
||||
* position is either degrees or meters. However, if no conversion is
|
||||
* given it remains volts.
|
||||
*
|
||||
* @author Alex Henning
|
||||
*/
|
||||
class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
public:
|
||||
/**
|
||||
* AnalogPotentiometer constructor.
|
||||
*
|
||||
* Use the scaling and offset values so that the output produces meaningful
|
||||
* values. I.E: you have a 270 degree potentiometer and you want the output
|
||||
* to be degrees with the halfway point as 0 degrees. The scale value is
|
||||
* 270.0(degrees)/5.0(volts) and the offset is -135.0 since the halfway point
|
||||
* after scaling is 135 degrees.
|
||||
*
|
||||
* @param channel The analog channel this potentiometer is plugged into.
|
||||
* @param scale The scaling to multiply the voltage by to get a meaningful
|
||||
* unit.
|
||||
* @param offset The offset to add to the scaled value for controlling the
|
||||
* zero value
|
||||
*/
|
||||
AnalogPotentiometer(int channel, double scale = 1.0, double offset = 0.0);
|
||||
|
||||
AnalogPotentiometer(AnalogInput* input, double scale = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
AnalogPotentiometer(AnalogInput& input, double scale = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
virtual ~AnalogPotentiometer();
|
||||
|
||||
/**
|
||||
* Get the current reading of the potentiomere.
|
||||
*
|
||||
* @return The current position of the potentiometer.
|
||||
*/
|
||||
virtual double Get() const;
|
||||
|
||||
/**
|
||||
* Implement the PIDSource interface.
|
||||
*
|
||||
* @return The current reading.
|
||||
*/
|
||||
virtual double PIDGet() override;
|
||||
|
||||
/*
|
||||
* Live Window code, only does anything if live window is activated.
|
||||
*/
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void InitTable(std::shared_ptr<ITable> subtable) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when entering the
|
||||
* LiveWindow.
|
||||
*/
|
||||
virtual void StartLiveWindowMode() override {}
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when exiting the
|
||||
* LiveWindow.
|
||||
*/
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
private:
|
||||
double m_scale, m_offset;
|
||||
AnalogInput* m_analog_input;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
bool m_init_analog_input;
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*/
|
||||
void initPot(AnalogInput* input, double scale, double offset);
|
||||
};
|
||||
100
wpilibc/sim/include/Counter.h
Normal file
100
wpilibc/sim/include/Counter.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CounterBase.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* All counters will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Counter : public SensorBase,
|
||||
public CounterBase,
|
||||
public LiveWindowSendable {
|
||||
public:
|
||||
explicit Counter(Mode mode = kTwoPulse);
|
||||
explicit Counter(uint32_t channel);
|
||||
// TODO: [Not Supported] explicit Counter(DigitalSource *source);
|
||||
// TODO: [Not Supported] explicit Counter(DigitalSource &source);
|
||||
// TODO: [Not Supported] explicit Counter(AnalogTrigger *source);
|
||||
// TODO: [Not Supported] explicit Counter(AnalogTrigger &source);
|
||||
// TODO: [Not Supported] Counter(EncodingType encodingType, DigitalSource
|
||||
// *upSource, DigitalSource *downSource, bool inverted);
|
||||
virtual ~Counter();
|
||||
|
||||
void SetUpSource(uint32_t channel);
|
||||
// TODO: [Not Supported] void SetUpSource(AnalogTrigger *analogTrigger,
|
||||
// AnalogTriggerType triggerType);
|
||||
// TODO: [Not Supported] void SetUpSource(AnalogTrigger &analogTrigger,
|
||||
// AnalogTriggerType triggerType);
|
||||
// TODO: [Not Supported] void SetUpSource(DigitalSource *source);
|
||||
// TODO: [Not Supported] void SetUpSource(DigitalSource &source);
|
||||
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
|
||||
void ClearUpSource();
|
||||
|
||||
void SetDownSource(uint32_t channel);
|
||||
// TODO: [Not Supported] void SetDownSource(AnalogTrigger *analogTrigger,
|
||||
// AnalogTriggerType triggerType);
|
||||
// TODO: [Not Supported] void SetDownSource(AnalogTrigger &analogTrigger,
|
||||
// AnalogTriggerType triggerType);
|
||||
// TODO: [Not Supported] void SetDownSource(DigitalSource *source);
|
||||
// TODO: [Not Supported] 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
|
||||
int32_t Get() const override;
|
||||
void Reset() override;
|
||||
double GetPeriod() const override;
|
||||
void SetMaxPeriod(double maxPeriod) override;
|
||||
void SetUpdateWhenEmpty(bool enabled);
|
||||
bool GetStopped() const override;
|
||||
bool GetDirection() const override;
|
||||
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
int GetSamplesToAverage() const;
|
||||
uint32_t GetFPGAIndex() const { return m_index; }
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
protected:
|
||||
// What makes the counter count up.
|
||||
// TODO: [Not Supported] DigitalSource *m_upSource;
|
||||
// What makes the counter count down.
|
||||
// TODO: [Not Supported] DigitalSource *m_downSource;
|
||||
void* m_counter; ///< The FPGA counter object.
|
||||
private:
|
||||
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.
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
30
wpilibc/sim/include/CounterBase.h
Normal file
30
wpilibc/sim/include/CounterBase.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* All counters will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class CounterBase {
|
||||
public:
|
||||
enum EncodingType { k1X, k2X, k4X };
|
||||
|
||||
virtual ~CounterBase() = default;
|
||||
virtual int32_t Get() const = 0;
|
||||
virtual void Reset() = 0;
|
||||
virtual double GetPeriod() const = 0;
|
||||
virtual void SetMaxPeriod(double maxPeriod) = 0;
|
||||
virtual bool GetStopped() const = 0;
|
||||
virtual bool GetDirection() const = 0;
|
||||
};
|
||||
44
wpilibc/sim/include/DigitalInput.h
Normal file
44
wpilibc/sim/include/DigitalInput.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "simulation/SimDigitalInput.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* 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 LiveWindowSendable {
|
||||
public:
|
||||
explicit DigitalInput(uint32_t channel);
|
||||
virtual ~DigitalInput() = default;
|
||||
uint32_t Get() const;
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
bool m_lastValue;
|
||||
SimDigitalInput* m_impl;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
49
wpilibc/sim/include/DoubleSolenoid.h
Normal file
49
wpilibc/sim/include/DoubleSolenoid.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* DoubleSolenoid class for running 2 channels of high voltage Digital Output
|
||||
* (PCM).
|
||||
*
|
||||
* The DoubleSolenoid class is typically used for pneumatics solenoids that
|
||||
* have two positions controlled by two separate channels.
|
||||
*/
|
||||
class DoubleSolenoid : public LiveWindowSendable, public ITableListener {
|
||||
public:
|
||||
enum Value { kOff, kForward, kReverse };
|
||||
|
||||
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() const;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
SimContinuousOutput* m_impl;
|
||||
Value m_value;
|
||||
bool m_reversed;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
141
wpilibc/sim/include/DriverStation.h
Normal file
141
wpilibc/sim/include/DriverStation.h
Normal file
@@ -0,0 +1,141 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
// Ensure that Winsock2.h is included before Windows.h, which can get
|
||||
// pulled in by anybody (e.g., Boost).
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include <condition_variable>
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include <mutex>
|
||||
#include "RobotState.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
struct HALCommonControlData;
|
||||
class AnalogInput;
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
/**
|
||||
* Provide access to the network communication data to / from the Driver
|
||||
* Station.
|
||||
*/
|
||||
class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
public:
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
|
||||
virtual ~DriverStation() = default;
|
||||
static DriverStation& GetInstance();
|
||||
static void ReportError(std::string error);
|
||||
static void ReportWarning(std::string error);
|
||||
static void ReportError(bool is_error, int32_t code, const std::string& error,
|
||||
const std::string& location,
|
||||
const std::string& stack);
|
||||
|
||||
static const uint32_t kBatteryChannel = 7;
|
||||
static const uint32_t kJoystickPorts = 4;
|
||||
static const uint32_t kJoystickAxes = 6;
|
||||
|
||||
float GetStickAxis(uint32_t stick, uint32_t axis);
|
||||
bool GetStickButton(uint32_t stick, uint32_t button);
|
||||
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() const;
|
||||
bool IsDisabled() const;
|
||||
bool IsAutonomous() const;
|
||||
bool IsOperatorControl() const;
|
||||
bool IsTest() const;
|
||||
bool IsFMSAttached() const;
|
||||
|
||||
uint32_t GetPacketNumber() const;
|
||||
Alliance GetAlliance() const;
|
||||
uint32_t GetLocation() const;
|
||||
void WaitForData();
|
||||
double GetMatchTime() const;
|
||||
float GetBatteryVoltage() const;
|
||||
uint16_t GetTeamNumber() const;
|
||||
|
||||
void IncrementUpdateNumber() { m_updateNumber++; }
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
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 const float kUpdatePeriod;
|
||||
|
||||
void stateCallback(const msgs::ConstDriverStationPtr& msg);
|
||||
void joystickCallback(const msgs::ConstFRCJoystickPtr& msg, int i);
|
||||
void joystickCallback0(const msgs::ConstFRCJoystickPtr& msg);
|
||||
void joystickCallback1(const msgs::ConstFRCJoystickPtr& msg);
|
||||
void joystickCallback2(const msgs::ConstFRCJoystickPtr& msg);
|
||||
void joystickCallback3(const msgs::ConstFRCJoystickPtr& msg);
|
||||
void joystickCallback4(const msgs::ConstFRCJoystickPtr& msg);
|
||||
void joystickCallback5(const msgs::ConstFRCJoystickPtr& msg);
|
||||
|
||||
uint8_t m_digitalOut = 0;
|
||||
std::condition_variable m_waitForDataCond;
|
||||
std::mutex m_waitForDataMutex;
|
||||
mutable std::recursive_mutex m_stateMutex;
|
||||
std::recursive_mutex m_joystickMutex;
|
||||
double m_approxMatchTimeOffset = 0;
|
||||
bool m_userInDisabled = false;
|
||||
bool m_userInAutonomous = false;
|
||||
bool m_userInTeleop = false;
|
||||
bool m_userInTest = false;
|
||||
|
||||
transport::SubscriberPtr stateSub;
|
||||
transport::SubscriberPtr joysticksSub[6];
|
||||
msgs::DriverStationPtr state;
|
||||
msgs::FRCJoystickPtr joysticks[6];
|
||||
};
|
||||
97
wpilibc/sim/include/Encoder.h
Normal file
97
wpilibc/sim/include/Encoder.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "CounterBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimEncoder.h"
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* All encoders will immediately start counting - Reset() them if you need them
|
||||
* to be zeroed before use.
|
||||
*/
|
||||
class Encoder : public SensorBase,
|
||||
public CounterBase,
|
||||
public PIDSource,
|
||||
public LiveWindowSendable {
|
||||
public:
|
||||
Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection = false,
|
||||
EncodingType encodingType = k4X);
|
||||
// TODO: [Not Supported] Encoder(DigitalSource *aSource, DigitalSource
|
||||
// *bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
|
||||
// TODO: [Not Supported] Encoder(DigitalSource &aSource, DigitalSource
|
||||
// &bSource, bool reverseDirection=false, EncodingType encodingType = k4X);
|
||||
virtual ~Encoder() = default;
|
||||
|
||||
// CounterBase interface
|
||||
int32_t Get() const override;
|
||||
int32_t GetRaw() const;
|
||||
int32_t GetEncodingScale() const;
|
||||
void Reset() override;
|
||||
double GetPeriod() const override;
|
||||
void SetMaxPeriod(double maxPeriod) override;
|
||||
bool GetStopped() const override;
|
||||
bool GetDirection() const override;
|
||||
|
||||
double GetDistance() const;
|
||||
double GetRate() const;
|
||||
void SetMinRate(double minRate);
|
||||
void SetDistancePerPulse(double distancePerPulse);
|
||||
void SetReverseDirection(bool reverseDirection);
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
int GetSamplesToAverage() const;
|
||||
void SetPIDSourceType(PIDSourceType pidSource);
|
||||
double PIDGet() override;
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
int32_t FPGAEncoderIndex() const { return 0; }
|
||||
|
||||
private:
|
||||
void InitEncoder(int channelA, int channelB, bool _reverseDirection,
|
||||
EncodingType encodingType);
|
||||
double DecodingScaleFactor() const;
|
||||
|
||||
// the A phase of the quad encoder
|
||||
// TODO: [Not Supported] DigitalSource *m_aSource;
|
||||
// the B phase of the quad encoder
|
||||
// TODO: [Not Supported] DigitalSource *m_bSource;
|
||||
// was the A source allocated locally?
|
||||
// TODO: [Not Supported] bool m_allocatedASource;
|
||||
// was the B source allocated locally?
|
||||
// TODO: [Not Supported] bool m_allocatedBSource;
|
||||
int channelA, channelB;
|
||||
double m_distancePerPulse; // distance of travel for each encoder tick
|
||||
EncodingType m_encodingType; // Encoding type
|
||||
int32_t m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
bool m_reverseDirection;
|
||||
SimEncoder* impl;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
87
wpilibc/sim/include/IterativeRobot.h
Normal file
87
wpilibc/sim/include/IterativeRobot.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RobotBase.h"
|
||||
#include "Timer.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 const double kDefaultPeriod;
|
||||
|
||||
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() = default;
|
||||
IterativeRobot() = default;
|
||||
|
||||
private:
|
||||
bool NextPeriodReady();
|
||||
|
||||
bool m_disabledInitialized = false;
|
||||
bool m_autonomousInitialized = false;
|
||||
bool m_teleopInitialized = false;
|
||||
bool m_testInitialized = false;
|
||||
double m_period = kDefaultPeriod;
|
||||
Timer m_mainLoopTimer;
|
||||
};
|
||||
26
wpilibc/sim/include/Jaguar.h
Normal file
26
wpilibc/sim/include/Jaguar.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
|
||||
/**
|
||||
* Luminary Micro Jaguar Speed Control.
|
||||
*/
|
||||
class Jaguar : public SafePWM, public SpeedController {
|
||||
public:
|
||||
explicit Jaguar(uint32_t channel);
|
||||
virtual ~Jaguar() = default;
|
||||
virtual void Set(float value, uint8_t syncGroup = 0);
|
||||
virtual float Get() const;
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
81
wpilibc/sim/include/Joystick.h
Normal file
81
wpilibc/sim/include/Joystick.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef JOYSTICK_H_
|
||||
#define JOYSTICK_H_
|
||||
|
||||
#include <memory>
|
||||
#include "ErrorBase.h"
|
||||
#include "GenericHID.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() = default;
|
||||
|
||||
Joystick(const Joystick&) = delete;
|
||||
Joystick& operator=(const Joystick&) = delete;
|
||||
|
||||
uint32_t GetAxisChannel(AxisType axis);
|
||||
void SetAxisChannel(AxisType axis, uint32_t channel);
|
||||
|
||||
virtual float GetX(JoystickHand hand = kRightHand) const override;
|
||||
virtual float GetY(JoystickHand hand = kRightHand) const override;
|
||||
virtual float GetZ() const override;
|
||||
virtual float GetTwist() const override;
|
||||
virtual float GetThrottle() const override;
|
||||
virtual float GetAxis(AxisType axis) const;
|
||||
float GetRawAxis(uint32_t axis) const override;
|
||||
|
||||
virtual bool GetTrigger(JoystickHand hand = kRightHand) const override;
|
||||
virtual bool GetTop(JoystickHand hand = kRightHand) const override;
|
||||
virtual bool GetBumper(JoystickHand hand = kRightHand) const override;
|
||||
virtual bool GetRawButton(uint32_t button) const override;
|
||||
virtual int GetPOV(uint32_t pov = 1) const override;
|
||||
bool GetButton(ButtonType button) const;
|
||||
static Joystick* GetStickForPort(uint32_t port);
|
||||
|
||||
virtual float GetMagnitude() const;
|
||||
virtual float GetDirectionRadians() const;
|
||||
virtual float GetDirectionDegrees() const;
|
||||
|
||||
private:
|
||||
DriverStation& m_ds;
|
||||
uint32_t m_port;
|
||||
std::unique_ptr<uint32_t[]> m_axes;
|
||||
std::unique_ptr<uint32_t[]> m_buttons;
|
||||
};
|
||||
|
||||
#endif
|
||||
23
wpilibc/sim/include/MotorSafety.h
Normal file
23
wpilibc/sim/include/MotorSafety.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define DEFAULT_SAFETY_EXPIRATION 0.1
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class MotorSafety {
|
||||
public:
|
||||
virtual void SetExpiration(float timeout) = 0;
|
||||
virtual float GetExpiration() const = 0;
|
||||
virtual bool IsAlive() const = 0;
|
||||
virtual void StopMotor() = 0;
|
||||
virtual void SetSafetyEnabled(bool enabled) = 0;
|
||||
virtual bool IsSafetyEnabled() const = 0;
|
||||
virtual void GetDescription(std::ostringstream& desc) const = 0;
|
||||
};
|
||||
44
wpilibc/sim/include/MotorSafetyHelper.h
Normal file
44
wpilibc/sim/include/MotorSafetyHelper.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
class MotorSafety;
|
||||
|
||||
class MotorSafetyHelper : public ErrorBase {
|
||||
public:
|
||||
MotorSafetyHelper(MotorSafety* safeObject);
|
||||
~MotorSafetyHelper();
|
||||
void Feed();
|
||||
void SetExpiration(float expirationTime);
|
||||
float GetExpiration() const;
|
||||
bool IsAlive() const;
|
||||
void Check();
|
||||
void SetSafetyEnabled(bool enabled);
|
||||
bool IsSafetyEnabled() const;
|
||||
static void CheckMotors();
|
||||
|
||||
private:
|
||||
// the expiration time for this object
|
||||
double m_expiration;
|
||||
// true if motor safety is enabled for this motor
|
||||
bool m_enabled;
|
||||
// the FPGA clock value when this motor has expired
|
||||
double m_stopTime;
|
||||
// protect accesses to the state for this object
|
||||
mutable priority_recursive_mutex m_syncMutex;
|
||||
MotorSafety* m_safeObject; // the object that is using the helper
|
||||
// List of all existing MotorSafetyHelper objects.
|
||||
static std::set<MotorSafetyHelper*> m_helperList;
|
||||
// protect accesses to the list of helpers
|
||||
static priority_recursive_mutex m_listMutex;
|
||||
};
|
||||
130
wpilibc/sim/include/NetworkCommunication/FRCComm.h
Normal file
130
wpilibc/sim/include/NetworkCommunication/FRCComm.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/*************************************************************
|
||||
* 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>
|
||||
#ifdef USE_THRIFT
|
||||
#define EXPORT_FUNC
|
||||
#else
|
||||
#define EXPORT_FUNC __declspec(dllexport) __cdecl
|
||||
#endif
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#define EXPORT_FUNC
|
||||
#endif
|
||||
|
||||
#define ERR_FRCSystem_NetCommNotResponding -44049
|
||||
#define ERR_FRCSystem_NoDSConnection -44018
|
||||
|
||||
enum AllianceStationID_t {
|
||||
kAllianceStationID_red1,
|
||||
kAllianceStationID_red2,
|
||||
kAllianceStationID_red3,
|
||||
kAllianceStationID_blue1,
|
||||
kAllianceStationID_blue2,
|
||||
kAllianceStationID_blue3,
|
||||
};
|
||||
|
||||
enum MatchType_t {
|
||||
kMatchType_none,
|
||||
kMatchType_practice,
|
||||
kMatchType_qualification,
|
||||
kMatchType_elimination,
|
||||
};
|
||||
|
||||
struct ControlWord_t {
|
||||
uint32_t enabled : 1;
|
||||
uint32_t autonomous : 1;
|
||||
uint32_t test : 1;
|
||||
uint32_t eStop : 1;
|
||||
uint32_t fmsAttached : 1;
|
||||
uint32_t dsAttached : 1;
|
||||
uint32_t control_reserved : 26;
|
||||
};
|
||||
|
||||
struct JoystickAxes_t {
|
||||
uint16_t count;
|
||||
int16_t axes[1];
|
||||
};
|
||||
|
||||
struct JoystickPOV_t {
|
||||
uint16_t count;
|
||||
int16_t povs[1];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int EXPORT_FUNC FRC_NetworkCommunication_Reserve(void *instance);
|
||||
#ifndef SIMULATION
|
||||
void EXPORT_FUNC
|
||||
getFPGAHardwareVersion(uint16_t *fpgaVersion, uint32_t *fpgaRevision);
|
||||
#endif
|
||||
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 setErrorData(const char *errors, int errorsLength, int wait_ms);
|
||||
|
||||
#ifdef SIMULATION
|
||||
void EXPORT_FUNC setNewDataSem(HANDLE);
|
||||
#else
|
||||
void EXPORT_FUNC setNewDataSem(pthread_cond_t *);
|
||||
#endif
|
||||
|
||||
// this uint32_t is really a LVRefNum
|
||||
int EXPORT_FUNC setNewDataOccurRef(uint32_t refnum);
|
||||
|
||||
int EXPORT_FUNC
|
||||
FRC_NetworkCommunication_getControlWord(struct ControlWord_t *controlWord);
|
||||
int EXPORT_FUNC FRC_NetworkCommunication_getAllianceStation(
|
||||
enum AllianceStationID_t *allianceStation);
|
||||
int EXPORT_FUNC FRC_NetworkCommunication_getMatchTime(float *matchTime);
|
||||
int EXPORT_FUNC
|
||||
FRC_NetworkCommunication_getJoystickAxes(uint8_t joystickNum,
|
||||
struct JoystickAxes_t *axes,
|
||||
uint8_t maxAxes);
|
||||
int EXPORT_FUNC FRC_NetworkCommunication_getJoystickButtons(uint8_t joystickNum,
|
||||
uint32_t *buttons,
|
||||
uint8_t *count);
|
||||
int EXPORT_FUNC
|
||||
FRC_NetworkCommunication_getJoystickPOVs(uint8_t joystickNum,
|
||||
struct JoystickPOV_t *povs,
|
||||
uint8_t maxPOVs);
|
||||
int EXPORT_FUNC
|
||||
FRC_NetworkCommunication_setJoystickOutputs(uint8_t joystickNum,
|
||||
uint32_t hidOutputs,
|
||||
uint16_t leftRumble,
|
||||
uint16_t rightRumble);
|
||||
int EXPORT_FUNC
|
||||
FRC_NetworkCommunication_getJoystickDesc(uint8_t joystickNum, uint8_t *isXBox,
|
||||
uint8_t *type, char *name,
|
||||
uint8_t *axisCount, uint8_t *axisTypes,
|
||||
uint8_t *buttonCount,
|
||||
uint8_t *povCount);
|
||||
|
||||
void EXPORT_FUNC FRC_NetworkCommunication_getVersionString(char *version);
|
||||
int 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);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
71
wpilibc/sim/include/Notifier.h
Normal file
71
wpilibc/sim/include/Notifier.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <thread>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
typedef std::function<void()> TimerEventHandler;
|
||||
|
||||
class Notifier : public ErrorBase {
|
||||
public:
|
||||
explicit Notifier(TimerEventHandler handler);
|
||||
|
||||
template <typename Callable, typename Arg, typename... Args>
|
||||
Notifier(Callable&& f, Arg&& arg, Args&&... args)
|
||||
: Notifier(std::bind(std::forward<Callable>(f), std::forward<Arg>(arg),
|
||||
std::forward<Args>(args)...)) {}
|
||||
virtual ~Notifier();
|
||||
|
||||
Notifier(const Notifier&) = delete;
|
||||
Notifier& operator=(const Notifier&) = delete;
|
||||
|
||||
void StartSingle(double delay);
|
||||
void StartPeriodic(double period);
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
static std::list<Notifier*> timerQueue;
|
||||
static priority_recursive_mutex queueMutex;
|
||||
static priority_mutex halMutex;
|
||||
static void* m_notifier;
|
||||
static std::atomic<int> refcount;
|
||||
|
||||
// Process the timer queue on a timer event
|
||||
static void ProcessQueue(uint32_t mask, void* params);
|
||||
|
||||
// Update the FPGA alarm since the queue has changed
|
||||
static void UpdateAlarm();
|
||||
|
||||
// Insert the Notifier in the timer queue
|
||||
void InsertInQueue(bool reschedule);
|
||||
|
||||
// Delete this Notifier from the timer queue
|
||||
void DeleteFromQueue();
|
||||
|
||||
// Address of the handler
|
||||
TimerEventHandler m_handler;
|
||||
// The relative time (either periodic or single)
|
||||
double m_period = 0;
|
||||
// Absolute expiration time for the current event
|
||||
double m_expirationTime = 0;
|
||||
// True if this is a periodic event
|
||||
bool m_periodic = false;
|
||||
// Indicates if this entry is queued
|
||||
bool m_queued = false;
|
||||
// Held by interrupt manager task while handler call is in progress
|
||||
priority_mutex m_handlerMutex;
|
||||
static std::thread m_task;
|
||||
static std::atomic<bool> m_stopped;
|
||||
static void Run();
|
||||
};
|
||||
107
wpilibc/sim/include/PWM.h
Normal file
107
wpilibc/sim/include/PWM.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
public:
|
||||
enum PeriodMultiplier {
|
||||
kPeriodMultiplier_1X = 1,
|
||||
kPeriodMultiplier_2X = 2,
|
||||
kPeriodMultiplier_4X = 4
|
||||
};
|
||||
|
||||
explicit PWM(uint32_t channel);
|
||||
virtual ~PWM();
|
||||
virtual void SetRaw(unsigned short value);
|
||||
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() const { return m_channel; }
|
||||
|
||||
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 const float kDefaultPwmPeriod;
|
||||
/**
|
||||
* kDefaultPwmCenter is the PWM range center in ms
|
||||
*/
|
||||
static const float kDefaultPwmCenter;
|
||||
/**
|
||||
* kDefaultPWMStepsDown is the number of PWM steps below the centerpoint
|
||||
*/
|
||||
static const int32_t kDefaultPwmStepsDown;
|
||||
static const int32_t kPwmDisabled;
|
||||
|
||||
virtual void SetPosition(float pos);
|
||||
virtual float GetPosition() const;
|
||||
virtual void SetSpeed(float speed);
|
||||
virtual float GetSpeed() const;
|
||||
|
||||
bool m_eliminateDeadband;
|
||||
int32_t m_centerPwm;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
SimContinuousOutput* impl;
|
||||
};
|
||||
74
wpilibc/sim/include/Relay.h
Normal file
74
wpilibc/sim/include/Relay.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class MotorSafetyHelper;
|
||||
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 MotorSafety,
|
||||
public SensorBase,
|
||||
public ITableListener,
|
||||
public LiveWindowSendable {
|
||||
public:
|
||||
enum Value { kOff, kOn, kForward, kReverse };
|
||||
enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
|
||||
|
||||
Relay(uint32_t channel, Direction direction = kBothDirections);
|
||||
virtual ~Relay();
|
||||
|
||||
void Set(Value value);
|
||||
Value Get() const;
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
void SetExpiration(float timeout) override;
|
||||
float GetExpiration() const override;
|
||||
bool IsAlive() const override;
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
Direction m_direction;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
SimContinuousOutput* impl;
|
||||
bool go_pos, go_neg;
|
||||
};
|
||||
57
wpilibc/sim/include/RobotBase.h
Normal file
57
wpilibc/sim/include/RobotBase.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
#include "DriverStation.h"
|
||||
#include "simulation/MainNode.h"
|
||||
#include "simulation/simTime.h"
|
||||
|
||||
#define START_ROBOT_CLASS(_ClassName_) \
|
||||
int main() { \
|
||||
(new _ClassName_())->StartCompetition(); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() const;
|
||||
bool IsDisabled() const;
|
||||
bool IsAutonomous() const;
|
||||
bool IsOperatorControl() const;
|
||||
bool IsTest() const;
|
||||
virtual void StartCompetition() = 0;
|
||||
|
||||
protected:
|
||||
RobotBase();
|
||||
virtual ~RobotBase() = default;
|
||||
|
||||
RobotBase(const RobotBase&) = delete;
|
||||
RobotBase& operator=(const RobotBase&) = delete;
|
||||
|
||||
DriverStation& m_ds;
|
||||
transport::SubscriberPtr time_sub;
|
||||
|
||||
private:
|
||||
static RobotBase* m_instance;
|
||||
};
|
||||
126
wpilibc/sim/include/RobotDrive.h
Normal file
126
wpilibc/sim/include/RobotDrive.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include "ErrorBase.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:
|
||||
enum MotorType {
|
||||
kFrontLeftMotor = 0,
|
||||
kFrontRightMotor = 1,
|
||||
kRearLeftMotor = 2,
|
||||
kRearRightMotor = 3
|
||||
};
|
||||
|
||||
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(std::shared_ptr<SpeedController> leftMotor,
|
||||
std::shared_ptr<SpeedController> rightMotor);
|
||||
RobotDrive(SpeedController* frontLeftMotor, SpeedController* rearLeftMotor,
|
||||
SpeedController* frontRightMotor, SpeedController* rearRightMotor);
|
||||
RobotDrive(SpeedController& frontLeftMotor, SpeedController& rearLeftMotor,
|
||||
SpeedController& frontRightMotor, SpeedController& rearRightMotor);
|
||||
RobotDrive(std::shared_ptr<SpeedController> frontLeftMotor,
|
||||
std::shared_ptr<SpeedController> rearLeftMotor,
|
||||
std::shared_ptr<SpeedController> frontRightMotor,
|
||||
std::shared_ptr<SpeedController> rearRightMotor);
|
||||
virtual ~RobotDrive() = default;
|
||||
|
||||
RobotDrive(const RobotDrive&) = delete;
|
||||
RobotDrive& operator=(const RobotDrive&) = delete;
|
||||
|
||||
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) override;
|
||||
float GetExpiration() const override;
|
||||
bool IsAlive() const override;
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
|
||||
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] = {1, 1, 1, 1};
|
||||
float m_sensitivity = 0.5;
|
||||
double m_maxOutput = 1.0;
|
||||
bool m_deleteSpeedControllers;
|
||||
std::shared_ptr<SpeedController> m_frontLeftMotor;
|
||||
std::shared_ptr<SpeedController> m_frontRightMotor;
|
||||
std::shared_ptr<SpeedController> m_rearLeftMotor;
|
||||
std::shared_ptr<SpeedController> m_rearRightMotor;
|
||||
// FIXME: 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;
|
||||
}
|
||||
};
|
||||
40
wpilibc/sim/include/SafePWM.h
Normal file
40
wpilibc/sim/include/SafePWM.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "PWM.h"
|
||||
|
||||
/**
|
||||
* 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);
|
||||
virtual ~SafePWM() = default;
|
||||
|
||||
void SetExpiration(float timeout);
|
||||
float GetExpiration() const;
|
||||
bool IsAlive() const;
|
||||
void StopMotor();
|
||||
bool IsSafetyEnabled() const;
|
||||
void SetSafetyEnabled(bool enabled);
|
||||
void GetDescription(std::ostringstream& desc) const;
|
||||
|
||||
virtual void SetSpeed(float speed);
|
||||
|
||||
private:
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
};
|
||||
26
wpilibc/sim/include/SampleRobot.h
Normal file
26
wpilibc/sim/include/SampleRobot.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RobotBase.h"
|
||||
|
||||
class SampleRobot : public RobotBase {
|
||||
public:
|
||||
SampleRobot();
|
||||
virtual ~SampleRobot() = default;
|
||||
virtual void RobotInit();
|
||||
virtual void Disabled();
|
||||
virtual void Autonomous();
|
||||
virtual void OperatorControl();
|
||||
virtual void Test();
|
||||
virtual void RobotMain();
|
||||
void StartCompetition();
|
||||
|
||||
private:
|
||||
bool m_robotMainOverridden;
|
||||
};
|
||||
44
wpilibc/sim/include/Solenoid.h
Normal file
44
wpilibc/sim/include/Solenoid.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Solenoid class for running high voltage Digital Output (PCM).
|
||||
*
|
||||
* The Solenoid class is typically used for pneumatics solenoids, but could be
|
||||
* used for any device within the current spec of the PCM.
|
||||
*/
|
||||
class Solenoid : 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() const;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(std::shared_ptr<ITable> subTable) override;
|
||||
std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
SimContinuousOutput* m_impl;
|
||||
bool m_on;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
36
wpilibc/sim/include/SpeedController.h
Normal file
36
wpilibc/sim/include/SpeedController.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
|
||||
/**
|
||||
* Interface for speed controlling devices.
|
||||
*/
|
||||
class SpeedController : public PIDOutput {
|
||||
public:
|
||||
virtual ~SpeedController() = default;
|
||||
/**
|
||||
* 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() const = 0;
|
||||
/**
|
||||
* Common interface for disabling a motor.
|
||||
*/
|
||||
virtual void Disable() = 0;
|
||||
};
|
||||
26
wpilibc/sim/include/Talon.h
Normal file
26
wpilibc/sim/include/Talon.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
|
||||
/**
|
||||
* CTRE Talon Speed Controller.
|
||||
*/
|
||||
class Talon : public SafePWM, public SpeedController {
|
||||
public:
|
||||
explicit Talon(uint32_t channel);
|
||||
virtual ~Talon() = default;
|
||||
virtual void Set(float value, uint8_t syncGroup = 0);
|
||||
virtual float Get() const;
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
26
wpilibc/sim/include/Victor.h
Normal file
26
wpilibc/sim/include/Victor.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
|
||||
/**
|
||||
* IFI Victor Speed Controller.
|
||||
*/
|
||||
class Victor : public SafePWM, public SpeedController {
|
||||
public:
|
||||
explicit Victor(uint32_t channel);
|
||||
virtual ~Victor() = default;
|
||||
virtual void Set(float value, uint8_t syncGroup = 0);
|
||||
virtual float Get() const;
|
||||
virtual void Disable();
|
||||
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
55
wpilibc/sim/include/WPILib.h
Normal file
55
wpilibc/sim/include/WPILib.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* WPILIb.h
|
||||
*
|
||||
* Created on: May 29, 2014
|
||||
* Author: alex
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define SIMULATION "gazebo"
|
||||
|
||||
#include <iostream>
|
||||
#include "string.h"
|
||||
|
||||
#include "Buttons/Button.h"
|
||||
#include "Buttons/InternalButton.h"
|
||||
#include "Buttons/JoystickButton.h"
|
||||
#include "Buttons/NetworkButton.h"
|
||||
#include "Buttons/Trigger.h"
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "Commands/CommandGroup.h"
|
||||
#include "Commands/PIDCommand.h"
|
||||
#include "Commands/PIDSubsystem.h"
|
||||
#include "Commands/PrintCommand.h"
|
||||
#include "Commands/Scheduler.h"
|
||||
#include "Commands/StartCommand.h"
|
||||
#include "Commands/Subsystem.h"
|
||||
#include "Commands/WaitCommand.h"
|
||||
#include "Commands/WaitForChildren.h"
|
||||
#include "Commands/WaitUntilCommand.h"
|
||||
|
||||
#include "SmartDashboard/SendableChooser.h"
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
|
||||
#include "AnalogGyro.h"
|
||||
#include "AnalogInput.h"
|
||||
#include "AnalogPotentiometer.h"
|
||||
#include "Counter.h"
|
||||
#include "DigitalInput.h"
|
||||
#include "DoubleSolenoid.h"
|
||||
#include "Encoder.h"
|
||||
#include "GenericHID.h"
|
||||
#include "IterativeRobot.h"
|
||||
#include "Jaguar.h"
|
||||
#include "Joystick.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "PIDController.h"
|
||||
#include "RobotBase.h"
|
||||
#include "RobotDrive.h"
|
||||
#include "SampleRobot.h"
|
||||
#include "Solenoid.h"
|
||||
#include "SpeedController.h"
|
||||
#include "Talon.h"
|
||||
#include "Victor.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
63
wpilibc/sim/include/simulation/MainNode.h
Normal file
63
wpilibc/sim/include/simulation/MainNode.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_MAIN_NODE_H
|
||||
#define _SIM_MAIN_NODE_H
|
||||
|
||||
#include <gazebo/gazebo_client.hh>
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class MainNode {
|
||||
public:
|
||||
static MainNode* GetInstance() {
|
||||
static MainNode instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
static transport::PublisherPtr Advertise(const std::string& topic,
|
||||
unsigned int _queueLimit = 10,
|
||||
bool _latch = false) {
|
||||
return GetInstance()->main->Advertise<M>(topic, _queueLimit, _latch);
|
||||
}
|
||||
|
||||
template <typename M, typename T>
|
||||
static transport::SubscriberPtr Subscribe(
|
||||
const std::string& topic,
|
||||
void (T::*fp)(const boost::shared_ptr<M const>&), T* obj,
|
||||
bool _latching = false) {
|
||||
return GetInstance()->main->Subscribe(topic, fp, obj, _latching);
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
static transport::SubscriberPtr Subscribe(
|
||||
const std::string& topic, void (*fp)(const boost::shared_ptr<M const>&),
|
||||
bool _latching = false) {
|
||||
return GetInstance()->main->Subscribe(topic, fp, _latching);
|
||||
}
|
||||
|
||||
transport::NodePtr main;
|
||||
|
||||
private:
|
||||
MainNode() {
|
||||
bool success = gazebo::client::setup();
|
||||
|
||||
if (success) {
|
||||
main = transport::NodePtr(new transport::Node());
|
||||
main->Init("frc");
|
||||
gazebo::transport::run();
|
||||
} else {
|
||||
std::cout << "An error has occured setting up gazebo_client!"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
46
wpilibc/sim/include/simulation/SimContinuousOutput.h
Normal file
46
wpilibc/sim/include/simulation/SimContinuousOutput.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_SPEED_CONTROLLER_H
|
||||
#define _SIM_SPEED_CONTROLLER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
// Ensure that Winsock2.h is included before Windows.h, which can get
|
||||
// pulled in by anybody (e.g., Boost).
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "SpeedController.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimContinuousOutput {
|
||||
private:
|
||||
transport::PublisherPtr pub;
|
||||
float speed;
|
||||
|
||||
public:
|
||||
SimContinuousOutput(std::string topic);
|
||||
|
||||
/**
|
||||
* Set the output value.
|
||||
*
|
||||
* The value is set using a range of -1.0 to 1.0, appropriately
|
||||
* scaling the value.
|
||||
*
|
||||
* @param value The value between -1.0 and 1.0 to set.
|
||||
*/
|
||||
void Set(float value);
|
||||
|
||||
/**
|
||||
* @return The most recently set value.
|
||||
*/
|
||||
float Get();
|
||||
};
|
||||
|
||||
#endif
|
||||
31
wpilibc/sim/include/simulation/SimDigitalInput.h
Normal file
31
wpilibc/sim/include/simulation/SimDigitalInput.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_DIGITAL_INPUT_H
|
||||
#define _SIM_DIGITAL_INPUT_H
|
||||
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimDigitalInput {
|
||||
public:
|
||||
SimDigitalInput(std::string topic);
|
||||
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
bool Get();
|
||||
|
||||
private:
|
||||
bool value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstBoolPtr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
37
wpilibc/sim/include/simulation/SimEncoder.h
Normal file
37
wpilibc/sim/include/simulation/SimEncoder.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_ENCODER_H
|
||||
#define _SIM_ENCODER_H
|
||||
|
||||
#include <gazebo/common/Time.hh>
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimEncoder {
|
||||
public:
|
||||
SimEncoder(std::string topic);
|
||||
|
||||
void Reset();
|
||||
void Start();
|
||||
void Stop();
|
||||
double GetPosition();
|
||||
double GetVelocity();
|
||||
|
||||
private:
|
||||
void sendCommand(std::string cmd);
|
||||
|
||||
double position, velocity;
|
||||
transport::SubscriberPtr posSub, velSub;
|
||||
transport::PublisherPtr commandPub;
|
||||
void positionCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
void velocityCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
31
wpilibc/sim/include/simulation/SimFloatInput.h
Normal file
31
wpilibc/sim/include/simulation/SimFloatInput.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_FLOAT_INPUT_H
|
||||
#define _SIM_FLOAT_INPUT_H
|
||||
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimFloatInput {
|
||||
public:
|
||||
SimFloatInput(std::string topic);
|
||||
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
double Get();
|
||||
|
||||
private:
|
||||
double value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
34
wpilibc/sim/include/simulation/SimGyro.h
Normal file
34
wpilibc/sim/include/simulation/SimGyro.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _SIM_GYRO_H
|
||||
#define _SIM_GYRO_H
|
||||
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimGyro {
|
||||
public:
|
||||
SimGyro(std::string topic);
|
||||
|
||||
void Reset();
|
||||
double GetAngle();
|
||||
double GetVelocity();
|
||||
|
||||
private:
|
||||
void sendCommand(std::string cmd);
|
||||
|
||||
double position, velocity;
|
||||
transport::SubscriberPtr posSub, velSub;
|
||||
transport::PublisherPtr commandPub;
|
||||
void positionCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
void velocityCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
26
wpilibc/sim/include/simulation/simTime.h
Normal file
26
wpilibc/sim/include/simulation/simTime.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014-2016. 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 the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
// Ensure that Winsock2.h is included before Windows.h, which can get
|
||||
// pulled in by anybody (e.g., Boost).
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "simulation/SimFloatInput.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
namespace wpilib {
|
||||
namespace internal {
|
||||
extern double simTime;
|
||||
extern void time_callback(const msgs::ConstFloat64Ptr& msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user