Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commands for differential drivetrains #381

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void initialize() {
public void execute() {
double currentTime = timer.get();
PathPlannerTrajectory.State targetState = generatedTrajectory.sample(currentTime);
if (!controller.isHolonomic() && path.isReversed()) {
targetState = targetState.reverse();
}

Pose2d currentPose = poseSupplier.get();
ChassisSpeeds currentSpeeds = speedsSupplier.get();
Expand All @@ -105,9 +108,16 @@ public void execute() {
Math.hypot(currentSpeeds.vxMetersPerSecond, currentSpeeds.vyMetersPerSecond);

PPLibTelemetry.setCurrentPose(currentPose);
PPLibTelemetry.setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging.logCurrentPose(currentPose);
PathPlannerLogging.logTargetPose(targetState.getTargetHolonomicPose());

if (controller.isHolonomic()) {
PPLibTelemetry.setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging.logTargetPose(targetState.getTargetHolonomicPose());
} else {
PPLibTelemetry.setTargetPose(targetState.getDifferentialPose());
PathPlannerLogging.logTargetPose(targetState.getDifferentialPose());
}

PPLibTelemetry.setVelocities(
currentVel,
targetState.velocityMps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,16 @@ public void execute() {
Math.hypot(currentSpeeds.vxMetersPerSecond, currentSpeeds.vyMetersPerSecond);

PPLibTelemetry.setCurrentPose(currentPose);
PPLibTelemetry.setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging.logCurrentPose(currentPose);
PathPlannerLogging.logTargetPose(targetState.getTargetHolonomicPose());

if (controller.isHolonomic()) {
PPLibTelemetry.setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging.logTargetPose(targetState.getTargetHolonomicPose());
} else {
PPLibTelemetry.setTargetPose(targetState.getDifferentialPose());
PathPlannerLogging.logTargetPose(targetState.getDifferentialPose());
}

PPLibTelemetry.setVelocities(
currentVel,
targetState.velocityMps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,15 @@ public ChassisSpeeds calculateRobotRelativeSpeeds(
public double getPositionalError() {
return translationError.getNorm();
}

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
@Override
public boolean isHolonomic() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ public void reset(Pose2d currentPose, ChassisSpeeds currentSpeeds) {
public double getPositionalError() {
return lastError;
}

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
@Override
public boolean isHolonomic() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ public void reset(Pose2d currentPose, ChassisSpeeds currentSpeeds) {
public double getPositionalError() {
return lastError;
}

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
@Override
public boolean isHolonomic() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ ChassisSpeeds calculateRobotRelativeSpeeds(
* @return Positional error, in meters
*/
double getPositionalError();

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
boolean isHolonomic();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void FollowPathCommand::Execute() {
units::second_t currentTime = m_timer.Get();
PathPlannerTrajectory::State targetState = m_generatedTrajectory.sample(
currentTime);
if (m_controller->isHolonomic()) {
targetState = targetState.reverse();
}

frc::Pose2d currentPose = m_poseSupplier();
frc::ChassisSpeeds currentSpeeds = m_speedsSupplier();
Expand Down Expand Up @@ -68,11 +71,18 @@ void FollowPathCommand::Execute() {
targetState);

PPLibTelemetry::setCurrentPose(currentPose);
PPLibTelemetry::setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging::logCurrentPose(currentPose);

if (m_controller->isHolonomic()) {
PPLibTelemetry::setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging::logTargetPose(targetState.getTargetHolonomicPose());
} else {
PPLibTelemetry::setTargetPose(targetState.getDifferentialPose());
PathPlannerLogging::logTargetPose(targetState.getDifferentialPose());
}

PPLibTelemetry::setVelocities(currentVel, targetState.velocity,
currentSpeeds.omega, targetSpeeds.omega);
PathPlannerLogging::logCurrentPose(currentPose);
PathPlannerLogging::logTargetPose(targetState.getTargetHolonomicPose());
PPLibTelemetry::setPathInaccuracy(m_controller->getPositionalError());

m_output(targetSpeeds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,18 @@ void PathfindingCommand::Execute() {
currentSpeeds.vx, currentSpeeds.vy);

PPLibTelemetry::setCurrentPose(currentPose);
PPLibTelemetry::setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging::logCurrentPose(currentPose);
PathPlannerLogging::logTargetPose(targetState.getTargetHolonomicPose());

if (m_controller->isHolonomic()) {
PPLibTelemetry::setTargetPose(targetState.getTargetHolonomicPose());
PathPlannerLogging::logTargetPose(
targetState.getTargetHolonomicPose());
} else {
PPLibTelemetry::setTargetPose(targetState.getDifferentialPose());
PathPlannerLogging::logTargetPose(
targetState.getDifferentialPose());
}

PPLibTelemetry::setVelocities(currentVel, targetState.velocity,
currentSpeeds.omega, targetSpeeds.omega);
PPLibTelemetry::setPathInaccuracy(m_controller->getPositionalError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ class PPHolonomicDriveController: public PathFollowingController {
const frc::Pose2d &currentPose,
const PathPlannerTrajectory::State &referenceState) override;

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
inline bool isHolonomic() override {
return true;
}

private:
using rpsPerMps_t = units::unit_t<units::compound_unit<units::radians_per_second, units::inverse<units::meters_per_second>>>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class PPLTVController: public frc::LTVUnicycleController,
return m_lastError;
}

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
inline bool isHolonomic() override {
return false;
}

private:
units::meter_t m_lastError;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class PPRamseteController: public frc::RamseteController,
return m_lastError;
}

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
inline bool isHolonomic() override {
return false;
}

private:
units::meter_t m_lastError;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ class PathFollowingController {
* @return Positional error, in meters
*/
virtual units::meter_t getPositionalError() = 0;

/**
* Is this controller for holonomic drivetrains? Used to handle some differences in functionality
* in the path following command.
*
* @return True if this controller is for a holonomic drive train
*/
virtual bool isHolonomic() = 0;
};
}