mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Fixed examples to build/run with new WPILib versions.
Also added some references/smart pointers to a couple places that seemed convenient to the user. I haven't updated the constructors for RobotDrive() related examples, pending the results of gerrit change https://usfirst.collab.net/gerrit/#/c/960/ A few things that we are noticing: --It might be nice if ReturnPIDInput() didn't have to be const; when people try to override it, they have to remember to put the const in and if they don't, then the compiler error isn't the most obvious (especially since this is a change). This would also apply to PIDGet() in the PIDSource interface. --SendableChooser still takes raw pointers. This could lead to an issue I had to debug briefly where you accidentally call GetSelected() on autoChooser and put the resulting raw pointer into a unique_ptr, which destroys the pointer when it goes out of scope. Specifically, I was testing the PacGoat example and I ended up with a situation where if auto mode was run once, it was fine, but if it was run twice, the selected command would have been destroyed by the unique_ptr. I believe that this just requires updating SendableChosser to take shared_ptr. --When the samples are compiled with -pedantic, it points out that START_ROBOT_CLASS macro expansion results in a redundant semicolon. Change-Id: Ib4c025a61263d0d2780d4253faa31713e15333a5
This commit is contained in:
committed by
Brad Miller (WPI)
parent
4f8c1dff2f
commit
e017f93f16
@@ -50,12 +50,16 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Sensor associated with the subsystem and with call it by the given
|
||||
* name.
|
||||
* @name AddSensor(subsystem, name, component)
|
||||
* Add a Sensor associated with the subsystem and call it by the given name.
|
||||
* @param subsystem The subsystem this component is part of.
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a sensor.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* @brief Use a STL smart pointer to share ownership of component.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name,
|
||||
std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
@@ -63,21 +67,42 @@ void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name
|
||||
m_components[component].isSensor = true;
|
||||
}
|
||||
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component) {
|
||||
/**
|
||||
* @brief Pass a reference to LiveWindow and retain ownership of the component.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable &component) {
|
||||
AddSensor(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
&component, [](LiveWindowSendable*){}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Actuator associated with the subsystem and with call it by the given
|
||||
* name.
|
||||
* @brief Use a raw pointer to the LiveWindow.
|
||||
* @deprecated Prefer smart pointers or references.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void LiveWindow::AddSensor(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable *component) {
|
||||
AddSensor(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
//@}
|
||||
|
||||
/**
|
||||
* @name AddActuator(subsystem, name, component)
|
||||
* Add an Actuator associated with the subsystem and call it by the given name.
|
||||
* @param subsystem The subsystem this component is part of.
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a actuator.
|
||||
*/
|
||||
//@{
|
||||
/**
|
||||
* @brief Use a STL smart pointer to share ownership of component.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
@@ -85,18 +110,30 @@ void LiveWindow::AddActuator(const std::string &subsystem, const std::string &na
|
||||
m_components[component].isSensor = false;
|
||||
}
|
||||
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
/**
|
||||
* @brief Pass a reference to LiveWindow and retain ownership of the component.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem,
|
||||
const std::string &name,
|
||||
LiveWindowSendable &component) {
|
||||
AddActuator(subsystem, name, std::shared_ptr<LiveWindowSendable>(
|
||||
&component, [](LiveWindowSendable*){}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Use a raw pointer to the LiveWindow.
|
||||
* @deprecated Prefer smart pointers or references.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
LiveWindowSendable *component) {
|
||||
AddActuator(subsystem, name,
|
||||
std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
//@}
|
||||
|
||||
/**
|
||||
* INTERNAL
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
[[deprecated]]
|
||||
void LiveWindow::AddSensor(std::string type, int channel,
|
||||
@@ -116,7 +153,7 @@ void LiveWindow::AddSensor(std::string type, int channel,
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
@@ -131,7 +168,7 @@ void LiveWindow::AddActuator(std::string type, int channel,
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL
|
||||
* Meant for internal use in other WPILib classes.
|
||||
*/
|
||||
void LiveWindow::AddActuator(std::string type, int module, int channel,
|
||||
LiveWindowSendable *component) {
|
||||
|
||||
Reference in New Issue
Block a user