mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[wpilib] separate expansion hub position and velocity constants (#8791)
this is because position and velocity control follow different rules; see #8773 Signed-off-by: Zach Harel <zach@zharel.me>
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "wpi/hardware/expansionhub/ExpansionHub.hpp"
|
||||
#include "wpi/hardware/expansionhub/ExpansionHubPidConstants.hpp"
|
||||
#include "wpi/hardware/expansionhub/ExpansionHubPositionConstants.hpp"
|
||||
#include "wpi/hardware/expansionhub/ExpansionHubVelocityConstants.hpp"
|
||||
#include "wpi/nt/BooleanTopic.hpp"
|
||||
#include "wpi/nt/DoubleTopic.hpp"
|
||||
#include "wpi/nt/IntegerTopic.hpp"
|
||||
@@ -120,14 +121,14 @@ class ExpansionHubMotor {
|
||||
*
|
||||
* @return Velocity PID constants object
|
||||
*/
|
||||
ExpansionHubPidConstants& GetVelocityPidConstants();
|
||||
ExpansionHubVelocityConstants& GetVelocityConstants();
|
||||
|
||||
/**
|
||||
* Gets the PID constants object for position PID.
|
||||
*
|
||||
* @return Position PID constants object
|
||||
*/
|
||||
ExpansionHubPidConstants& GetPositionPidConstants();
|
||||
ExpansionHubPositionConstants& GetPositionConstants();
|
||||
|
||||
/**
|
||||
* Gets if the underlying ExpansionHub is connected.
|
||||
@@ -165,7 +166,7 @@ class ExpansionHubMotor {
|
||||
|
||||
wpi::nt::DoublePublisher m_distancePerCountPublisher;
|
||||
|
||||
ExpansionHubPidConstants m_velocityPidConstants;
|
||||
ExpansionHubPidConstants m_positionPidConstants;
|
||||
ExpansionHubVelocityConstants m_velocityConstants;
|
||||
ExpansionHubPositionConstants m_positionConstants;
|
||||
};
|
||||
} // namespace wpi
|
||||
|
||||
@@ -6,24 +6,25 @@
|
||||
|
||||
#include "wpi/nt/BooleanTopic.hpp"
|
||||
#include "wpi/nt/DoubleTopic.hpp"
|
||||
#include "wpi/nt/IntegerTopic.hpp"
|
||||
|
||||
namespace wpi {
|
||||
class ExpansionHubMotor;
|
||||
|
||||
/** This class contains PID constants for an ExpansionHub motor. */
|
||||
class ExpansionHubPidConstants {
|
||||
/** This class contains feedback and feedforward constants for an ExpansionHub
|
||||
* motor. */
|
||||
class ExpansionHubPositionConstants {
|
||||
public:
|
||||
/**
|
||||
* Sets the PID Controller gain parameters.
|
||||
*
|
||||
* Sets the proportional, integral, and differential coefficients.
|
||||
* Set the proportional, integral, and differential coefficients.
|
||||
*
|
||||
* @param p The proportional coefficient. Must be >= 0.
|
||||
* @param i The integral coefficient. Must be >= 0.
|
||||
* @param d The differential coefficient. Must be >= 0.
|
||||
* @param p The proportional coefficient.
|
||||
* @param i The integral coefficient.
|
||||
* @param d The derivative coefficient.
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
void SetPID(double p, double i, double d);
|
||||
ExpansionHubPositionConstants& SetPID(double p, double i, double d);
|
||||
|
||||
/**
|
||||
* Sets the feed forward gains to the specified values.
|
||||
@@ -31,13 +32,12 @@ class ExpansionHubPidConstants {
|
||||
* The units should be radians for angular systems and meters for linear
|
||||
* systems.
|
||||
*
|
||||
* The PID control period is 10ms
|
||||
* The motor control period is 10ms
|
||||
*
|
||||
* @param s The static gain in volts.
|
||||
* @param v The velocity gain in V/(units/s).
|
||||
* @param a The acceleration gain in V/(units/s²).
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
void SetFF(double s, double v, double a);
|
||||
ExpansionHubPositionConstants& SetS(double s);
|
||||
|
||||
/**
|
||||
* Enables continuous input.
|
||||
@@ -48,31 +48,36 @@ class ExpansionHubPidConstants {
|
||||
*
|
||||
* @param minimumInput The minimum value expected from the input.
|
||||
* @param maximumInput The maximum value expected from the input.
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
void EnableContinuousInput(double minimumInput, double maximumInput);
|
||||
ExpansionHubPositionConstants& EnableContinuousInput(double minimumInput,
|
||||
double maximumInput);
|
||||
|
||||
/**
|
||||
* Disables continuous input.
|
||||
* Disable continuous input mode.
|
||||
*
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
void DisableContinuousInput();
|
||||
ExpansionHubPositionConstants& DisableContinuousInput();
|
||||
|
||||
ExpansionHubPidConstants(ExpansionHubPidConstants&) = delete;
|
||||
ExpansionHubPidConstants& operator=(ExpansionHubPidConstants&) = delete;
|
||||
ExpansionHubPositionConstants(ExpansionHubPositionConstants&) = delete;
|
||||
ExpansionHubPositionConstants& operator=(ExpansionHubPositionConstants&) =
|
||||
delete;
|
||||
|
||||
ExpansionHubPidConstants(ExpansionHubPidConstants&&) = default;
|
||||
ExpansionHubPidConstants& operator=(ExpansionHubPidConstants&&) = default;
|
||||
ExpansionHubPositionConstants(ExpansionHubPositionConstants&&) = default;
|
||||
ExpansionHubPositionConstants& operator=(ExpansionHubPositionConstants&&) =
|
||||
default;
|
||||
|
||||
friend class ExpansionHubMotor;
|
||||
|
||||
private:
|
||||
ExpansionHubPidConstants(int usbId, int channel, bool isVelocityPid);
|
||||
ExpansionHubPositionConstants(int hubNumber, int motorNumber);
|
||||
|
||||
wpi::nt::DoublePublisher m_pPublisher;
|
||||
wpi::nt::DoublePublisher m_iPublisher;
|
||||
wpi::nt::DoublePublisher m_dPublisher;
|
||||
|
||||
wpi::nt::DoublePublisher m_sPublisher;
|
||||
wpi::nt::DoublePublisher m_vPublisher;
|
||||
wpi::nt::DoublePublisher m_aPublisher;
|
||||
|
||||
wpi::nt::BooleanPublisher m_continuousPublisher;
|
||||
wpi::nt::DoublePublisher m_continuousMinimumPublisher;
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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 "wpi/nt/DoubleTopic.hpp"
|
||||
|
||||
namespace wpi {
|
||||
class ExpansionHubMotor;
|
||||
|
||||
/** This class contains feedback and feedforward constants for an ExpansionHub
|
||||
* motor. */
|
||||
class ExpansionHubVelocityConstants {
|
||||
public:
|
||||
/**
|
||||
* Sets the PID Controller gain parameters.
|
||||
*
|
||||
* Set the proportional, integral, and differential coefficients.
|
||||
*
|
||||
* @param p The proportional coefficient.
|
||||
* @param i The integral coefficient.
|
||||
* @param d The derivative coefficient.
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
ExpansionHubVelocityConstants& SetPID(double p, double i, double d);
|
||||
|
||||
/**
|
||||
* Sets the feed forward gains to the specified values.
|
||||
*
|
||||
* The units should be radians for angular systems and meters for linear
|
||||
* systems.
|
||||
*
|
||||
* The motor control period is 10ms
|
||||
*
|
||||
* @param s The static gain in volts.
|
||||
* @param v The velocity gain in volts per unit per second.
|
||||
* @param a The acceleration gain in volts per unit per second squared.
|
||||
* @return This object, for method chaining.
|
||||
*/
|
||||
ExpansionHubVelocityConstants& SetFF(double s, double v, double a);
|
||||
|
||||
ExpansionHubVelocityConstants(ExpansionHubVelocityConstants&) = delete;
|
||||
ExpansionHubVelocityConstants& operator=(ExpansionHubVelocityConstants&) =
|
||||
delete;
|
||||
|
||||
ExpansionHubVelocityConstants(ExpansionHubVelocityConstants&&) = default;
|
||||
ExpansionHubVelocityConstants& operator=(ExpansionHubVelocityConstants&&) =
|
||||
default;
|
||||
|
||||
friend class ExpansionHubMotor;
|
||||
|
||||
private:
|
||||
ExpansionHubVelocityConstants(int hubNumber, int motorNumber);
|
||||
|
||||
wpi::nt::DoublePublisher m_pPublisher;
|
||||
wpi::nt::DoublePublisher m_iPublisher;
|
||||
wpi::nt::DoublePublisher m_dPublisher;
|
||||
|
||||
wpi::nt::DoublePublisher m_sPublisher;
|
||||
wpi::nt::DoublePublisher m_vPublisher;
|
||||
wpi::nt::DoublePublisher m_aPublisher;
|
||||
};
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user