SCRIPT Move cc files

This commit is contained in:
PJ Reiniger
2025-11-07 19:55:39 -05:00
committed by Peter Johnson
parent 10b4a0c971
commit 7ca1be9bae
1197 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
// 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 <units/voltage.h>
namespace frc {
/**
* Interface for motor controlling devices.
*/
class MotorController {
public:
virtual ~MotorController() = default;
/**
* Common interface for setting the speed of a motor controller.
*
* @param speed The speed to set. Value should be between -1.0 and 1.0.
*/
virtual void Set(double speed) = 0;
/**
* Sets the voltage output of the MotorController. Compensates for
* the current bus voltage to ensure that the desired voltage is output even
* if the battery voltage is below 12V - highly useful when the voltage
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
*
* <p>NOTE: This function *must* be called regularly in order for voltage
* compensation to work properly - unlike the ordinary set function, it is not
* "set it and forget it."
*
* @param output The voltage to output.
*/
virtual void SetVoltage(units::volt_t output);
/**
* Common interface for getting the current set speed of a motor controller.
*
* @return The current set speed. Value is between -1.0 and 1.0.
*/
virtual double Get() const = 0;
/**
* Common interface for inverting direction of a motor controller.
*
* @param isInverted The state of inversion, true is inverted.
*/
virtual void SetInverted(bool isInverted) = 0;
/**
* Common interface for returning the inversion state of a motor controller.
*
* @return isInverted The state of inversion, true is inverted.
*/
virtual bool GetInverted() const = 0;
/**
* Common interface for disabling a motor.
*/
virtual void Disable() = 0;
/**
* Common interface to stop the motor until Set is called again.
*/
virtual void StopMotor() = 0;
};
} // namespace frc

View File

@@ -0,0 +1,75 @@
// 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 <functional>
#include <vector>
#include <wpi/deprecated.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/motorcontrol/MotorController.h"
WPI_IGNORE_DEPRECATED
namespace frc {
/**
* Allows multiple MotorController objects to be linked together.
*/
class [[deprecated(
"Use PWMMotorController::AddFollower() or if using CAN motor controllers,"
"use their method of following.")]] MotorControllerGroup
: public wpi::Sendable,
public MotorController,
public wpi::SendableHelper<MotorControllerGroup> {
public:
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @tparam MotorControllers The MotorController types.
* @param motorController The first MotorController to add
* @param motorControllers The MotorControllers to add
*/
template <class... MotorControllers>
explicit MotorControllerGroup(MotorController& motorController,
MotorControllers&... motorControllers)
: m_motorControllers(std::vector<std::reference_wrapper<MotorController>>{
motorController, motorControllers...}) {
Initialize();
}
/**
* Create a new MotorControllerGroup with the provided MotorControllers.
*
* @param motorControllers The MotorControllers to add.
*/
explicit MotorControllerGroup(
std::vector<std::reference_wrapper<MotorController>>&& motorControllers);
MotorControllerGroup(MotorControllerGroup&&) = default;
MotorControllerGroup& operator=(MotorControllerGroup&&) = default;
void Set(double speed) override;
void SetVoltage(units::volt_t output) override;
double Get() const override;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
void StopMotor() override;
void InitSendable(wpi::SendableBuilder& builder) override;
private:
bool m_isInverted = false;
std::vector<std::reference_wrapper<MotorController>> m_motorControllers;
void Initialize();
};
} // namespace frc
WPI_UNIGNORE_DEPRECATED

View File

@@ -0,0 +1,123 @@
// 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 <string>
#include <units/time.h>
#include <wpi/mutex.h>
#include "frc/Timer.h"
namespace frc {
/**
* The Motor Safety feature acts as a watchdog timer for an individual motor. It
* operates by maintaining a timer that tracks how long it has been since the
* feed() method has been called for that actuator. Code in the Driver Station
* class initiates a comparison of these timers to the timeout values for any
* actuator with safety enabled every 5 received packets (100ms nominal).
*
* The subclass should call Feed() whenever the motor value is updated.
*/
class MotorSafety {
public:
MotorSafety();
virtual ~MotorSafety();
MotorSafety(MotorSafety&& rhs);
MotorSafety& operator=(MotorSafety&& rhs);
/**
* Feed the motor safety object.
*
* Resets the timer on this object that is used to do the timeouts.
*/
void Feed();
/**
* Set the expiration time for the corresponding motor safety object.
*
* @param expirationTime The timeout value.
*/
void SetExpiration(units::second_t expirationTime);
/**
* Retrieve the timeout value for the corresponding motor safety object.
*
* @return the timeout value.
*/
units::second_t GetExpiration() const;
/**
* Determine if the motor is still operating or has timed out.
*
* @return true if the motor is still operating normally and hasn't timed out.
*/
bool IsAlive() const;
/**
* Enable/disable motor safety for this device.
*
* Turn on and off the motor safety option for this PWM object.
*
* @param enabled True if motor safety is enforced for this object.
*/
void SetSafetyEnabled(bool enabled);
/**
* Return the state of the motor safety enabled flag.
*
* Return if the motor safety is currently enabled for this device.
*
* @return True if motor safety is enforced for this device.
*/
bool IsSafetyEnabled() const;
/**
* Check if this motor has exceeded its timeout.
*
* This method is called periodically to determine if this motor has exceeded
* its timeout value. If it has, the stop method is called, and the motor is
* shut down until its value is updated again.
*/
void Check();
/**
* Check the motors to see if any have timed out.
*
* This static method is called periodically to poll all the motors and stop
* any that have timed out.
*/
static void CheckMotors();
/**
* Called to stop the motor when the timeout expires.
*/
virtual void StopMotor() = 0;
/**
* Returns a description to print when an error occurs.
*
* @return Description to print when an error occurs.
*/
virtual std::string GetDescription() const = 0;
private:
static constexpr auto kDefaultSafetyExpiration = 100_ms;
// The expiration time for this object
units::second_t m_expiration = kDefaultSafetyExpiration;
// True if motor safety is enabled for this motor
bool m_enabled = false;
// The FPGA clock value when the motor has expired
units::second_t m_stopTime = Timer::GetFPGATimestamp();
mutable wpi::mutex m_thisMutex;
};
} // namespace frc

