[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:
Thad House
2025-03-20 19:23:22 -07:00
committed by GitHub
parent 2e21a41f87
commit e2cc9e0059
96 changed files with 1037 additions and 2453 deletions

View File

@@ -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

View File

@@ -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.

View 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