-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFollowingPath.java
More file actions
91 lines (72 loc) · 3.13 KB
/
FollowingPath.java
File metadata and controls
91 lines (72 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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.
package frc.robot.commands.Autonomous;
import com.pathplanner.lib.PathPlanner;
import com.pathplanner.lib.PathPlannerTrajectory;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.controller.RamseteController;
import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.wpilibj2.command.CommandBase;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.RamseteCommand;
import frc.robot.Constants.AutoConstants;
import frc.robot.Constants.DriveConstants;
import frc.robot.subsystems.Drivetrain;
/** An example command that uses an example subsystem. */
public class FollowingPath extends CommandBase {
private Trajectory traj;
private Drivetrain m_drive;
//private int pcx, pcy;
private String fileName;
//private double ks, kv, ka;
public FollowingPath(Trajectory traj) {
this.traj = traj;
//this.fileName = fileName;
//this.m_drive = m_drive;
//traj = PathPlanner.generatePath(new PathConstraints(3.0, 4.0), pointlist);
//An example trajectory to follow. All units in meters
addRequirements(m_drive);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
followPath();
}
public void followPath() {
//feedforward.calculate(pc.getVelo(), pc.getVelo()+pc.getPID().getVelocityError(), pc.getPID().getPeriod());
//Supplier<Pose2d> supply = () -> track.getPos();
CommandScheduler.getInstance().schedule(new RamseteCommand(traj, m_drive::getPose, AutoConstants.controller,
AutoConstants.feedforward, DriveConstants.kDriveKinematics, m_drive::getWheelSpeeds,
new PIDController(DriveConstants.kPDriveVel, 0, 0),
new PIDController(DriveConstants.kPDriveVel, 0, 0), m_drive::tankDriveVolts, m_drive));
}
public Trajectory getTraj() {
return traj;
}
public String fileName() {
return fileName;
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
public CommandBase chargingStartion(){
PathPlannerTrajectory trajectory = PathPlanner.loadPath("DirectDock-M", 0,0);
PathPlannerTrajectory traj = PathPlanner.loadPath("TestNew", AutoConstants.kMaxSpeedMetersPerSecond,
AutoConstants.kMaxAccelerationMetersPerSecondSquared);
RamseteCommand command = new RamseteCommand(traj, m_drive::getPose, new RamseteController(AutoConstants.kRamseteB, AutoConstants.kRamseteZeta),
AutoConstants.feedforward, DriveConstants.kDriveKinematics, m_drive::getWheelSpeeds,
new PIDController(DriveConstants.kPDriveVel, 0, 0), new PIDController(DriveConstants.kPDriveVel, 0, 0), m_drive::tankDriveVolts, m_drive);
return Commands.sequence();
}
}