mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
wpilibc: Add overloads for units (#1815)
Add unit-taking overloads to the following classes: - IterativeRobotBase - LinearFilter - Notifier - TimedRobot - Timer (HasPeriodPassed only) - frc2::PIDController The corresponding non-units-taking functions have been deprecated. The return value of TimedRobot::GetPeriod() was updated. This is a breaking change, users should use to<double> to get the value in seconds. Other return values, e.g. Timer::Get(), have NOT been updated due to much wider use.
This commit is contained in:
committed by
Peter Johnson
parent
f1d71da8a9
commit
c07ac23532
@@ -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. */
|
||||
@@ -8,6 +8,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <units/units.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/IterativeRobotBase.h"
|
||||
@@ -25,7 +27,7 @@ namespace frc {
|
||||
*/
|
||||
class TimedRobot : public IterativeRobotBase, public ErrorBase {
|
||||
public:
|
||||
static constexpr double kDefaultPeriod = 0.02;
|
||||
static constexpr units::second_t kDefaultPeriod = 20_ms;
|
||||
|
||||
/**
|
||||
* Provide an alternate "main loop" via StartCompetition().
|
||||
@@ -35,14 +37,22 @@ class TimedRobot : public IterativeRobotBase, public ErrorBase {
|
||||
/**
|
||||
* Get the time period between calls to Periodic() functions.
|
||||
*/
|
||||
double GetPeriod() const;
|
||||
units::second_t GetPeriod() const;
|
||||
|
||||
/**
|
||||
* Constructor for TimedRobot.
|
||||
*
|
||||
* @param period Period in seconds.
|
||||
*/
|
||||
explicit TimedRobot(double period = kDefaultPeriod);
|
||||
WPI_DEPRECATED("Use constructor with unit-safety instead.")
|
||||
explicit TimedRobot(double period);
|
||||
|
||||
/**
|
||||
* Constructor for TimedRobot.
|
||||
*
|
||||
* @param period Period.
|
||||
*/
|
||||
explicit TimedRobot(units::second_t period = kDefaultPeriod);
|
||||
|
||||
~TimedRobot() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user