mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[hal, wpilib] PWM Rewrite (#7845)
The HAL will only contain the output period and the raw microseconds. Higher level things such as SimDevice can handle everything else.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
#include <units/length.h>
|
||||
|
||||
#include "frc/motorcontrol/PWMMotorController.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class PWMMotorController;
|
||||
|
||||
namespace sim {
|
||||
|
||||
class PWMMotorControllerSim {
|
||||
public:
|
||||
explicit PWMMotorControllerSim(const PWMMotorController& motorctrl);
|
||||
|
||||
explicit PWMMotorControllerSim(int channel);
|
||||
|
||||
double GetSpeed() const;
|
||||
|
||||
private:
|
||||
hal::SimDouble m_simSpeed;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -27,13 +27,6 @@ class PWMSim {
|
||||
*/
|
||||
explicit PWMSim(const PWM& pwm);
|
||||
|
||||
/**
|
||||
* Constructs from a PWMMotorController object.
|
||||
*
|
||||
* @param motorctrl PWMMotorController to simulate
|
||||
*/
|
||||
explicit PWMSim(const PWMMotorController& motorctrl);
|
||||
|
||||
/**
|
||||
* Constructs from a PWM channel number.
|
||||
*
|
||||
@@ -91,56 +84,6 @@ class PWMSim {
|
||||
*/
|
||||
void SetPulseMicrosecond(int32_t microsecondPulseTime);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the PWM speed changes.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify whether to run the callback with the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the PWM speed.
|
||||
*
|
||||
* @return the PWM speed (-1.0 to 1.0)
|
||||
*/
|
||||
double GetSpeed() const;
|
||||
|
||||
/**
|
||||
* Set the PWM speed.
|
||||
*
|
||||
* @param speed the PWM speed (-1.0 to 1.0)
|
||||
*/
|
||||
void SetSpeed(double speed);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the PWM position changes.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify whether to run the callback with the initial value
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterPositionCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Get the PWM position.
|
||||
*
|
||||
* @return the PWM position (0.0 to 1.0)
|
||||
*/
|
||||
double GetPosition() const;
|
||||
|
||||
/**
|
||||
* Set the PWM position.
|
||||
*
|
||||
* @param position the PWM position (0.0 to 1.0)
|
||||
*/
|
||||
void SetPosition(double position);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the PWM period scale changes.
|
||||
*
|
||||
@@ -149,7 +92,7 @@ class PWMSim {
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
|
||||
std::unique_ptr<CallbackStore> RegisterOutputPeriodCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
@@ -157,39 +100,14 @@ class PWMSim {
|
||||
*
|
||||
* @return the PWM period scale
|
||||
*/
|
||||
int GetPeriodScale() const;
|
||||
int GetOutputPeriod() const;
|
||||
|
||||
/**
|
||||
* Set the PWM period scale.
|
||||
*
|
||||
* @param periodScale the PWM period scale
|
||||
* @param period the PWM period scale
|
||||
*/
|
||||
void SetPeriodScale(int periodScale);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the PWM zero latch state changes.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify whether to run the callback with the initial state
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check whether the PWM is zero latched.
|
||||
*
|
||||
* @return true if zero latched
|
||||
*/
|
||||
bool GetZeroLatch() const;
|
||||
|
||||
/**
|
||||
* Define whether the PWM has been zero latched.
|
||||
*
|
||||
* @param zeroLatch true to indicate zero latched
|
||||
*/
|
||||
void SetZeroLatch(bool zeroLatch);
|
||||
void SetOutputPeriod(int period);
|
||||
|
||||
/**
|
||||
* Reset all simulation data.
|
||||
|
||||
31
wpilibc/src/main/native/include/frc/simulation/ServoSim.h
Normal file
31
wpilibc/src/main/native/include/frc/simulation/ServoSim.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
#include <units/length.h>
|
||||
|
||||
#include "frc/Servo.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class Servo;
|
||||
|
||||
namespace sim {
|
||||
class ServoSim {
|
||||
public:
|
||||
explicit ServoSim(const Servo& servo);
|
||||
|
||||
explicit ServoSim(int channel);
|
||||
|
||||
double GetPosition() const;
|
||||
|
||||
double GetAngle() const;
|
||||
|
||||
private:
|
||||
hal::SimDouble m_simPosition;
|
||||
};
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user