2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
#include "frc/simulation/CallbackStore.h"
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
2020-07-15 23:48:09 -07:00
|
|
|
|
|
|
|
|
class Encoder;
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated encoder.
|
|
|
|
|
*/
|
2018-05-11 12:38:23 -07:00
|
|
|
class EncoderSim {
|
|
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs from an Encoder object.
|
|
|
|
|
*
|
|
|
|
|
* @param encoder Encoder to simulate
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
explicit EncoderSim(const Encoder& encoder);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an EncoderSim for a digital input channel. Encoders take two
|
|
|
|
|
* channels, so either one may be specified.
|
|
|
|
|
*
|
|
|
|
|
* @param channel digital input channel
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
* @throws NoSuchElementException if no Encoder is configured for that channel
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static EncoderSim CreateForChannel(int channel);
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an EncoderSim for a simulated index.
|
|
|
|
|
* The index is incremented for each simulated Encoder.
|
|
|
|
|
*
|
|
|
|
|
* @param index simulator index
|
|
|
|
|
* @return Simulated object
|
|
|
|
|
*/
|
2020-07-15 23:48:09 -07:00
|
|
|
static EncoderSim CreateForIndex(int index);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetInitialized() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetInitialized(bool initialized);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterCountCallback(NotifyCallback callback,
|
2020-07-15 23:48:09 -07:00
|
|
|
bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
int GetCount() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetCount(int count);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterPeriodCallback(NotifyCallback callback,
|
2020-07-15 23:48:09 -07:00
|
|
|
bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetPeriod() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetPeriod(double period);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterResetCallback(NotifyCallback callback,
|
2020-07-15 23:48:09 -07:00
|
|
|
bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetReset() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetReset(bool reset);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterMaxPeriodCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetMaxPeriod() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetMaxPeriod(double maxPeriod);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterDirectionCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
bool GetDirection() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetDirection(bool direction);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterReverseDirectionCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
|
|
|
|
bool GetReverseDirection() const;
|
|
|
|
|
|
|
|
|
|
void SetReverseDirection(bool reverseDirection);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterSamplesToAverageCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
|
|
|
|
|
|
|
|
|
int GetSamplesToAverage() const;
|
|
|
|
|
|
|
|
|
|
void SetSamplesToAverage(int samplesToAverage);
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2018-07-12 23:11:26 -04:00
|
|
|
std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
|
2020-07-15 23:48:09 -07:00
|
|
|
NotifyCallback callback, bool initialNotify);
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetDistancePerPulse() const;
|
2018-08-16 01:17:59 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetDistancePerPulse(double distancePerPulse);
|
2018-07-12 23:11:26 -04:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void ResetData();
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetDistance(double distance);
|
2020-04-03 08:33:38 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetDistance();
|
2020-04-03 08:33:38 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
void SetRate(double rate);
|
2020-04-03 08:33:38 -07:00
|
|
|
|
2020-07-15 23:48:09 -07:00
|
|
|
double GetRate();
|
2020-04-03 08:33:38 -07:00
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
private:
|
2020-07-04 10:10:43 -07:00
|
|
|
explicit EncoderSim(int index) : m_index{index} {}
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|