View File

@@ -0,0 +1,171 @@
// 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 <concepts>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
#include <hal/SimDevice.h>
#include <units/voltage.h>
#include <wpi/deprecated.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include "frc/MotorSafety.h"
#include "frc/PWM.h"
#include "frc/motorcontrol/MotorController.h"
namespace frc {
WPI_IGNORE_DEPRECATED
/**
* Common base class for all PWM Motor Controllers.
*/
class PWMMotorController : public MotorController,
public MotorSafety,
public wpi::Sendable,
public wpi::SendableHelper<PWMMotorController> {
public:
PWMMotorController(PWMMotorController&&) = default;
PWMMotorController& operator=(PWMMotorController&&) = default;
/**
* Set the PWM value.
*
* The PWM value is set using a range of -1.0 to 1.0, appropriately scaling
* the value for the FPGA.
*
* @param value The speed value between -1.0 and 1.0 to set.
*/
void Set(double value) override;
/**
* Sets the voltage output of the PWMMotorController. Compensates for
* the current bus voltage to ensure that the desired voltage is output even
* if the battery voltage is below 12V - highly useful when the voltage
* outputs are "meaningful" (e.g. they come from a feedforward calculation).
*
* <p>NOTE: This function *must* be called regularly in order for voltage
* compensation to work properly - unlike the ordinary set function, it is not
* "set it and forget it."
*
* @param output The voltage to output.
*/
void SetVoltage(units::volt_t output) override;
/**
* Get the recently set value of the PWM. This value is affected by the
* inversion property. If you want the value that is sent directly to the
* MotorController, use PWM::GetSpeed() instead.
*
* @return The most recently set value for the PWM between -1.0 and 1.0.
*/
double Get() const override;
/**
* Gets the voltage output of the motor controller, nominally between -12 V
* and 12 V.
*
* @return The voltage of the motor controller, nominally between -12 V and 12
* V.
*/
virtual units::volt_t GetVoltage() const;
void SetInverted(bool isInverted) override;
bool GetInverted() const override;
void Disable() override;
// MotorSafety interface
void StopMotor() override;
std::string GetDescription() const override;
int GetChannel() const;
/**
* Optionally eliminate the deadband from a motor controller.
*
* @param eliminateDeadband If true, set the motor curve on the motor
* controller to eliminate the deadband in the middle
* of the range. Otherwise, keep the full range
* without modifying any values.
*/
void EnableDeadbandElimination(bool eliminateDeadband);
/**
* Make the given PWM motor controller follow the output of this one.
*
* @param follower The motor controller follower.
*/
void AddFollower(PWMMotorController& follower);
/**
* Make the given PWM motor controller follow the output of this one.
*
* @param follower The motor controller follower.
*/
template <std::derived_from<PWMMotorController> T>
void AddFollower(T&& follower) {
m_owningFollowers.emplace_back(
std::make_unique<std::decay_t<T>>(std::forward<T>(follower)));
}
protected:
/**
* Constructor for a PWM Motor %Controller connected via PWM.
*
* @param name Name to use for SendableRegistry
* @param channel The PWM channel that the controller is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
PWMMotorController(std::string_view name, int channel);
void InitSendable(wpi::SendableBuilder& builder) override;
/// PWM instances for motor controller.
PWM m_pwm;
void SetSpeed(double speed);
double GetSpeed() const;
void SetBounds(units::microsecond_t maxPwm,
units::microsecond_t deadbandMaxPwm,
units::microsecond_t centerPwm,
units::microsecond_t deadbandMinPwm,
units::microsecond_t minPwm);
private:
bool m_isInverted = false;
std::vector<PWMMotorController*> m_nonowningFollowers;
std::vector<std::unique_ptr<PWMMotorController>> m_owningFollowers;
hal::SimDevice m_simDevice;
hal::SimDouble m_simSpeed;
bool m_eliminateDeadband{0};
units::microsecond_t m_minPwm{0};
units::microsecond_t m_deadbandMinPwm{0};
units::microsecond_t m_centerPwm{0};
units::microsecond_t m_deadbandMaxPwm{0};
units::microsecond_t m_maxPwm{0};
units::microsecond_t GetMinPositivePwm() const;
units::microsecond_t GetMaxNegativePwm() const;
units::microsecond_t GetPositiveScaleFactor() const;
units::microsecond_t GetNegativeScaleFactor() const;
PWM* GetPwm() { return &m_pwm; }
};
WPI_UNIGNORE_DEPRECATED
} // namespace frc