mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
committed by
Peter Johnson
parent
120ceb3427
commit
5ca00dddbe
@@ -43,10 +43,15 @@ void TimedRobot::SetPeriod(double period) {
|
||||
m_period = period;
|
||||
|
||||
if (m_startLoop) {
|
||||
m_loop->StartPeriodic(m_period);
|
||||
m_loop->StartPeriodic(period);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time period between calls to Periodic() functions.
|
||||
*/
|
||||
double TimedRobot::GetPeriod() const { return m_period; }
|
||||
|
||||
TimedRobot::TimedRobot() {
|
||||
m_loop = std::make_unique<Notifier>(&TimedRobot::LoopFunc, this);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "IterativeRobotBase.h"
|
||||
@@ -30,13 +31,14 @@ class TimedRobot : public IterativeRobotBase {
|
||||
void StartCompetition() override;
|
||||
|
||||
void SetPeriod(double seconds);
|
||||
double GetPeriod() const;
|
||||
|
||||
protected:
|
||||
TimedRobot();
|
||||
virtual ~TimedRobot();
|
||||
|
||||
private:
|
||||
double m_period = kDefaultPeriod;
|
||||
std::atomic<double> m_period{kDefaultPeriod};
|
||||
|
||||
// Prevents loop from starting if user calls SetPeriod() in RobotInit()
|
||||
bool m_startLoop = false;
|
||||
|
||||
@@ -21,7 +21,7 @@ import edu.wpi.first.wpilibj.hal.HAL;
|
||||
public class TimedRobot extends IterativeRobotBase {
|
||||
public static final double DEFAULT_PERIOD = 0.02;
|
||||
|
||||
private double m_period = DEFAULT_PERIOD;
|
||||
private volatile double m_period = DEFAULT_PERIOD;
|
||||
|
||||
// Prevents loop from starting if user calls setPeriod() in robotInit()
|
||||
private boolean m_startLoop = false;
|
||||
@@ -68,4 +68,11 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
m_loop.startPeriodic(m_period);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time period between calls to Periodic() functions.
|
||||
*/
|
||||
public double getPeriod() {
|
||||
return m_period;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user