mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Add format script which invokes clang-format on the C++ source code (#41)
On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
committed by
Peter Johnson
parent
68690643d2
commit
e14e45da76
@@ -17,34 +17,35 @@ 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.
|
||||
*
|
||||
* 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;
|
||||
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();
|
||||
explicit AnalogGyro(uint32_t channel);
|
||||
virtual ~AnalogGyro() = default;
|
||||
float GetAngle() const;
|
||||
void Calibrate() override;
|
||||
double GetRate() const;
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
void InitAnalogGyro(int channel);
|
||||
private:
|
||||
void InitAnalogGyro(int channel);
|
||||
|
||||
SimGyro* impl;
|
||||
SimGyro* impl;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -7,51 +7,54 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/SimFloatInput.h"
|
||||
#include "SensorBase.h"
|
||||
#include "PIDSource.h"
|
||||
#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.
|
||||
* 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];
|
||||
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;
|
||||
explicit AnalogInput(uint32_t channel);
|
||||
virtual ~AnalogInput() = default;
|
||||
|
||||
float GetVoltage() const;
|
||||
float GetAverageVoltage() const;
|
||||
float GetVoltage() const;
|
||||
float GetAverageVoltage() const;
|
||||
|
||||
uint32_t GetChannel() const;
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
double PIDGet() override;
|
||||
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;
|
||||
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;
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
SimFloatInput* m_impl;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -22,71 +22,74 @@
|
||||
* @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);
|
||||
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);
|
||||
|
||||
AnalogPotentiometer(AnalogInput &input, double scale = 1.0, double offset = 0.0);
|
||||
AnalogPotentiometer(AnalogInput& input, double scale = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
virtual ~AnalogPotentiometer();
|
||||
virtual ~AnalogPotentiometer();
|
||||
|
||||
/**
|
||||
* Get the current reading of the potentiomere.
|
||||
*
|
||||
* @return The current position of the potentiometer.
|
||||
*/
|
||||
virtual double Get() const;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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 {}
|
||||
|
||||
/*
|
||||
* 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 exiting the
|
||||
* LiveWindow.
|
||||
*/
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when entering the LiveWindow.
|
||||
*/
|
||||
virtual void StartLiveWindowMode() override {}
|
||||
private:
|
||||
double m_scale, m_offset;
|
||||
AnalogInput* m_analog_input;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
bool m_init_analog_input;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*/
|
||||
void initPot(AnalogInput* input, double scale, double offset);
|
||||
};
|
||||
|
||||
@@ -7,89 +7,94 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "CounterBase.h"
|
||||
#include "SensorBase.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.
|
||||
*
|
||||
* 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:
|
||||
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();
|
||||
|
||||
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 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 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 SetUpDownCounterMode();
|
||||
void SetExternalDirectionMode();
|
||||
void SetSemiPeriodMode(bool highSemiPeriod);
|
||||
void SetPulseLengthMode(float threshold);
|
||||
void SetReverseDirection(bool reverseDirection);
|
||||
|
||||
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;
|
||||
|
||||
// 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 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;
|
||||
|
||||
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:
|
||||
// TODO: [Not Supported] DigitalSource *m_upSource; ///< What makes the counter count up.
|
||||
// TODO: [Not Supported] DigitalSource *m_downSource; ///< What makes the counter count down.
|
||||
void* m_counter; ///< The FPGA counter object.
|
||||
private:
|
||||
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.
|
||||
|
||||
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;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -9,27 +9,22 @@
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
};
|
||||
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;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -7,36 +7,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/SimDigitalInput.h"
|
||||
#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.
|
||||
*
|
||||
* 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;
|
||||
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;
|
||||
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;
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
bool m_lastValue;
|
||||
SimDigitalInput* m_impl;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -20,35 +20,30 @@
|
||||
* 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
|
||||
};
|
||||
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;
|
||||
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,
|
||||
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;
|
||||
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;
|
||||
private:
|
||||
SimContinuousOutput* m_impl;
|
||||
Value m_value;
|
||||
bool m_reversed;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
#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>
|
||||
// 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 "SensorBase.h"
|
||||
#include "RobotState.h"
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include <mutex>
|
||||
#include "RobotState.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
struct HALCommonControlData;
|
||||
class AnalogInput;
|
||||
@@ -27,120 +27,115 @@ class AnalogInput;
|
||||
using namespace gazebo;
|
||||
|
||||
/**
|
||||
* Provide access to the network communication data to / from the Driver Station.
|
||||
* Provide access to the network communication data to / from the Driver
|
||||
* Station.
|
||||
*/
|
||||
class DriverStation : public SensorBase, public RobotStateInterface
|
||||
{
|
||||
public:
|
||||
enum Alliance
|
||||
{
|
||||
kRed,
|
||||
kBlue,
|
||||
kInvalid
|
||||
};
|
||||
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);
|
||||
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;
|
||||
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 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);
|
||||
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;
|
||||
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;
|
||||
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; }
|
||||
|
||||
void IncrementUpdateNumber()
|
||||
{
|
||||
m_updateNumber++;
|
||||
}
|
||||
protected:
|
||||
DriverStation();
|
||||
|
||||
/** 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;
|
||||
}
|
||||
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;
|
||||
|
||||
protected:
|
||||
DriverStation();
|
||||
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);
|
||||
|
||||
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;
|
||||
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;
|
||||
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];
|
||||
transport::SubscriberPtr stateSub;
|
||||
transport::SubscriberPtr joysticksSub[6];
|
||||
msgs::DriverStationPtr state;
|
||||
msgs::FRCJoystickPtr joysticks[6];
|
||||
};
|
||||
|
||||
@@ -7,83 +7,91 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/SimEncoder.h"
|
||||
#include "CounterBase.h"
|
||||
#include "SensorBase.h"
|
||||
#include "Counter.h"
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#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.
|
||||
*
|
||||
* 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:
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
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;
|
||||
|
||||
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; }
|
||||
|
||||
int32_t FPGAEncoderIndex() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private:
|
||||
void InitEncoder(int channelA, int channelB, bool _reverseDirection,
|
||||
EncodingType encodingType);
|
||||
double DecodingScaleFactor() const;
|
||||
|
||||
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;
|
||||
|
||||
// TODO: [Not Supported] DigitalSource *m_aSource; // the A phase of the quad encoder
|
||||
// TODO: [Not Supported] DigitalSource *m_bSource; // the B phase of the quad encoder
|
||||
// TODO: [Not Supported] bool m_allocatedASource; // was the A source allocated locally?
|
||||
// TODO: [Not Supported] bool m_allocatedBSource; // was the B source allocated locally?
|
||||
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;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -7,30 +7,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Timer.h"
|
||||
#include "RobotBase.h"
|
||||
#include "Timer.h"
|
||||
|
||||
/**
|
||||
* IterativeRobot implements a specific type of Robot Program framework, extending the RobotBase class.
|
||||
* 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.
|
||||
* 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:
|
||||
* 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
|
||||
* - 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).
|
||||
* 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()
|
||||
@@ -38,44 +45,43 @@
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
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 StartCompetition();
|
||||
|
||||
virtual void RobotInit();
|
||||
virtual void DisabledInit();
|
||||
virtual void AutonomousInit();
|
||||
virtual void TeleopInit();
|
||||
virtual void TestInit();
|
||||
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();
|
||||
virtual void DisabledPeriodic();
|
||||
virtual void AutonomousPeriodic();
|
||||
virtual void TeleopPeriodic();
|
||||
virtual void TestPeriodic();
|
||||
|
||||
void SetPeriod(double period);
|
||||
double GetPeriod();
|
||||
double GetLoopsPerSec();
|
||||
void SetPeriod(double period);
|
||||
double GetPeriod();
|
||||
double GetLoopsPerSec();
|
||||
|
||||
protected:
|
||||
virtual ~IterativeRobot() = default;
|
||||
IterativeRobot() = default;
|
||||
protected:
|
||||
virtual ~IterativeRobot() = default;
|
||||
IterativeRobot() = default;
|
||||
|
||||
private:
|
||||
bool NextPeriodReady();
|
||||
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;
|
||||
bool m_disabledInitialized = false;
|
||||
bool m_autonomousInitialized = false;
|
||||
bool m_teleopInitialized = false;
|
||||
bool m_testInitialized = false;
|
||||
double m_period = kDefaultPeriod;
|
||||
Timer m_mainLoopTimer;
|
||||
};
|
||||
|
||||
@@ -7,21 +7,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
#include "PIDOutput.h"
|
||||
|
||||
/**
|
||||
* Luminary Micro Jaguar Speed Control
|
||||
* 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();
|
||||
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;
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
|
||||
@@ -9,71 +9,73 @@
|
||||
#define JOYSTICK_H_
|
||||
|
||||
#include <memory>
|
||||
#include "GenericHID.h"
|
||||
#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.
|
||||
*
|
||||
* 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;
|
||||
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;
|
||||
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;
|
||||
Joystick(const Joystick&) = delete;
|
||||
Joystick& operator=(const Joystick&) = delete;
|
||||
|
||||
uint32_t GetAxisChannel(AxisType axis);
|
||||
void SetAxisChannel(AxisType axis, uint32_t channel);
|
||||
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 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 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;
|
||||
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;
|
||||
private:
|
||||
DriverStation& m_ds;
|
||||
uint32_t m_port;
|
||||
std::unique_ptr<uint32_t[]> m_axes;
|
||||
std::unique_ptr<uint32_t[]> m_buttons;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,14 +11,13 @@
|
||||
|
||||
#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;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ class MotorSafety;
|
||||
|
||||
class MotorSafetyHelper : public ErrorBase {
|
||||
public:
|
||||
MotorSafetyHelper(MotorSafety *safeObject);
|
||||
MotorSafetyHelper(MotorSafety* safeObject);
|
||||
~MotorSafetyHelper();
|
||||
void Feed();
|
||||
void SetExpiration(float expirationTime);
|
||||
@@ -28,14 +28,17 @@ class MotorSafetyHelper : public ErrorBase {
|
||||
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
|
||||
mutable priority_recursive_mutex
|
||||
m_syncMutex; // protect accesses to the state for this object
|
||||
MotorSafety *m_safeObject; // the object that is using the helper
|
||||
// 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;
|
||||
static priority_recursive_mutex
|
||||
m_listMutex; // protect accesses to the list of helpers
|
||||
// protect accesses to the list of helpers
|
||||
static priority_recursive_mutex m_listMutex;
|
||||
};
|
||||
|
||||
@@ -23,8 +23,7 @@ class Notifier : public ErrorBase {
|
||||
|
||||
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),
|
||||
: Notifier(std::bind(std::forward<Callable>(f), std::forward<Arg>(arg),
|
||||
std::forward<Args>(args)...)) {}
|
||||
virtual ~Notifier();
|
||||
|
||||
@@ -39,11 +38,11 @@ class Notifier : public ErrorBase {
|
||||
static std::list<Notifier*> timerQueue;
|
||||
static priority_recursive_mutex queueMutex;
|
||||
static priority_mutex halMutex;
|
||||
static void *m_notifier;
|
||||
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);
|
||||
static void ProcessQueue(uint32_t mask, void* params);
|
||||
|
||||
// Update the FPGA alarm since the queue has changed
|
||||
static void UpdateAlarm();
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -17,12 +17,13 @@
|
||||
/**
|
||||
* 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.
|
||||
* 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:
|
||||
* 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
|
||||
@@ -30,77 +31,77 @@
|
||||
* - 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
|
||||
};
|
||||
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;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
bool m_eliminateDeadband;
|
||||
int32_t m_centerPwm;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
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;
|
||||
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;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
SimContinuousOutput* impl;
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
SimContinuousOutput* impl;
|
||||
};
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -21,38 +21,30 @@ 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).
|
||||
*
|
||||
* 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
|
||||
};
|
||||
public:
|
||||
enum Value { kOff, kOn, kForward, kReverse };
|
||||
enum Direction { kBothDirections, kForwardOnly, kReverseOnly };
|
||||
|
||||
Relay(uint32_t channel, Direction direction = kBothDirections);
|
||||
virtual ~Relay();
|
||||
Relay(uint32_t channel, Direction direction = kBothDirections);
|
||||
virtual ~Relay();
|
||||
|
||||
void Set(Value value);
|
||||
Value Get() const;
|
||||
uint32_t GetChannel() const;
|
||||
void Set(Value value);
|
||||
Value Get() const;
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
void SetExpiration(float timeout) override;
|
||||
float GetExpiration() const override;
|
||||
@@ -62,21 +54,21 @@ public:
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
|
||||
void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
Direction m_direction;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
SimContinuousOutput* impl;
|
||||
bool go_pos, go_neg;
|
||||
};
|
||||
|
||||
@@ -9,48 +9,49 @@
|
||||
|
||||
#include "Base.h"
|
||||
#include "DriverStation.h"
|
||||
#include "simulation/simTime.h"
|
||||
#include "simulation/MainNode.h"
|
||||
#include "simulation/simTime.h"
|
||||
|
||||
#define START_ROBOT_CLASS(_ClassName_) \
|
||||
int main() \
|
||||
{ \
|
||||
(new _ClassName_())->StartCompetition(); \
|
||||
return 0; \
|
||||
}
|
||||
#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.
|
||||
*
|
||||
* 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);
|
||||
class RobotBase {
|
||||
friend class RobotDeleter;
|
||||
|
||||
bool IsEnabled() const;
|
||||
bool IsDisabled() const;
|
||||
bool IsAutonomous() const;
|
||||
bool IsOperatorControl() const;
|
||||
bool IsTest() const;
|
||||
virtual void StartCompetition() = 0;
|
||||
public:
|
||||
static RobotBase& getInstance();
|
||||
static void setInstance(RobotBase* robot);
|
||||
|
||||
protected:
|
||||
RobotBase();
|
||||
virtual ~RobotBase() = default;
|
||||
bool IsEnabled() const;
|
||||
bool IsDisabled() const;
|
||||
bool IsAutonomous() const;
|
||||
bool IsOperatorControl() const;
|
||||
bool IsTest() const;
|
||||
virtual void StartCompetition() = 0;
|
||||
|
||||
RobotBase(const RobotBase&) = delete;
|
||||
RobotBase& operator=(const RobotBase&) = delete;
|
||||
protected:
|
||||
RobotBase();
|
||||
virtual ~RobotBase() = default;
|
||||
|
||||
DriverStation &m_ds;
|
||||
RobotBase(const RobotBase&) = delete;
|
||||
RobotBase& operator=(const RobotBase&) = delete;
|
||||
|
||||
DriverStation& m_ds;
|
||||
transport::SubscriberPtr time_sub;
|
||||
|
||||
private:
|
||||
static RobotBase *m_instance;
|
||||
private:
|
||||
static RobotBase* m_instance;
|
||||
};
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include "ErrorBase.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
|
||||
@@ -17,105 +17,110 @@ 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.
|
||||
* 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
|
||||
};
|
||||
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(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;
|
||||
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 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;
|
||||
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);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,33 +7,34 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MotorSafety.h"
|
||||
#include "PWM.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
#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.
|
||||
*
|
||||
* 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;
|
||||
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;
|
||||
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;
|
||||
virtual void SetSpeed(float speed);
|
||||
|
||||
private:
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
};
|
||||
|
||||
@@ -9,19 +9,18 @@
|
||||
|
||||
#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();
|
||||
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;
|
||||
private:
|
||||
bool m_robotMainOverridden;
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "simulation/SimContinuousOutput.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -16,30 +16,29 @@
|
||||
/**
|
||||
* 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.
|
||||
* 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;
|
||||
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,
|
||||
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;
|
||||
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;
|
||||
private:
|
||||
SimContinuousOutput* m_impl;
|
||||
bool m_on;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -12,25 +12,25 @@
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -7,21 +7,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
#include "PIDOutput.h"
|
||||
|
||||
/**
|
||||
* CTRE Talon Speed Controller
|
||||
* 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();
|
||||
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;
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
|
||||
@@ -7,21 +7,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PIDOutput.h"
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
#include "PIDOutput.h"
|
||||
|
||||
/**
|
||||
* IFI Victor Speed Controller
|
||||
* 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();
|
||||
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;
|
||||
virtual void PIDWrite(float output) override;
|
||||
};
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
#define SIMULATION "gazebo"
|
||||
|
||||
#include "string.h"
|
||||
#include <iostream>
|
||||
#include "string.h"
|
||||
|
||||
#include "Buttons/Trigger.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"
|
||||
@@ -32,25 +32,24 @@
|
||||
#include "SmartDashboard/SendableChooser.h"
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
|
||||
#include "RobotBase.h"
|
||||
#include "SampleRobot.h"
|
||||
#include "IterativeRobot.h"
|
||||
#include "SpeedController.h"
|
||||
#include "Talon.h"
|
||||
#include "Victor.h"
|
||||
#include "Jaguar.h"
|
||||
#include "Solenoid.h"
|
||||
#include "DoubleSolenoid.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
#include "AnalogGyro.h"
|
||||
#include "AnalogInput.h"
|
||||
#include "AnalogPotentiometer.h"
|
||||
#include "Counter.h"
|
||||
#include "DigitalInput.h"
|
||||
#include "DoubleSolenoid.h"
|
||||
#include "Encoder.h"
|
||||
#include "AnalogGyro.h"
|
||||
#include "GenericHID.h"
|
||||
#include "IterativeRobot.h"
|
||||
#include "Jaguar.h"
|
||||
#include "Joystick.h"
|
||||
#include "PIDController.h"
|
||||
#include "RobotDrive.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"
|
||||
|
||||
@@ -8,54 +8,56 @@
|
||||
#ifndef _SIM_MAIN_NODE_H
|
||||
#define _SIM_MAIN_NODE_H
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#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;
|
||||
}
|
||||
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>
|
||||
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, 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);
|
||||
}
|
||||
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();
|
||||
transport::NodePtr main;
|
||||
|
||||
if (success){
|
||||
main = transport::NodePtr(new transport::Node());
|
||||
main->Init("frc");
|
||||
gazebo::transport::run();
|
||||
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;
|
||||
}
|
||||
else {
|
||||
std::cout << "An error has occured setting up gazebo_client!" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
/* 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>
|
||||
// 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>
|
||||
@@ -21,27 +20,27 @@
|
||||
using namespace gazebo;
|
||||
|
||||
class SimContinuousOutput {
|
||||
private:
|
||||
transport::PublisherPtr pub;
|
||||
float speed;
|
||||
private:
|
||||
transport::PublisherPtr pub;
|
||||
float speed;
|
||||
|
||||
public:
|
||||
SimContinuousOutput(std::string topic);
|
||||
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);
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* @return The most recently set value.
|
||||
*/
|
||||
float Get();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,28 +5,27 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _SIM_DIGITAL_INPUT_H
|
||||
#define _SIM_DIGITAL_INPUT_H
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimDigitalInput {
|
||||
public:
|
||||
SimDigitalInput(std::string topic);
|
||||
public:
|
||||
SimDigitalInput(std::string topic);
|
||||
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
bool Get();
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
bool Get();
|
||||
|
||||
private:
|
||||
bool value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstBoolPtr &msg);
|
||||
private:
|
||||
bool value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstBoolPtr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,34 +5,33 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _SIM_ENCODER_H
|
||||
#define _SIM_ENCODER_H
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#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);
|
||||
public:
|
||||
SimEncoder(std::string topic);
|
||||
|
||||
void Reset();
|
||||
void Start();
|
||||
void Stop();
|
||||
double GetPosition();
|
||||
double GetVelocity();
|
||||
void Reset();
|
||||
void Start();
|
||||
void Stop();
|
||||
double GetPosition();
|
||||
double GetVelocity();
|
||||
|
||||
private:
|
||||
void sendCommand(std::string cmd);
|
||||
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);
|
||||
double position, velocity;
|
||||
transport::SubscriberPtr posSub, velSub;
|
||||
transport::PublisherPtr commandPub;
|
||||
void positionCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
void velocityCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,28 +5,27 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _SIM_FLOAT_INPUT_H
|
||||
#define _SIM_FLOAT_INPUT_H
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimFloatInput {
|
||||
public:
|
||||
SimFloatInput(std::string topic);
|
||||
public:
|
||||
SimFloatInput(std::string topic);
|
||||
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
double Get();
|
||||
/**
|
||||
* @return The value of the potentiometer.
|
||||
*/
|
||||
double Get();
|
||||
|
||||
private:
|
||||
double value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstFloat64Ptr &msg);
|
||||
private:
|
||||
double value;
|
||||
transport::SubscriberPtr sub;
|
||||
void callback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,31 +5,30 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _SIM_GYRO_H
|
||||
#define _SIM_GYRO_H
|
||||
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
#include <gazebo/transport/transport.hh>
|
||||
#include "simulation/gz_msgs/msgs.h"
|
||||
|
||||
using namespace gazebo;
|
||||
|
||||
class SimGyro {
|
||||
public:
|
||||
SimGyro(std::string topic);
|
||||
public:
|
||||
SimGyro(std::string topic);
|
||||
|
||||
void Reset();
|
||||
double GetAngle();
|
||||
double GetVelocity();
|
||||
void Reset();
|
||||
double GetAngle();
|
||||
double GetVelocity();
|
||||
|
||||
private:
|
||||
void sendCommand(std::string cmd);
|
||||
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);
|
||||
double position, velocity;
|
||||
transport::SubscriberPtr posSub, velSub;
|
||||
transport::PublisherPtr commandPub;
|
||||
void positionCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
void velocityCallback(const msgs::ConstFloat64Ptr& msg);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
#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>
|
||||
// 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"
|
||||
@@ -19,7 +18,9 @@
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
namespace wpilib { namespace internal {
|
||||
extern double simTime;
|
||||
extern void time_callback(const msgs::ConstFloat64Ptr &msg);
|
||||
}}
|
||||
namespace wpilib {
|
||||
namespace internal {
|
||||
extern double simTime;
|
||||
extern void time_callback(const msgs::ConstFloat64Ptr& msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user