Compare commits

...

33 Commits

Author SHA1 Message Date
Prateek Machiraju
e874ba9313 Add Color classes for use with AddressableLED (#2127)
Both floating point and 8-bit integer classes are included, as well as a wide selection of color constants.

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
2019-12-30 00:01:20 -06:00
Peter Johnson
96348e835a Fix C++ SendableRegistry::AddChild() (#2207)
Add a Sendable* overload so pointers to sendable objects work appropriately.
Otherwise an AddLW(this) in a child (which is a Sendable*) could be a
different pointer than a void* to the same object.

For example:
  AnalogInput constructor calls AddLW(this)
  AnalogPotentiometer constructor calls AddChild(analog input pointer)

Also add handling for the child object moving (if it's Sendable).
2019-12-29 23:37:14 -06:00
Oblarg
d91796f8d2 fix clang-format version number (#2206) 2019-12-29 21:31:26 -06:00
Peter Johnson
9abce8eb06 Fix subsystem LiveWindow usage (#2202) 2019-12-29 21:28:38 -06:00
Peter Johnson
8b4508ad53 Use default path for networktables.ini in simulation (#2205) 2019-12-29 18:55:02 -06:00
Oblarg
5b7dd186d2 Add templates for new commands for vscode plugin (#2016) 2019-12-29 15:02:49 -06:00
Peter Johnson
6ea13ea8f3 ntcore: Add support for local-only operation (#2204)
StartLocal() causes future calls to StartServer() or StartClient() to have
no effect. StopLocal() re-enables these calls.
2019-12-29 14:56:41 -06:00
Oblarg
44bcf7fb4d Java examples: use non-static imports for constants (#2191) 2019-12-29 14:55:49 -06:00
Oblarg
c7a1dfc0bc Add SlewRateLimiter class (#2192)
This is extremely useful for implementing various "ramping" functions
(such as voltage ramps, setpoint ramps, etc). Usage is straightforward;
it behaves like all of our other filter classes. C++ version is unit-safe.
2019-12-29 13:36:28 -06:00
Peter Johnson
a12bb447e4 Fail cmake build if python3 generate_numbers.py fails (#2203) 2019-12-29 13:12:00 -06:00
Declan Freeman-Gleason
c4bd54ef44 Add JNI binding to suppress driver station error/warning messages (#2200)
This is to allow suppressing an ugly stack trace/error message in a unit test in #2197. It doesn't support the full HALSIM_SetSendError callback stuff (i.e. you can only suppress, not intercept, stack traces with this).
2019-12-27 21:11:26 -06:00
Austin Shalit
f9a11cce5e Remove -no-module-directories flag from javadoc build (#2201) 2019-12-27 10:19:49 -06:00
Peter Johnson
6008671c30 Report WPILib version as part of usage reporting (#2199) 2019-12-26 22:34:10 -06:00
Peter Johnson
7b952d599d Add usage reporting for many new things (#2184)
- new CommandScheduler
- kinematics and odometry classes
- new PIDController
- ProfiledPIDController
- TrapezoidProfile (reported in Constraints class)

Also update instances.txt to match latest NI version.

One side effect is that a couple of classes are no longer constexpr.
2019-12-25 00:42:14 -06:00
Peter Johnson
93cdf68694 Add Constants.cpp for MecanumControllerCommand example (#2196) 2019-12-24 16:19:02 -06:00
Peter Johnson
0c6f24562f Fix bug in ULEB128 decoding (#2195) 2019-12-24 14:12:42 -06:00
Thad House
bdc1cab013 Add support for configuring SPI Auto Stall Config (#2193) 2019-12-24 12:52:58 -06:00
Prateek Machiraju
3259cffc63 Add transform methods to Trajectory (#2187) 2019-12-23 13:16:30 -06:00
Oblarg
67b59f2b31 Minor improvements/fixes to new command framework (#2186) 2019-12-23 01:09:25 -06:00
sciencewhiz
1ce24a7a2f Add 2020 speed controllers (#2188)
Add CTRE TalonFX (PWMTalonFX)
Add Playing with Fusion Venom (PWMVenom)
2019-12-22 13:51:43 -06:00
Prateek Machiraju
635882a9f7 Add getter for initial pose in Trajectory (#2180) 2019-12-21 06:57:39 -08:00
Thad House
71a22861eb Use ManagedStatic for CameraServer (#2174) 2019-12-20 14:20:38 -08:00
Thad House
9cb69c5b46 Add a way to pass in a preconstructed value to ManagedStatic (#2175)
A lot of our cases don't need the lazy construction, but do need manual destruction.
2019-12-20 14:06:22 -08:00
Thad House
5e08bb28f8 Add docs and lifecycle tasks for faster dev builds (#2182) 2019-12-20 13:48:26 -08:00
Oblarg
ea4d1a39e1 Update characterization values to match real robot (#2183)
This is in preparation for an end-to-end trajectory tutorial example.

Co-Authored-By: Dalton Smith <gamefollower26@gmail.com>
2019-12-20 13:46:13 -08:00
Prateek Machiraju
31b588d961 Fix ArmFeedforward Javadocs (#2176) 2019-12-15 14:34:18 -08:00
Thad House
0b80d566ad Use ChipObject HMB function for LED (#2173)
It's fixed in v9 and up.
2019-12-14 21:15:32 -08:00
Peter Johnson
f8294e689b Sim GUI: Add a bit of spacing to the analog inputs (#2170)
This helps make it clear they are separate controls.
2019-12-14 10:49:01 -08:00
Peter Johnson
b78f115fcf Work around VS2019 16.4.0 bugs (#2171)
Work around frontend bug in scoped_lock and code generation bug in reverse_iterator in gtest.

See https://github.com/google/googletest/pull/2635
2019-12-14 10:48:19 -08:00
sciencewhiz
b468c51251 Change AddressableLED example to use consistent PWM port (#2168) 2019-12-11 15:39:36 -08:00
Prateek Machiraju
023c088290 Add toString() to relevant kinematics classes (#2160) 2019-12-09 21:35:43 -08:00
Thad House
8a11d13a39 Fix C++ DutyCycleEncoder int constructor (#2166) 2019-12-09 21:35:00 -08:00
Claudius Tewari
daa81c64a7 Minor javadoc fix in SwerveDriveKinematicsConstraint (#2167) 2019-12-09 21:34:32 -08:00
206 changed files with 5169 additions and 734 deletions

View File

@@ -37,7 +37,7 @@ So you want to contribute your changes back to WPILib. Great! We have a few cont
## Coding Guidelines
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 5.0 with wpiformat.
WPILib uses modified Google style guides for both C++ and Java, which can be found in the [styleguide repository](https://github.com/wpilibsuite/styleguide). Autoformatters are available for many popular editors at https://github.com/google/styleguide. Running wpiformat is required for all contributions and is enforced by our continuous integration system. We currently use clang-format 6.0 with wpiformat.
While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines. If you are looking for some easy ramp-up tasks, finding areas that don't follow the style guide and fixing them is very welcome.

15
FasterBuilds.md Normal file
View File

@@ -0,0 +1,15 @@
# Faster Builds for Developers
When you run `./gradlew build`, it builds EVERYTHING. This means debug and release builds for desktop and all installed cross compilers. For many developers, this is way too much, and causes much developer pain.
To help with some of these things, common tasks have shortcuts to only build necessary things for common development and testing tasks.
## Development (Desktop)
For projects `wpiutil`, `ntcore`, `cscore`, `hal` `wpilibOldCommands`, `wpilibNewCommands` and `cameraserver`, a `testDesktopJava` and a `testDesktopCpp` task exists. These can be ran with `./gradlew :projectName:task`, and will only build the minimum things required to run those tests.
For `wpilibc`, a `testDesktopCpp` task exists. For `wpilibj`, a `testDesktopJava` task exists.
For `wpilibcExamples`, a `buildDesktopCpp` task exists (These can't be ran, but they can compile).
For `wpilibjExamples`, a `buildDesktopJava` task exists.

View File

@@ -13,6 +13,7 @@
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/DenseMap.h>
#include <wpi/ManagedStatic.h>
#include <wpi/SmallString.h>
#include <wpi/StringMap.h>
#include <wpi/mutex.h>
@@ -47,8 +48,14 @@ struct CameraServer::Impl {
};
CameraServer* CameraServer::GetInstance() {
static CameraServer instance;
return &instance;
struct Creator {
static void* call() { return new CameraServer{}; }
};
struct Deleter {
static void call(void* ptr) { delete static_cast<CameraServer*>(ptr); }
};
static wpi::ManagedStatic<CameraServer, Creator, Deleter> instance;
return &(*instance);
}
static wpi::StringRef MakeSourceValue(CS_Source source,

View File

@@ -412,7 +412,11 @@ std::unique_ptr<PropertyImpl> HttpCameraImpl::CreateEmptyProperty(
}
bool HttpCameraImpl::CacheProperties(CS_Status* status) const {
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
std::scoped_lock<wpi::mutex> lock(m_mutex);
#else
std::scoped_lock lock(m_mutex);
#endif
// Pretty typical set of video modes
m_videoModes.clear();

View File

@@ -78,7 +78,11 @@ template <typename THandle, typename TStruct, int typeValue, typename TMutex>
template <typename... Args>
THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
Args&&... args) {
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
std::scoped_lock<TMutex> lock(m_handleMutex);
#else
std::scoped_lock sync(m_handleMutex);
#endif
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {

View File

@@ -125,7 +125,6 @@ task generateJavaDocs(type: Javadoc) {
ext.entryPoint = "$destinationDir/index.html"
if (JavaVersion.current().isJava11Compatible()) {
options.addBooleanOption('-no-module-directories', true)
doLast {
// This is a work-around for https://bugs.openjdk.java.net/browse/JDK-8211194. Can be removed once that issue is fixed on JDK's side
// Since JDK 11, package-list is missing from javadoc output files and superseded by element-list file, but a lot of external tools still need it

View File

@@ -3,6 +3,7 @@ kLanguage_CPlusPlus = 2
kLanguage_Java = 3
kLanguage_Python = 4
kLanguage_DotNet = 5
kLanguage_Kotlin = 6
kCANPlugin_BlackJagBridge = 1
kCANPlugin_2CAN = 2
kFramework_Iterative = 1
@@ -41,4 +42,11 @@ kDriverStationEIO_TouchSlider = 11
kADXL345_SPI = 1
kADXL345_I2C = 2
kCommand_Scheduler = 1
kCommand2_Scheduler = 2
kSmartDashboard_Instance = 1
kKinematics_DifferentialDrive = 1
kKinematics_MecanumDrive = 2
kKinematics_SwerveDrive = 3
kOdometry_DifferentialDrive = 1
kOdometry_MecanumDrive = 2
kOdometry_SwerveDrive = 3

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -61,4 +61,6 @@ public class SPIJNI extends JNIWrapper {
double timeout);
public static native int spiGetAutoDroppedCount(int port);
public static native void spiConfigureAutoStall(int port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead);
}

View File

@@ -79,6 +79,15 @@ public class DriverStationSim {
DriverStationDataJNI.notifyNewData();
}
/**
* Toggles suppression of DriverStation.reportError and reportWarning messages.
*
* @param shouldSend If false then messages will will be suppressed.
*/
public void setSendError(boolean shouldSend) {
DriverStationDataJNI.setSendError(shouldSend);
}
public void resetData() {
DriverStationDataJNI.resetData();
}

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -49,5 +49,7 @@ public class DriverStationDataJNI extends JNIWrapper {
public static native void registerAllCallbacks(NotifyCallback callback, boolean initialNotify);
public static native void notifyNewData();
public static native void setSendError(boolean shouldSend);
public static native void resetData();
}

View File

@@ -9,6 +9,8 @@
#include <cstring>
#include <FRC_FPGA_ChipObject/fpgainterfacecapi/NiFpga_HMB.h>
#include "ConstantsInternal.h"
#include "DigitalInternal.h"
#include "HALInitializer.h"
@@ -19,14 +21,6 @@
using namespace hal;
extern "C" {
NiFpga_Status NiFpga_ClientFunctionCall(NiFpga_Session session, uint32_t group,
uint32_t functionId,
const void* inBuffer,
size_t inBufferSize, void* outBuffer,
size_t outBufferSize);
} // extern "C"
namespace {
struct AddressableLED {
std::unique_ptr<tLED> led;
@@ -52,43 +46,6 @@ void InitializeAddressableLED() {
} // namespace init
} // namespace hal
// Shim for broken ChipObject function
static const uint32_t clientFeature_hostMemoryBuffer = 0;
static const uint32_t hostMemoryBufferFunction_open = 2;
// Input arguments for HMB open
struct AtomicHMBOpenInputs {
const char* memoryName;
};
// Output arguments for HMB open
struct AtomicHMBOpenOutputs {
size_t size;
void* virtualAddress;
};
static NiFpga_Status OpenHostMemoryBuffer(NiFpga_Session session,
const char* memoryName,
void** virtualAddress, size_t* size) {
struct AtomicHMBOpenOutputs outputs;
struct AtomicHMBOpenInputs inputs;
inputs.memoryName = memoryName;
NiFpga_Status retval = NiFpga_ClientFunctionCall(
session, clientFeature_hostMemoryBuffer, hostMemoryBufferFunction_open,
&inputs, sizeof(struct AtomicHMBOpenInputs), &outputs,
sizeof(struct AtomicHMBOpenOutputs));
if (NiFpga_IsError(retval)) {
return retval;
}
*virtualAddress = outputs.virtualAddress;
if (size != NULL) {
*size = outputs.size;
}
return retval;
}
extern "C" {
HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
@@ -146,8 +103,8 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
uint32_t session = led->led->getSystemInterface()->getHandle();
*status = OpenHostMemoryBuffer(session, "HMB_0_LED", &led->ledBuffer,
&led->ledBufferSize);
*status = NiFpga_OpenHostMemoryBuffer(session, "HMB_0_LED", &led->ledBuffer,
&led->ledBufferSize);
if (*status != 0) {
addressableLEDHandles->Free(handle);

View File

@@ -631,12 +631,21 @@ int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
return spiSystem->readTransferSkippedFullCount(status);
}
// These 2 functions are so the new stall functionality
// can be tested. How they're used is not very clear
// but I want them to be testable so we can add an impl.
// We will not be including these in the headers
void* HAL_GetSPIDMAManager() { return spiAutoDMA.get(); }
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status) {
std::scoped_lock lock(spiAutoMutex);
// FPGA only has one auto SPI engine
if (port != spiAutoPort) {
*status = INCOMPATIBLE_STATE;
return;
}
void* HAL_GetSPISystem() { return spiSystem.get(); }
tSPI::tStallConfig stallConfig;
stallConfig.CsToSclkTicks = static_cast<uint8_t>(csToSclkTicks);
stallConfig.StallTicks = static_cast<uint16_t>(stallTicks);
stallConfig.Pow2BytesPerRead = static_cast<uint8_t>(pow2BytesPerRead);
spiSystem->writeStallConfig(stallConfig, status);
}
} // extern "C"

View File

@@ -394,4 +394,20 @@ Java_edu_wpi_first_hal_SPIJNI_spiGetAutoDroppedCount
return retval;
}
/*
* Class: edu_wpi_first_hal_SPIJNI
* Method: spiConfigureAutoStall
* Signature: (IIII)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_SPIJNI_spiConfigureAutoStall
(JNIEnv* env, jclass, jint port, jint csToSclkTicks, jint stallTicks,
jint pow2BytesPerRead)
{
int32_t status = 0;
HAL_ConfigureSPIAutoStall(static_cast<HAL_SPIPort>(port), csToSclkTicks,
stallTicks, pow2BytesPerRead, &status);
CheckStatus(env, status);
}
} // extern "C"

View File

@@ -27,6 +27,7 @@
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tDutyCycle.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tEncoder.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tGlobal.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tHMB.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tInterrupt.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tLED.h>
#include <FRC_FPGA_ChipObject/nRoboRIO_FPGANamespace/tPWM.h>

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -244,6 +244,19 @@ int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
*/
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status);
/**
* Configure the Auto SPI Stall time between reads.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP.
* @param csToSclkTicks the number of ticks to wait before asserting the cs pin
* @param stallTicks the number of ticks to stall for
* @param pow2BytesPerRead the number of bytes to read before stalling
*/
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -74,7 +74,11 @@ class SimCallbackRegistry : public impl::SimCallbackRegistryBase {
template <typename... U>
void Invoke(U&&... u) const {
#ifdef _MSC_VER // work around VS2019 16.4.0 bug
std::scoped_lock<wpi::recursive_spinlock> lock(m_mutex);
#else
std::scoped_lock lock(m_mutex);
#endif
if (m_callbacks) {
const char* name = GetName();
for (auto&& cb : *m_callbacks)

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -18,6 +18,8 @@ void InitializeSPI() {}
} // namespace init
} // namespace hal
extern "C" {
void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
hal::init::CheckInit();
SimSPIData[port].initialized = true;
@@ -63,3 +65,9 @@ int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
return 0;
}
void HAL_ConfigureSPIAutoStall(HAL_SPIPort port, int32_t csToSclkTicks,
int32_t stallTicks, int32_t pow2BytesPerRead,
int32_t* status) {}
} // extern "C"

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -14,6 +14,7 @@
#include "CallbackStore.h"
#include "edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI.h"
#include "mockdata/DriverStationData.h"
#include "mockdata/MockHooks.h"
using namespace wpi::java;
@@ -446,6 +447,25 @@ Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_notifyNewData
HALSIM_NotifyDriverStationNewData();
}
/*
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
* Method: setSendError
* Signature: (Z)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setSendError
(JNIEnv*, jclass, jboolean shouldSend)
{
if (shouldSend) {
HALSIM_SetSendError(nullptr);
} else {
HALSIM_SetSendError([](HAL_Bool isError, int32_t errorCode,
HAL_Bool isLVCode, const char* details,
const char* location, const char* callStack,
HAL_Bool printMsg) { return 1; });
}
}
/*
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
* Method: resetData

View File

@@ -44,6 +44,7 @@ public final class NetworkTableInstance implements AutoCloseable {
public static final int kNetModeClient = 0x02;
public static final int kNetModeStarting = 0x04;
public static final int kNetModeFailure = 0x08;
public static final int kNetModeLocal = 0x10;
/**
* The default port that network tables operates on.
@@ -675,6 +676,23 @@ public final class NetworkTableInstance implements AutoCloseable {
return NetworkTablesJNI.getNetworkMode(m_handle);
}
/**
* Starts local-only operation. Prevents calls to startServer or startClient
* from taking effect. Has no effect if startServer or startClient
* has already been called.
*/
public void startLocal() {
NetworkTablesJNI.startLocal(m_handle);
}
/**
* Stops local-only operation. startServer or startClient can be called after
* this call to start a server or client.
*/
public void stopLocal() {
NetworkTablesJNI.stopLocal(m_handle);
}
/**
* Starts a server using the networktables.ini as the persistent file,
* using the default listening address and port.

View File

@@ -139,6 +139,8 @@ public final class NetworkTablesJNI {
public static native void setNetworkIdentity(int inst, String name);
public static native int getNetworkMode(int inst);
public static native void startLocal(int inst);
public static native void stopLocal(int inst);
public static native void startServer(int inst, String persistFilename, String listenAddress, int port);
public static native void stopServer(int inst);
public static native void startClient(int inst);

View File

@@ -115,6 +115,16 @@ DispatcherBase::~DispatcherBase() { Stop(); }
unsigned int DispatcherBase::GetNetworkMode() const { return m_networkMode; }
void DispatcherBase::StartLocal() {
{
std::scoped_lock lock(m_user_mutex);
if (m_active) return;
m_active = true;
}
m_networkMode = NT_NET_MODE_LOCAL;
m_storage.SetDispatcher(this, false);
}
void DispatcherBase::StartServer(
const Twine& persist_filename,
std::unique_ptr<wpi::NetworkAcceptor> acceptor) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -48,6 +48,7 @@ class DispatcherBase : public IDispatcher {
virtual ~DispatcherBase();
unsigned int GetNetworkMode() const;
void StartLocal();
void StartServer(const Twine& persist_filename,
std::unique_ptr<wpi::NetworkAcceptor> acceptor);
void StartClient();

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -1368,6 +1368,30 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_getNetworkMode
return nt::GetNetworkMode(inst);
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: startLocal
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_startLocal
(JNIEnv*, jclass, jint inst)
{
nt::StartLocal(inst);
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: stopLocal
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_stopLocal
(JNIEnv*, jclass, jint inst)
{
nt::StopLocal(inst);
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: startServer

View File

@@ -539,6 +539,10 @@ unsigned int NT_GetNetworkMode(NT_Inst inst) {
return nt::GetNetworkMode(inst);
}
void NT_StartLocal(NT_Inst inst) { nt::StartLocal(inst); }
void NT_StopLocal(NT_Inst inst) { nt::StopLocal(inst); }
void NT_StartServer(NT_Inst inst, const char* persist_filename,
const char* listen_address, unsigned int port) {
nt::StartServer(inst, persist_filename, listen_address, port);

View File

@@ -742,6 +742,20 @@ unsigned int GetNetworkMode(NT_Inst inst) {
return ii->dispatcher.GetNetworkMode();
}
void StartLocal(NT_Inst inst) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) return;
ii->dispatcher.StartLocal();
}
void StopLocal(NT_Inst inst) {
auto ii = InstanceImpl::Get(Handle{inst}.GetTypedInst(Handle::kInstance));
if (!ii) return;
ii->dispatcher.Stop();
}
void StartServer(StringRef persist_filename, const char* listen_address,
unsigned int port) {
auto ii = InstanceImpl::GetDefault();

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -61,7 +61,8 @@ class NetworkTableInstance final {
kNetModeServer = NT_NET_MODE_SERVER,
kNetModeClient = NT_NET_MODE_CLIENT,
kNetModeStarting = NT_NET_MODE_STARTING,
kNetModeFailure = NT_NET_MODE_FAILURE
kNetModeFailure = NT_NET_MODE_FAILURE,
kNetModeLocal = NT_NET_MODE_LOCAL
};
/**
@@ -298,6 +299,19 @@ class NetworkTableInstance final {
*/
unsigned int GetNetworkMode() const;
/**
* Starts local-only operation. Prevents calls to StartServer or StartClient
* from taking effect. Has no effect if StartServer or StartClient
* has already been called.
*/
void StartLocal();
/**
* Stops local-only operation. StartServer or StartClient can be called after
* this call to start a server or client.
*/
void StopLocal();
/**
* Starts a server using the specified filename, listening address, and port.
*

View File

@@ -81,6 +81,10 @@ inline unsigned int NetworkTableInstance::GetNetworkMode() const {
return ::nt::GetNetworkMode(m_handle);
}
inline void NetworkTableInstance::StartLocal() { ::nt::StartLocal(m_handle); }
inline void NetworkTableInstance::StopLocal() { ::nt::StopLocal(m_handle); }
inline void NetworkTableInstance::StartServer(const Twine& persist_filename,
const char* listen_address,
unsigned int port) {

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -95,6 +95,7 @@ enum NT_NetworkMode {
NT_NET_MODE_CLIENT = 0x02, /* running in client mode */
NT_NET_MODE_STARTING = 0x04, /* flag for starting (either client or server) */
NT_NET_MODE_FAILURE = 0x08, /* flag for failure (either client or server) */
NT_NET_MODE_LOCAL = 0x10, /* running in local-only mode */
};
/*
@@ -1037,6 +1038,19 @@ void NT_SetNetworkIdentity(NT_Inst inst, const char* name, size_t name_len);
*/
unsigned int NT_GetNetworkMode(NT_Inst inst);
/**
* Starts local-only operation. Prevents calls to NT_StartServer or
* NT_StartClient from taking effect. Has no effect if NT_StartServer or
* NT_StartClient has already been called.
*/
void NT_StartLocal(NT_Inst inst);
/**
* Stops local-only operation. NT_StartServer or NT_StartClient can be called
* after this call to start a server or client.
*/
void NT_StopLocal(NT_Inst inst);
/**
* Starts a server using the specified filename, listening address, and port.
*

View File

@@ -1130,6 +1130,19 @@ unsigned int GetNetworkMode();
*/
unsigned int GetNetworkMode(NT_Inst inst);
/**
* Starts local-only operation. Prevents calls to StartServer or StartClient
* from taking effect. Has no effect if StartServer or StartClient
* has already been called.
*/
void StartLocal(NT_Inst inst);
/**
* Stops local-only operation. StartServer or StartClient can be called after
* this call to start a server or client.
*/
void StopLocal(NT_Inst inst);
/**
* Starts a server using the specified filename, listening address, and port.
*

View File

@@ -8,9 +8,9 @@ nativeUtils {
wpi {
configureDependencies {
wpiVersion = "-1"
niLibVersion = "2020.9.1"
niLibVersion = "2020.10.1"
opencvVersion = "3.4.7-2"
googleTestVersion = "1.9.0-3-437e100"
googleTestVersion = "1.9.0-4-437e100-1"
imguiVersion = "1.72b-2"
}
}

View File

@@ -0,0 +1,21 @@
model {
tasks {
def ts = $.testSuites
project.tasks.register('testDesktopCpp') { testTask->
def systemArch = getCurrentArch()
def found = false
ts.each {
if (it in GoogleTestTestSuiteSpec && it.name == "${nativeName}Test") {
it.binaries.each {
if (found) return
def arch = it.targetPlatform.name
if (arch == systemArch && it.buildType.name == 'debug') {
testTask.dependsOn it.tasks.run
found = true
}
}
}
}
}
}
}

View File

@@ -70,6 +70,7 @@ task checkCommands(type: Task) {
assert it.tags != null
assert it.foldername != null
assert it.replacename != null
assert it.commandversion != null
if (project.isCppCommands) {
assert it.headers != null
assert !it.headers.isEmpty()

View File

@@ -0,0 +1,3 @@
tasks.register('testDesktopJava') {
dependsOn test
}

View File

@@ -141,6 +141,9 @@ model {
}
}
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
tasks.withType(RunTestExecutable) {
args "--gtest_output=xml:test_detail.xml"
outputs.dir outputDir

View File

@@ -275,6 +275,9 @@ model {
}
}
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
ext.getJniSpecClass = {
return JniNativeLibrarySpec
}

View File

@@ -24,9 +24,18 @@ static void DisplayAnalogInputs() {
bool hasInputs = false;
static int numAnalog = HAL_GetNumAnalogInputs();
static int numAccum = HAL_GetNumAccumulators();
bool first = true;
for (int i = 0; i < numAnalog; ++i) {
if (HALSIM_GetAnalogInInitialized(i)) {
hasInputs = true;
if (!first) {
ImGui::Spacing();
ImGui::Spacing();
} else {
first = false;
}
char name[32];
std::snprintf(name, sizeof(name), "In[%d]", i);
if (i < numAccum && HALSIM_GetAnalogGyroInitialized(i)) {

View File

@@ -89,7 +89,7 @@ public final class CommandScheduler implements Sendable {
CommandScheduler() {
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand_Scheduler);
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand2_Scheduler);
SendableRegistry.addLW(this, "Scheduler");
}

View File

@@ -25,10 +25,20 @@ public abstract class PIDSubsystem extends SubsystemBase {
* Creates a new PIDSubsystem.
*
* @param controller the PIDController to use
* @param initialPosition the initial setpoint of the subsystem
*/
public PIDSubsystem(PIDController controller, double initialPosition) {
setSetpoint(initialPosition);
m_controller = requireNonNullParam(controller, "controller", "PIDSubsystem");
}
/**
* Creates a new PIDSubsystem. Initial setpoint is zero.
*
* @param controller the PIDController to use
*/
public PIDSubsystem(PIDController controller) {
requireNonNullParam(controller, "controller", "PIDSubsystem");
m_controller = controller;
this(controller, 0);
}
@Override

View File

@@ -27,10 +27,21 @@ public abstract class ProfiledPIDSubsystem extends SubsystemBase {
* Creates a new ProfiledPIDSubsystem.
*
* @param controller the ProfiledPIDController to use
* @param initialPosition the initial goal position of the controller
*/
public ProfiledPIDSubsystem(ProfiledPIDController controller,
double initialPosition) {
m_controller = requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem");
setGoal(initialPosition);
}
/**
* Creates a new ProfiledPIDSubsystem. Initial goal position is zero.
*
* @param controller the ProfiledPIDController to use
*/
public ProfiledPIDSubsystem(ProfiledPIDController controller) {
requireNonNullParam(controller, "controller", "ProfiledPIDSubsystem");
m_controller = controller;
this(controller, 0);
}
@Override

View File

@@ -76,7 +76,6 @@ public abstract class SubsystemBase implements Subsystem, Sendable {
*/
public void addChild(String name, Sendable child) {
SendableRegistry.addLW(child, getSubsystem(), name);
SendableRegistry.addChild(this, child);
}
@Override

View File

@@ -9,6 +9,8 @@ package edu.wpi.first.wpilibj2.command;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
/**
* A subsystem that generates and runs trapezoidal motion profiles automatically. The user
* specifies how to use the current state of the motion profile by overriding the `useState` method.
@@ -20,41 +22,53 @@ public abstract class TrapezoidProfileSubsystem extends SubsystemBase {
private TrapezoidProfile.State m_state;
private TrapezoidProfile.State m_goal;
/**
* Creates a new TrapezoidProfileSubsystem.
*
* @param constraints The constraints (maximum velocity and acceleration) for the profiles.
* @param initialPosition The initial position of the controller mechanism when the subsystem
* is constructed.
*/
public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints,
double initialPosition) {
m_constraints = constraints;
m_state = new TrapezoidProfile.State(initialPosition, 0);
m_period = 0.02;
}
private boolean m_enabled = true;
/**
* Creates a new TrapezoidProfileSubsystem.
*
* @param constraints The constraints (maximum velocity and acceleration) for the profiles.
* @param initialPosition The initial position of the controller mechanism when the subsystem
* @param initialPosition The initial position of the controlled mechanism when the subsystem
* is constructed.
* @param period The period of the main robot loop, in seconds.
*/
public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints,
double initialPosition,
double period) {
m_constraints = constraints;
m_constraints = requireNonNullParam(constraints, "constraints", "TrapezoidProfileSubsystem");
m_state = new TrapezoidProfile.State(initialPosition, 0);
setGoal(initialPosition);
m_period = period;
}
/**
* Creates a new TrapezoidProfileSubsystem.
*
* @param constraints The constraints (maximum velocity and acceleration) for the profiles.
* @param initialPosition The initial position of the controlled mechanism when the subsystem
* is constructed.
*/
public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints,
double initialPosition) {
this(constraints, initialPosition, 0.02);
}
/**
* Creates a new TrapezoidProfileSubsystem.
*
* @param constraints The constraints (maximum velocity and acceleration) for the profiles.
*/
public TrapezoidProfileSubsystem(TrapezoidProfile.Constraints constraints) {
this(constraints, 0, 0.02);
}
@Override
public void periodic() {
var profile = new TrapezoidProfile(m_constraints, m_goal, m_state);
m_state = profile.calculate(m_period);
useState(m_state);
if (m_enabled) {
useState(m_state);
}
}
/**
@@ -75,6 +89,20 @@ public abstract class TrapezoidProfileSubsystem extends SubsystemBase {
setGoal(new TrapezoidProfile.State(goal, 0));
}
/**
* Enable the TrapezoidProfileSubsystem's output.
*/
public void enable() {
m_enabled = true;
}
/**
* Disable the TrapezoidProfileSubsystem's output.
*/
public void disable() {
m_enabled = false;
}
/**
* Users should override this to consume the current state of the motion profile.
*

View File

@@ -11,6 +11,7 @@
#include <frc/WPIErrors.h>
#include <frc/smartdashboard/SendableBuilder.h>
#include <frc/smartdashboard/SendableRegistry.h>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
#include <networktables/NetworkTableEntry.h>
#include <wpi/DenseMap.h>
@@ -67,6 +68,8 @@ static bool ContainsKey(const TMap& map, TKey keyToCheck) {
}
CommandScheduler::CommandScheduler() : m_impl(new Impl) {
HAL_Report(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand2_Scheduler);
frc::SendableRegistry::GetInstance().AddLW(this, "Scheduler");
}

View File

@@ -9,8 +9,10 @@
using namespace frc2;
PIDSubsystem::PIDSubsystem(PIDController controller)
: m_controller{controller} {}
PIDSubsystem::PIDSubsystem(PIDController controller, double initialPosition)
: m_controller{controller} {
SetSetpoint(initialPosition);
}
void PIDSubsystem::Periodic() {
if (m_enabled) {

View File

@@ -63,5 +63,4 @@ void SubsystemBase::SetSubsystem(const wpi::Twine& name) {
void SubsystemBase::AddChild(std::string name, frc::Sendable* child) {
auto& registry = frc::SendableRegistry::GetInstance();
registry.AddLW(child, GetSubsystem(), name);
registry.AddChild(this, child);
}

View File

@@ -24,8 +24,9 @@ class PIDSubsystem : public SubsystemBase {
* Creates a new PIDSubsystem.
*
* @param controller the PIDController to use
* @param initialPosition the initial setpoint of the subsystem
*/
explicit PIDSubsystem(PIDController controller);
explicit PIDSubsystem(PIDController controller, double initialPosition = 0);
void Periodic() override;
@@ -62,7 +63,7 @@ class PIDSubsystem : public SubsystemBase {
protected:
PIDController m_controller;
bool m_enabled;
bool m_enabled{false};
/**
* Returns the measurement of the process variable used by the PIDController.

View File

@@ -32,9 +32,13 @@ class ProfiledPIDSubsystem : public SubsystemBase {
* Creates a new ProfiledPIDSubsystem.
*
* @param controller the ProfiledPIDController to use
* @param initialPosition the initial goal position of the subsystem
*/
explicit ProfiledPIDSubsystem(frc::ProfiledPIDController<Distance> controller)
: m_controller{controller} {}
explicit ProfiledPIDSubsystem(frc::ProfiledPIDController<Distance> controller,
Distance_t initialPosition = Distance_t{0})
: m_controller{controller} {
SetGoal(initialPosition);
}
void Periodic() override {
if (m_enabled) {

View File

@@ -42,7 +42,7 @@ class TrapezoidProfileCommand
*/
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
std::function<void(State)> output,
std::initializer_list<Subsystem*> requirements)
std::initializer_list<Subsystem*> requirements = {})
: m_profile(profile), m_output(output) {
this->AddRequirements(requirements);
}

View File

@@ -37,18 +37,21 @@ class TrapezoidProfileSubsystem : public SubsystemBase {
* when the subsystem is constructed.
* @param period The period of the main robot loop, in seconds.
*/
TrapezoidProfileSubsystem(Constraints constraints, Distance_t position,
units::second_t period = 20_ms)
explicit TrapezoidProfileSubsystem(Constraints constraints,
Distance_t initialPosition = Distance_t{0},
units::second_t period = 20_ms)
: m_constraints(constraints),
m_state{position, Velocity_t(0)},
m_goal{position, Velocity_t{0}},
m_state{initialPosition, Velocity_t(0)},
m_goal{initialPosition, Velocity_t{0}},
m_period(period) {}
void Periodic() override {
auto profile =
frc::TrapezoidProfile<Distance>(m_constraints, m_goal, m_state);
m_state = profile.Calculate(m_period);
UseState(m_state);
if (m_enabled) {
UseState(m_state);
}
}
/**
@@ -74,10 +77,21 @@ class TrapezoidProfileSubsystem : public SubsystemBase {
*/
virtual void UseState(State state) = 0;
/**
* Enable the TrapezoidProfileSubsystem's output.
*/
void Enable() { m_enabled = true; }
/**
* Disable the TrapezoidProfileSubsystem's output.
*/
void Disable() { m_enabled = false; }
private:
Constraints m_constraints;
State m_state;
State m_goal;
units::second_t m_period;
bool m_enabled{false};
};
} // namespace frc2

View File

@@ -184,7 +184,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
*/
public void addChild(String name, Sendable child) {
SendableRegistry.addLW(child, getSubsystem(), name);
SendableRegistry.addChild(this, child);
}
/**
@@ -195,7 +194,6 @@ public abstract class Subsystem implements Sendable, AutoCloseable {
public void addChild(Sendable child) {
SendableRegistry.setSubsystem(child, getSubsystem());
SendableRegistry.enableLiveWindow(child);
SendableRegistry.addChild(this, child);
}
/**

View File

@@ -101,7 +101,6 @@ void Subsystem::AddChild(const wpi::Twine& name, Sendable* child) {
void Subsystem::AddChild(const wpi::Twine& name, Sendable& child) {
auto& registry = SendableRegistry::GetInstance();
registry.AddLW(&child, registry.GetSubsystem(this), name);
registry.AddChild(this, &child);
}
void Subsystem::AddChild(std::shared_ptr<Sendable> child) { AddChild(*child); }
@@ -112,7 +111,6 @@ void Subsystem::AddChild(Sendable& child) {
auto& registry = SendableRegistry::GetInstance();
registry.SetSubsystem(&child, registry.GetSubsystem(this));
registry.EnableLiveWindow(&child);
registry.AddChild(this, &child);
}
void Subsystem::ConfirmCommand() {

View File

@@ -231,6 +231,8 @@ model {
}
}
apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
tasks.withType(RunTestExecutable) {
args "--gtest_output=xml:test_detail.xml"
outputs.dir outputDir

View File

@@ -20,7 +20,9 @@ DutyCycleEncoder::DutyCycleEncoder(int channel)
: m_dutyCycle{std::make_shared<DutyCycle>(
std::make_shared<DigitalInput>(channel))},
m_analogTrigger{m_dutyCycle.get()},
m_counter{} {}
m_counter{} {
Init();
}
DutyCycleEncoder::DutyCycleEncoder(DutyCycle& dutyCycle)
: m_dutyCycle{&dutyCycle, NullDeleter<DutyCycle>{}},

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "frc/PWMTalonFX.h"
#include <hal/FRCUsageReporting.h>
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
PWMTalonFX::PWMTalonFX(int channel) : PWMSpeedController(channel) {
SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetSpeed(0.0);
SetZeroLatch();
HAL_Report(HALUsageReporting::kResourceType_TalonFX, GetChannel() + 1);
SendableRegistry::GetInstance().SetName(this, "PWMTalonFX", GetChannel());
}

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "frc/PWMVenom.h"
#include <hal/FRCUsageReporting.h>
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
PWMVenom::PWMVenom(int channel) : PWMSpeedController(channel) {
SetBounds(2.004, 1.52, 1.50, 1.48, 0.997);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetSpeed(0.0);
SetZeroLatch();
HAL_Report(HALUsageReporting::kResourceType_FusionVenom, GetChannel() + 1);
SendableRegistry::GetInstance().SetName(this, "PWMVenom", GetChannel());
}

View File

@@ -311,6 +311,14 @@ int SPI::GetAutoDroppedCount() {
return val;
}
void SPI::ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks,
int stallTicks, int pow2BytesPerRead) {
int32_t status = 0;
HAL_ConfigureSPIAutoStall(m_port, csToSclkTicks, stallTicks, pow2BytesPerRead,
&status);
wpi_setHALError(status);
}
void SPI::InitAccumulator(units::second_t period, int cmd, int xferSize,
int validMask, int validValue, int dataShift,
int dataSize, bool isSigned, bool bigEndian) {

View File

@@ -22,7 +22,7 @@ PIDController::PIDController(double Kp, double Ki, double Kd,
: m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), m_period(period) {
static int instances = 0;
instances++;
HAL_Report(HALUsageReporting::kResourceType_PIDController, instances);
HAL_Report(HALUsageReporting::kResourceType_PIDController2, instances);
frc::SendableRegistry::GetInstance().Add(this, "PIDController", instances);
}

View File

@@ -0,0 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "frc/controller/ProfiledPIDController.h"
#include <hal/FRCUsageReporting.h>
void frc::detail::ReportProfiledPIDController() {
static int instances = 0;
++instances;
HAL_Report(HALUsageReporting::kResourceType_ProfiledPIDController, instances);
}

View File

@@ -7,6 +7,8 @@
#include "frc/kinematics/DifferentialDriveOdometry.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
DifferentialDriveOdometry::DifferentialDriveOdometry(
@@ -14,6 +16,8 @@ DifferentialDriveOdometry::DifferentialDriveOdometry(
: m_pose(initialPose) {
m_previousAngle = m_pose.Rotation();
m_gyroOffset = m_pose.Rotation() - gyroAngle;
HAL_Report(HALUsageReporting::kResourceType_Odometry,
HALUsageReporting::kOdometry_DifferentialDrive);
}
const Pose2d& DifferentialDriveOdometry::Update(const Rotation2d& gyroAngle,

View File

@@ -7,6 +7,8 @@
#include "frc/kinematics/MecanumDriveOdometry.h"
#include <hal/FRCUsageReporting.h>
using namespace frc;
MecanumDriveOdometry::MecanumDriveOdometry(MecanumDriveKinematics kinematics,
@@ -15,6 +17,8 @@ MecanumDriveOdometry::MecanumDriveOdometry(MecanumDriveKinematics kinematics,
: m_kinematics(kinematics), m_pose(initialPose) {
m_previousAngle = m_pose.Rotation();
m_gyroOffset = m_pose.Rotation() - gyroAngle;
HAL_Report(HALUsageReporting::kResourceType_Odometry,
HALUsageReporting::kOdometry_MecanumDrive);
}
const Pose2d& MecanumDriveOdometry::UpdateWithTime(

View File

@@ -134,6 +134,12 @@ void SendableRegistry::AddLW(Sendable* sendable, const wpi::Twine& subsystem,
comp.subsystem = subsystem.str();
}
void SendableRegistry::AddChild(Sendable* parent, Sendable* child) {
std::scoped_lock lock(m_impl->mutex);
auto& comp = m_impl->GetOrAdd(child);
comp.parent = parent;
}
void SendableRegistry::AddChild(Sendable* parent, void* child) {
std::scoped_lock lock(m_impl->mutex);
auto& comp = m_impl->GetOrAdd(child);
@@ -147,6 +153,10 @@ bool SendableRegistry::Remove(Sendable* sendable) {
UID compUid = it->getSecond();
m_impl->components.erase(compUid - 1);
m_impl->componentMap.erase(it);
// update any parent pointers
for (auto&& comp : m_impl->components) {
if (comp->parent == sendable) comp->parent = nullptr;
}
return true;
}
@@ -164,6 +174,10 @@ void SendableRegistry::Move(Sendable* to, Sendable* from) {
comp.builder.ClearProperties();
to->InitSendable(comp.builder);
}
// update any parent pointers
for (auto&& comp : m_impl->components) {
if (comp->parent == from) comp->parent = to;
}
}
bool SendableRegistry::Contains(const Sendable* sendable) const {

View File

@@ -107,6 +107,33 @@ Trajectory::State Trajectory::Sample(units::second_t t) const {
(t - prevSample.t) / (sample.t - prevSample.t));
}
Trajectory Trajectory::TransformBy(const Transform2d& transform) {
auto& firstState = m_states[0];
auto& firstPose = firstState.pose;
// Calculate the transformed first pose.
auto newFirstPose = firstPose + transform;
auto newStates = m_states;
newStates[0].pose = newFirstPose;
for (unsigned int i = 1; i < newStates.size(); i++) {
auto& state = newStates[i];
// We are transforming relative to the coordinate frame of the new initial
// pose.
state.pose = newFirstPose + (state.pose - firstPose);
}
return Trajectory(newStates);
}
Trajectory Trajectory::RelativeTo(const Pose2d& pose) {
auto newStates = m_states;
for (auto& state : newStates) {
state.pose = state.pose.RelativeTo(pose);
}
return Trajectory(newStates);
}
void frc::to_json(wpi::json& json, const Trajectory::State& state) {
json = wpi::json{{"time", state.t.to<double>()},
{"velocity", state.velocity.to<double>()},

View File

@@ -36,7 +36,7 @@ int frc::RunHALInitialization() {
return -1;
}
HAL_Report(HALUsageReporting::kResourceType_Language,
HALUsageReporting::kLanguage_CPlusPlus);
HALUsageReporting::kLanguage_CPlusPlus, 0, GetWPILibVersion());
wpi::outs() << "\n********** Robot program starting **********\n";
return 0;
}
@@ -124,7 +124,11 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) {
auto inst = nt::NetworkTableInstance::GetDefault();
inst.SetNetworkIdentity("Robot");
#ifdef __FRC_ROBORIO__
inst.StartServer("/home/lvuser/networktables.ini");
#else
inst.StartServer();
#endif
SmartDashboard::init();

View File

@@ -15,6 +15,8 @@
#include <wpi/ArrayRef.h>
#include "frc/ErrorBase.h"
#include "util/Color.h"
#include "util/Color8Bit.h"
namespace frc {
@@ -54,6 +56,28 @@ class AddressableLED : public ErrorBase {
* @param v the v value [0-255]
*/
void SetHSV(int h, int s, int v);
/*
* Sets a specific LED in the buffer.
*
* @param color The color of the LED
*/
void SetLED(const Color& color) {
this->r = color.red * 255;
this->g = color.green * 255;
this->b = color.blue * 255;
}
/*
* Sets a specific LED in the buffer.
*
* @param color The color of the LED
*/
void SetLED(const Color8Bit& color) {
this->r = color.red;
this->g = color.green;
this->b = color.blue;
}
};
/**

View File

@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "frc/PWMSpeedController.h"
namespace frc {
/**
* Cross the Road Electronics (CTRE) Talon FX Speed Controller with PWM
* control.
*
* Note that the Talon FX uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
* experience issues such as asymmetric behavior around the deadband or
* inability to saturate the controller in either direction, calibration is
* recommended. The calibration procedure can be found in the Talon FX User
* Manual available from Cross The Road Electronics.
*
* \li 2.004ms = full "forward"
* \li 1.520ms = the "high end" of the deadband range
* \li 1.500ms = center of the deadband range (off)
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMTalonFX : public PWMSpeedController {
public:
/**
* Construct a Talon FX connected via PWM.
*
* @param channel The PWM channel that the Talon FX is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
explicit PWMTalonFX(int channel);
PWMTalonFX(PWMTalonFX&&) = default;
PWMTalonFX& operator=(PWMTalonFX&&) = default;
};
} // namespace frc

View File

@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "frc/PWMSpeedController.h"
namespace frc {
/**
* Playing with Fusion Venom Smart Motor with PWM control.
*
* Note that the Venom uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
* experience issues such as asymmetric behavior around the deadband or
* inability to saturate the controller in either direction, calibration is
* recommended.
*
* \li 2.004ms = full "forward"
* \li 1.520ms = the "high end" of the deadband range
* \li 1.500ms = center of the deadband range (off)
* \li 1.480ms = the "low end" of the deadband range
* \li 0.997ms = full "reverse"
*/
class PWMVenom : public PWMSpeedController {
public:
/**
* Construct a Venom connected via PWM.
*
* @param channel The PWM channel that the Venom is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
explicit PWMVenom(int channel);
PWMVenom(PWMVenom&&) = default;
PWMVenom& operator=(PWMVenom&&) = default;
};
} // namespace frc

View File

@@ -269,6 +269,19 @@ class SPI : public ErrorBase {
*/
int GetAutoDroppedCount();
/**
* Configure the Auto SPI Stall time between reads.
*
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for
* MXP.
* @param csToSclkTicks the number of ticks to wait before asserting the cs
* pin
* @param stallTicks the number of ticks to stall for
* @param pow2BytesPerRead the number of bytes to read before stalling
*/
void ConfigureAutoStall(HAL_SPIPort port, int csToSclkTicks, int stallTicks,
int pow2BytesPerRead);
/**
* Initialize the accumulator.
*

View File

@@ -0,0 +1,74 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/Timer.h>
#include <algorithm>
#include <units/units.h>
namespace frc {
/**
* A class that limits the rate of change of an input value. Useful for
* implementing voltage, setpoint, and/or output ramps. A slew-rate limit
* is most appropriate when the quantity being controlled is a velocity or
* a voltage; when controlling a position, consider using a TrapezoidProfile
* instead.
*
* @see TrapezoidProfile
*/
template <class Unit>
class SlewRateLimiter {
using Unit_t = units::unit_t<Unit>;
using Rate = units::compound_unit<Unit, units::inverse<units::seconds>>;
using Rate_t = units::unit_t<Rate>;
public:
/**
* Creates a new SlewRateLimiter with the given rate limit and initial value.
*
* @param rateLimit The rate-of-change limit.
* @param initialValue The initial value of the input.
*/
explicit SlewRateLimiter(Rate_t rateLimit, Unit_t initialValue = Unit_t{0})
: m_rateLimit{rateLimit}, m_prevVal{initialValue} {
m_timer.Start();
}
/**
* Filters the input to limit its slew rate.
*
* @param input The input value whose slew rate is to be limited.
* @return The filtered value, which will not change faster than the slew
* rate.
*/
Unit_t Calculate(Unit_t input) {
m_prevVal += std::clamp(input - m_prevVal, -m_rateLimit * m_timer.Get(),
m_rateLimit * m_timer.Get());
m_timer.Reset();
return m_prevVal;
}
/**
* Resets the slew rate limiter to the specified value; ignores the rate limit
* when doing so.
*
* @param value The value to reset to.
*/
void Reset(Unit_t value) {
m_timer.Reset();
m_prevVal = value;
}
private:
frc2::Timer m_timer;
Rate_t m_rateLimit;
Unit_t m_prevVal;
};
} // namespace frc

View File

@@ -21,6 +21,9 @@
#include "frc/trajectory/TrapezoidProfile.h"
namespace frc {
namespace detail {
void ReportProfiledPIDController();
} // namespace detail
/**
* Implements a PID control loop whose setpoint is constrained by a trapezoid
@@ -54,7 +57,9 @@ class ProfiledPIDController
*/
ProfiledPIDController(double Kp, double Ki, double Kd,
Constraints constraints, units::second_t period = 20_ms)
: m_controller(Kp, Ki, Kd, period), m_constraints(constraints) {}
: m_controller(Kp, Ki, Kd, period), m_constraints(constraints) {
detail::ReportProfiledPIDController();
}
~ProfiledPIDController() override = default;

View File

@@ -7,6 +7,7 @@
#pragma once
#include <hal/FRCUsageReporting.h>
#include <units/units.h>
#include "frc/kinematics/ChassisSpeeds.h"
@@ -31,8 +32,11 @@ class DifferentialDriveKinematics {
* empirical value may be larger than the physical measured value due to
* scrubbing effects.
*/
constexpr explicit DifferentialDriveKinematics(units::meter_t trackWidth)
: trackWidth(trackWidth) {}
explicit DifferentialDriveKinematics(units::meter_t trackWidth)
: trackWidth(trackWidth) {
HAL_Report(HALUsageReporting::kResourceType_Kinematics,
HALUsageReporting::kKinematics_DifferentialDrive);
}
/**
* Returns a chassis speed from left and right component velocities using

View File

@@ -9,6 +9,7 @@
#include <Eigen/Core>
#include <Eigen/QR>
#include <hal/FRCUsageReporting.h>
#include "frc/geometry/Translation2d.h"
#include "frc/kinematics/ChassisSpeeds.h"
@@ -63,6 +64,8 @@ class MecanumDriveKinematics {
SetInverseKinematics(frontLeftWheel, frontRightWheel, rearLeftWheel,
rearRightWheel);
m_forwardKinematics = m_inverseKinematics.householderQr();
HAL_Report(HALUsageReporting::kResourceType_Kinematics,
HALUsageReporting::kKinematics_MecanumDrive);
}
MecanumDriveKinematics(const MecanumDriveKinematics&) = default;

View File

@@ -12,6 +12,7 @@
#include <Eigen/Core>
#include <Eigen/QR>
#include <hal/FRCUsageReporting.h>
#include <units/units.h>
#include "frc/geometry/Rotation2d.h"
@@ -71,6 +72,9 @@ class SwerveDriveKinematics {
}
m_forwardKinematics = m_inverseKinematics.householderQr();
HAL_Report(HALUsageReporting::kResourceType_Kinematics,
HALUsageReporting::kKinematics_SwerveDrive);
}
SwerveDriveKinematics(const SwerveDriveKinematics&) = default;

View File

@@ -7,6 +7,8 @@
#pragma once
#include <hal/FRCUsageReporting.h>
namespace frc {
template <size_t NumModules>
SwerveDriveOdometry<NumModules>::SwerveDriveOdometry(
@@ -15,6 +17,8 @@ SwerveDriveOdometry<NumModules>::SwerveDriveOdometry(
: m_kinematics(kinematics), m_pose(initialPose) {
m_previousAngle = m_pose.Rotation();
m_gyroOffset = m_pose.Rotation() - gyroAngle;
HAL_Report(HALUsageReporting::kResourceType_Odometry,
HALUsageReporting::kOdometry_SwerveDrive);
}
template <size_t NumModules>

View File

@@ -118,6 +118,15 @@ class SendableRegistry {
void AddLW(Sendable* sendable, const wpi::Twine& subsystem,
const wpi::Twine& name);
/**
* Adds a child object to an object. Adds the child object to the registry
* if it's not already present.
*
* @param parent parent object
* @param child child object
*/
void AddChild(Sendable* parent, Sendable* child);
/**
* Adds a child object to an object. Adds the child object to the registry
* if it's not already present.

View File

@@ -12,6 +12,7 @@
#include <units/units.h>
#include "frc/geometry/Pose2d.h"
#include "frc/geometry/Transform2d.h"
namespace wpi {
class json;
@@ -105,6 +106,34 @@ class Trajectory {
*/
State Sample(units::second_t t) const;
/**
* Transforms all poses in the trajectory by the given transform. This is
* useful for converting a robot-relative trajectory into a field-relative
* trajectory. This works with respect to the first pose in the trajectory.
*
* @param transform The transform to transform the trajectory by.
* @return The transformed trajectory.
*/
Trajectory TransformBy(const Transform2d& transform);
/**
* Transforms all poses in the trajectory so that they are relative to the
* given pose. This is useful for converting a field-relative trajectory
* into a robot-relative trajectory.
*
* @param pose The pose that is the origin of the coordinate frame that
* the current trajectory will be transformed into.
* @return The transformed trajectory.
*/
Trajectory RelativeTo(const Pose2d& pose);
/**
* Returns the initial pose of the trajectory.
*
* @return The initial pose of the trajectory.
*/
Pose2d InitialPose() const { return Sample(0_s).pose; }
private:
std::vector<State> m_states;
units::second_t m_totalTime;

View File

@@ -7,6 +7,7 @@
#pragma once
#include <hal/FRCUsageReporting.h>
#include <units/units.h>
namespace frc {
@@ -53,6 +54,13 @@ class TrapezoidProfile {
public:
class Constraints {
public:
Constraints() {
HAL_Report(HALUsageReporting::kResourceType_TrapezoidProfile, 1);
}
Constraints(Velocity_t maxVelocity_, Acceleration_t maxAcceleration_)
: maxVelocity{maxVelocity_}, maxAcceleration{maxAcceleration_} {
HAL_Report(HALUsageReporting::kResourceType_TrapezoidProfile, 1);
}
Velocity_t maxVelocity{0};
Acceleration_t maxAcceleration{0};
};

View File

@@ -0,0 +1,949 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <algorithm>
namespace frc {
/**
* Represents colors that can be used with Addressable LEDs.
*
* Limited to 12 bits of precision.
*/
class Color {
public:
/*
* FIRST Colors
*/
/**
* #1560BD.
*/
static const Color kDenim;
/**
* #0066B3.
*/
static const Color kFirstBlue;
/**
* #ED1C24.
*/
static const Color kFirstRed;
/*
* Standard Colors
*/
/**
* #F0F8FF.
*/
static const Color kAliceBlue;
/**
* #FAEBD7.
*/
static const Color kAntiqueWhite;
/**
* #00FFFF.
*/
static const Color kAqua;
/**
* #7FFFD4.
*/
static const Color kAquamarine;
/**
* #F0FFFF.
*/
static const Color kAzure;
/**
* #F5F5DC.
*/
static const Color kBeige;
/**
* #FFE4C4.
*/
static const Color kBisque;
/**
* #000000.
*/
static const Color kBlack;
/**
* #FFEBCD.
*/
static const Color kBlanchedAlmond;
/**
* #0000FF.
*/
static const Color kBlue;
/**
* #8A2BE2.
*/
static const Color kBlueViolet;
/**
* #A52A2A.
*/
static const Color kBrown;
/**
* #DEB887.
*/
static const Color kBurlywood;
/**
* #5F9EA0.
*/
static const Color kCadetBlue;
/**
* #7FFF00.
*/
static const Color kChartreuse;
/**
* #D2691E.
*/
static const Color kChocolate;
/**
* #FF7F50.
*/
static const Color kCoral;
/**
* #6495ED.
*/
static const Color kCornflowerBlue;
/**
* #FFF8DC.
*/
static const Color kCornsilk;
/**
* #DC143C.
*/
static const Color kCrimson;
/**
* #00FFFF.
*/
static const Color kCyan;
/**
* #00008B.
*/
static const Color kDarkBlue;
/**
* #008B8B.
*/
static const Color kDarkCyan;
/**
* #B8860B.
*/
static const Color kDarkGoldenrod;
/**
* #A9A9A9.
*/
static const Color kDarkGray;
/**
* #006400.
*/
static const Color kDarkGreen;
/**
* #BDB76B.
*/
static const Color kDarkKhaki;
/**
* #8B008B.
*/
static const Color kDarkMagenta;
/**
* #556B2F.
*/
static const Color kDarkOliveGreen;
/**
* #FF8C00.
*/
static const Color kDarkOrange;
/**
* #9932CC.
*/
static const Color kDarkOrchid;
/**
* #8B0000.
*/
static const Color kDarkRed;
/**
* #E9967A.
*/
static const Color kDarkSalmon;
/**
* #8FBC8F.
*/
static const Color kDarkSeaGreen;
/**
* #483D8B.
*/
static const Color kDarkSlateBlue;
/**
* #2F4F4F.
*/
static const Color kDarkSlateGray;
/**
* #00CED1.
*/
static const Color kDarkTurquoise;
/**
* #9400D3.
*/
static const Color kDarkViolet;
/**
* #FF1493.
*/
static const Color kDeepPink;
/**
* #00BFFF.
*/
static const Color kDeepSkyBlue;
/**
* #696969.
*/
static const Color kDimGray;
/**
* #1E90FF.
*/
static const Color kDodgerBlue;
/**
* #B22222.
*/
static const Color kFirebrick;
/**
* #FFFAF0.
*/
static const Color kFloralWhite;
/**
* #228B22.
*/
static const Color kForestGreen;
/**
* #FF00FF.
*/
static const Color kFuchsia;
/**
* #DCDCDC.
*/
static const Color kGainsboro;
/**
* #F8F8FF.
*/
static const Color kGhostWhite;
/**
* #FFD700.
*/
static const Color kGold;
/**
* #DAA520.
*/
static const Color kGoldenrod;
/**
* #808080.
*/
static const Color kGray;
/**
* #008000.
*/
static const Color kGreen;
/**
* #ADFF2F.
*/
static const Color kGreenYellow;
/**
* #F0FFF0.
*/
static const Color kHoneydew;
/**
* #FF69B4.
*/
static const Color kHotPink;
/**
* #CD5C5C.
*/
static const Color kIndianRed;
/**
* #4B0082.
*/
static const Color kIndigo;
/**
* #FFFFF0.
*/
static const Color kIvory;
/**
* #F0E68C.
*/
static const Color kKhaki;
/**
* #E6E6FA.
*/
static const Color kLavender;
/**
* #FFF0F5.
*/
static const Color kLavenderBlush;
/**
* #7CFC00.
*/
static const Color kLawnGreen;
/**
* #FFFACD.
*/
static const Color kLemonChiffon;
/**
* #ADD8E6.
*/
static const Color kLightBlue;
/**
* #F08080.
*/
static const Color kLightCoral;
/**
* #E0FFFF.
*/
static const Color kLightCyan;
/**
* #FAFAD2.
*/
static const Color kLightGoldenrodYellow;
/**
* #D3D3D3.
*/
static const Color kLightGray;
/**
* #90EE90.
*/
static const Color kLightGreen;
/**
* #FFB6C1.
*/
static const Color kLightPink;
/**
* #FFA07A.
*/
static const Color kLightSalmon;
/**
* #20B2AA.
*/
static const Color kLightSeagGeen;
/**
* #87CEFA.
*/
static const Color kLightSkyBlue;
/**
* #778899.
*/
static const Color kLightSlateGray;
/**
* #B0C4DE.
*/
static const Color kLightSteellue;
/**
* #FFFFE0.
*/
static const Color kLightYellow;
/**
* #00FF00.
*/
static const Color kLime;
/**
* #32CD32.
*/
static const Color kLimeGreen;
/**
* #FAF0E6.
*/
static const Color kLinen;
/**
* #FF00FF.
*/
static const Color kMagenta;
/**
* #800000.
*/
static const Color kMaroon;
/**
* #66CDAA.
*/
static const Color kMediumAquamarine;
/**
* #0000CD.
*/
static const Color kMediumBlue;
/**
* #BA55D3.
*/
static const Color kMediumOrchid;
/**
* #9370DB.
*/
static const Color kMediumPurple;
/**
* #3CB371.
*/
static const Color kMediumSeaGreen;
/**
* #7B68EE.
*/
static const Color kMediumSlateBlue;
/**
* #00FA9A.
*/
static const Color kMediumSpringGreen;
/**
* #48D1CC.
*/
static const Color kMediumTurquoise;
/**
* #C71585.
*/
static const Color kMediumVioletRed;
/**
* #191970.
*/
static const Color kMidnightBlue;
/**
* #F5FFFA.
*/
static const Color kMintcream;
/**
* #FFE4E1.
*/
static const Color kMistyRose;
/**
* #FFE4B5.
*/
static const Color kMoccasin;
/**
* #FFDEAD.
*/
static const Color kNavajoWhite;
/**
* #000080.
*/
static const Color kNavy;
/**
* #FDF5E6.
*/
static const Color kOldLace;
/**
* #808000.
*/
static const Color kOlive;
/**
* #6B8E23.
*/
static const Color kOliveDrab;
/**
* #FFA500.
*/
static const Color kOrange;
/**
* #FF4500.
*/
static const Color kOrangeRed;
/**
* #DA70D6.
*/
static const Color kOrchid;
/**
* #EEE8AA.
*/
static const Color kPaleGoldenrod;
/**
* #98FB98.
*/
static const Color kPaleGreen;
/**
* #AFEEEE.
*/
static const Color kPaleTurquoise;
/**
* #DB7093.
*/
static const Color kPaleVioletRed;
/**
* #FFEFD5.
*/
static const Color kPapayaWhip;
/**
* #FFDAB9.
*/
static const Color kPeachPuff;
/**
* #CD853F.
*/
static const Color kPeru;
/**
* #FFC0CB.
*/
static const Color kPink;
/**
* #DDA0DD.
*/
static const Color kPlum;
/**
* #B0E0E6.
*/
static const Color kPowderBlue;
/**
* #800080.
*/
static const Color kPurple;
/**
* #FF0000.
*/
static const Color kRed;
/**
* #BC8F8F.
*/
static const Color kRosyBrown;
/**
* #4169E1.
*/
static const Color kRoyalBlue;
/**
* #8B4513.
*/
static const Color kSaddleBrown;
/**
* #FA8072.
*/
static const Color kSalmon;
/**
* #F4A460.
*/
static const Color kSandyBrown;
/**
* #2E8B57.
*/
static const Color kSeaGreen;
/**
* #FFF5EE.
*/
static const Color kSeashell;
/**
* #A0522D.
*/
static const Color kSienna;
/**
* #C0C0C0.
*/
static const Color kSilver;
/**
* #87CEEB.
*/
static const Color kSkyBlue;
/**
* #6A5ACD.
*/
static const Color kSlateBlue;
/**
* #708090.
*/
static const Color kSlateGray;
/**
* #FFFAFA.
*/
static const Color kSnow;
/**
* #00FF7F.
*/
static const Color kSpringGreen;
/**
* #4682B4.
*/
static const Color kSteelBlue;
/**
* #D2B48C.
*/
static const Color kTan;
/**
* #008080.
*/
static const Color kTeal;
/**
* #D8BFD8.
*/
static const Color kThistle;
/**
* #FF6347.
*/
static const Color kTomato;
/**
* #40E0D0.
*/
static const Color kTurquoise;
/**
* #EE82EE.
*/
static const Color kViolet;
/**
* #F5DEB3.
*/
static const Color kWheat;
/**
* #FFFFFF.
*/
static const Color kWhite;
/**
* #F5F5F5.
*/
static const Color kWhiteSmoke;
/**
* #FFFF00.
*/
static const Color kYellow;
/**
* #9ACD32.
*/
static const Color kYellowGreen;
constexpr Color() = default;
/**
* Constructs a Color.
*
* @param red Red value (0-1)
* @param green Green value (0-1)
* @param blue Blue value (0-1)
*/
constexpr Color(double r, double g, double b)
: red(roundAndClamp(r)),
green(roundAndClamp(g)),
blue(roundAndClamp(b)) {}
double red = 0.0;
double green = 0.0;
double blue = 0.0;
private:
static constexpr double kPrecision = 1.0 / (1 << 12);
static constexpr double roundAndClamp(double value) {
const auto rounded =
(static_cast<int>(value / kPrecision) + 0.5) * kPrecision;
return std::clamp(rounded, 0.0, 1.0);
}
};
inline bool operator==(const Color& c1, const Color& c2) {
return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
}
/*
* FIRST Colors
*/
inline constexpr Color Color::kDenim{0.0823529412, 0.376470589, 0.7411764706};
inline constexpr Color Color::kFirstBlue{0.0, 0.4, 0.7019607844};
inline constexpr Color Color::kFirstRed{0.9294117648, 0.1098039216,
0.1411764706};
/*
* Standard Colors
*/
inline constexpr Color Color::kAliceBlue{0.9411765f, 0.972549f, 1.0f};
inline constexpr Color Color::kAntiqueWhite{0.98039216f, 0.92156863f,
0.84313726f};
inline constexpr Color Color::kAqua{0.0f, 1.0f, 1.0f};
inline constexpr Color Color::kAquamarine{0.49803922f, 1.0f, 0.83137256f};
inline constexpr Color Color::kAzure{0.9411765f, 1.0f, 1.0f};
inline constexpr Color Color::kBeige{0.9607843f, 0.9607843f, 0.8627451f};
inline constexpr Color Color::kBisque{1.0f, 0.89411765f, 0.76862746f};
inline constexpr Color Color::kBlack{0.0f, 0.0f, 0.0f};
inline constexpr Color Color::kBlanchedAlmond{1.0f, 0.92156863f, 0.8039216f};
inline constexpr Color Color::kBlue{0.0f, 0.0f, 1.0f};
inline constexpr Color Color::kBlueViolet{0.5411765f, 0.16862746f, 0.8862745f};
inline constexpr Color Color::kBrown{0.64705884f, 0.16470589f, 0.16470589f};
inline constexpr Color Color::kBurlywood{0.87058824f, 0.72156864f, 0.5294118f};
inline constexpr Color Color::kCadetBlue{0.37254903f, 0.61960787f, 0.627451f};
inline constexpr Color Color::kChartreuse{0.49803922f, 1.0f, 0.0f};
inline constexpr Color Color::kChocolate{0.8235294f, 0.4117647f, 0.11764706f};
inline constexpr Color Color::kCoral{1.0f, 0.49803922f, 0.3137255f};
inline constexpr Color Color::kCornflowerBlue{0.39215687f, 0.58431375f,
0.92941177f};
inline constexpr Color Color::kCornsilk{1.0f, 0.972549f, 0.8627451f};
inline constexpr Color Color::kCrimson{0.8627451f, 0.078431375f, 0.23529412f};
inline constexpr Color Color::kCyan{0.0f, 1.0f, 1.0f};
inline constexpr Color Color::kDarkBlue{0.0f, 0.0f, 0.54509807f};
inline constexpr Color Color::kDarkCyan{0.0f, 0.54509807f, 0.54509807f};
inline constexpr Color Color::kDarkGoldenrod{0.72156864f, 0.5254902f,
0.043137256f};
inline constexpr Color Color::kDarkGray{0.6627451f, 0.6627451f, 0.6627451f};
inline constexpr Color Color::kDarkGreen{0.0f, 0.39215687f, 0.0f};
inline constexpr Color Color::kDarkKhaki{0.7411765f, 0.7176471f, 0.41960785f};
inline constexpr Color Color::kDarkMagenta{0.54509807f, 0.0f, 0.54509807f};
inline constexpr Color Color::kDarkOliveGreen{0.33333334f, 0.41960785f,
0.18431373f};
inline constexpr Color Color::kDarkOrange{1.0f, 0.54901963f, 0.0f};
inline constexpr Color Color::kDarkOrchid{0.6f, 0.19607843f, 0.8f};
inline constexpr Color Color::kDarkRed{0.54509807f, 0.0f, 0.0f};
inline constexpr Color Color::kDarkSalmon{0.9137255f, 0.5882353f, 0.47843137f};
inline constexpr Color Color::kDarkSeaGreen{0.56078434f, 0.7372549f,
0.56078434f};
inline constexpr Color Color::kDarkSlateBlue{0.28235295f, 0.23921569f,
0.54509807f};
inline constexpr Color Color::kDarkSlateGray{0.18431373f, 0.30980393f,
0.30980393f};
inline constexpr Color Color::kDarkTurquoise{0.0f, 0.80784315f, 0.81960785f};
inline constexpr Color Color::kDarkViolet{0.5803922f, 0.0f, 0.827451f};
inline constexpr Color Color::kDeepPink{1.0f, 0.078431375f, 0.5764706f};
inline constexpr Color Color::kDeepSkyBlue{0.0f, 0.7490196f, 1.0f};
inline constexpr Color Color::kDimGray{0.4117647f, 0.4117647f, 0.4117647f};
inline constexpr Color Color::kDodgerBlue{0.11764706f, 0.5647059f, 1.0f};
inline constexpr Color Color::kFirebrick{0.69803923f, 0.13333334f, 0.13333334f};
inline constexpr Color Color::kFloralWhite{1.0f, 0.98039216f, 0.9411765f};
inline constexpr Color Color::kForestGreen{0.13333334f, 0.54509807f,
0.13333334f};
inline constexpr Color Color::kFuchsia{1.0f, 0.0f, 1.0f};
inline constexpr Color Color::kGainsboro{0.8627451f, 0.8627451f, 0.8627451f};
inline constexpr Color Color::kGhostWhite{0.972549f, 0.972549f, 1.0f};
inline constexpr Color Color::kGold{1.0f, 0.84313726f, 0.0f};
inline constexpr Color Color::kGoldenrod{0.85490197f, 0.64705884f, 0.1254902f};
inline constexpr Color Color::kGray{0.5019608f, 0.5019608f, 0.5019608f};
inline constexpr Color Color::kGreen{0.0f, 0.5019608f, 0.0f};
inline constexpr Color Color::kGreenYellow{0.6784314f, 1.0f, 0.18431373f};
inline constexpr Color Color::kHoneydew{0.9411765f, 1.0f, 0.9411765f};
inline constexpr Color Color::kHotPink{1.0f, 0.4117647f, 0.7058824f};
inline constexpr Color Color::kIndianRed{0.8039216f, 0.36078432f, 0.36078432f};
inline constexpr Color Color::kIndigo{0.29411766f, 0.0f, 0.50980395f};
inline constexpr Color Color::kIvory{1.0f, 1.0f, 0.9411765f};
inline constexpr Color Color::kKhaki{0.9411765f, 0.9019608f, 0.54901963f};
inline constexpr Color Color::kLavender{0.9019608f, 0.9019608f, 0.98039216f};
inline constexpr Color Color::kLavenderBlush{1.0f, 0.9411765f, 0.9607843f};
inline constexpr Color Color::kLawnGreen{0.4862745f, 0.9882353f, 0.0f};
inline constexpr Color Color::kLemonChiffon{1.0f, 0.98039216f, 0.8039216f};
inline constexpr Color Color::kLightBlue{0.6784314f, 0.84705883f, 0.9019608f};
inline constexpr Color Color::kLightCoral{0.9411765f, 0.5019608f, 0.5019608f};
inline constexpr Color Color::kLightCyan{0.8784314f, 1.0f, 1.0f};
inline constexpr Color Color::kLightGoldenrodYellow{0.98039216f, 0.98039216f,
0.8235294f};
inline constexpr Color Color::kLightGray{0.827451f, 0.827451f, 0.827451f};
inline constexpr Color Color::kLightGreen{0.5647059f, 0.93333334f, 0.5647059f};
inline constexpr Color Color::kLightPink{1.0f, 0.7137255f, 0.75686276f};
inline constexpr Color Color::kLightSalmon{1.0f, 0.627451f, 0.47843137f};
inline constexpr Color Color::kLightSeagGeen{0.1254902f, 0.69803923f,
0.6666667f};
inline constexpr Color Color::kLightSkyBlue{0.5294118f, 0.80784315f,
0.98039216f};
inline constexpr Color Color::kLightSlateGray{0.46666667f, 0.53333336f, 0.6f};
inline constexpr Color Color::kLightSteellue{0.6901961f, 0.76862746f,
0.87058824f};
inline constexpr Color Color::kLightYellow{1.0f, 1.0f, 0.8784314f};
inline constexpr Color Color::kLime{0.0f, 1.0f, 0.0f};
inline constexpr Color Color::kLimeGreen{0.19607843f, 0.8039216f, 0.19607843f};
inline constexpr Color Color::kLinen{0.98039216f, 0.9411765f, 0.9019608f};
inline constexpr Color Color::kMagenta{1.0f, 0.0f, 1.0f};
inline constexpr Color Color::kMaroon{0.5019608f, 0.0f, 0.0f};
inline constexpr Color Color::kMediumAquamarine{0.4f, 0.8039216f, 0.6666667f};
inline constexpr Color Color::kMediumBlue{0.0f, 0.0f, 0.8039216f};
inline constexpr Color Color::kMediumOrchid{0.7294118f, 0.33333334f, 0.827451f};
inline constexpr Color Color::kMediumPurple{0.5764706f, 0.4392157f,
0.85882354f};
inline constexpr Color Color::kMediumSeaGreen{0.23529412f, 0.7019608f,
0.44313726f};
inline constexpr Color Color::kMediumSlateBlue{0.48235294f, 0.40784314f,
0.93333334f};
inline constexpr Color Color::kMediumSpringGreen{0.0f, 0.98039216f, 0.6039216f};
inline constexpr Color Color::kMediumTurquoise{0.28235295f, 0.81960785f, 0.8f};
inline constexpr Color Color::kMediumVioletRed{0.78039217f, 0.08235294f,
0.52156866f};
inline constexpr Color Color::kMidnightBlue{0.09803922f, 0.09803922f,
0.4392157f};
inline constexpr Color Color::kMintcream{0.9607843f, 1.0f, 0.98039216f};
inline constexpr Color Color::kMistyRose{1.0f, 0.89411765f, 0.88235295f};
inline constexpr Color Color::kMoccasin{1.0f, 0.89411765f, 0.70980394f};
inline constexpr Color Color::kNavajoWhite{1.0f, 0.87058824f, 0.6784314f};
inline constexpr Color Color::kNavy{0.0f, 0.0f, 0.5019608f};
inline constexpr Color Color::kOldLace{0.99215686f, 0.9607843f, 0.9019608f};
inline constexpr Color Color::kOlive{0.5019608f, 0.5019608f, 0.0f};
inline constexpr Color Color::kOliveDrab{0.41960785f, 0.5568628f, 0.13725491f};
inline constexpr Color Color::kOrange{1.0f, 0.64705884f, 0.0f};
inline constexpr Color Color::kOrangeRed{1.0f, 0.27058825f, 0.0f};
inline constexpr Color Color::kOrchid{0.85490197f, 0.4392157f, 0.8392157f};
inline constexpr Color Color::kPaleGoldenrod{0.93333334f, 0.9098039f,
0.6666667f};
inline constexpr Color Color::kPaleGreen{0.59607846f, 0.9843137f, 0.59607846f};
inline constexpr Color Color::kPaleTurquoise{0.6862745f, 0.93333334f,
0.93333334f};
inline constexpr Color Color::kPaleVioletRed{0.85882354f, 0.4392157f,
0.5764706f};
inline constexpr Color Color::kPapayaWhip{1.0f, 0.9372549f, 0.8352941f};
inline constexpr Color Color::kPeachPuff{1.0f, 0.85490197f, 0.7254902f};
inline constexpr Color Color::kPeru{0.8039216f, 0.52156866f, 0.24705882f};
inline constexpr Color Color::kPink{1.0f, 0.7529412f, 0.79607844f};
inline constexpr Color Color::kPlum{0.8666667f, 0.627451f, 0.8666667f};
inline constexpr Color Color::kPowderBlue{0.6901961f, 0.8784314f, 0.9019608f};
inline constexpr Color Color::kPurple{0.5019608f, 0.0f, 0.5019608f};
inline constexpr Color Color::kRed{1.0f, 0.0f, 0.0f};
inline constexpr Color Color::kRosyBrown{0.7372549f, 0.56078434f, 0.56078434f};
inline constexpr Color Color::kRoyalBlue{0.25490198f, 0.4117647f, 0.88235295f};
inline constexpr Color Color::kSaddleBrown{0.54509807f, 0.27058825f,
0.07450981f};
inline constexpr Color Color::kSalmon{0.98039216f, 0.5019608f, 0.44705883f};
inline constexpr Color Color::kSandyBrown{0.95686275f, 0.6431373f, 0.3764706f};
inline constexpr Color Color::kSeaGreen{0.18039216f, 0.54509807f, 0.34117648f};
inline constexpr Color Color::kSeashell{1.0f, 0.9607843f, 0.93333334f};
inline constexpr Color Color::kSienna{0.627451f, 0.32156864f, 0.1764706f};
inline constexpr Color Color::kSilver{0.7529412f, 0.7529412f, 0.7529412f};
inline constexpr Color Color::kSkyBlue{0.5294118f, 0.80784315f, 0.92156863f};
inline constexpr Color Color::kSlateBlue{0.41568628f, 0.3529412f, 0.8039216f};
inline constexpr Color Color::kSlateGray{0.4392157f, 0.5019608f, 0.5647059f};
inline constexpr Color Color::kSnow{1.0f, 0.98039216f, 0.98039216f};
inline constexpr Color Color::kSpringGreen{0.0f, 1.0f, 0.49803922f};
inline constexpr Color Color::kSteelBlue{0.27450982f, 0.50980395f, 0.7058824f};
inline constexpr Color Color::kTan{0.8235294f, 0.7058824f, 0.54901963f};
inline constexpr Color Color::kTeal{0.0f, 0.5019608f, 0.5019608f};
inline constexpr Color Color::kThistle{0.84705883f, 0.7490196f, 0.84705883f};
inline constexpr Color Color::kTomato{1.0f, 0.3882353f, 0.2784314f};
inline constexpr Color Color::kTurquoise{0.2509804f, 0.8784314f, 0.8156863f};
inline constexpr Color Color::kViolet{0.93333334f, 0.50980395f, 0.93333334f};
inline constexpr Color Color::kWheat{0.9607843f, 0.87058824f, 0.7019608f};
inline constexpr Color Color::kWhite{1.0f, 1.0f, 1.0f};
inline constexpr Color Color::kWhiteSmoke{0.9607843f, 0.9607843f, 0.9607843f};
inline constexpr Color Color::kYellow{1.0f, 1.0f, 0.0f};
inline constexpr Color Color::kYellowGreen{0.6039216f, 0.8039216f, 0.19607843f};
} // namespace frc

View File

@@ -0,0 +1,58 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <algorithm>
#include "Color.h"
namespace frc {
/**
* Represents colors that can be used with Addressable LEDs.
*/
class Color8Bit {
public:
constexpr Color8Bit() = default;
/**
* Constructs a Color8Bit.
*
* @param red Red value (0-255)
* @param green Green value (0-255)
* @param blue Blue value (0-255)
*/
constexpr Color8Bit(int r, int g, int b)
: red(std::clamp(r, 0, 255)),
green(std::clamp(g, 0, 255)),
blue(std::clamp(b, 0, 255)) {}
/**
* Constructs a Color8Bit from a Color.
*
* @param color The color
*/
constexpr Color8Bit(const Color& color)
: red(color.red * 255),
green(color.green * 255),
blue(color.blue * 255) {}
constexpr operator Color() const {
return Color(red / 255.0, green / 255.0, blue / 255.0);
}
int red = 0;
int green = 0;
int blue = 0;
};
inline bool operator==(const Color8Bit& c1, const Color8Bit& c2) {
return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
}
} // namespace frc

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <thread>
#include "frc/SlewRateLimiter.h"
#include "gtest/gtest.h"
TEST(SlewRateLimiterTest, SlewRateLimitTest) {
frc::SlewRateLimiter<units::meters> limiter(1_mps);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
EXPECT_TRUE(limiter.Calculate(2_m) < 2_m);
}
TEST(SlewRateLimiterTest, SlewRateNoLimitTest) {
frc::SlewRateLimiter<units::meters> limiter(1_mps);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
EXPECT_EQ(limiter.Calculate(0.5_m), 0.5_m);
}

View File

@@ -0,0 +1,70 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include <vector>
#include "frc/trajectory/Trajectory.h"
#include "frc/trajectory/TrajectoryConfig.h"
#include "frc/trajectory/TrajectoryGenerator.h"
#include "gtest/gtest.h"
void TestSameShapedTrajectory(std::vector<frc::Trajectory::State> statesA,
std::vector<frc::Trajectory::State> statesB) {
for (unsigned int i = 0; i < statesA.size() - 1; i++) {
auto a1 = statesA[i].pose;
auto a2 = statesA[i + 1].pose;
auto b1 = statesB[i].pose;
auto b2 = statesB[i + 1].pose;
auto a = a2.RelativeTo(a1);
auto b = b2.RelativeTo(b1);
EXPECT_NEAR(a.Translation().X().to<double>(),
b.Translation().X().to<double>(), 1E-9);
EXPECT_NEAR(a.Translation().Y().to<double>(),
b.Translation().Y().to<double>(), 1E-9);
EXPECT_NEAR(a.Rotation().Radians().to<double>(),
b.Rotation().Radians().to<double>(), 1E-9);
}
}
TEST(TrajectoryTransforms, TransformBy) {
frc::TrajectoryConfig config{3_mps, 3_mps_sq};
auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
frc::Pose2d{}, {}, frc::Pose2d{1_m, 1_m, frc::Rotation2d(90_deg)},
config);
auto transformedTrajectory =
trajectory.TransformBy({{1_m, 2_m}, frc::Rotation2d(30_deg)});
auto firstPose = transformedTrajectory.Sample(0_s).pose;
EXPECT_NEAR(firstPose.Translation().X().to<double>(), 1.0, 1E-9);
EXPECT_NEAR(firstPose.Translation().Y().to<double>(), 2.0, 1E-9);
EXPECT_NEAR(firstPose.Rotation().Degrees().to<double>(), 30.0, 1E-9);
TestSameShapedTrajectory(trajectory.States(), transformedTrajectory.States());
}
TEST(TrajectoryTransforms, RelativeTo) {
frc::TrajectoryConfig config{3_mps, 3_mps_sq};
auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
frc::Pose2d{1_m, 2_m, frc::Rotation2d(30_deg)}, {},
frc::Pose2d{5_m, 7_m, frc::Rotation2d(90_deg)}, config);
auto transformedTrajectory =
trajectory.RelativeTo({1_m, 2_m, frc::Rotation2d(30_deg)});
auto firstPose = transformedTrajectory.Sample(0_s).pose;
EXPECT_NEAR(firstPose.Translation().X().to<double>(), 0, 1E-9);
EXPECT_NEAR(firstPose.Translation().Y().to<double>(), 0, 1E-9);
EXPECT_NEAR(firstPose.Rotation().Degrees().to<double>(), 0, 1E-9);
TestSameShapedTrajectory(trajectory.States(), transformedTrajectory.States());
}

View File

@@ -6,6 +6,8 @@ apply plugin: 'visual-studio'
apply plugin: 'edu.wpi.first.NativeUtils'
apply plugin: ExtraTasks
evaluationDependsOn(':hal')
apply from: '../shared/config.gradle'
ext.examplesMap = [:]
@@ -222,6 +224,25 @@ model {
}
apply from: 'publish.gradle'
model {
tasks {
def c = $.components
project.tasks.register('buildDesktopCpp') { compileTask->
def systemArch = getCurrentArch()
c.each {
if (it in NativeExecutableSpec && it.name) {
it.binaries.each {
def arch = it.targetPlatform.name
if (arch == systemArch && it.buildType.name == 'debug') {
compileTask.dependsOn it.tasks.link
}
}
}
}
}
}
}
ext {
templateDirectory = new File("$projectDir/src/main/cpp/templates/")
templateFile = new File("$projectDir/src/main/cpp/templates/templates.json")

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeCommand2.h"
ReplaceMeCommand2::ReplaceMeCommand2() {
// Use addRequirements() here to declare subsystem dependencies.
}
// Called when the command is initially scheduled.
void ReplaceMeCommand2::Initialize() {}
// Called repeatedly when this Command is scheduled to run
void ReplaceMeCommand2::Execute() {}
// Called once the command ends or is interrupted.
void ReplaceMeCommand2::End(bool interrupted) {}
// Returns true when the command should end.
bool ReplaceMeCommand2::IsFinished() { return false; }

View File

@@ -0,0 +1,32 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/CommandHelper.h>
/**
* An example command.
*
* <p>Note that this extends CommandHelper, rather extending CommandBase
* directly; this is crucially important, or else the decorator functions in
* Command will *not* work!
*/
class ReplaceMeCommand2
: public frc2::CommandHelper<frc2::CommandBase, ReplaceMeCommand2> {
public:
ReplaceMeCommand2();
void Initialize() override;
void Execute() override;
void End(bool interrupted) override;
bool IsFinished() override;
};

View File

@@ -12,10 +12,11 @@
"source": [
"ReplaceMeEmptyClass.cpp"
],
"replacename": "ReplaceMeEmptyClass"
"replacename": "ReplaceMeEmptyClass",
"commandversion": 0
},
{
"name": "Command",
"name": "Command (Old)",
"description": "Create a base command",
"tags": [
"command"
@@ -27,10 +28,11 @@
"source": [
"ReplaceMeCommand.cpp"
],
"replacename": "ReplaceMeCommand"
"replacename": "ReplaceMeCommand",
"commandversion": 1
},
{
"name": "Command Group",
"name": "Command Group (Old)",
"description": "Create a command group",
"tags": [
"commandgroup"
@@ -42,10 +44,11 @@
"source": [
"ReplaceMeCommandGroup.cpp"
],
"replacename": "ReplaceMeCommandGroup"
"replacename": "ReplaceMeCommandGroup",
"commandversion": 1
},
{
"name": "Instant Command",
"name": "Instant Command (Old)",
"description": "A command that runs immediately",
"tags": [
"instantcommand"
@@ -57,10 +60,11 @@
"source": [
"ReplaceMeInstantCommand.cpp"
],
"replacename": "ReplaceMeInstantCommand"
"replacename": "ReplaceMeInstantCommand",
"commandversion": 1
},
{
"name": "Subsystem",
"name": "Subsystem (Old)",
"description": "A subsystem",
"tags": [
"subsystem"
@@ -72,10 +76,11 @@
"source": [
"ReplaceMeSubsystem.cpp"
],
"replacename": "ReplaceMeSubsystem"
"replacename": "ReplaceMeSubsystem",
"commandversion": 1
},
{
"name": "PID Subsystem",
"name": "PID Subsystem (Old)",
"description": "A subsystem that runs a PID loop",
"tags": [
"pidsubsystem",
@@ -88,10 +93,11 @@
"source": [
"ReplaceMePIDSubsystem.cpp"
],
"replacename": "ReplaceMePIDSubsystem"
"replacename": "ReplaceMePIDSubsystem",
"commandversion": 1
},
{
"name": "Timed Command",
"name": "Timed Command (Old)",
"description": "A command that runs for a specified time",
"tags": [
"timedcommand"
@@ -103,10 +109,11 @@
"source": [
"ReplaceMeTimedCommand.cpp"
],
"replacename": "ReplaceMeTimedCommand"
"replacename": "ReplaceMeTimedCommand",
"commandversion": 1
},
{
"name": "Trigger",
"name": "Trigger (Old)",
"description": "A command that runs off of a trigger",
"tags": [
"trigger"
@@ -118,6 +125,215 @@
"source": [
"ReplaceMeTrigger.cpp"
],
"replacename": "ReplaceMeTrigger"
"replacename": "ReplaceMeTrigger",
"commandversion": 1
},
{
"name": "Command (New)",
"description": "A command.",
"tags": [
"command"
],
"foldername": "command2",
"headers": [
"ReplaceMeCommand2.h"
],
"source": [
"ReplaceMeCommand2.cpp"
],
"replacename": "ReplaceMeCommand2",
"commandversion": 2
},
{
"name": "InstantCommand (New)",
"description": "A command that finishes instantly.",
"tags": [
"instantcommand"
],
"foldername": "instantcommand",
"headers": [
"ReplaceMeInstantCommand2.h"
],
"source": [
"ReplaceMeInstantCommand2.cpp"
],
"replacename": "ReplaceMeInstantCommand2",
"commandversion": 2
},
{
"name": "ParallelCommandGroup (New)",
"description": "A command group that runs commands in parallel, ending when all commands have finished.",
"tags": [
"parallelcommandgroup"
],
"foldername": "parallelcommandgroup",
"headers": [
"ReplaceMeParallelCommandGroup.h"
],
"source": [
"ReplaceMeParallelCommandGroup.cpp"
],
"replacename": "ReplaceMeParallelCommandGroup",
"commandversion": 2
},
{
"name": "ParallelDeadlineGroup (New)",
"description": "A command group that runs commands in parallel, ending when a specific command has finished.",
"tags": [
"paralleldeadlinegroup"
],
"foldername": "paralleldeadlinegroup",
"headers": [
"ReplaceMeParallelDeadlineGroup.h"
],
"source": [
"ReplaceMeParallelDeadlineGroup.cpp"
],
"replacename": "ReplaceMeParallelDeadlineGroup",
"commandversion": 2
},
{
"name": "ParallelRaceGroup (New)",
"description": "A command that runs commands in parallel, ending as soon as any command has finished.",
"tags": [
"parallelracegroup"
],
"foldername": "parallelracegroup",
"headers": [
"ReplaceMeParallelRaceGroup.h"
],
"source": [
"ReplaceMeParallelRaceGroup.cpp"
],
"replacename": "ReplaceMeParallelRaceGroup",
"commandversion": 2
},
{
"name": "PIDCommand (New)",
"description": "A command that runs a PIDController.",
"tags": [
"pidcommand"
],
"foldername": "pidcommand",
"headers": [
"ReplaceMePIDCommand.h"
],
"source": [
"ReplaceMePIDCommand.cpp"
],
"replacename": "ReplaceMePIDCommand",
"commandversion": 2
},
{
"name": "PIDSubsystem (New)",
"description": "A subsystem that runs a PIDController.",
"tags": [
"pidsubsystem"
],
"foldername": "pidsubsystem2",
"headers": [
"ReplaceMePIDSubsystem2.h"
],
"source": [
"ReplaceMePIDSubsystem2.cpp"
],
"replacename": "ReplaceMePIDSubsystem2",
"commandversion": 2
},
{
"name": "ProfiledPIDCommand (New)",
"description": "A command that runs a ProfiledPIDController.",
"tags": [
"profiledpidcommand"
],
"foldername": "profiledpidcommand",
"headers": [
"ReplaceMeProfiledPIDCommand.h"
],
"source": [
"ReplaceMeProfiledPIDCommand.cpp"
],
"replacename": "ReplaceMeProfiledPIDCommand",
"commandversion": 2
},
{
"name": "ProfiledPIDSubsystem (New)",
"description": "A subsystem that runs a ProfiledPIDController.",
"tags": [
"profiledpidsubsystem"
],
"foldername": "profiledpidsubsystem",
"headers": [
"ReplaceMeProfiledPIDSubsystem.h"
],
"source": [
"ReplaceMeProfiledPIDSubsystem.cpp"
],
"replacename": "ReplaceMeProfiledPIDSubsystem",
"commandversion": 2
},
{
"name": "SequentialCommandGroup (New)",
"description": "A command group that runs commands in sequence.",
"tags": [
"sequentialcommandgroup"
],
"foldername": "sequentialcommandgroup",
"headers": [
"ReplaceMeSequentialCommandGroup.h"
],
"source": [
"ReplaceMeSequentialCommandGroup.cpp"
],
"replacename": "ReplaceMeSequentialCommandGroup",
"commandversion": 2
},
{
"name": "Subsystem (New)",
"description": "A robot subsystem.",
"tags": [
"subsystem"
],
"foldername": "subsystem2",
"headers": [
"ReplaceMeSubsystem2.h"
],
"source": [
"ReplaceMeSubsystem2.cpp"
],
"replacename": "ReplaceMeSubsystem2",
"commandversion": 2
},
{
"name": "TrapezoidProfileCommand (New)",
"description": "A command that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilecommand"
],
"foldername": "trapezoidprofilecommand",
"headers": [
"ReplaceMeTrapezoidProfileCommand.h"
],
"source": [
"ReplaceMeTrapezoidProfileCommand.cpp"
],
"replacename": "ReplaceMeTrapezoidProfileCommand",
"commandversion": 2
},
{
"name": "TrapezoidProfileSubsystem (New)",
"description": "A command that executes a trapezoidal motion profile.",
"tags": [
"trapezoidprofilesubsystem"
],
"foldername": "trapezoidprofilesubsystem",
"headers": [
"ReplaceMeTrapezoidProfileSubsystem.h"
],
"source": [
"ReplaceMeTrapezoidProfileSubsystem.cpp"
],
"replacename": "ReplaceMeTrapezoidProfileSubsystem",
"commandversion": 2
}
]

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeInstantCommand2.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeInstantCommand2::ReplaceMeInstantCommand2() {
// Use addRequirements() here to declare subsystem dependencies.
}
// Called when the command is initially scheduled.
void ReplaceMeInstantCommand2::Initialize() {}

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/InstantCommand.h>
class ReplaceMeInstantCommand2
: public frc2::CommandHelper<frc2::InstantCommand,
ReplaceMeInstantCommand2> {
public:
ReplaceMeInstantCommand2();
void Initialize() override;
};

View File

@@ -0,0 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeParallelCommandGroup.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeParallelCommandGroup::ReplaceMeParallelCommandGroup() {
// Add your commands here, e.g.
// AddCommands(FooCommand(), BarCommand());
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/ParallelCommandGroup.h>
class ReplaceMeParallelCommandGroup
: public frc2::CommandHelper<frc2::ParallelCommandGroup,
ReplaceMeParallelCommandGroup> {
public:
ReplaceMeParallelCommandGroup();
};

View File

@@ -0,0 +1,21 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeParallelDeadlineGroup.h"
#include <frc2/command/InstantCommand.h>
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeParallelDeadlineGroup::ReplaceMeParallelDeadlineGroup()
: CommandHelper(
// The deadline command
frc2::InstantCommand([] {})) {
// Add your commands here, e.g.
// AddCommands(FooCommand(), BarCommand());
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/ParallelDeadlineGroup.h>
class ReplaceMeParallelDeadlineGroup
: public frc2::CommandHelper<frc2::ParallelDeadlineGroup,
ReplaceMeParallelDeadlineGroup> {
public:
ReplaceMeParallelDeadlineGroup();
};

View File

@@ -0,0 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeParallelRaceGroup.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeParallelRaceGroup::ReplaceMeParallelRaceGroup() {
// Add your commands here, e.g.
// AddCommands(FooCommand(), BarCommand());
}

View File

@@ -0,0 +1,18 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/ParallelRaceGroup.h>
class ReplaceMeParallelRaceGroup
: public frc2::CommandHelper<frc2::ParallelRaceGroup,
ReplaceMeParallelRaceGroup> {
public:
ReplaceMeParallelRaceGroup();
};

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMePIDCommand.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMePIDCommand::ReplaceMePIDCommand()
: CommandHelper(frc2::PIDController(0, 0, 0),
// This should return the measurement
[] { return 0; },
// This should return the setpoint (can also be a constant)
[] { return 0; },
// This uses the output
[](double output) {
// Use the output here
}) {}
// Returns true when the command should end.
bool ReplaceMePIDCommand::IsFinished() { return false; }

View File

@@ -0,0 +1,19 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/PIDCommand.h>
class ReplaceMePIDCommand
: public frc2::CommandHelper<frc2::PIDCommand, ReplaceMePIDCommand> {
public:
ReplaceMePIDCommand();
bool IsFinished() override;
};

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMePIDSubsystem2.h"
ReplaceMePIDSubsystem2::ReplaceMePIDSubsystem2()
: PIDSubsystem(
// The PIDController used by the subsystem
frc2::PIDController(0, 0, 0)) {}
void ReplaceMePIDSubsystem2::UseOutput(double output, double setpoint) {
// Use the output here
}
double ReplaceMePIDSubsystem2::GetMeasurement() {
// Return the process variable measurement here
return 0;
}

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/PIDSubsystem.h>
class ReplaceMePIDSubsystem2 : public frc2::PIDSubsystem {
public:
ReplaceMePIDSubsystem2();
protected:
void UseOutput(double output, double setpoint) override;
double GetMeasurement() override;
};

View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeProfiledPIDCommand.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeProfiledPIDCommand::ReplaceMeProfiledPIDCommand()
: CommandHelper(
// The ProfiledPIDController that the command will use
frc::ProfiledPIDController<units::meter>(
// The PID gains
0, 0, 0,
// The motion profile constraints
{0_mps, 0_mps_sq}),
// This should return the measurement
[] { return 0_m; },
// This should return the goal state (can also be a constant)
[] {
return frc::TrapezoidProfile<units::meter>::State{0_m, 0_mps};
},
// This uses the output and current trajectory setpoint
[](double output,
frc::TrapezoidProfile<units::meter>::State setpoint) {
// Use the output and setpoint here
}) {}
// Returns true when the command should end.
bool ReplaceMeProfiledPIDCommand::IsFinished() { return false; }

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/CommandHelper.h>
#include <frc2/command/ProfiledPIDCommand.h>
class ReplaceMeProfiledPIDCommand
: public frc2::CommandHelper<frc2::ProfiledPIDCommand<units::meter>,
ReplaceMeProfiledPIDCommand> {
public:
ReplaceMeProfiledPIDCommand();
bool IsFinished() override;
};

View File

@@ -0,0 +1,27 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeProfiledPIDSubsystem.h"
ReplaceMeProfiledPIDSubsystem::ReplaceMeProfiledPIDSubsystem()
: ProfiledPIDSubsystem(
// The ProfiledPIDController used by the subsystem
frc::ProfiledPIDController<units::meter>(
// The PID gains
0, 0, 0,
// The constraints for the motion profiles
{0_mps, 0_mps_sq})) {}
void ReplaceMeProfiledPIDSubsystem::UseOutput(
double output, frc::TrapezoidProfile<units::meter>::State setpoint) {
// Use the output and current trajectory setpoint here
}
units::meter_t ReplaceMeProfiledPIDSubsystem::GetMeasurement() {
// Return the process variable measurement here
return 0_m;
}

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <frc2/command/ProfiledPIDSubsystem.h>
class ReplaceMeProfiledPIDSubsystem
: public frc2::ProfiledPIDSubsystem<units::meter> {
public:
ReplaceMeProfiledPIDSubsystem();
protected:
void UseOutput(double output,
frc::TrapezoidProfile<units::meter>::State setpoint) override;
units::meter_t GetMeasurement() override;
};

View File

@@ -0,0 +1,16 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ReplaceMeSequentialCommandGroup.h"
// NOTE: Consider using this command inline, rather than writing a subclass.
// For more information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
ReplaceMeSequentialCommandGroup::ReplaceMeSequentialCommandGroup() {
// Add your commands here, e.g.
// AddCommands(FooCommand(), BarCommand());
}

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