mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code in wpilibC++Devices and a substantial portion of it in wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests are untouched except where it is necessary to make them work with the rest of the libraries. There is still a lot to do in the following areas: -The HAL (which we may not want to touch at all). -The I2C, Serial, and SPI interfaces in wpilibC++Devices, which I haven't gotten around to doing yet. -Most wpilibC++Devices classes have void* pointers for interacting with the HAL. -InterruptableSensorBase passes a void *params for the interrupt handler. -I haven't converted all the const char* to std::strings. -There are plenty of other cases of raw pointers still existing. -This doesn't fall directly under raw pointer stuff, but move syntax and rvalue references could be introduced in many places. -I haven't touched vision code. -The Resource classes conflict (one is in the hal, the other in wpilibC++). Someone should figure out a more permanent fix (eg, just renaming them), then doing what I did (making a new namespace for one of them, essentially the same as renaming it). A few other things: -I created a NullDeleter class which is marked as deprecated. What this does is it can be passed as the deleter to a std::shared_ptr so that when you are converting raw pointers to shared_ptrs the shared_ptr doesn't do any deletion if someone else owns the raw pointer. This should only be used in making old raw pointer UIs. -I had to alter the build.gradle so that it did not emit errors when deprecated functions called deprecated functions. Unfortunately, gradle doesn't appear to be actually printing out gcc warnigns for some reason. The best way I have found to fix this is to patch the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff) so that a deprecated function calling a deprecated function is fine but a non-deprecated function calling a deprecated function will throw a warning (which we then elevate with -Werror). I believe that clang deals with this properly, although I have not tried it myself. Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(All-WPILib)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -fPIC")
|
||||
# TODO: When the compiler allows us to actually call deprecated functions from
|
||||
# within deprecated functions, remove -Wno-error=deprecated-declarations
|
||||
# (this will cause calling deprecated functions to be treated as a warning
|
||||
# rather than an error).
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-error=deprecated-declarations -fPIC")
|
||||
|
||||
file(GLOB_RECURSE NI_LIBS ni-libraries/*.so*)
|
||||
list(REMOVE_ITEM NI_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/ni-libraries/libwpi.so ${CMAKE_CURRENT_SOURCE_DIR}/ni-libraries/libwpi_2015.so)
|
||||
|
||||
@@ -106,6 +106,10 @@ subprojects {
|
||||
cppCompiler.withArguments { args ->
|
||||
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
|
||||
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic'
|
||||
//TODO: When the compiler allows us to actually call deprecated functions from within
|
||||
// deprecated function, remove this line (this will cause calling deprecated functions
|
||||
// to be treated as a warning rather than an error).
|
||||
args << '-Wno-error=deprecated-declarations'
|
||||
args.remove('-m32')
|
||||
}
|
||||
linker.withArguments { args ->
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
|
||||
void DisabledPeriodic()
|
||||
{
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void AutonomousInit()
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
|
||||
void AutonomousPeriodic()
|
||||
{
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void TeleopInit()
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
|
||||
void TeleopPeriodic()
|
||||
{
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void TestPeriodic()
|
||||
|
||||
@@ -33,7 +33,7 @@ void Robot::AutonomousInit() {
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void Robot::TeleopInit() {
|
||||
@@ -46,7 +46,7 @@ void Robot::TeleopInit() {
|
||||
}
|
||||
|
||||
void Robot::TeleopPeriodic() {
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void Robot::TestPeriodic() {
|
||||
|
||||
@@ -45,7 +45,7 @@ void Robot::AutonomousInit() {
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
Log();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void Robot::TeleopInit() {
|
||||
}
|
||||
|
||||
void Robot::TeleopPeriodic() {
|
||||
Scheduler::GetInstance()->Run();
|
||||
Scheduler::GetInstance().Run();
|
||||
Log();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
// TODO: Replace this with something appropriate to avoid conflicts with
|
||||
// wpilibC++ Resource class (which performs an essentially identical function).
|
||||
namespace hal {
|
||||
|
||||
/**
|
||||
* The Resource class is a convenient way to track allocated resources.
|
||||
* It tracks them as indicies in the range [0 .. elements - 1].
|
||||
@@ -23,19 +29,18 @@ class Resource
|
||||
public:
|
||||
Resource(const Resource&) = delete;
|
||||
Resource& operator=(const Resource&) = delete;
|
||||
virtual ~Resource();
|
||||
explicit Resource(uint32_t size);
|
||||
virtual ~Resource() = default;
|
||||
static void CreateResourceObject(Resource **r, uint32_t elements);
|
||||
uint32_t Allocate(const char *resourceDesc);
|
||||
uint32_t Allocate(uint32_t index, const char *resourceDesc);
|
||||
void Free(uint32_t index);
|
||||
|
||||
private:
|
||||
explicit Resource(uint32_t size);
|
||||
|
||||
bool *m_isAllocated;
|
||||
::std::vector<bool> m_isAllocated;
|
||||
priority_recursive_mutex m_allocateLock;
|
||||
uint32_t m_size;
|
||||
|
||||
static priority_recursive_mutex m_createLock;
|
||||
};
|
||||
|
||||
} // namespace hal
|
||||
|
||||
@@ -574,11 +574,11 @@ struct trigger_t {
|
||||
};
|
||||
typedef struct trigger_t AnalogTrigger;
|
||||
|
||||
static Resource *triggers = NULL;
|
||||
static hal::Resource *triggers = NULL;
|
||||
|
||||
void* initializeAnalogTrigger(void* port_pointer, uint32_t *index, int32_t *status) {
|
||||
Port* port = (Port*) port_pointer;
|
||||
Resource::CreateResourceObject(&triggers, tAnalogTrigger::kNumSystems);
|
||||
hal::Resource::CreateResourceObject(&triggers, tAnalogTrigger::kNumSystems);
|
||||
|
||||
AnalogTrigger* trigger = new AnalogTrigger();
|
||||
trigger->port = (AnalogPort*) initializeAnalogInputPort(port, status);
|
||||
|
||||
@@ -66,9 +66,9 @@ priority_recursive_mutex digitalI2CMXPMutex;
|
||||
tDIO* digitalSystem = NULL;
|
||||
tRelay* relaySystem = NULL;
|
||||
tPWM* pwmSystem = NULL;
|
||||
Resource *DIOChannels = NULL;
|
||||
Resource *DO_PWMGenerators = NULL;
|
||||
Resource *PWMChannels = NULL;
|
||||
hal::Resource *DIOChannels = NULL;
|
||||
hal::Resource *DO_PWMGenerators = NULL;
|
||||
hal::Resource *PWMChannels = NULL;
|
||||
|
||||
bool digitalSystemsInitialized = false;
|
||||
|
||||
@@ -92,9 +92,9 @@ tSPI *spiSystem;
|
||||
void initializeDigital(int32_t *status) {
|
||||
if (digitalSystemsInitialized) return;
|
||||
|
||||
Resource::CreateResourceObject(&DIOChannels, tDIO::kNumSystems * kDigitalPins);
|
||||
Resource::CreateResourceObject(&DO_PWMGenerators, tDIO::kNumPWMDutyCycleAElements + tDIO::kNumPWMDutyCycleBElements);
|
||||
Resource::CreateResourceObject(&PWMChannels, tPWM::kNumSystems * kPwmPins);
|
||||
hal::Resource::CreateResourceObject(&DIOChannels, tDIO::kNumSystems * kDigitalPins);
|
||||
hal::Resource::CreateResourceObject(&DO_PWMGenerators, tDIO::kNumPWMDutyCycleAElements + tDIO::kNumPWMDutyCycleBElements);
|
||||
hal::Resource::CreateResourceObject(&PWMChannels, tPWM::kNumSystems * kPwmPins);
|
||||
digitalSystem = tDIO::create(status);
|
||||
|
||||
// Relay Setup
|
||||
@@ -292,7 +292,7 @@ void setPWMDutyCycle(void* pwmGenerator, double dutyCycle, int32_t *status) {
|
||||
}
|
||||
if(id < 4)
|
||||
digitalSystem->writePWMDutyCycleA(id, (uint8_t)rawDutyCycle, status);
|
||||
else
|
||||
else
|
||||
digitalSystem->writePWMDutyCycleB(id - 4, (uint8_t)rawDutyCycle, status);
|
||||
}
|
||||
}
|
||||
@@ -594,10 +594,10 @@ struct counter_t {
|
||||
};
|
||||
typedef struct counter_t Counter;
|
||||
|
||||
static Resource *counters = NULL;
|
||||
static hal::Resource *counters = NULL;
|
||||
|
||||
void* initializeCounter(Mode mode, uint32_t *index, int32_t *status) {
|
||||
Resource::CreateResourceObject(&counters, tCounter::kNumSystems);
|
||||
hal::Resource::CreateResourceObject(&counters, tCounter::kNumSystems);
|
||||
*index = counters->Allocate("Counter");
|
||||
if (*index == ~0ul) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
@@ -919,7 +919,7 @@ struct encoder_t {
|
||||
typedef struct encoder_t Encoder;
|
||||
|
||||
static const double DECODING_SCALING_FACTOR = 0.25;
|
||||
static Resource *quadEncoders = NULL;
|
||||
static hal::Resource *quadEncoders = NULL;
|
||||
|
||||
void* initializeEncoder(uint8_t port_a_module, uint32_t port_a_pin, bool port_a_analog_trigger,
|
||||
uint8_t port_b_module, uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
@@ -931,7 +931,7 @@ void* initializeEncoder(uint8_t port_a_module, uint32_t port_a_pin, bool port_a_
|
||||
remapDigitalSource(port_a_analog_trigger, port_a_pin, port_a_module);
|
||||
remapDigitalSource(port_b_analog_trigger, port_b_pin, port_b_module);
|
||||
|
||||
Resource::CreateResourceObject(&quadEncoders, tEncoder::kNumSystems);
|
||||
hal::Resource::CreateResourceObject(&quadEncoders, tEncoder::kNumSystems);
|
||||
encoder->index = quadEncoders->Allocate("4X Encoder");
|
||||
*index = encoder->index;
|
||||
// TODO: if (index == ~0ul) { CloneError(quadEncoders); return; }
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <cstddef>
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
namespace hal {
|
||||
|
||||
priority_recursive_mutex Resource::m_createLock;
|
||||
|
||||
/**
|
||||
@@ -16,15 +18,9 @@ priority_recursive_mutex Resource::m_createLock;
|
||||
* Allocate a bool array of values that will get initialized to indicate that no resources
|
||||
* have been allocated yet. The indicies of the resources are [0 .. elements - 1].
|
||||
*/
|
||||
Resource::Resource(uint32_t elements)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
m_size = elements;
|
||||
m_isAllocated = new bool[m_size];
|
||||
for (uint32_t i=0; i < m_size; i++)
|
||||
{
|
||||
m_isAllocated[i] = false;
|
||||
}
|
||||
Resource::Resource(uint32_t elements) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
m_isAllocated = std::vector<bool>(elements, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,15 +42,6 @@ Resource::Resource(uint32_t elements)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the allocated array or resources.
|
||||
* This happens when the module is unloaded (provided it was statically allocated).
|
||||
*/
|
||||
Resource::~Resource()
|
||||
{
|
||||
delete[] m_isAllocated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a resource.
|
||||
* When a resource is requested, mark it allocated. In this case, a free resource value
|
||||
@@ -63,7 +50,7 @@ Resource::~Resource()
|
||||
uint32_t Resource::Allocate(const char *resourceDesc)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
for (uint32_t i=0; i < m_size; i++)
|
||||
for (uint32_t i=0; i < m_isAllocated.size(); i++)
|
||||
{
|
||||
if (!m_isAllocated[i])
|
||||
{
|
||||
@@ -83,7 +70,7 @@ uint32_t Resource::Allocate(const char *resourceDesc)
|
||||
uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index >= m_size)
|
||||
if (index >= m_isAllocated.size())
|
||||
{
|
||||
// TODO: wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return ~0ul;
|
||||
@@ -107,7 +94,7 @@ void Resource::Free(uint32_t index)
|
||||
{
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index == ~0ul) return;
|
||||
if (index >= m_size)
|
||||
if (index >= m_isAllocated.size())
|
||||
{
|
||||
// TODO: wpi_setWPIError(NotAllocated);
|
||||
return;
|
||||
@@ -119,3 +106,5 @@ void Resource::Free(uint32_t index)
|
||||
}
|
||||
m_isAllocated[index] = false;
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
NetworkTableKeyListenerAdapter(std::string relativeKey, std::string fullKey, NetworkTable* targetSource, ITableListener* targetListener);
|
||||
virtual ~NetworkTableKeyListenerAdapter();
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
ValueChanged(source.get(), key, value, isNew);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,17 +14,22 @@ class NetworkTableListenerAdapter;
|
||||
#include "tables/ITable.h"
|
||||
#include <string>
|
||||
|
||||
class NetworkTableListenerAdapter : public ITableListener {
|
||||
private:
|
||||
std::string prefix;
|
||||
ITable* targetSource;
|
||||
ITableListener* targetListener;
|
||||
|
||||
class NetworkTableListenerAdapter : public ITableListener{
|
||||
private:
|
||||
std::string prefix;
|
||||
ITable* targetSource;
|
||||
ITableListener* targetListener;
|
||||
public:
|
||||
NetworkTableListenerAdapter(std::string prefix, ITable* targetSource, ITableListener* targetListener);
|
||||
virtual ~NetworkTableListenerAdapter();
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
|
||||
public:
|
||||
NetworkTableListenerAdapter(std::string prefix, ITable* targetSource,
|
||||
ITableListener* targetListener);
|
||||
virtual ~NetworkTableListenerAdapter();
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
bool isNew);
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
ValueChanged(source.get(), key, value, isNew);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETWORKTABLELISTENERADAPTER_H_ */
|
||||
|
||||
@@ -29,6 +29,10 @@ public:
|
||||
NetworkTableSubListenerAdapter(std::string& prefix, NetworkTable* targetSource, ITableListener* targetListener);
|
||||
virtual ~NetworkTableSubListenerAdapter();
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew);
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
ValueChanged(source.get(), key, value, isNew);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@ class ITableListener;
|
||||
|
||||
#include "tables/ITable.h"
|
||||
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* A listener that listens to changes in values in a {@link ITable}
|
||||
*
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
@@ -34,7 +33,18 @@ class ITableListener {
|
||||
* @param value the new value
|
||||
* @param isNew true if the key did not previously exist in the table, otherwise it is false
|
||||
*/
|
||||
virtual void ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) = 0;
|
||||
virtual void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key, EntryValue value, bool isNew) = 0;
|
||||
|
||||
virtual void ValueChanged(ITable* source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
ValueChanged(::std::shared_ptr<ITable>(source, NullDeleter<ITable>()), key, value, isNew);
|
||||
}
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
struct[[deprecated]] NullDeleter {
|
||||
void operator()(T*) const noexcept {};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,3 +11,12 @@
|
||||
TypeName& operator=(const TypeName&) = delete; \
|
||||
TypeName(TypeName&&) = default; \
|
||||
TypeName& operator=(TypeName&&) = default
|
||||
|
||||
// A struct to use as a deleter when a std::shared_ptr must wrap a raw pointer
|
||||
// that is being deleted by someone else.
|
||||
// This should only be called in deprecated functions; using it anywhere else
|
||||
// will throw warnings.
|
||||
template<class T>
|
||||
struct [[deprecated]] NullDeleter {
|
||||
void operator()(T *) const noexcept {};
|
||||
};
|
||||
|
||||
@@ -10,17 +10,18 @@
|
||||
|
||||
#include "Buttons/Button.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class NetworkButton : public Button {
|
||||
public:
|
||||
NetworkButton(const char *tableName, const char *field);
|
||||
NetworkButton(ITable *table, const char *field);
|
||||
NetworkButton(::std::shared_ptr<ITable> table, const char *field);
|
||||
virtual ~NetworkButton() = default;
|
||||
|
||||
virtual bool Get();
|
||||
|
||||
private:
|
||||
ITable *m_netTable;
|
||||
::std::shared_ptr<ITable> m_netTable;
|
||||
std::string m_field;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define __TRIGGER_H__
|
||||
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include <memory>
|
||||
|
||||
class Command;
|
||||
|
||||
@@ -41,12 +42,12 @@ class Trigger : public Sendable {
|
||||
void CancelWhenActive(Command *command);
|
||||
void ToggleWhenActive(Command *command);
|
||||
|
||||
virtual void InitTable(ITable *table);
|
||||
virtual ITable *GetTable() const;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table);
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const;
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
|
||||
protected:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class CommandGroup;
|
||||
class Subsystem;
|
||||
@@ -175,14 +176,14 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
|
||||
public:
|
||||
virtual std::string GetName();
|
||||
virtual void InitTable(ITable *table);
|
||||
virtual ITable *GetTable() const;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table);
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const;
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
virtual void ValueChanged(ITable *source, const std::string &key,
|
||||
virtual void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew);
|
||||
|
||||
protected:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "PIDOutput.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PIDController;
|
||||
|
||||
class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
@@ -23,7 +25,7 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
PIDCommand(double p, double i, double d);
|
||||
PIDCommand(double p, double i, double d, double period);
|
||||
PIDCommand(double p, double i, double d, double f, double period);
|
||||
virtual ~PIDCommand();
|
||||
virtual ~PIDCommand() = default;
|
||||
|
||||
void SetSetpointRelative(double deltaSetpoint);
|
||||
|
||||
@@ -47,10 +49,10 @@ class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
PIDController *m_controller;
|
||||
std::unique_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
virtual void InitTable(ITable *table);
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table);
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "PIDOutput.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* This class is designed to handle the case where there is a {@link Subsystem}
|
||||
* which uses a single {@link PIDController} almost constantly (for instance,
|
||||
@@ -34,7 +36,7 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
PIDSubsystem(double p, double i, double d);
|
||||
PIDSubsystem(double p, double i, double d, double f);
|
||||
PIDSubsystem(double p, double i, double d, double f, double period);
|
||||
virtual ~PIDSubsystem();
|
||||
virtual ~PIDSubsystem() = default;
|
||||
|
||||
void Enable();
|
||||
void Disable();
|
||||
@@ -63,10 +65,10 @@ class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
|
||||
private:
|
||||
/** The internal {@link PIDController} */
|
||||
PIDController *m_controller;
|
||||
std::unique_ptr<PIDController> m_controller;
|
||||
|
||||
public:
|
||||
virtual void InitTable(ITable *table);
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table);
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
@@ -26,7 +27,7 @@ class Subsystem;
|
||||
|
||||
class Scheduler : public ErrorBase, public NamedSendable {
|
||||
public:
|
||||
static Scheduler *GetInstance();
|
||||
static Scheduler &GetInstance();
|
||||
|
||||
void AddCommand(Command *command);
|
||||
void AddButton(ButtonScheduler *button);
|
||||
@@ -39,8 +40,8 @@ class Scheduler : public ErrorBase, public NamedSendable {
|
||||
|
||||
void UpdateTable();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(ITable *subTable);
|
||||
ITable *GetTable() const;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable);
|
||||
::std::shared_ptr<ITable> GetTable() const;
|
||||
std::string GetName();
|
||||
std::string GetType() const;
|
||||
|
||||
@@ -64,7 +65,7 @@ class Scheduler : public ErrorBase, public NamedSendable {
|
||||
StringArray *commands = nullptr;
|
||||
NumberArray *ids = nullptr;
|
||||
NumberArray *toCancel = nullptr;
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
bool m_runningCommandsChanged = false;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class Command;
|
||||
|
||||
@@ -38,12 +39,12 @@ class Subsystem : public ErrorBase, public NamedSendable {
|
||||
|
||||
public:
|
||||
virtual std::string GetName();
|
||||
virtual void InitTable(ITable *table);
|
||||
virtual ITable *GetTable() const;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table);
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const;
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
|
||||
protected:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,18 +21,18 @@ class Error {
|
||||
typedef int32_t Code;
|
||||
|
||||
Error();
|
||||
void Clone(Error& error);
|
||||
void Clone(const Error& error);
|
||||
Code GetCode() const;
|
||||
const char* GetMessage() const;
|
||||
const char* GetFilename() const;
|
||||
const char* GetFunction() const;
|
||||
std::string GetMessage() const;
|
||||
std::string GetFilename() const;
|
||||
std::string GetFunction() const;
|
||||
uint32_t GetLineNumber() const;
|
||||
const ErrorBase* GetOriginatingObject() const;
|
||||
double GetTimestamp() const;
|
||||
void Clear();
|
||||
void Set(Code code, const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber,
|
||||
const ErrorBase* originatingObject);
|
||||
void Set(Code code, const std::string& contextMessage,
|
||||
const std::string& filename, const std::string& function,
|
||||
uint32_t lineNumber, const ErrorBase* originatingObject);
|
||||
|
||||
private:
|
||||
void Report();
|
||||
|
||||
@@ -56,26 +56,33 @@ class ErrorBase {
|
||||
virtual ~ErrorBase() = default;
|
||||
virtual Error& GetError();
|
||||
virtual const Error& GetError() const;
|
||||
virtual void SetErrnoError(const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber) const;
|
||||
virtual void SetImaqError(int success, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
virtual void SetErrnoError(const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const;
|
||||
virtual void SetImaqError(int success, const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const;
|
||||
virtual void SetError(Error::Code code, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
uint32_t lineNumber) const;
|
||||
virtual void SetWPIError(const char* errorMessage, Error::Code code,
|
||||
const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber) const;
|
||||
virtual void CloneError(ErrorBase* rhs) const;
|
||||
virtual void SetError(Error::Code code, const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function, uint32_t lineNumber) const;
|
||||
virtual void SetWPIError(const std::string& errorMessage, Error::Code code,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const;
|
||||
virtual void CloneError(const ErrorBase& rhs) const;
|
||||
virtual void ClearError() const;
|
||||
virtual bool StatusIsFatal() const;
|
||||
static void SetGlobalError(Error::Code code, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
uint32_t lineNumber);
|
||||
static void SetGlobalWPIError(const char* errorMessage,
|
||||
const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
static void SetGlobalError(Error::Code code,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function, uint32_t lineNumber);
|
||||
static void SetGlobalWPIError(const std::string& errorMessage,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber);
|
||||
static Error& GetGlobalError();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Commands/Scheduler.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
struct LiveWindowComponent {
|
||||
std::string subsystem;
|
||||
@@ -29,12 +30,22 @@ struct LiveWindowComponent {
|
||||
*/
|
||||
class LiveWindow {
|
||||
public:
|
||||
static LiveWindow *GetInstance();
|
||||
static LiveWindow &GetInstance();
|
||||
void Run();
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void AddSensor(const char *subsystem, const char *name,
|
||||
LiveWindowSendable *component);
|
||||
void AddSensor(const char *subsystem, const char *name,
|
||||
::std::shared_ptr<LiveWindowSendable> component);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void AddActuator(const char *subsystem, const char *name,
|
||||
LiveWindowSendable *component);
|
||||
void AddActuator(const char *subsystem, const char *name,
|
||||
::std::shared_ptr<LiveWindowSendable> component);
|
||||
void AddSensor(std::string type, int channel, LiveWindowSendable *component);
|
||||
void AddActuator(std::string type, int channel,
|
||||
LiveWindowSendable *component);
|
||||
@@ -53,13 +64,13 @@ class LiveWindow {
|
||||
void Initialize();
|
||||
void InitializeLiveWindowComponents();
|
||||
|
||||
std::vector<LiveWindowSendable *> m_sensors;
|
||||
std::map<LiveWindowSendable *, LiveWindowComponent> m_components;
|
||||
std::vector<::std::shared_ptr<LiveWindowSendable>> m_sensors;
|
||||
std::map<::std::shared_ptr<LiveWindowSendable>, LiveWindowComponent> m_components;
|
||||
|
||||
ITable *m_liveWindowTable;
|
||||
ITable *m_statusTable;
|
||||
::std::shared_ptr<ITable> m_liveWindowTable;
|
||||
::std::shared_ptr<ITable> m_statusTable;
|
||||
|
||||
Scheduler *m_scheduler;
|
||||
Scheduler &m_scheduler;
|
||||
|
||||
bool m_enabled = false;
|
||||
bool m_firstTime = true;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
class LiveWindowStatusListener : public ITableListener {
|
||||
public:
|
||||
virtual void ValueChanged(ITable* source, const std::string& key,
|
||||
virtual void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew);
|
||||
};
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "PIDInterface.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "Notifier.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PIDOutput;
|
||||
class PIDSource;
|
||||
class Notifier;
|
||||
|
||||
/**
|
||||
* Class implements a PID Control Loop.
|
||||
@@ -31,7 +33,7 @@ class PIDController : public LiveWindowSendable,
|
||||
float period = 0.05);
|
||||
PIDController(float p, float i, float d, float f, PIDSource *source,
|
||||
PIDOutput *output, float period = 0.05);
|
||||
virtual ~PIDController();
|
||||
virtual ~PIDController() = default;
|
||||
virtual float Get() const;
|
||||
virtual void SetContinuous(bool continuous = true);
|
||||
virtual void SetInputRange(float minimumInput, float maximumInput);
|
||||
@@ -59,7 +61,7 @@ class PIDController : public LiveWindowSendable,
|
||||
|
||||
virtual void Reset() override;
|
||||
|
||||
virtual void InitTable(ITable *table) override;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> table) override;
|
||||
|
||||
private:
|
||||
float m_P; // factor for "proportional" control
|
||||
@@ -92,22 +94,22 @@ class PIDController : public LiveWindowSendable,
|
||||
PIDSource *m_pidInput;
|
||||
PIDOutput *m_pidOutput;
|
||||
|
||||
Notifier *m_controlLoop;
|
||||
std::unique_ptr<Notifier> m_controlLoop;
|
||||
|
||||
void Initialize(float p, float i, float d, float f, PIDSource *source,
|
||||
PIDOutput *output, float period = 0.05);
|
||||
static void CallCalculate(void *controller);
|
||||
|
||||
virtual ITable *GetTable() const override;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const override;
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void ValueChanged(ITable *source, const std::string &key,
|
||||
virtual void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual void StartLiveWindowMode() override;
|
||||
virtual void StopLiveWindowMode() override;
|
||||
|
||||
protected:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
virtual void Calculate();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PIDController);
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
@@ -22,18 +24,16 @@
|
||||
*/
|
||||
class Resource : public ErrorBase {
|
||||
public:
|
||||
virtual ~Resource();
|
||||
static void CreateResourceObject(Resource **r, uint32_t elements);
|
||||
virtual ~Resource() = default;
|
||||
static void CreateResourceObject(::std::unique_ptr<Resource>& r, uint32_t elements);
|
||||
explicit Resource(uint32_t size);
|
||||
uint32_t Allocate(const char *resourceDesc);
|
||||
uint32_t Allocate(uint32_t index, const char *resourceDesc);
|
||||
void Free(uint32_t index);
|
||||
|
||||
private:
|
||||
explicit Resource(uint32_t size);
|
||||
|
||||
bool *m_isAllocated;
|
||||
std::vector<bool> m_isAllocated;
|
||||
priority_recursive_mutex m_allocateLock;
|
||||
uint32_t m_size;
|
||||
|
||||
static priority_recursive_mutex m_createLock;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class RobotStateInterface {
|
||||
public:
|
||||
virtual ~RobotStateInterface() = default;
|
||||
@@ -17,10 +19,11 @@ class RobotStateInterface {
|
||||
|
||||
class RobotState {
|
||||
private:
|
||||
static RobotStateInterface* impl;
|
||||
static ::std::shared_ptr<RobotStateInterface> impl;
|
||||
|
||||
public:
|
||||
static void SetImplementation(RobotStateInterface* i);
|
||||
static void SetImplementation(RobotStateInterface& i);
|
||||
static void SetImplementation(::std::shared_ptr<RobotStateInterface> i);
|
||||
static bool IsDisabled();
|
||||
static bool IsEnabled();
|
||||
static bool IsOperatorControl();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define __SMART_DASHBOARD_DATA__
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "tables/ITable.h"
|
||||
|
||||
class Sendable {
|
||||
@@ -17,12 +18,12 @@ class Sendable {
|
||||
* Initializes a table for this sendable object.
|
||||
* @param subtable The table to put the values in.
|
||||
*/
|
||||
virtual void InitTable(ITable* subtable) = 0;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable) = 0;
|
||||
|
||||
/**
|
||||
* @return the table that is currently associated with the sendable
|
||||
*/
|
||||
virtual ITable* GetTable() const = 0;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const = 0;
|
||||
|
||||
/**
|
||||
* @return the string representation of the named data type that will be used
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "SmartDashboard/Sendable.h"
|
||||
#include "tables/ITable.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
@@ -38,14 +39,14 @@ class SendableChooser : public Sendable {
|
||||
void AddDefault(const char *name, void *object);
|
||||
void *GetSelected();
|
||||
|
||||
virtual void InitTable(ITable *subtable);
|
||||
virtual ITable *GetTable() const;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable);
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const;
|
||||
virtual std::string GetSmartDashboardType() const;
|
||||
|
||||
private:
|
||||
std::string m_defaultChoice;
|
||||
std::map<std::string, void *> m_choices;
|
||||
ITable *m_table;
|
||||
::std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,14 +43,14 @@ class SmartDashboard : public SensorBase {
|
||||
virtual ~SmartDashboard() = default;
|
||||
|
||||
/** The {@link NetworkTable} used by {@link SmartDashboard} */
|
||||
static ITable *m_table;
|
||||
static ::std::shared_ptr<ITable> m_table;
|
||||
|
||||
/**
|
||||
* A map linking tables in the SmartDashboard to the {@link
|
||||
* SmartDashboardData} objects
|
||||
* they came from.
|
||||
*/
|
||||
static std::map<ITable *, Sendable *> m_tablesToData;
|
||||
static std::map<::std::shared_ptr<ITable> , Sendable *> m_tablesToData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* WPI task is a wrapper for the native Task object.
|
||||
* All WPILib tasks are managed by a static task manager for simplified cleanup.
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
ButtonScheduler::ButtonScheduler(bool last, Trigger *button, Command *orders)
|
||||
: m_pressedLast(last), m_button(button), m_command(orders) {}
|
||||
|
||||
void ButtonScheduler::Start() { Scheduler::GetInstance()->AddButton(this); }
|
||||
void ButtonScheduler::Start() { Scheduler::GetInstance().AddButton(this); }
|
||||
|
||||
@@ -13,7 +13,7 @@ NetworkButton::NetworkButton(const char *tableName, const char *field)
|
||||
m_netTable(NetworkTable::GetTable(tableName)),
|
||||
m_field(field) {}
|
||||
|
||||
NetworkButton::NetworkButton(ITable *table, const char *field)
|
||||
NetworkButton::NetworkButton(::std::shared_ptr<ITable> table, const char *field)
|
||||
: m_netTable(table), m_field(field) {}
|
||||
|
||||
bool NetworkButton::Get() {
|
||||
|
||||
@@ -52,11 +52,11 @@ void Trigger::ToggleWhenActive(Command *command) {
|
||||
|
||||
std::string Trigger::GetSmartDashboardType() const { return "Button"; }
|
||||
|
||||
void Trigger::InitTable(ITable *table) {
|
||||
void Trigger::InitTable(::std::shared_ptr<ITable> table) {
|
||||
m_table = table;
|
||||
if (m_table != nullptr) {
|
||||
m_table->PutBoolean("pressed", Get());
|
||||
}
|
||||
}
|
||||
|
||||
ITable *Trigger::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Trigger::GetTable() const { return m_table; }
|
||||
|
||||
@@ -145,7 +145,7 @@ void Command::Start() {
|
||||
CommandIllegalUse,
|
||||
"Can not start a command that is part of a command group");
|
||||
|
||||
Scheduler::GetInstance()->AddCommand(this);
|
||||
Scheduler::GetInstance().AddCommand(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -369,7 +369,7 @@ std::string Command::GetName() {
|
||||
|
||||
std::string Command::GetSmartDashboardType() const { return "Command"; }
|
||||
|
||||
void Command::InitTable(ITable *table) {
|
||||
void Command::InitTable(::std::shared_ptr<ITable> table) {
|
||||
if (m_table != nullptr) m_table->RemoveTableListener(this);
|
||||
m_table = table;
|
||||
if (m_table != nullptr) {
|
||||
@@ -380,9 +380,9 @@ void Command::InitTable(ITable *table) {
|
||||
}
|
||||
}
|
||||
|
||||
ITable *Command::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Command::GetTable() const { return m_table; }
|
||||
|
||||
void Command::ValueChanged(ITable *source, const std::string &key,
|
||||
void Command::ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
if (value.b) {
|
||||
if (!IsRunning()) Start();
|
||||
|
||||
@@ -13,34 +13,32 @@
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d, double f,
|
||||
double period)
|
||||
: Command(name) {
|
||||
m_controller = new PIDController(p, i, d, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double f, double period) {
|
||||
m_controller = new PIDController(p, i, d, f, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d)
|
||||
: Command(name) {
|
||||
m_controller = new PIDController(p, i, d, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d,
|
||||
double period)
|
||||
: Command(name) {
|
||||
m_controller = new PIDController(p, i, d, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d) {
|
||||
m_controller = new PIDController(p, i, d, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(double p, double i, double d, double period) {
|
||||
m_controller = new PIDController(p, i, d, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::~PIDCommand() { delete m_controller; }
|
||||
|
||||
void PIDCommand::_Initialize() { m_controller->Enable(); }
|
||||
|
||||
void PIDCommand::_End() { m_controller->Disable(); }
|
||||
@@ -55,7 +53,7 @@ void PIDCommand::PIDWrite(float output) { UsePIDOutput(output); }
|
||||
|
||||
double PIDCommand::PIDGet() const { return ReturnPIDInput(); }
|
||||
|
||||
PIDController *PIDCommand::GetPIDController() const { return m_controller; }
|
||||
PIDController *PIDCommand::GetPIDController() const { return m_controller.get(); }
|
||||
|
||||
void PIDCommand::SetSetpoint(double setpoint) {
|
||||
m_controller->SetSetpoint(setpoint);
|
||||
@@ -66,7 +64,7 @@ double PIDCommand::GetSetpoint() const { return m_controller->GetSetpoint(); }
|
||||
double PIDCommand::GetPosition() const { return ReturnPIDInput(); }
|
||||
|
||||
std::string PIDCommand::GetSmartDashboardType() const { return "PIDCommand"; }
|
||||
void PIDCommand::InitTable(ITable *table) {
|
||||
void PIDCommand::InitTable(::std::shared_ptr<ITable> table) {
|
||||
m_controller->InitTable(table);
|
||||
Command::InitTable(table);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d)
|
||||
: Subsystem(name) {
|
||||
m_controller = new PIDController(p, i, d, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d)
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
double f)
|
||||
: Subsystem(name) {
|
||||
m_controller = new PIDController(p, i, d, f, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
double f, double period)
|
||||
: Subsystem(name) {
|
||||
m_controller = new PIDController(p, i, d, f, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(double p, double i, double d)
|
||||
: Subsystem("PIDSubsystem") {
|
||||
m_controller = new PIDController(p, i, d, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d)
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(double p, double i, double d, double f)
|
||||
: Subsystem("PIDSubsystem") {
|
||||
m_controller = new PIDController(p, i, d, f, this, this);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,11 +96,9 @@ PIDSubsystem::PIDSubsystem(double p, double i, double d, double f)
|
||||
PIDSubsystem::PIDSubsystem(double p, double i, double d, double f,
|
||||
double period)
|
||||
: Subsystem("PIDSubsystem") {
|
||||
m_controller = new PIDController(p, i, d, f, this, this, period);
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
}
|
||||
|
||||
PIDSubsystem::~PIDSubsystem() { delete m_controller; }
|
||||
|
||||
/**
|
||||
* Enables the internal {@link PIDController}
|
||||
*/
|
||||
@@ -117,7 +115,7 @@ void PIDSubsystem::Disable() { m_controller->Disable(); }
|
||||
*
|
||||
* @return the {@link PIDController} used by this {@link PIDSubsystem}
|
||||
*/
|
||||
PIDController *PIDSubsystem::GetPIDController() { return m_controller; }
|
||||
PIDController *PIDSubsystem::GetPIDController() { return m_controller.get(); }
|
||||
|
||||
/**
|
||||
* Sets the setpoint to the given value. If {@link PIDCommand#SetRange(double,
|
||||
@@ -213,7 +211,7 @@ void PIDSubsystem::PIDWrite(float output) { UsePIDOutput(output); }
|
||||
double PIDSubsystem::PIDGet() const { return ReturnPIDInput(); }
|
||||
|
||||
std::string PIDSubsystem::GetSmartDashboardType() const { return "PIDCommand"; }
|
||||
void PIDSubsystem::InitTable(ITable *table) {
|
||||
void PIDSubsystem::InitTable(::std::shared_ptr<ITable> table) {
|
||||
m_controller->InitTable(table);
|
||||
Subsystem::InitTable(table);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ Scheduler::Scheduler() {
|
||||
* Returns the {@link Scheduler}, creating it if one does not exist.
|
||||
* @return the {@link Scheduler}
|
||||
*/
|
||||
Scheduler *Scheduler::GetInstance() {
|
||||
Scheduler &Scheduler::GetInstance() {
|
||||
static Scheduler instance;
|
||||
return &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
@@ -258,7 +258,7 @@ std::string Scheduler::GetType() const { return "Scheduler"; }
|
||||
|
||||
std::string Scheduler::GetSmartDashboardType() const { return "Scheduler"; }
|
||||
|
||||
void Scheduler::InitTable(ITable *subTable) {
|
||||
void Scheduler::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
commands = new StringArray();
|
||||
ids = new NumberArray();
|
||||
@@ -269,4 +269,4 @@ void Scheduler::InitTable(ITable *subTable) {
|
||||
m_table->PutValue("Cancel", *toCancel);
|
||||
}
|
||||
|
||||
ITable *Scheduler::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Scheduler::GetTable() const { return m_table; }
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
Subsystem::Subsystem(const char *name) {
|
||||
m_name = name;
|
||||
Scheduler::GetInstance()->RegisterSubsystem(this);
|
||||
Scheduler::GetInstance().RegisterSubsystem(this);
|
||||
}
|
||||
/**
|
||||
* Initialize the default command for this subsystem
|
||||
@@ -126,7 +126,7 @@ std::string Subsystem::GetName() { return m_name; }
|
||||
|
||||
std::string Subsystem::GetSmartDashboardType() const { return "Subsystem"; }
|
||||
|
||||
void Subsystem::InitTable(ITable *table) {
|
||||
void Subsystem::InitTable(::std::shared_ptr<ITable> table) {
|
||||
m_table = table;
|
||||
if (m_table != nullptr) {
|
||||
if (m_defaultCommand != nullptr) {
|
||||
@@ -144,4 +144,4 @@ void Subsystem::InitTable(ITable *table) {
|
||||
}
|
||||
}
|
||||
|
||||
ITable *Subsystem::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Subsystem::GetTable() const { return m_table; }
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
Error::Error() {}
|
||||
|
||||
void Error::Clone(Error& error) {
|
||||
void Error::Clone(const Error& error) {
|
||||
m_code = error.m_code;
|
||||
m_message = error.m_message;
|
||||
m_filename = error.m_filename;
|
||||
@@ -31,11 +31,11 @@ void Error::Clone(Error& error) {
|
||||
|
||||
Error::Code Error::GetCode() const { return m_code; }
|
||||
|
||||
const char* Error::GetMessage() const { return m_message.c_str(); }
|
||||
std::string Error::GetMessage() const { return m_message; }
|
||||
|
||||
const char* Error::GetFilename() const { return m_filename.c_str(); }
|
||||
std::string Error::GetFilename() const { return m_filename; }
|
||||
|
||||
const char* Error::GetFunction() const { return m_function.c_str(); }
|
||||
std::string Error::GetFunction() const { return m_function; }
|
||||
|
||||
uint32_t Error::GetLineNumber() const { return m_lineNumber; }
|
||||
|
||||
@@ -45,9 +45,9 @@ const ErrorBase* Error::GetOriginatingObject() const {
|
||||
|
||||
double Error::GetTimestamp() const { return m_timestamp; }
|
||||
|
||||
void Error::Set(Code code, const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber,
|
||||
const ErrorBase* originatingObject) {
|
||||
void Error::Set(Code code, const std::string& contextMessage,
|
||||
const std::string& filename, const std::string& function,
|
||||
uint32_t lineNumber, const ErrorBase* originatingObject) {
|
||||
bool report = true;
|
||||
|
||||
if (code == m_code && GetTime() - m_timestamp < 1) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
priority_mutex ErrorBase::_globalErrorMutex;
|
||||
Error ErrorBase::_globalError;
|
||||
@@ -42,15 +43,19 @@ void ErrorBase::ClearError() const { m_error.Clear(); }
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetErrnoError(const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber) const {
|
||||
char err[256];
|
||||
void ErrorBase::SetErrnoError(const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const {
|
||||
std::string err;
|
||||
int errNo = errno;
|
||||
if (errNo == 0) {
|
||||
sprintf(err, "OK: %s", contextMessage);
|
||||
err = "OK: " + contextMessage;
|
||||
} else {
|
||||
snprintf(err, 256, "%s (0x%08X): %s", strerror(errNo), errNo,
|
||||
contextMessage);
|
||||
char buf[256];
|
||||
snprintf(buf, 256, "%s (0x%08X): %s", strerror(errNo), errNo,
|
||||
contextMessage.c_str());
|
||||
err = buf;
|
||||
}
|
||||
|
||||
// Set the current error information for this object.
|
||||
@@ -73,16 +78,17 @@ void ErrorBase::SetErrnoError(const char* contextMessage, const char* filename,
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetImaqError(int success, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
void ErrorBase::SetImaqError(int success, const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const {
|
||||
// If there was an error
|
||||
if (success <= 0) {
|
||||
char err[256];
|
||||
sprintf(err, "%i: %s", success, contextMessage);
|
||||
std::stringstream err;
|
||||
err << success << ": " << contextMessage;
|
||||
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(success, err, filename, function, lineNumber, this);
|
||||
m_error.Set(success, err.str(), filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::unique_lock<priority_mutex> mutex(_globalErrorMutex);
|
||||
@@ -101,8 +107,9 @@ void ErrorBase::SetImaqError(int success, const char* contextMessage,
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetError(Error::Code code, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
void ErrorBase::SetError(Error::Code code, const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
@@ -126,11 +133,12 @@ void ErrorBase::SetError(Error::Code code, const char* contextMessage,
|
||||
* @param function Function of the error source
|
||||
* @param lineNumber Line number of the error source
|
||||
*/
|
||||
void ErrorBase::SetWPIError(const char* errorMessage, Error::Code code,
|
||||
const char* contextMessage, const char* filename,
|
||||
const char* function, uint32_t lineNumber) const {
|
||||
char err[256];
|
||||
sprintf(err, "%s: %s", errorMessage, contextMessage);
|
||||
void ErrorBase::SetWPIError(const std::string& errorMessage, Error::Code code,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) const {
|
||||
std::string err = errorMessage + ": " + contextMessage;
|
||||
|
||||
// Set the current error information for this object.
|
||||
m_error.Set(code, err, filename, function, lineNumber, this);
|
||||
@@ -142,8 +150,8 @@ void ErrorBase::SetWPIError(const char* errorMessage, Error::Code code,
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::CloneError(ErrorBase* rhs) const {
|
||||
m_error.Clone(rhs->GetError());
|
||||
void ErrorBase::CloneError(const ErrorBase& rhs) const {
|
||||
m_error.Clone(rhs.GetError());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,8 +161,10 @@ void ErrorBase::CloneError(ErrorBase* rhs) const {
|
||||
*/
|
||||
bool ErrorBase::StatusIsFatal() const { return m_error.GetCode() < 0; }
|
||||
|
||||
void ErrorBase::SetGlobalError(Error::Code code, const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
void ErrorBase::SetGlobalError(Error::Code code,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
@@ -166,12 +176,12 @@ void ErrorBase::SetGlobalError(Error::Code code, const char* contextMessage,
|
||||
}
|
||||
}
|
||||
|
||||
void ErrorBase::SetGlobalWPIError(const char* errorMessage,
|
||||
const char* contextMessage,
|
||||
const char* filename, const char* function,
|
||||
void ErrorBase::SetGlobalWPIError(const std::string& errorMessage,
|
||||
const std::string& contextMessage,
|
||||
const std::string& filename,
|
||||
const std::string& function,
|
||||
uint32_t lineNumber) {
|
||||
char err[256];
|
||||
sprintf(err, "%s: %s", errorMessage, contextMessage);
|
||||
std::string err = errorMessage + ": " + contextMessage;
|
||||
|
||||
std::unique_lock<priority_mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() != 0) {
|
||||
|
||||
@@ -9,19 +9,18 @@
|
||||
* regardless of
|
||||
* how many times GetInstance is called.
|
||||
*/
|
||||
LiveWindow *LiveWindow::GetInstance() {
|
||||
LiveWindow &LiveWindow::GetInstance() {
|
||||
static LiveWindow instance;
|
||||
return &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* LiveWindow constructor.
|
||||
* Allocate the necessary tables.
|
||||
*/
|
||||
LiveWindow::LiveWindow() {
|
||||
m_liveWindowTable = NetworkTable::GetTable("LiveWindow");
|
||||
m_statusTable = m_liveWindowTable->GetSubTable("~STATUS~");
|
||||
m_scheduler = Scheduler::GetInstance();
|
||||
LiveWindow::LiveWindow() : m_scheduler(Scheduler::GetInstance()) {
|
||||
m_liveWindowTable.reset(NetworkTable::GetTable("LiveWindow"));
|
||||
m_statusTable.reset(m_liveWindowTable->GetSubTable("~STATUS~"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,8 +34,8 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
InitializeLiveWindowComponents();
|
||||
m_firstTime = false;
|
||||
}
|
||||
m_scheduler->SetEnabled(false);
|
||||
m_scheduler->RemoveAll();
|
||||
m_scheduler.SetEnabled(false);
|
||||
m_scheduler.RemoveAll();
|
||||
for (auto& elem : m_components) {
|
||||
elem.first->StartLiveWindowMode();
|
||||
}
|
||||
@@ -44,7 +43,7 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
for (auto& elem : m_components) {
|
||||
elem.first->StopLiveWindowMode();
|
||||
}
|
||||
m_scheduler->SetEnabled(true);
|
||||
m_scheduler.SetEnabled(true);
|
||||
}
|
||||
m_enabled = enabled;
|
||||
m_statusTable->PutBoolean("LW Enabled", m_enabled);
|
||||
@@ -58,12 +57,17 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
* @param component A LiveWindowSendable component that represents a sensor.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const char *subsystem, const char *name,
|
||||
LiveWindowSendable *component) {
|
||||
::std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
m_components[component].isSensor = true;
|
||||
}
|
||||
|
||||
void LiveWindow::AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component) {
|
||||
AddSensor(subsystem, name, ::std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Actuator associated with the subsystem and with call it by the given
|
||||
* name.
|
||||
@@ -72,15 +76,23 @@ void LiveWindow::AddSensor(const char *subsystem, const char *name,
|
||||
* @param component A LiveWindowSendable component that represents a actuator.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const char *subsystem, const char *name,
|
||||
LiveWindowSendable *component) {
|
||||
::std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
m_components[component].isSensor = false;
|
||||
}
|
||||
|
||||
void LiveWindow::AddActuator(const char *subsystem, const char *name,
|
||||
LiveWindowSendable *component) {
|
||||
AddActuator(subsystem, name,
|
||||
::std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL
|
||||
*/
|
||||
[[deprecated]]
|
||||
void LiveWindow::AddSensor(std::string type, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
std::ostringstream oss;
|
||||
@@ -90,9 +102,11 @@ void LiveWindow::AddSensor(std::string type, int channel,
|
||||
types.copy(cc, types.size());
|
||||
cc[types.size()] = '\0';
|
||||
AddSensor("Ungrouped", cc, component);
|
||||
if (std::find(m_sensors.begin(), m_sensors.end(), component) ==
|
||||
::std::shared_ptr<LiveWindowSendable> component_stl(
|
||||
component, NullDeleter<LiveWindowSendable>());
|
||||
if (std::find(m_sensors.begin(), m_sensors.end(), component_stl) ==
|
||||
m_sensors.end())
|
||||
m_sensors.push_back(component);
|
||||
m_sensors.push_back(component_stl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +120,8 @@ void LiveWindow::AddActuator(std::string type, int channel,
|
||||
auto cc = new char[types.size() + 1];
|
||||
types.copy(cc, types.size());
|
||||
cc[types.size()] = '\0';
|
||||
AddActuator("Ungrouped", cc, component);
|
||||
AddActuator("Ungrouped", cc, ::std::shared_ptr<LiveWindowSendable>(
|
||||
component, [](LiveWindowSendable *) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +135,8 @@ void LiveWindow::AddActuator(std::string type, int module, int channel,
|
||||
auto cc = new char[types.size() + 1];
|
||||
types.copy(cc, types.size());
|
||||
cc[types.size()] = '\0';
|
||||
AddActuator("Ungrouped", cc, component);
|
||||
AddActuator("Ungrouped", cc, ::std::shared_ptr<LiveWindowSendable>(
|
||||
component, [](LiveWindowSendable *) {}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,25 +162,21 @@ void LiveWindow::Run() {
|
||||
|
||||
/**
|
||||
* Initialize all the LiveWindow elements the first time we enter LiveWindow
|
||||
* mode.
|
||||
* By holding off creating the NetworkTable entries, it allows them to be
|
||||
* redefined
|
||||
* before the first time in LiveWindow mode. This allows default sensor and
|
||||
* actuator
|
||||
* values to be created that are replaced with the custom names from users
|
||||
* calling
|
||||
* addActuator and addSensor.
|
||||
* mode. By holding off creating the NetworkTable entries, it allows them to be
|
||||
* redefined before the first time in LiveWindow mode. This allows default
|
||||
* sensor and actuator values to be created that are replaced with the custom
|
||||
* names from users calling addActuator and addSensor.
|
||||
*/
|
||||
void LiveWindow::InitializeLiveWindowComponents() {
|
||||
for (auto& elem : m_components) {
|
||||
LiveWindowSendable *component = elem.first;
|
||||
::std::shared_ptr<LiveWindowSendable> component = elem.first;
|
||||
LiveWindowComponent c = elem.second;
|
||||
std::string subsystem = c.subsystem;
|
||||
std::string name = c.name;
|
||||
m_liveWindowTable->GetSubTable(subsystem)
|
||||
->PutString("~TYPE~", "LW Subsystem");
|
||||
ITable *table =
|
||||
m_liveWindowTable->GetSubTable(subsystem)->GetSubTable(name);
|
||||
::std::shared_ptr<ITable> table(
|
||||
m_liveWindowTable->GetSubTable(subsystem)->GetSubTable(name));
|
||||
table->PutString("~TYPE~", component->GetSmartDashboardType());
|
||||
table->PutString("Name", name);
|
||||
table->PutString("Subsystem", subsystem);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "LiveWindow/LiveWindowStatusListener.h"
|
||||
#include "Commands/Scheduler.h"
|
||||
|
||||
void LiveWindowStatusListener::ValueChanged(ITable* source,
|
||||
void LiveWindowStatusListener::ValueChanged(::std::shared_ptr<ITable> source,
|
||||
const std::string& key,
|
||||
EntryValue value, bool isNew) {}
|
||||
|
||||
@@ -20,11 +20,7 @@ priority_recursive_mutex Resource::m_createLock;
|
||||
*/
|
||||
Resource::Resource(uint32_t elements) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
m_size = elements;
|
||||
m_isAllocated = new bool[m_size];
|
||||
for (uint32_t i = 0; i < m_size; i++) {
|
||||
m_isAllocated[i] = false;
|
||||
}
|
||||
m_isAllocated = ::std::vector<bool>(elements, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,21 +33,14 @@ Resource::Resource(uint32_t elements) {
|
||||
* track, that is, it will allocate resource numbers in the range
|
||||
* [0 .. elements - 1].
|
||||
*/
|
||||
/*static*/ void Resource::CreateResourceObject(Resource **r,
|
||||
/*static*/ void Resource::CreateResourceObject(::std::unique_ptr<Resource>& r,
|
||||
uint32_t elements) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_createLock);
|
||||
if (*r == nullptr) {
|
||||
*r = new Resource(elements);
|
||||
if (!r) {
|
||||
r = std::make_unique<Resource>(elements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the allocated array or resources.
|
||||
* This happens when the module is unloaded (provided it was statically
|
||||
* allocated).
|
||||
*/
|
||||
Resource::~Resource() { delete[] m_isAllocated; }
|
||||
|
||||
/**
|
||||
* Allocate a resource.
|
||||
* When a resource is requested, mark it allocated. In this case, a free
|
||||
@@ -60,7 +49,7 @@ Resource::~Resource() { delete[] m_isAllocated; }
|
||||
*/
|
||||
uint32_t Resource::Allocate(const char *resourceDesc) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
for (uint32_t i = 0; i < m_size; i++) {
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
m_isAllocated[i] = true;
|
||||
return i;
|
||||
@@ -78,7 +67,7 @@ uint32_t Resource::Allocate(const char *resourceDesc) {
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index >= m_size) {
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return ~0ul;
|
||||
}
|
||||
@@ -100,7 +89,7 @@ uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc) {
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index == ~0ul) return;
|
||||
if (index >= m_size) {
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
#include "RobotState.h"
|
||||
|
||||
RobotStateInterface* RobotState::impl = nullptr;
|
||||
#include "Base.h"
|
||||
|
||||
void RobotState::SetImplementation(RobotStateInterface* i) { impl = i; }
|
||||
::std::shared_ptr<RobotStateInterface> RobotState::impl = nullptr;
|
||||
|
||||
void RobotState::SetImplementation(RobotStateInterface& i) {
|
||||
impl = ::std::shared_ptr<RobotStateInterface>(
|
||||
&i, NullDeleter<RobotStateInterface>());
|
||||
}
|
||||
|
||||
void RobotState::SetImplementation(
|
||||
::std::shared_ptr<RobotStateInterface> i) {
|
||||
impl = i;
|
||||
}
|
||||
|
||||
bool RobotState::IsDisabled() {
|
||||
if (impl != nullptr) {
|
||||
|
||||
@@ -53,7 +53,7 @@ void *SendableChooser::GetSelected() {
|
||||
return m_choices[selected];
|
||||
}
|
||||
|
||||
void SendableChooser::InitTable(ITable *subtable) {
|
||||
void SendableChooser::InitTable(::std::shared_ptr<ITable> subtable) {
|
||||
StringArray keys;
|
||||
m_table = subtable;
|
||||
if (m_table != nullptr) {
|
||||
@@ -66,7 +66,7 @@ void SendableChooser::InitTable(ITable *subtable) {
|
||||
}
|
||||
}
|
||||
|
||||
ITable *SendableChooser::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> SendableChooser::GetTable() const { return m_table; }
|
||||
|
||||
std::string SendableChooser::GetSmartDashboardType() const {
|
||||
return "String Chooser";
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
#include "networktables/NetworkTable.h"
|
||||
#include "HLUsageReporting.h"
|
||||
|
||||
ITable *SmartDashboard::m_table = nullptr;
|
||||
std::map<ITable *, Sendable *> SmartDashboard::m_tablesToData;
|
||||
::std::shared_ptr<ITable> SmartDashboard::m_table = nullptr;
|
||||
std::map<::std::shared_ptr<ITable> , Sendable *> SmartDashboard::m_tablesToData;
|
||||
|
||||
void SmartDashboard::init() {
|
||||
m_table = NetworkTable::GetTable("SmartDashboard");
|
||||
m_table.reset(NetworkTable::GetTable("SmartDashboard"));
|
||||
|
||||
HLUsageReporting::ReportSmartDashboard();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ void SmartDashboard::PutData(std::string key, Sendable *data) {
|
||||
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
||||
return;
|
||||
}
|
||||
ITable *dataTable = m_table->GetSubTable(key);
|
||||
::std::shared_ptr<ITable> dataTable(m_table->GetSubTable(key));
|
||||
dataTable->PutString("~TYPE~", data->GetSmartDashboardType());
|
||||
data->InitTable(dataTable);
|
||||
m_tablesToData[dataTable] = data;
|
||||
@@ -63,7 +63,7 @@ void SmartDashboard::PutData(NamedSendable *value) {
|
||||
* @return the value
|
||||
*/
|
||||
Sendable *SmartDashboard::GetData(std::string key) {
|
||||
ITable *subtable = m_table->GetSubTable(key);
|
||||
::std::shared_ptr<ITable> subtable(m_table->GetSubTable(key));
|
||||
Sendable *data = m_tablesToData[subtable];
|
||||
if (data == nullptr) {
|
||||
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key.c_str());
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "I2C.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* ADXL345 Accelerometer on I2C.
|
||||
@@ -63,12 +64,12 @@ class ADXL345_I2C : public Accelerometer,
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void InitTable(ITable *subtable) override;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual ITable *GetTable() const override;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const override;
|
||||
virtual void StartLiveWindowMode() override {}
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
private:
|
||||
ITable *m_table;
|
||||
::std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "SPI.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DigitalInput;
|
||||
class DigitalOutput;
|
||||
|
||||
@@ -54,7 +56,7 @@ class ADXL345_SPI : public Accelerometer,
|
||||
|
||||
public:
|
||||
ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
|
||||
virtual ~ADXL345_SPI();
|
||||
virtual ~ADXL345_SPI() = default;
|
||||
|
||||
// Accelerometer interface
|
||||
virtual void SetRange(Range range) override;
|
||||
@@ -66,18 +68,18 @@ class ADXL345_SPI : public Accelerometer,
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void InitTable(ITable* subtable) override;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual ITable* GetTable() const override;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const override;
|
||||
virtual void StartLiveWindowMode() override {}
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
protected:
|
||||
void Init(Range range);
|
||||
|
||||
SPI* m_spi;
|
||||
std::unique_ptr<SPI> m_spi;
|
||||
SPI::Port m_port;
|
||||
|
||||
private:
|
||||
ITable* m_table;
|
||||
::std::shared_ptr<ITable> m_table;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Handle operation of an analog accelerometer.
|
||||
* The accelerometer reads acceleration directly through the sensor. Many
|
||||
@@ -24,8 +26,14 @@ class AnalogAccelerometer : public SensorBase,
|
||||
public LiveWindowSendable {
|
||||
public:
|
||||
explicit AnalogAccelerometer(int32_t channel);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct an "
|
||||
"AnalogAccelerometer with its own AnalogInput, then call the "
|
||||
"AnalogAccelerometer(int channel). If you want to keep your own copy of "
|
||||
"the AnalogInput, use std::shared_ptr.")]]
|
||||
explicit AnalogAccelerometer(AnalogInput *channel);
|
||||
virtual ~AnalogAccelerometer();
|
||||
explicit AnalogAccelerometer(::std::shared_ptr<AnalogInput> channel);
|
||||
virtual ~AnalogAccelerometer() = default;
|
||||
|
||||
float GetAcceleration() const;
|
||||
void SetSensitivity(float sensitivity);
|
||||
@@ -36,16 +44,16 @@ class AnalogAccelerometer : public SensorBase,
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
void InitAccelerometer();
|
||||
|
||||
AnalogInput *m_AnalogInput;
|
||||
::std::shared_ptr<AnalogInput> m_analogInput;
|
||||
float m_voltsPerG = 1.0;
|
||||
float m_zeroGVoltage = 2.5;
|
||||
bool m_allocatedChannel;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Analog input class.
|
||||
*
|
||||
@@ -60,7 +62,7 @@ class AnalogInput : public SensorBase,
|
||||
void SetAccumulatorDeadband(int32_t deadband);
|
||||
int64_t GetAccumulatorValue() const;
|
||||
uint32_t GetAccumulatorCount() const;
|
||||
void GetAccumulatorOutput(int64_t *value, uint32_t *count) const;
|
||||
void GetAccumulatorOutput(int64_t &value, uint32_t &count) const;
|
||||
|
||||
static void SetSampleRate(float samplesPerSecond);
|
||||
static float GetSampleRate();
|
||||
@@ -71,13 +73,14 @@ class AnalogInput : public SensorBase,
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
//TODO: Adjust HAL to avoid use of raw pointers.
|
||||
void *m_port;
|
||||
int64_t m_accumulatorOffset;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "SensorBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* MXP analog output class.
|
||||
@@ -26,12 +27,12 @@ class AnalogOutput : public SensorBase, public LiveWindowSendable {
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
protected:
|
||||
uint32_t m_channel;
|
||||
void *m_port;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
#include "AnalogInput.h"
|
||||
#include "interfaces/Potentiometer.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class for reading analog potentiometers. Analog potentiometers read
|
||||
* in an analog voltage that corresponds to a position. The position is
|
||||
@@ -35,13 +36,18 @@ class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
explicit AnalogPotentiometer(int channel, double fullRange = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct an "
|
||||
"AnalogPotentiometer with its own AnalogInput, then call the "
|
||||
"AnalogPotentiometer(int channel). If you want to keep your own copy of "
|
||||
"the AnalogInput, use std::shared_ptr.")]]
|
||||
explicit AnalogPotentiometer(AnalogInput *input, double fullRange = 1.0,
|
||||
double offset = 0.0);
|
||||
|
||||
explicit AnalogPotentiometer(AnalogInput &input, double fullRange = 1.0,
|
||||
double offset = 0.0);
|
||||
explicit AnalogPotentiometer(::std::shared_ptr<AnalogInput> input,
|
||||
double fullRange = 1.0, double offset = 0.0);
|
||||
|
||||
virtual ~AnalogPotentiometer();
|
||||
virtual ~AnalogPotentiometer() = default;
|
||||
|
||||
/**
|
||||
* Get the current reading of the potentiomer.
|
||||
@@ -61,9 +67,9 @@ class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
* Live Window code, only does anything if live window is activated.
|
||||
*/
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void InitTable(ITable *subtable) override;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual ITable *GetTable() const override;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
/**
|
||||
* AnalogPotentiometers don't have to do anything special when entering the
|
||||
@@ -78,13 +84,8 @@ class AnalogPotentiometer : public Potentiometer, public LiveWindowSendable {
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
private:
|
||||
::std::shared_ptr<AnalogInput> m_analog_input;
|
||||
double m_fullRange, m_offset;
|
||||
AnalogInput *m_analog_input;
|
||||
ITable *m_table;
|
||||
::std::shared_ptr<ITable> m_table;
|
||||
bool m_init_analog_input;
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*/
|
||||
void initPot(AnalogInput *input, double fullRange, double offset);
|
||||
};
|
||||
|
||||
@@ -24,10 +24,10 @@ class AnalogTrigger : public SensorBase {
|
||||
void SetLimitsRaw(int32_t lower, int32_t upper);
|
||||
void SetAveraged(bool useAveragedValue);
|
||||
void SetFiltered(bool useFilteredValue);
|
||||
uint32_t GetIndex();
|
||||
uint32_t GetIndex() const;
|
||||
bool GetInWindow();
|
||||
bool GetTriggerState();
|
||||
AnalogTriggerOutput *CreateOutput(AnalogTriggerType type);
|
||||
::std::shared_ptr<AnalogTriggerOutput> CreateOutput(AnalogTriggerType type) const;
|
||||
|
||||
private:
|
||||
uint8_t m_index;
|
||||
|
||||
@@ -66,9 +66,12 @@ class AnalogTriggerOutput : public DigitalSource {
|
||||
virtual bool GetAnalogTriggerForRouting() const override;
|
||||
|
||||
protected:
|
||||
AnalogTriggerOutput(AnalogTrigger *trigger, AnalogTriggerType outputType);
|
||||
AnalogTriggerOutput(const AnalogTrigger &trigger, AnalogTriggerType outputType);
|
||||
|
||||
private:
|
||||
AnalogTrigger *m_trigger;
|
||||
// Uses reference rather than smart pointer because a user can not construct
|
||||
// an AnalogTriggerOutput themselves and because the AnalogTriggerOutput
|
||||
// should always be in scope at the same time as an AnalogTrigger.
|
||||
const AnalogTrigger &m_trigger;
|
||||
AnalogTriggerType m_outputType;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "SensorBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Built-in accelerometer.
|
||||
*
|
||||
@@ -28,12 +30,12 @@ class BuiltInAccelerometer : public Accelerometer,
|
||||
virtual double GetZ() override;
|
||||
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
virtual void InitTable(ITable *subtable) override;
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable) override;
|
||||
virtual void UpdateTable() override;
|
||||
virtual ITable *GetTable() const override;
|
||||
virtual ::std::shared_ptr<ITable> GetTable() const override;
|
||||
virtual void StartLiveWindowMode() override {}
|
||||
virtual void StopLiveWindowMode() override {}
|
||||
|
||||
private:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
|
||||
#include <atomic>
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* Luminary Micro / Vex Robotics Jaguar Speed Control
|
||||
@@ -132,7 +134,7 @@ class CANJaguar : public MotorSafety,
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(char *desc) const override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
uint8_t GetDeviceID() const;
|
||||
|
||||
// SpeedController overrides
|
||||
@@ -228,18 +230,18 @@ class CANJaguar : public MotorSafety,
|
||||
|
||||
void verify();
|
||||
|
||||
MotorSafetyHelper *m_safetyHelper = nullptr;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
|
||||
void ValueChanged(ITable *source, const std::string &key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key, EntryValue value,
|
||||
bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
|
||||
private:
|
||||
void InitCANJaguar();
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class CanTalonSRX;
|
||||
|
||||
/**
|
||||
@@ -42,7 +44,7 @@ class CANTalon : public MotorSafety,
|
||||
};
|
||||
explicit CANTalon(int deviceNumber);
|
||||
explicit CANTalon(int deviceNumber, int controlPeriodMs);
|
||||
virtual ~CANTalon();
|
||||
virtual ~CANTalon() = default;
|
||||
|
||||
// PIDOutput interface
|
||||
virtual void PIDWrite(float output) override;
|
||||
@@ -57,7 +59,7 @@ class CANTalon : public MotorSafety,
|
||||
virtual void StopMotor() override;
|
||||
virtual void SetSafetyEnabled(bool enabled) override;
|
||||
virtual bool IsSafetyEnabled() const override;
|
||||
virtual void GetDescription(char *desc) const override;
|
||||
virtual void GetDescription(std::ostringstream& desc) const override;
|
||||
|
||||
// CANSpeedController interface
|
||||
virtual float Get() const override;
|
||||
@@ -155,14 +157,14 @@ class CANTalon : public MotorSafety,
|
||||
double GetSetpoint() const override;
|
||||
|
||||
// LiveWindow stuff.
|
||||
void ValueChanged(ITable *source, const std::string &key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key, EntryValue value,
|
||||
bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
// SpeedController overrides
|
||||
virtual void SetInverted(bool isInverted) override;
|
||||
@@ -181,10 +183,10 @@ class CANTalon : public MotorSafety,
|
||||
};
|
||||
|
||||
int m_deviceNumber;
|
||||
CanTalonSRX *m_impl;
|
||||
MotorSafetyHelper *m_safetyHelper;
|
||||
std::unique_ptr<CanTalonSRX> m_impl;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
int m_profile = 0; // Profile from CANTalon to use. Set to zero until we can
|
||||
// actually test this.
|
||||
// actually test this.
|
||||
|
||||
bool m_controlEnabled = true;
|
||||
ControlMode m_controlMode = kPercentVbus;
|
||||
@@ -201,6 +203,6 @@ class CANTalon : public MotorSafety,
|
||||
void ApplyControlMode(CANSpeedController::ControlMode mode);
|
||||
|
||||
// LiveWindow stuff.
|
||||
ITable *m_table;
|
||||
::std::shared_ptr<ITable> m_table;
|
||||
bool m_isInverted;
|
||||
};
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "tables/ITableListener.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* PCM compressor
|
||||
*/
|
||||
@@ -46,9 +48,9 @@ class Compressor : public SensorBase,
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void ValueChanged(ITable *source, const std::string &key, EntryValue value,
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key, EntryValue value,
|
||||
bool isNew) override;
|
||||
|
||||
protected:
|
||||
@@ -57,7 +59,7 @@ class Compressor : public SensorBase,
|
||||
private:
|
||||
void SetCompressor(bool on);
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
#endif /* Compressor_H_ */
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "SensorBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.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
|
||||
@@ -29,28 +31,52 @@ class Counter : public SensorBase,
|
||||
public:
|
||||
explicit Counter(Mode mode = kTwoPulse);
|
||||
explicit Counter(int32_t channel);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct a Counter "
|
||||
"with its own DigitalSource, then call the Counter(int channel). If you "
|
||||
"want to keep your own copy of the DigitalSource, use "
|
||||
"std::shared_ptr.")]]
|
||||
explicit Counter(DigitalSource *source);
|
||||
explicit Counter(DigitalSource &source);
|
||||
explicit Counter(::std::shared_ptr<DigitalSource> source);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated. Use pass-by-reference instead.")]]
|
||||
explicit Counter(AnalogTrigger *trigger);
|
||||
explicit Counter(AnalogTrigger &trigger);
|
||||
explicit Counter(const AnalogTrigger &trigger);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to use shared_ptr instead.")]]
|
||||
Counter(EncodingType encodingType, DigitalSource *upSource,
|
||||
DigitalSource *downSource, bool inverted);
|
||||
Counter(EncodingType encodingType, ::std::shared_ptr<DigitalSource> upSource,
|
||||
::std::shared_ptr<DigitalSource> downSource, bool inverted);
|
||||
virtual ~Counter();
|
||||
|
||||
void SetUpSource(int32_t channel);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to call either SetUpSource(int) or "
|
||||
"SetUpSource(shared_ptr).")]]
|
||||
void SetUpSource(AnalogTrigger *analogTrigger, AnalogTriggerType triggerType);
|
||||
void SetUpSource(AnalogTrigger &analogTrigger, AnalogTriggerType triggerType);
|
||||
void SetUpSource(::std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType);
|
||||
[[deprecated("Raw pointers are deprecated. Use std::shared_ptr instead.")]]
|
||||
void SetUpSource(DigitalSource *source);
|
||||
void SetUpSource(::std::shared_ptr<DigitalSource> source);
|
||||
[[deprecated("References are deprecated. Use std::shared_ptr instead.")]]
|
||||
void SetUpSource(DigitalSource &source);
|
||||
void SetUpSourceEdge(bool risingEdge, bool fallingEdge);
|
||||
void ClearUpSource();
|
||||
|
||||
void SetDownSource(int32_t channel);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to call either SetDownSource(int) "
|
||||
"or SetDownSource(shared_ptr).")]]
|
||||
void SetDownSource(AnalogTrigger *analogTrigger,
|
||||
AnalogTriggerType triggerType);
|
||||
void SetDownSource(AnalogTrigger &analogTrigger,
|
||||
void SetDownSource(::std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType);
|
||||
[[deprecated("Raw pointers are deprecated. Use std::shared_ptr instead.")]]
|
||||
void SetDownSource(DigitalSource *source);
|
||||
void SetDownSource(::std::shared_ptr<DigitalSource> source);
|
||||
[[deprecated("References are deprecated. Use std::shared_ptr instead.")]]
|
||||
void SetDownSource(DigitalSource &source);
|
||||
void SetDownSourceEdge(bool risingEdge, bool fallingEdge);
|
||||
void ClearDownSource();
|
||||
@@ -79,17 +105,18 @@ class Counter : public SensorBase,
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
virtual std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
protected:
|
||||
DigitalSource *m_upSource = nullptr; ///< What makes the counter count up.
|
||||
DigitalSource *m_downSource = nullptr; ///< What makes the counter count down.
|
||||
void *m_counter = nullptr; ///< The FPGA counter object.
|
||||
// Makes the counter count up.
|
||||
::std::shared_ptr<DigitalSource> m_upSource;
|
||||
// Makes the counter count down.
|
||||
::std::shared_ptr<DigitalSource> m_downSource;
|
||||
// The FPGA counter object
|
||||
void *m_counter = nullptr; ///< The FPGA counter object.
|
||||
private:
|
||||
bool m_allocatedUpSource = false; ///< Was the upSource allocated locally?
|
||||
bool m_allocatedDownSource = false; ///< Was the downSource allocated locally?
|
||||
uint32_t m_index = 0; ///< The index of this counter.
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "DigitalSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class to read a digital input.
|
||||
* This class will read digital inputs and return the current value on the
|
||||
@@ -35,11 +37,11 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(ITable *subTable);
|
||||
ITable *GetTable() const;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable);
|
||||
::std::shared_ptr<ITable> GetTable() const;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class to write to digital outputs.
|
||||
* Write values to the digital output channels. Other devices implemented
|
||||
@@ -36,18 +38,18 @@ class DigitalOutput : public DigitalSource,
|
||||
virtual uint32_t GetModuleForRouting() const;
|
||||
virtual bool GetAnalogTriggerForRouting() const;
|
||||
|
||||
virtual void ValueChanged(ITable *source, const std::string &key,
|
||||
virtual void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew);
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(ITable *subTable);
|
||||
ITable *GetTable() const;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable);
|
||||
::std::shared_ptr<ITable> GetTable() const;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
void *m_pwmGenerator;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* DoubleSolenoid class for running 2 channels of high voltage Digital Output
|
||||
* (PCM).
|
||||
@@ -32,14 +34,14 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
bool IsFwdSolenoidBlackListed() const;
|
||||
bool IsRevSolenoidBlackListed() const;
|
||||
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key, EntryValue value,
|
||||
bool isNew);
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(ITable* subTable);
|
||||
ITable* GetTable() const;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable);
|
||||
::std::shared_ptr<ITable> GetTable() const;
|
||||
|
||||
private:
|
||||
uint32_t m_forwardChannel; ///< The forward channel on the module to control.
|
||||
@@ -47,5 +49,5 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
uint8_t m_forwardMask; ///< The mask for the forward channel.
|
||||
uint8_t m_reverseMask; ///< The mask for the reverse channel.
|
||||
|
||||
ITable* m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
|
||||
virtual ~DriverStation();
|
||||
static DriverStation *GetInstance();
|
||||
static DriverStation &GetInstance();
|
||||
static void ReportError(std::string error);
|
||||
|
||||
static const uint32_t kJoystickPorts = 6;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class DigitalSource;
|
||||
|
||||
/**
|
||||
@@ -47,8 +49,19 @@ class Encoder : public SensorBase,
|
||||
|
||||
Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection = false,
|
||||
EncodingType encodingType = k4X);
|
||||
Encoder(::std::shared_ptr<DigitalSource> aSource,
|
||||
::std::shared_ptr<DigitalSource> bSource,
|
||||
bool reverseDirection = false, EncodingType encodingType = k4X);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you wish to construct your own copy of "
|
||||
"the DigitalSource and pass it to the constructor, use an "
|
||||
"std::shared_ptr instead.")]]
|
||||
Encoder(DigitalSource *aSource, DigitalSource *bSource,
|
||||
bool reverseDirection = false, EncodingType encodingType = k4X);
|
||||
[[deprecated(
|
||||
"References are deprecated; if you wish to construct your own copy of "
|
||||
"the DigitalSource and pass it to the constructor, use an "
|
||||
"std::shared_ptr instead.")]]
|
||||
Encoder(DigitalSource &aSource, DigitalSource &bSource,
|
||||
bool reverseDirection = false, EncodingType encodingType = k4X);
|
||||
virtual ~Encoder();
|
||||
@@ -74,17 +87,18 @@ class Encoder : public SensorBase,
|
||||
double PIDGet() const override;
|
||||
|
||||
void SetIndexSource(uint32_t channel, IndexingType type = kResetOnRisingEdge);
|
||||
[[deprecated("Raw pointers are deprecated; use references instead.")]]
|
||||
void SetIndexSource(DigitalSource *source,
|
||||
IndexingType type = kResetOnRisingEdge);
|
||||
void SetIndexSource(DigitalSource &source,
|
||||
void SetIndexSource(const DigitalSource &source,
|
||||
IndexingType type = kResetOnRisingEdge);
|
||||
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
int32_t GetFPGAIndex() const { return m_index; }
|
||||
|
||||
@@ -92,18 +106,17 @@ class Encoder : public SensorBase,
|
||||
void InitEncoder(bool _reverseDirection, EncodingType encodingType);
|
||||
double DecodingScaleFactor() const;
|
||||
|
||||
DigitalSource *m_aSource; // the A phase of the quad encoder
|
||||
DigitalSource *m_bSource; // the B phase of the quad encoder
|
||||
bool m_allocatedASource; // was the A source allocated locally?
|
||||
bool m_allocatedBSource; // was the B source allocated locally?
|
||||
::std::shared_ptr<DigitalSource> m_aSource; // the A phase of the quad encoder
|
||||
::std::shared_ptr<DigitalSource> m_bSource; // the B phase of the quad encoder
|
||||
void *m_encoder = nullptr;
|
||||
int32_t m_index = 0; // The encoder's FPGA index.
|
||||
double m_distancePerPulse = 1.0; // distance of travel for each encoder tick
|
||||
Counter *m_counter = nullptr; // Counter object for 1x and 2x encoding
|
||||
::std::unique_ptr<Counter> m_counter =
|
||||
nullptr; // Counter object for 1x and 2x encoding
|
||||
EncodingType m_encodingType; // Encoding type
|
||||
int32_t m_encodingScale; // 1x, 2x, or 4x, per the encodingType
|
||||
PIDSourceParameter
|
||||
m_pidSource = kDistance; // Encoder parameter that sources a PID controller
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Counter.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Alias for counter class.
|
||||
@@ -22,7 +23,8 @@ class GearTooth : public Counter {
|
||||
static constexpr double kGearToothThreshold = 55e-6;
|
||||
GearTooth(uint32_t channel, bool directionSensitive = false);
|
||||
GearTooth(DigitalSource *source, bool directionSensitive = false);
|
||||
GearTooth(DigitalSource &source, bool directionSensitive = false);
|
||||
GearTooth(::std::shared_ptr<DigitalSource> source,
|
||||
bool directionSensitive = false);
|
||||
virtual ~GearTooth() = default;
|
||||
void EnableDirectionSensing(bool directionSensitive);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class AnalogInput;
|
||||
|
||||
/**
|
||||
@@ -37,9 +39,12 @@ class Gyro : public SensorBase, public PIDSource, public LiveWindowSendable {
|
||||
static constexpr float kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
|
||||
explicit Gyro(int32_t channel);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; consider calling the Gyro constructor with "
|
||||
"a channel number or passing a shared_ptr instead.")]]
|
||||
explicit Gyro(AnalogInput *channel);
|
||||
explicit Gyro(AnalogInput &channel);
|
||||
virtual ~Gyro();
|
||||
explicit Gyro(::std::shared_ptr<AnalogInput> channel);
|
||||
virtual ~Gyro() = default;
|
||||
virtual float GetAngle() const;
|
||||
virtual double GetRate() const;
|
||||
void SetSensitivity(float voltsPerDegreePerSecond);
|
||||
@@ -55,18 +60,17 @@ class Gyro : public SensorBase, public PIDSource, public LiveWindowSendable {
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
protected:
|
||||
AnalogInput *m_analog;
|
||||
::std::shared_ptr<AnalogInput> m_analog;
|
||||
|
||||
private:
|
||||
float m_voltsPerDegreePerSecond;
|
||||
float m_offset;
|
||||
bool m_channelAllocated;
|
||||
uint32_t m_center;
|
||||
PIDSourceParameter m_pidSource;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "SensorBase.h"
|
||||
#include "Resource.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class InterruptableSensorBase : public SensorBase {
|
||||
public:
|
||||
enum WaitResult {
|
||||
@@ -46,5 +48,5 @@ class InterruptableSensorBase : public SensorBase {
|
||||
uint32_t m_interruptIndex;
|
||||
void AllocateInterrupts(bool watcher);
|
||||
|
||||
static Resource *m_interrupts;
|
||||
static ::std::unique_ptr<Resource> m_interrupts;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#define JOYSTICK_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "GenericHID.h"
|
||||
#include "ErrorBase.h"
|
||||
|
||||
@@ -62,7 +64,7 @@ class Joystick : public GenericHID, public ErrorBase {
|
||||
} HIDType;
|
||||
explicit Joystick(uint32_t port);
|
||||
Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes);
|
||||
virtual ~Joystick();
|
||||
virtual ~Joystick() = default;
|
||||
|
||||
uint32_t GetAxisChannel(AxisType axis) const;
|
||||
void SetAxisChannel(AxisType axis, uint32_t channel);
|
||||
@@ -103,10 +105,10 @@ class Joystick : public GenericHID, public ErrorBase {
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(Joystick);
|
||||
|
||||
DriverStation *m_ds = nullptr;
|
||||
DriverStation &m_ds;
|
||||
uint32_t m_port;
|
||||
uint32_t *m_axes = nullptr;
|
||||
uint32_t *m_buttons = nullptr;
|
||||
::std::vector<uint32_t> m_axes;
|
||||
::std::vector<uint32_t> m_buttons;
|
||||
uint32_t m_outputs = 0;
|
||||
uint16_t m_leftRumble = 0;
|
||||
uint16_t m_rightRumble = 0;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#define DEFAULT_SAFETY_EXPIRATION 0.1
|
||||
|
||||
#include <sstream>
|
||||
|
||||
class MotorSafety {
|
||||
public:
|
||||
virtual void SetExpiration(float timeout) = 0;
|
||||
@@ -16,5 +18,5 @@ class MotorSafety {
|
||||
virtual void StopMotor() = 0;
|
||||
virtual void SetSafetyEnabled(bool enabled) = 0;
|
||||
virtual bool IsSafetyEnabled() const = 0;
|
||||
virtual void GetDescription(char *desc) const = 0;
|
||||
virtual void GetDescription(std::ostringstream& desc) const = 0;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "ErrorBase.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
class MotorSafety;
|
||||
|
||||
class MotorSafetyHelper : public ErrorBase {
|
||||
@@ -31,10 +33,8 @@ class MotorSafetyHelper : public ErrorBase {
|
||||
mutable priority_recursive_mutex
|
||||
m_syncMutex; // protect accesses to the state for this object
|
||||
MotorSafety *m_safeObject; // the object that is using the helper
|
||||
MotorSafetyHelper *
|
||||
m_nextHelper; // next object in the list of MotorSafetyHelpers
|
||||
static MotorSafetyHelper *
|
||||
m_headHelper; // the head of the list of MotorSafetyHelper objects
|
||||
// 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
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class implements the PWM generation in the FPGA.
|
||||
*
|
||||
@@ -97,16 +99,16 @@ class PWM : public SensorBase,
|
||||
int32_t m_deadbandMinPwm;
|
||||
int32_t m_minPwm;
|
||||
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key, EntryValue value,
|
||||
bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable* subTable) override;
|
||||
ITable* GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
ITable* m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "SensorBase.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class for getting voltage, current, temperature, power and energy from the
|
||||
* CAN PDP.
|
||||
@@ -36,11 +38,11 @@ class PowerDistributionPanel : public SensorBase, public LiveWindowSendable {
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
uint8_t m_module;
|
||||
};
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class Preferences : public ErrorBase, public ITableListener {
|
||||
bool ContainsKey(const char *key);
|
||||
void Remove(const char *key);
|
||||
|
||||
void ValueChanged(ITable *source, const std::string &key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string &key, EntryValue value,
|
||||
bool isNew) override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITable.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Class for Spike style relay outputs.
|
||||
* Relays are intended to be connected to spikes or similar relays. The relay
|
||||
@@ -38,16 +40,16 @@ class Relay : public SensorBase,
|
||||
void Set(Value value);
|
||||
Value Get() const;
|
||||
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key, EntryValue value,
|
||||
bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable* subTable) override;
|
||||
ITable* GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
ITable* m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
|
||||
private:
|
||||
uint32_t m_channel;
|
||||
|
||||
@@ -62,7 +62,7 @@ class RobotBase {
|
||||
virtual void Prestart();
|
||||
|
||||
Task *m_task = nullptr;
|
||||
DriverStation *m_ds = nullptr;
|
||||
DriverStation &m_ds;
|
||||
|
||||
private:
|
||||
static RobotBase *m_instance;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "MotorSafety.h"
|
||||
#include "MotorSafetyHelper.h"
|
||||
@@ -42,13 +44,23 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel);
|
||||
RobotDrive(uint32_t frontLeftMotorChannel, uint32_t rearLeftMotorChannel,
|
||||
uint32_t frontRightMotorChannel, uint32_t rearRightMotorChannel);
|
||||
[[deprecated("Raw pointers are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor);
|
||||
[[deprecated("References are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor);
|
||||
RobotDrive(::std::shared_ptr<SpeedController> leftMotor,
|
||||
::std::shared_ptr<SpeedController> rightMotor);
|
||||
[[deprecated("Raw pointers are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
|
||||
SpeedController *frontRightMotor, SpeedController *rearRightMotor);
|
||||
[[deprecated("References are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
|
||||
SpeedController &frontRightMotor, SpeedController &rearRightMotor);
|
||||
virtual ~RobotDrive();
|
||||
RobotDrive(::std::shared_ptr<SpeedController> frontLeftMotor,
|
||||
::std::shared_ptr<SpeedController> rearLeftMotor,
|
||||
::std::shared_ptr<SpeedController> frontRightMotor,
|
||||
::std::shared_ptr<SpeedController> rearRightMotor);
|
||||
virtual ~RobotDrive() = default;
|
||||
|
||||
void Drive(float outputMagnitude, float curve);
|
||||
void TankDrive(GenericHID *leftStick, GenericHID *rightStick,
|
||||
@@ -88,7 +100,7 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
void StopMotor() override;
|
||||
bool IsSafetyEnabled() const override;
|
||||
void SetSafetyEnabled(bool enabled) override;
|
||||
void GetDescription(char *desc) const override;
|
||||
void GetDescription(std::ostringstream& desc) const override;
|
||||
|
||||
protected:
|
||||
void InitRobotDrive();
|
||||
@@ -99,12 +111,11 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
static const int32_t kMaxNumberOfMotors = 4;
|
||||
float m_sensitivity = 0.5;
|
||||
double m_maxOutput = 1.0;
|
||||
bool m_deleteSpeedControllers;
|
||||
SpeedController *m_frontLeftMotor = nullptr;
|
||||
SpeedController *m_frontRightMotor = nullptr;
|
||||
SpeedController *m_rearLeftMotor = nullptr;
|
||||
SpeedController *m_rearRightMotor = nullptr;
|
||||
MotorSafetyHelper *m_safetyHelper = nullptr;
|
||||
::std::shared_ptr<SpeedController> m_frontLeftMotor = nullptr;
|
||||
::std::shared_ptr<SpeedController> m_frontRightMotor = nullptr;
|
||||
::std::shared_ptr<SpeedController> m_rearLeftMotor = nullptr;
|
||||
::std::shared_ptr<SpeedController> m_rearRightMotor = nullptr;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
uint8_t m_syncGroup = 0;
|
||||
|
||||
private:
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
#include "MotorSafety.h"
|
||||
#include "PWM.h"
|
||||
|
||||
class MotorSafetyHelper;
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* A safe version of the PWM class.
|
||||
@@ -23,7 +24,7 @@ class MotorSafetyHelper;
|
||||
class SafePWM : public PWM, public MotorSafety {
|
||||
public:
|
||||
explicit SafePWM(uint32_t channel);
|
||||
~SafePWM();
|
||||
virtual ~SafePWM() = default;
|
||||
|
||||
void SetExpiration(float timeout);
|
||||
float GetExpiration() const;
|
||||
@@ -31,10 +32,10 @@ class SafePWM : public PWM, public MotorSafety {
|
||||
void StopMotor();
|
||||
bool IsSafetyEnabled() const;
|
||||
void SetSafetyEnabled(bool enabled);
|
||||
void GetDescription(char *desc) const;
|
||||
void GetDescription(std::ostringstream& desc) const;
|
||||
|
||||
virtual void SetSpeed(float speed);
|
||||
|
||||
private:
|
||||
MotorSafetyHelper *m_safetyHelper;
|
||||
std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
|
||||
};
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "SafePWM.h"
|
||||
#include "SpeedController.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Standard hobby style servo.
|
||||
*
|
||||
@@ -28,16 +30,16 @@ class Servo : public SafePWM {
|
||||
static float GetMaxAngle() { return kMaxServoAngle; }
|
||||
static float GetMinAngle() { return kMinServoAngle; }
|
||||
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
bool isNew) override;
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) override;
|
||||
void UpdateTable() override;
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable* subTable) override;
|
||||
ITable* GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
ITable* m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
|
||||
private:
|
||||
float GetServoAngleRange() const { return kMaxServoAngle - kMinServoAngle; }
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Solenoid class for running high voltage Digital Output (PCM).
|
||||
*
|
||||
@@ -28,16 +30,16 @@ class Solenoid : public SolenoidBase,
|
||||
virtual bool Get() const;
|
||||
bool IsBlackListed() const;
|
||||
|
||||
void ValueChanged(ITable* source, const std::string& key, EntryValue value,
|
||||
void ValueChanged(::std::shared_ptr<ITable> source, const std::string& key, EntryValue value,
|
||||
bool isNew);
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
void StopLiveWindowMode();
|
||||
std::string GetSmartDashboardType() const;
|
||||
void InitTable(ITable* subTable);
|
||||
ITable* GetTable() const;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable);
|
||||
::std::shared_ptr<ITable> GetTable() const;
|
||||
|
||||
private:
|
||||
uint32_t m_channel; ///< The channel on the module to control.
|
||||
ITable* m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "Port.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* SolenoidBase class is the common base class for the Solenoid and
|
||||
* DoubleSolenoid classes.
|
||||
@@ -33,5 +35,5 @@ class SolenoidBase : public SensorBase {
|
||||
static void* m_ports[m_maxModules][m_maxPorts];
|
||||
uint32_t m_moduleNumber; ///< Slot number where the module is plugged into
|
||||
///the chassis.
|
||||
static Resource* m_allocated;
|
||||
static ::std::unique_ptr<Resource> m_allocated;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "Counter.h"
|
||||
#include "Task.h"
|
||||
#include "PIDSource.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
@@ -14,7 +15,8 @@
|
||||
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
class Counter;
|
||||
#include <memory>
|
||||
|
||||
class DigitalInput;
|
||||
class DigitalOutput;
|
||||
|
||||
@@ -40,10 +42,21 @@ class Ultrasonic : public SensorBase,
|
||||
public:
|
||||
enum DistanceUnit { kInches = 0, kMilliMeters = 1 };
|
||||
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer either specifying the channel "
|
||||
"numbers as integers or passing shared_ptrs.")]]
|
||||
Ultrasonic(DigitalOutput *pingChannel, DigitalInput *echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
|
||||
[[deprecated(
|
||||
"References are deprecated; prefer either specifying the channel numbers "
|
||||
"as integers or passing shared_ptrs.")]]
|
||||
Ultrasonic(DigitalOutput &pingChannel, DigitalInput &echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
|
||||
Ultrasonic(::std::shared_ptr<DigitalOutput> pingChannel,
|
||||
::std::shared_ptr<DigitalInput> echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
Ultrasonic(uint32_t pingChannel, uint32_t echoChannel,
|
||||
DistanceUnit units = kInches);
|
||||
virtual ~Ultrasonic();
|
||||
@@ -64,8 +77,8 @@ class Ultrasonic : public SensorBase,
|
||||
void StartLiveWindowMode() override;
|
||||
void StopLiveWindowMode() override;
|
||||
std::string GetSmartDashboardType() const override;
|
||||
void InitTable(ITable *subTable) override;
|
||||
ITable *GetTable() const override;
|
||||
void InitTable(::std::shared_ptr<ITable> subTable) override;
|
||||
::std::shared_ptr<ITable> GetTable() const override;
|
||||
|
||||
private:
|
||||
void Initialize();
|
||||
@@ -85,13 +98,13 @@ class Ultrasonic : public SensorBase,
|
||||
static std::atomic<bool> m_automaticEnabled; // automatic round robin mode
|
||||
static priority_mutex m_mutex; // synchronize access to the list of sensors
|
||||
|
||||
DigitalInput *m_echoChannel;
|
||||
DigitalOutput *m_pingChannel;
|
||||
::std::shared_ptr<DigitalOutput> m_pingChannel;
|
||||
::std::shared_ptr<DigitalInput> m_echoChannel;
|
||||
bool m_allocatedChannels;
|
||||
bool m_enabled;
|
||||
Counter *m_counter;
|
||||
Counter m_counter;
|
||||
Ultrasonic *m_nextSensor;
|
||||
DistanceUnit m_units;
|
||||
|
||||
ITable *m_table = nullptr;
|
||||
::std::shared_ptr<ITable> m_table = nullptr;
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ ADXL345_I2C::ADXL345_I2C(Port port, Range range) : I2C(port, kAddress) {
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_ADXL345,
|
||||
HALUsageReporting::kADXL345_I2C, 0);
|
||||
LiveWindow::GetInstance()->AddSensor("ADXL345_I2C", port, this);
|
||||
LiveWindow::GetInstance().AddSensor("ADXL345_I2C", port, this);
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
@@ -88,17 +88,15 @@ std::string ADXL345_I2C::GetSmartDashboardType() const {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void ADXL345_I2C::InitTable(ITable *subtable) {
|
||||
void ADXL345_I2C::InitTable(::std::shared_ptr<ITable> subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
void ADXL345_I2C::UpdateTable() {
|
||||
if (m_table != nullptr) {
|
||||
m_table->PutNumber("X", GetX());
|
||||
m_table->PutNumber("Y", GetY());
|
||||
m_table->PutNumber("Z", GetZ());
|
||||
}
|
||||
m_table->PutNumber("X", GetX());
|
||||
m_table->PutNumber("Y", GetY());
|
||||
m_table->PutNumber("Z", GetZ());
|
||||
}
|
||||
|
||||
ITable *ADXL345_I2C::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> ADXL345_I2C::GetTable() const { return m_table; }
|
||||
|
||||
@@ -25,14 +25,14 @@ constexpr double ADXL345_SPI::kGsPerLSB;
|
||||
ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range) {
|
||||
m_port = port;
|
||||
Init(range);
|
||||
LiveWindow::GetInstance()->AddSensor("ADXL345_SPI", port, this);
|
||||
LiveWindow::GetInstance().AddSensor("ADXL345_SPI", port, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal common init function.
|
||||
*/
|
||||
void ADXL345_SPI::Init(Range range) {
|
||||
m_spi = new SPI(m_port);
|
||||
m_spi = std::make_unique<SPI>(m_port);
|
||||
m_spi->SetClockRate(500000);
|
||||
m_spi->SetMSBFirst();
|
||||
m_spi->SetSampleDataOnFalling();
|
||||
@@ -51,14 +51,6 @@ void ADXL345_SPI::Init(Range range) {
|
||||
HALUsageReporting::kADXL345_SPI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
ADXL345_SPI::~ADXL345_SPI() {
|
||||
delete m_spi;
|
||||
m_spi = nullptr;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
void ADXL345_SPI::SetRange(Range range) {
|
||||
uint8_t commands[2];
|
||||
@@ -130,7 +122,7 @@ std::string ADXL345_SPI::GetSmartDashboardType() const {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void ADXL345_SPI::InitTable(ITable* subtable) {
|
||||
void ADXL345_SPI::InitTable(::std::shared_ptr<ITable> subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
@@ -143,4 +135,4 @@ void ADXL345_SPI::UpdateTable() {
|
||||
}
|
||||
}
|
||||
|
||||
ITable* ADXL345_SPI::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> ADXL345_SPI::GetTable() const { return m_table; }
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
void AnalogAccelerometer::InitAccelerometer() {
|
||||
HALReport(HALUsageReporting::kResourceType_Accelerometer,
|
||||
m_AnalogInput->GetChannel());
|
||||
LiveWindow::GetInstance()->AddSensor("Accelerometer",
|
||||
m_AnalogInput->GetChannel(), this);
|
||||
m_analogInput->GetChannel());
|
||||
LiveWindow::GetInstance().AddSensor("Accelerometer",
|
||||
m_analogInput->GetChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,37 +27,41 @@ void AnalogAccelerometer::InitAccelerometer() {
|
||||
* connected to
|
||||
*/
|
||||
AnalogAccelerometer::AnalogAccelerometer(int32_t channel) {
|
||||
m_AnalogInput = new AnalogInput(channel);
|
||||
m_allocatedChannel = true;
|
||||
m_analogInput = ::std::make_shared<AnalogInput>(channel);
|
||||
InitAccelerometer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of Accelerometer from an existing AnalogInput.
|
||||
* Make a new instance of accelerometer given an AnalogInput. This is
|
||||
* particularly
|
||||
* useful if the port is going to be read as an analog channel as well as
|
||||
* through
|
||||
* the Accelerometer class.
|
||||
* particularly useful if the port is going to be read as an analog channel as
|
||||
* well as through the Accelerometer class.
|
||||
* @param channel The existing AnalogInput object for the analog input the
|
||||
* accelerometer is connected to
|
||||
*/
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput *channel) {
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput *channel)
|
||||
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
m_AnalogInput = channel;
|
||||
InitAccelerometer();
|
||||
}
|
||||
m_allocatedChannel = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the analog components used for the accelerometer.
|
||||
* Create a new instance of Accelerometer from an existing AnalogInput.
|
||||
* Make a new instance of accelerometer given an AnalogInput. This is
|
||||
* particularly useful if the port is going to be read as an analog channel as
|
||||
* well as through the Accelerometer class.
|
||||
* @param channel The existing AnalogInput object for the analog input the
|
||||
* accelerometer is connected to
|
||||
*/
|
||||
AnalogAccelerometer::~AnalogAccelerometer() {
|
||||
if (m_allocatedChannel) {
|
||||
delete m_AnalogInput;
|
||||
AnalogAccelerometer::AnalogAccelerometer(::std::shared_ptr<AnalogInput> channel)
|
||||
: m_analogInput(channel) {
|
||||
if (channel == nullptr) {
|
||||
wpi_setWPIError(NullParameter);
|
||||
} else {
|
||||
InitAccelerometer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +73,7 @@ AnalogAccelerometer::~AnalogAccelerometer() {
|
||||
* @return The current acceleration of the sensor in Gs.
|
||||
*/
|
||||
float AnalogAccelerometer::GetAcceleration() const {
|
||||
return (m_AnalogInput->GetAverageVoltage() - m_zeroGVoltage) / m_voltsPerG;
|
||||
return (m_analogInput->GetAverageVoltage() - m_zeroGVoltage) / m_voltsPerG;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,9 +121,9 @@ std::string AnalogAccelerometer::GetSmartDashboardType() const {
|
||||
return "Accelerometer";
|
||||
}
|
||||
|
||||
void AnalogAccelerometer::InitTable(ITable *subTable) {
|
||||
void AnalogAccelerometer::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *AnalogAccelerometer::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> AnalogAccelerometer::GetTable() const { return m_table; }
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
static Resource *inputs = nullptr;
|
||||
static ::std::unique_ptr<Resource> inputs;
|
||||
|
||||
const uint8_t AnalogInput::kAccumulatorModuleNumber;
|
||||
const uint32_t AnalogInput::kAccumulatorNumChannels;
|
||||
@@ -25,7 +25,7 @@ const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
*/
|
||||
AnalogInput::AnalogInput(uint32_t channel) {
|
||||
char buf[64];
|
||||
Resource::CreateResourceObject(&inputs, kAnalogInputs);
|
||||
Resource::CreateResourceObject(inputs, kAnalogInputs);
|
||||
|
||||
if (!checkAnalogInputChannel(channel)) {
|
||||
snprintf(buf, 64, "analog input %d", channel);
|
||||
@@ -35,7 +35,7 @@ AnalogInput::AnalogInput(uint32_t channel) {
|
||||
|
||||
snprintf(buf, 64, "Analog Input %d", channel);
|
||||
if (inputs->Allocate(channel, buf) == ~0ul) {
|
||||
CloneError(inputs);
|
||||
CloneError(*inputs);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ AnalogInput::AnalogInput(uint32_t channel) {
|
||||
m_port = initializeAnalogInputPort(port, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
|
||||
LiveWindow::GetInstance().AddSensor("AnalogInput", channel, this);
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
|
||||
}
|
||||
|
||||
@@ -353,15 +353,15 @@ uint32_t AnalogInput::GetAccumulatorCount() const {
|
||||
* This function reads the value and count from the FPGA atomically.
|
||||
* This can be used for averaging.
|
||||
*
|
||||
* @param value Pointer to the 64-bit accumulated output.
|
||||
* @param count Pointer to the number of accumulation cycles.
|
||||
* @param value Reference to the 64-bit accumulated output.
|
||||
* @param count Reference to the number of accumulation cycles.
|
||||
*/
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t *value, uint32_t *count) const {
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t &value, uint32_t &count) const {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
getAccumulatorOutput(m_port, value, count, &status);
|
||||
getAccumulatorOutput(m_port, &value, &count, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
*value += m_accumulatorOffset;
|
||||
value += m_accumulatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,9 +412,9 @@ std::string AnalogInput::GetSmartDashboardType() const {
|
||||
return "Analog Input";
|
||||
}
|
||||
|
||||
void AnalogInput::InitTable(ITable *subTable) {
|
||||
void AnalogInput::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *AnalogInput::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> AnalogInput::GetTable() const { return m_table; }
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
static Resource *outputs = nullptr;
|
||||
static ::std::unique_ptr<Resource> outputs;
|
||||
|
||||
/**
|
||||
* Construct an analog output on the given channel.
|
||||
@@ -18,7 +18,7 @@ static Resource *outputs = nullptr;
|
||||
* @param The channel number on the roboRIO to represent.
|
||||
*/
|
||||
AnalogOutput::AnalogOutput(uint32_t channel) {
|
||||
Resource::CreateResourceObject(&outputs, kAnalogOutputs);
|
||||
Resource::CreateResourceObject(outputs, kAnalogOutputs);
|
||||
|
||||
char buf[64];
|
||||
|
||||
@@ -29,7 +29,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
|
||||
}
|
||||
|
||||
if (outputs->Allocate(channel, buf) == ~0ul) {
|
||||
CloneError(outputs);
|
||||
CloneError(*outputs);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
|
||||
m_port = initializeAnalogOutputPort(port, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
LiveWindow::GetInstance()->AddActuator("AnalogOutput", m_channel, this);
|
||||
LiveWindow::GetInstance().AddActuator("AnalogOutput", m_channel, this);
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogOutput, m_channel);
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ std::string AnalogOutput::GetSmartDashboardType() const {
|
||||
return "Analog Output";
|
||||
}
|
||||
|
||||
void AnalogOutput::InitTable(ITable *subTable) {
|
||||
void AnalogOutput::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *AnalogOutput::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> AnalogOutput::GetTable() const { return m_table; }
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
|
||||
#include "AnalogPotentiometer.h"
|
||||
#include "ControllerPower.h"
|
||||
|
||||
/**
|
||||
* Common initialization code called by all constructors.
|
||||
*/
|
||||
void AnalogPotentiometer::initPot(AnalogInput *input, double fullRange,
|
||||
double offset) {
|
||||
m_fullRange = fullRange;
|
||||
m_offset = offset;
|
||||
m_analog_input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an Analog Potentiometer object from a channel number.
|
||||
* @param channel The channel number on the roboRIO to represent. 0-3 are
|
||||
@@ -22,10 +11,10 @@ void AnalogPotentiometer::initPot(AnalogInput *input, double fullRange,
|
||||
* output at 0V.
|
||||
*/
|
||||
AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
||||
double offset) {
|
||||
m_init_analog_input = true;
|
||||
initPot(new AnalogInput(channel), fullRange, offset);
|
||||
}
|
||||
double offset)
|
||||
: m_analog_input(::std::make_unique<AnalogInput>(channel)),
|
||||
m_fullRange(fullRange),
|
||||
m_offset(offset) {}
|
||||
|
||||
/**
|
||||
* Construct an Analog Potentiometer object from an existing Analog Input
|
||||
@@ -37,36 +26,23 @@ AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
||||
* output at 0V.
|
||||
*/
|
||||
AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double fullRange,
|
||||
double offset) {
|
||||
m_init_analog_input = false;
|
||||
initPot(input, fullRange, offset);
|
||||
}
|
||||
double offset)
|
||||
: m_analog_input(input, NullDeleter<AnalogInput>()),
|
||||
m_fullRange(fullRange),
|
||||
m_offset(offset) {}
|
||||
|
||||
/**
|
||||
* Construct an Analog Potentiometer object from an existing Analog Input
|
||||
* reference.
|
||||
* @param channel The existing Analog Input reference
|
||||
* pointer.
|
||||
* @param channel The existing Analog Input pointer
|
||||
* @param fullRange The angular value (in desired units) representing the full
|
||||
* 0-5V range of the input.
|
||||
* @param offset The angular value (in desired units) representing the angular
|
||||
* output at 0V.
|
||||
*/
|
||||
AnalogPotentiometer::AnalogPotentiometer(AnalogInput &input, double fullRange,
|
||||
double offset) {
|
||||
m_init_analog_input = false;
|
||||
initPot(&input, fullRange, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor. Releases the Analog Input resource if it was allocated by this
|
||||
* object
|
||||
*/
|
||||
AnalogPotentiometer::~AnalogPotentiometer() {
|
||||
if (m_init_analog_input) {
|
||||
delete m_analog_input;
|
||||
m_init_analog_input = false;
|
||||
}
|
||||
}
|
||||
AnalogPotentiometer::AnalogPotentiometer(::std::shared_ptr<AnalogInput> input,
|
||||
double fullRange, double offset)
|
||||
: m_analog_input(input), m_fullRange(fullRange), m_offset(offset) {}
|
||||
|
||||
/**
|
||||
* Get the current reading of the potentiometer.
|
||||
@@ -97,7 +73,7 @@ std::string AnalogPotentiometer::GetSmartDashboardType() const {
|
||||
/**
|
||||
* Live Window code, only does anything if live window is activated.
|
||||
*/
|
||||
void AnalogPotentiometer::InitTable(ITable *subtable) {
|
||||
void AnalogPotentiometer::InitTable(::std::shared_ptr<ITable> subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
@@ -108,4 +84,4 @@ void AnalogPotentiometer::UpdateTable() {
|
||||
}
|
||||
}
|
||||
|
||||
ITable *AnalogPotentiometer::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> AnalogPotentiometer::GetTable() const { return m_table; }
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//#include "NetworkCommunication/UsageReporting.h"
|
||||
#include "Resource.h"
|
||||
#include "WPIErrors.h"
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* Constructor for an analog trigger given a channel number.
|
||||
@@ -109,7 +110,7 @@ void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
* This is the FPGA index of this analog trigger instance.
|
||||
* @return The index of the analog trigger.
|
||||
*/
|
||||
uint32_t AnalogTrigger::GetIndex() {
|
||||
uint32_t AnalogTrigger::GetIndex() const {
|
||||
if (StatusIsFatal()) return ~0ul;
|
||||
return m_index;
|
||||
}
|
||||
@@ -150,7 +151,9 @@ bool AnalogTrigger::GetTriggerState() {
|
||||
* @param type An enum of the type of output object to create.
|
||||
* @return A pointer to a new AnalogTriggerOutput object.
|
||||
*/
|
||||
AnalogTriggerOutput *AnalogTrigger::CreateOutput(AnalogTriggerType type) {
|
||||
::std::shared_ptr<AnalogTriggerOutput> AnalogTrigger::CreateOutput(
|
||||
AnalogTriggerType type) const {
|
||||
if (StatusIsFatal()) return nullptr;
|
||||
return new AnalogTriggerOutput(this, type);
|
||||
return ::std::shared_ptr<AnalogTriggerOutput>(
|
||||
new AnalogTriggerOutput(*this, type), NullDeleter<AnalogTriggerOutput>());
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
* @param outputType An enum that specifies the output on the trigger to
|
||||
* represent.
|
||||
*/
|
||||
AnalogTriggerOutput::AnalogTriggerOutput(AnalogTrigger *trigger,
|
||||
AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger &trigger,
|
||||
AnalogTriggerType outputType)
|
||||
: m_trigger(trigger), m_outputType(outputType) {
|
||||
HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput,
|
||||
trigger->GetIndex(), outputType);
|
||||
trigger.GetIndex(), outputType);
|
||||
}
|
||||
|
||||
AnalogTriggerOutput::~AnalogTriggerOutput() {
|
||||
@@ -46,7 +46,7 @@ AnalogTriggerOutput::~AnalogTriggerOutput() {
|
||||
bool AnalogTriggerOutput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool result =
|
||||
getAnalogTriggerOutput(m_trigger->m_trigger, m_outputType, &status);
|
||||
getAnalogTriggerOutput(m_trigger.m_trigger, m_outputType, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return result;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ bool AnalogTriggerOutput::Get() const {
|
||||
* @return The value to be written to the channel field of a routing mux.
|
||||
*/
|
||||
uint32_t AnalogTriggerOutput::GetChannelForRouting() const {
|
||||
return (m_trigger->m_index << 2) + m_outputType;
|
||||
return (m_trigger.m_index << 2) + m_outputType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
|
||||
"Built-in accelerometer");
|
||||
LiveWindow::GetInstance()->AddSensor((std::string) "BuiltInAccel", 0, this);
|
||||
LiveWindow::GetInstance().AddSensor((std::string) "BuiltInAccel", 0, this);
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
@@ -52,7 +52,7 @@ std::string BuiltInAccelerometer::GetSmartDashboardType() const {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void BuiltInAccelerometer::InitTable(ITable* subtable) {
|
||||
void BuiltInAccelerometer::InitTable(::std::shared_ptr<ITable> subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
@@ -65,4 +65,4 @@ void BuiltInAccelerometer::UpdateTable() {
|
||||
}
|
||||
}
|
||||
|
||||
ITable* BuiltInAccelerometer::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> BuiltInAccelerometer::GetTable() const { return m_table; }
|
||||
|
||||
@@ -31,7 +31,7 @@ static const uint32_t kFullMessageIDMask =
|
||||
|
||||
static const int32_t kReceiveStatusAttempts = 50;
|
||||
|
||||
static Resource *allocated = nullptr;
|
||||
static ::std::unique_ptr<Resource> allocated;
|
||||
|
||||
static int32_t sendMessageHelper(uint32_t messageID, const uint8_t *data,
|
||||
uint8_t dataSize, int32_t period) {
|
||||
@@ -72,7 +72,7 @@ static int32_t sendMessageHelper(uint32_t messageID, const uint8_t *data,
|
||||
* Common initialization code called by all constructors.
|
||||
*/
|
||||
void CANJaguar::InitCANJaguar() {
|
||||
m_safetyHelper = new MotorSafetyHelper(this);
|
||||
m_safetyHelper = std::make_unique<MotorSafetyHelper>(this);
|
||||
|
||||
bool receivedFirmwareVersion = false;
|
||||
uint8_t dataBuffer[8];
|
||||
@@ -149,7 +149,7 @@ void CANJaguar::InitCANJaguar() {
|
||||
}
|
||||
HALReport(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber,
|
||||
m_controlMode);
|
||||
LiveWindow::GetInstance()->AddActuator("CANJaguar", m_deviceNumber, this);
|
||||
LiveWindow::GetInstance().AddActuator("CANJaguar", m_deviceNumber, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,10 +180,10 @@ CANJaguar::CANJaguar(uint8_t deviceNumber)
|
||||
: m_deviceNumber(deviceNumber) {
|
||||
char buf[64];
|
||||
snprintf(buf, 64, "CANJaguar device number %d", m_deviceNumber);
|
||||
Resource::CreateResourceObject(&allocated, 63);
|
||||
Resource::CreateResourceObject(allocated, 63);
|
||||
|
||||
if (allocated->Allocate(m_deviceNumber - 1, buf) == ~0ul) {
|
||||
CloneError(allocated);
|
||||
CloneError(*allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -218,9 +218,6 @@ CANJaguar::~CANJaguar() {
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage(
|
||||
m_deviceNumber | LM_API_VCOMP_T_SET, nullptr, 0,
|
||||
CAN_SEND_PERIOD_STOP_REPEATING, &status);
|
||||
|
||||
delete m_safetyHelper;
|
||||
m_safetyHelper = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1926,8 +1923,8 @@ void CANJaguar::SetSafetyEnabled(bool enabled) {
|
||||
if (m_safetyHelper) m_safetyHelper->SetSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
void CANJaguar::GetDescription(char *desc) const {
|
||||
sprintf(desc, "CANJaguar ID %d", m_deviceNumber);
|
||||
void CANJaguar::GetDescription(std::ostringstream& desc) const {
|
||||
desc << "CANJaguar ID " << m_deviceNumber;
|
||||
}
|
||||
|
||||
uint8_t CANJaguar::GetDeviceID() const { return m_deviceNumber; }
|
||||
@@ -1940,7 +1937,7 @@ uint8_t CANJaguar::GetDeviceID() const { return m_deviceNumber; }
|
||||
*/
|
||||
void CANJaguar::StopMotor() { DisableControl(); }
|
||||
|
||||
void CANJaguar::ValueChanged(ITable *source, const std::string &key,
|
||||
void CANJaguar::ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
Set(value.f);
|
||||
}
|
||||
@@ -1982,9 +1979,9 @@ std::string CANJaguar::GetSmartDashboardType() const {
|
||||
return "Speed Controller";
|
||||
}
|
||||
|
||||
void CANJaguar::InitTable(ITable *subTable) {
|
||||
void CANJaguar::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *CANJaguar::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> CANJaguar::GetTable() const { return m_table; }
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "ctre/CanTalonSRX.h"
|
||||
#include <unistd.h> // usleep
|
||||
/**
|
||||
* Constructor for the CANTalon device.
|
||||
* @param deviceNumber The CAN ID of the Talon SRX
|
||||
*/
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* Constructor for the CANTalon device.
|
||||
* @param deviceNumber The CAN ID of the Talon SRX
|
||||
*/
|
||||
CANTalon::CANTalon(int deviceNumber)
|
||||
: m_deviceNumber(deviceNumber),
|
||||
m_impl(new CanTalonSRX(deviceNumber)),
|
||||
@@ -41,10 +43,6 @@ CANTalon::CANTalon(int deviceNumber, int controlPeriodMs)
|
||||
ApplyControlMode(m_controlMode);
|
||||
m_impl->SetProfileSlotSelect(m_profile);
|
||||
}
|
||||
CANTalon::~CANTalon() {
|
||||
delete m_impl;
|
||||
delete m_safetyHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out the PID value as seen in the PIDOutput base object.
|
||||
@@ -1246,8 +1244,8 @@ void CANTalon::SetSafetyEnabled(bool enabled) {
|
||||
m_safetyHelper->SetSafetyEnabled(enabled);
|
||||
}
|
||||
|
||||
void CANTalon::GetDescription(char* desc) const {
|
||||
sprintf(desc, "CANTalon ID %d", m_deviceNumber);
|
||||
void CANTalon::GetDescription(std::ostringstream& desc) const {
|
||||
desc << "CANTalon ID " << m_deviceNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1273,7 +1271,7 @@ bool CANTalon::GetInverted() const { return m_isInverted; }
|
||||
*/
|
||||
void CANTalon::StopMotor() { Disable(); }
|
||||
|
||||
void CANTalon::ValueChanged(ITable* source, const std::string& key,
|
||||
void CANTalon::ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
Set(value.f);
|
||||
}
|
||||
@@ -1300,9 +1298,9 @@ std::string CANTalon::GetSmartDashboardType() const {
|
||||
return "Speed Controller";
|
||||
}
|
||||
|
||||
void CANTalon::InitTable(ITable* subTable) {
|
||||
void CANTalon::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable* CANTalon::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> CANTalon::GetTable() const { return m_table; }
|
||||
|
||||
@@ -260,14 +260,14 @@ void Compressor::StopLiveWindowMode() {}
|
||||
|
||||
std::string Compressor::GetSmartDashboardType() const { return "Compressor"; }
|
||||
|
||||
void Compressor::InitTable(ITable* subTable) {
|
||||
void Compressor::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable* Compressor::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Compressor::GetTable() const { return m_table; }
|
||||
|
||||
void Compressor::ValueChanged(ITable* source, const std::string& key,
|
||||
void Compressor::ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
|
||||
EntryValue value, bool isNew) {
|
||||
if (value.b)
|
||||
Start();
|
||||
|
||||
@@ -60,11 +60,11 @@ Counter::Counter(DigitalSource *source) : Counter() {
|
||||
* an Analog Trigger).
|
||||
*
|
||||
* The counter will start counting immediately.
|
||||
* @param source A reference to the existing DigitalSource object. It will be
|
||||
* @param source A pointer to the existing DigitalSource object. It will be
|
||||
* set as the Up Source.
|
||||
*/
|
||||
Counter::Counter(DigitalSource &source) : Counter() {
|
||||
SetUpSource(&source);
|
||||
Counter::Counter(::std::shared_ptr<DigitalSource> source) : Counter() {
|
||||
SetUpSource(source);
|
||||
ClearDownSource();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,6 @@ Counter::Counter(int32_t channel) : Counter() {
|
||||
Counter::Counter(AnalogTrigger *trigger) : Counter() {
|
||||
SetUpSource(trigger->CreateOutput(kState));
|
||||
ClearDownSource();
|
||||
m_allocatedUpSource = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +102,9 @@ Counter::Counter(AnalogTrigger *trigger) : Counter() {
|
||||
* The counter will start counting immediately.
|
||||
* @param trigger The reference to the existing AnalogTrigger object.
|
||||
*/
|
||||
Counter::Counter(AnalogTrigger &trigger) : Counter() {
|
||||
Counter::Counter(const AnalogTrigger &trigger) : Counter() {
|
||||
SetUpSource(trigger.CreateOutput(kState));
|
||||
ClearDownSource();
|
||||
m_allocatedUpSource = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,10 +115,27 @@ Counter::Counter(AnalogTrigger &trigger) : Counter() {
|
||||
* @param downSource The pointer to the DigitalSource to set as the down source
|
||||
* @param inverted True to invert the output (reverse the direction)
|
||||
*/
|
||||
|
||||
Counter::Counter(EncodingType encodingType, DigitalSource *upSource,
|
||||
DigitalSource *downSource, bool inverted)
|
||||
: Counter(kExternalDirection) {
|
||||
: Counter(encodingType,
|
||||
::std::shared_ptr<DigitalSource>(upSource,
|
||||
NullDeleter<DigitalSource>()),
|
||||
::std::shared_ptr<DigitalSource>(downSource,
|
||||
NullDeleter<DigitalSource>()),
|
||||
inverted) {}
|
||||
|
||||
/**
|
||||
* Create an instance of a Counter object.
|
||||
* Creates a full up-down counter given two Digital Sources
|
||||
* @param encodingType The quadrature decoding mode (1x or 2x)
|
||||
* @param upSource The pointer to the DigitalSource to set as the up source
|
||||
* @param downSource The pointer to the DigitalSource to set as the down source
|
||||
* @param inverted True to invert the output (reverse the direction)
|
||||
*/
|
||||
Counter::Counter(EncodingType encodingType,
|
||||
::std::shared_ptr<DigitalSource> upSource,
|
||||
::std::shared_ptr<DigitalSource> downSource, bool inverted)
|
||||
: Counter(kExternalDirection) {
|
||||
if (encodingType != k1X && encodingType != k2X) {
|
||||
wpi_setWPIErrorWithContext(
|
||||
ParameterOutOfRange,
|
||||
@@ -148,14 +163,6 @@ Counter::Counter(EncodingType encodingType, DigitalSource *upSource,
|
||||
*/
|
||||
Counter::~Counter() {
|
||||
SetUpdateWhenEmpty(true);
|
||||
if (m_allocatedUpSource) {
|
||||
delete m_upSource;
|
||||
m_upSource = nullptr;
|
||||
}
|
||||
if (m_allocatedDownSource) {
|
||||
delete m_downSource;
|
||||
m_downSource = nullptr;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
freeCounter(m_counter, &status);
|
||||
@@ -170,8 +177,7 @@ Counter::~Counter() {
|
||||
*/
|
||||
void Counter::SetUpSource(int32_t channel) {
|
||||
if (StatusIsFatal()) return;
|
||||
SetUpSource(new DigitalInput(channel));
|
||||
m_allocatedUpSource = true;
|
||||
SetUpSource(::std::make_shared<DigitalInput>(channel));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,9 +187,9 @@ void Counter::SetUpSource(int32_t channel) {
|
||||
*/
|
||||
void Counter::SetUpSource(AnalogTrigger *analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) return;
|
||||
SetUpSource(analogTrigger->CreateOutput(triggerType));
|
||||
m_allocatedUpSource = true;
|
||||
SetUpSource(::std::shared_ptr<AnalogTrigger>(analogTrigger,
|
||||
NullDeleter<AnalogTrigger>()),
|
||||
triggerType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,9 +197,10 @@ void Counter::SetUpSource(AnalogTrigger *analogTrigger,
|
||||
* @param analogTrigger The analog trigger object that is used for the Up Source
|
||||
* @param triggerType The analog trigger output that will trigger the counter.
|
||||
*/
|
||||
void Counter::SetUpSource(AnalogTrigger &analogTrigger,
|
||||
void Counter::SetUpSource(::std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
SetUpSource(&analogTrigger, triggerType);
|
||||
if (StatusIsFatal()) return;
|
||||
SetUpSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,16 +208,11 @@ void Counter::SetUpSource(AnalogTrigger &analogTrigger,
|
||||
* Set the up counting DigitalSource.
|
||||
* @param source Pointer to the DigitalSource object to set as the up source
|
||||
*/
|
||||
void Counter::SetUpSource(DigitalSource *source) {
|
||||
void Counter::SetUpSource(::std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_allocatedUpSource) {
|
||||
delete m_upSource;
|
||||
m_upSource = nullptr;
|
||||
m_allocatedUpSource = false;
|
||||
}
|
||||
m_upSource = source;
|
||||
if (m_upSource->StatusIsFatal()) {
|
||||
CloneError(m_upSource);
|
||||
CloneError(*m_upSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
setCounterUpSource(m_counter, source->GetChannelForRouting(),
|
||||
@@ -219,12 +221,20 @@ void Counter::SetUpSource(DigitalSource *source) {
|
||||
}
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(DigitalSource *source) {
|
||||
SetUpSource(
|
||||
::std::shared_ptr<DigitalSource>(source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source object that causes the counter to count up.
|
||||
* Set the up counting DigitalSource.
|
||||
* @param source Reference to the DigitalSource object to set as the up source
|
||||
*/
|
||||
void Counter::SetUpSource(DigitalSource &source) { SetUpSource(&source); }
|
||||
void Counter::SetUpSource(DigitalSource &source) {
|
||||
SetUpSource(
|
||||
::std::shared_ptr<DigitalSource>(&source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the edge sensitivity on an up counting source.
|
||||
@@ -249,11 +259,7 @@ void Counter::SetUpSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
*/
|
||||
void Counter::ClearUpSource() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_allocatedUpSource) {
|
||||
delete m_upSource;
|
||||
m_upSource = nullptr;
|
||||
m_allocatedUpSource = false;
|
||||
}
|
||||
m_upSource.reset();
|
||||
int32_t status = 0;
|
||||
clearCounterUpSource(m_counter, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -266,8 +272,7 @@ void Counter::ClearUpSource() {
|
||||
*/
|
||||
void Counter::SetDownSource(int32_t channel) {
|
||||
if (StatusIsFatal()) return;
|
||||
SetDownSource(new DigitalInput(channel));
|
||||
m_allocatedDownSource = true;
|
||||
SetDownSource(::std::make_shared<DigitalInput>(channel));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,9 +283,7 @@ void Counter::SetDownSource(int32_t channel) {
|
||||
*/
|
||||
void Counter::SetDownSource(AnalogTrigger *analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
if (StatusIsFatal()) return;
|
||||
SetDownSource(analogTrigger->CreateOutput(triggerType));
|
||||
m_allocatedDownSource = true;
|
||||
SetDownSource(::std::shared_ptr<AnalogTrigger>(analogTrigger, NullDeleter<AnalogTrigger>()), triggerType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,9 +292,10 @@ void Counter::SetDownSource(AnalogTrigger *analogTrigger,
|
||||
* Source
|
||||
* @param triggerType The analog trigger output that will trigger the counter.
|
||||
*/
|
||||
void Counter::SetDownSource(AnalogTrigger &analogTrigger,
|
||||
void Counter::SetDownSource(::std::shared_ptr<AnalogTrigger> analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
SetDownSource(&analogTrigger, triggerType);
|
||||
if (StatusIsFatal()) return;
|
||||
SetDownSource(analogTrigger->CreateOutput(triggerType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,16 +303,11 @@ void Counter::SetDownSource(AnalogTrigger &analogTrigger,
|
||||
* Set the down counting DigitalSource.
|
||||
* @param source Pointer to the DigitalSource object to set as the down source
|
||||
*/
|
||||
void Counter::SetDownSource(DigitalSource *source) {
|
||||
void Counter::SetDownSource(::std::shared_ptr<DigitalSource> source) {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_allocatedDownSource) {
|
||||
delete m_downSource;
|
||||
m_downSource = nullptr;
|
||||
m_allocatedDownSource = false;
|
||||
}
|
||||
m_downSource = source;
|
||||
if (m_downSource->StatusIsFatal()) {
|
||||
CloneError(m_downSource);
|
||||
CloneError(*m_downSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
setCounterDownSource(m_counter, source->GetChannelForRouting(),
|
||||
@@ -317,12 +316,18 @@ void Counter::SetDownSource(DigitalSource *source) {
|
||||
}
|
||||
}
|
||||
|
||||
void Counter::SetDownSource(DigitalSource *source) {
|
||||
SetDownSource(::std::shared_ptr<DigitalSource>(source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source object that causes the counter to count down.
|
||||
* Set the down counting DigitalSource.
|
||||
* @param source Reference to the DigitalSource object to set as the down source
|
||||
*/
|
||||
void Counter::SetDownSource(DigitalSource &source) { SetDownSource(&source); }
|
||||
void Counter::SetDownSource(DigitalSource &source) {
|
||||
SetDownSource(::std::shared_ptr<DigitalSource>(&source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the edge sensitivity on a down counting source.
|
||||
@@ -347,11 +352,7 @@ void Counter::SetDownSourceEdge(bool risingEdge, bool fallingEdge) {
|
||||
*/
|
||||
void Counter::ClearDownSource() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_allocatedDownSource) {
|
||||
delete m_downSource;
|
||||
m_downSource = nullptr;
|
||||
m_allocatedDownSource = false;
|
||||
}
|
||||
m_downSource.reset();
|
||||
int32_t status = 0;
|
||||
clearCounterDownSource(m_counter, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -581,9 +582,9 @@ void Counter::StopLiveWindowMode() {}
|
||||
|
||||
std::string Counter::GetSmartDashboardType() const { return "Counter"; }
|
||||
|
||||
void Counter::InitTable(ITable *subTable) {
|
||||
void Counter::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *Counter::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> Counter::GetTable() const { return m_table; }
|
||||
|
||||
@@ -31,7 +31,7 @@ DigitalInput::DigitalInput(uint32_t channel) {
|
||||
allocateDIO(m_digital_ports[channel], true, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
LiveWindow::GetInstance()->AddSensor("DigitalInput", channel, this);
|
||||
LiveWindow::GetInstance().AddSensor("DigitalInput", channel, this);
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalInput, channel);
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ std::string DigitalInput::GetSmartDashboardType() const {
|
||||
return "DigitalInput";
|
||||
}
|
||||
|
||||
void DigitalInput::InitTable(ITable *subTable) {
|
||||
void DigitalInput::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *DigitalInput::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> DigitalInput::GetTable() const { return m_table; }
|
||||
|
||||
@@ -194,7 +194,7 @@ uint32_t DigitalOutput::GetModuleForRouting() const { return 0; }
|
||||
*/
|
||||
bool DigitalOutput::GetAnalogTriggerForRouting() const { return false; }
|
||||
|
||||
void DigitalOutput::ValueChanged(ITable *source, const std::string &key,
|
||||
void DigitalOutput::ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
Set(value.b);
|
||||
}
|
||||
@@ -217,9 +217,9 @@ std::string DigitalOutput::GetSmartDashboardType() const {
|
||||
return "Digital Output";
|
||||
}
|
||||
|
||||
void DigitalOutput::InitTable(ITable *subTable) {
|
||||
void DigitalOutput::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *DigitalOutput::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> DigitalOutput::GetTable() const { return m_table; }
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
::std::unique_ptr<Resource> SolenoidBase::m_allocated =
|
||||
::std::make_unique<Resource>(solenoid_kNumDO7_0Elements *
|
||||
kSolenoidChannels);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Uses the default PCM ID of 0
|
||||
@@ -47,13 +51,13 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
return;
|
||||
}
|
||||
Resource::CreateResourceObject(
|
||||
&m_allocated, solenoid_kNumDO7_0Elements * kSolenoidChannels);
|
||||
m_allocated, solenoid_kNumDO7_0Elements * kSolenoidChannels);
|
||||
|
||||
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_forwardChannel,
|
||||
m_moduleNumber);
|
||||
if (m_allocated->Allocate(
|
||||
m_moduleNumber * kSolenoidChannels + m_forwardChannel, buf) == ~0ul) {
|
||||
CloneError(m_allocated);
|
||||
CloneError(*m_allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
m_moduleNumber);
|
||||
if (m_allocated->Allocate(
|
||||
m_moduleNumber * kSolenoidChannels + m_reverseChannel, buf) == ~0ul) {
|
||||
CloneError(m_allocated);
|
||||
CloneError(*m_allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,7 +75,7 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
m_moduleNumber);
|
||||
HALReport(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel,
|
||||
m_moduleNumber);
|
||||
LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", m_moduleNumber,
|
||||
LiveWindow::GetInstance().AddActuator("DoubleSolenoid", m_moduleNumber,
|
||||
m_forwardChannel, this);
|
||||
}
|
||||
|
||||
@@ -147,7 +151,7 @@ bool DoubleSolenoid::IsRevSolenoidBlackListed() const {
|
||||
return (blackList & m_reverseMask) ? 1 : 0;
|
||||
}
|
||||
|
||||
void DoubleSolenoid::ValueChanged(ITable *source, const std::string &key,
|
||||
void DoubleSolenoid::ValueChanged(::std::shared_ptr<ITable> source, const std::string &key,
|
||||
EntryValue value, bool isNew) {
|
||||
Value lvalue = kOff;
|
||||
std::string *val = (std::string *)value.ptr;
|
||||
@@ -184,9 +188,9 @@ std::string DoubleSolenoid::GetSmartDashboardType() const {
|
||||
return "Double Solenoid";
|
||||
}
|
||||
|
||||
void DoubleSolenoid::InitTable(ITable *subTable) {
|
||||
void DoubleSolenoid::InitTable(::std::shared_ptr<ITable> subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *DoubleSolenoid::GetTable() const { return m_table; }
|
||||
::std::shared_ptr<ITable> DoubleSolenoid::GetTable() const { return m_table; }
|
||||
|
||||
@@ -88,9 +88,9 @@ void DriverStation::Run() {
|
||||
* Return a pointer to the singleton DriverStation.
|
||||
* @return Pointer to the DS instance
|
||||
*/
|
||||
DriverStation* DriverStation::GetInstance() {
|
||||
DriverStation &DriverStation::GetInstance() {
|
||||
static DriverStation instance;
|
||||
return &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user