Hello, I am looking into using Pathweaver for the 2019 FRC challenge and am having difficulties implementing the path into code. Where exactly should the code for following a path be written and how do I make the robot follow the path? Any help or examples would be great.
Take a look at this section of the WPI ScreenSteps Live documentation (and this article in particular). Please let us know if you have other questions!
Thank you for the reply, which library should contains the Notifier class? VScode says the object is not defined when I try implementing it.
try adding this import at the top of your file: import edu.wpi.first.wpilibj.Notifier;
Also FYI, VS Code has a cool feature where a light bulb appears in the left margin when you click on a line with an error and you need to import something, misspell something or another quick fix.
3rd edit: better image
I will definitely try this tomorrow thank you again!
Hello, I read the wpi about PathWeaver thoroughly, but i still didn’t know how to make my robot to follow the path.
This my code.
public class Robot extends TimedRobot {
DifferentialDrive m_robotDrive;
VictorSP l_wheel;
VictorSP r_wheel;
Joystick m_stick;
Timer m_timer;
Encoder l_enc;
Encoder r_enc;
ADXRS450_Gyro m_gyro;
EncoderFollower l_enc_follower;
EncoderFollower r_enc_follower;
Notifier m_enc_notifier;
private static final int k_ticks_per_rev = 4096;
// number of encoder counts per wheel revolution
private static final double k_wheel_diameter = 4.0 / 12.0;
//diameter of the wheels
private static final double k_max_velocity = 10;
//maximum velocity of the robot
private static final int k_left_encoder_port_a = 0;
private static final int k_left_encoder_port_b = 1;
private static final int k_right_encoder_port_a = 2;
private static final int k_right_encoder_port_b = 3;
//the port numbers for the encoders connected to the left and right side of the drivetrain
private static final String k_path_name = “cargoShip”;
//name of this path
@Override
public void robotInit() {
m_robotDrive = new DifferentialDrive(l_wheel, r_wheel);
l_wheel = new VictorSP(1);
r_wheel = new VictorSP(2);
m_stick = new Joystick(1);
m_timer = new Timer();
l_enc = new Encoder(k_left_encoder_port_a,k_left_encoder_port_b);
r_enc = new Encoder(k_right_encoder_port_a,k_right_encoder_port_b);
m_gyro = new ADXRS450_Gyro();
m_gyro.calibrate();
m_gyro.reset();
}
@Override
public void autonomousInit() {
Trajectory left_trajectory = PathfinderFRC.getTrajectory(k_path_name + ".left");
Trajectory right_trajectory = PathfinderFRC.getTrajectory(k_path_name + ".right");
//the path you draw is the center of the robot
//but the path the wheels follow are the left and right ones
l_enc_follower = new EncoderFollower(left_trajectory);
r_enc_follower = new EncoderFollower(right_trajectory);
l_enc_follower.configureEncoder(l_enc.get(), k_ticks_per_rev, k_wheel_diameter);
//initial position.4096.2 radius
// You must tune the PID values on the following line!
l_enc_follower.configurePIDVA(1.0, 0.0, 0.0, 1 / k_max_velocity, 0);
r_enc_follower.configureEncoder(r_enc.get(), k_ticks_per_rev, k_wheel_diameter);
//initial position.4096.2 radius
// You must tune the PID values on the following line!
r_enc_follower.configurePIDVA(1.0, 0.0, 0.0, 1 / k_max_velocity, 0);
m_enc_notifier = new Notifier(this::followPath);
m_enc_notifier.startPeriodic(left_trajectory.get(0).dt);
}
private void followPath() {
if (l_enc_follower.isFinished() || r_enc_follower.isFinished())
{
m_enc_notifier.stop();
}
else
{
double left_speed = l_enc_follower.calculate(l_enc.get());
double right_speed = r_enc_follower.calculate(r_enc.get());
double heading = m_gyro.getAngle();
double desired_heading = Pathfinder.r2d(l_enc_follower.getHeading());
double heading_difference = Pathfinder.boundHalfDegrees(desired_heading - heading);
double turn = 0.8 * (-1.0/80.0) * heading_difference;
l_wheel.set(left_speed + turn);
r_wheel.set(right_speed - turn);
}
}
@Override
public void autonomousPeriodic() {
}
Path Weaver is not producing correct csv files currently. See this post.
Do you have the pathfinder Json file in your vendor dependencies folder? It won’t build otherwise.
Yes, I have the pathfinder Json file in my vendor dependencies folder. But, after i deploy gradle and build successfully then enable my driverstation. I shows that there is no robot code.
And also i am not sure whether i should put followpath() in the autonomousPeriodic or not.
It’s almost certainly crashing trying to load the files. Did you put the generated cargoShip.left and cargoShip.right files into the src/main/deploy directory?
Ya, I just found I do not put them into the src/main/deploy directory. I will try it later to deploy the code.
Thank you guys!
When I try running pathweaver using the example code from WPI it says that the differential drive motor outputs aren’t updated enough and then it un-deploys the bot. Do you know what the issue could be?
If the error you are receiving looks something like this:
Example Error
HAL: CAN Receive has Timed Out
Error at frc.robot.Main.main(Main.java:27): HAL: CAN Receive has Timed Out
edu.wpi.first.hal.PDPJNI.getPDPTotalCurrent(Native Method)
edu.wpi.first.wpilibj.PowerDistributionPanel.getTotalCurrent(PowerDistributionPanel.java:79)
edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl.lambda$addDoubleProperty$3(SendableBuilderImpl.java:242)
edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl.updateTable(SendableBuilderImpl.java:95)
edu.wpi.first.wpilibj.livewindow.LiveWindow.updateValues(LiveWindow.java:290)
edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:263)
edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:81)
edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:263)
frc.robot.Main.main(Main.java:27)
Watchdog not fed within 0.020000s
Loop time of 0.02s overrun
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:273): Loop time of 0.02s overrun``
And if you are using any sort of motor controllers driven over the CAN bus (i.e. REV Spark Max, TalonSRX, VictorSPX, etc.), you are likely experiencing the issue that people are talking about here:
and here
Please post the error message if this doesn’t address your problem and I’ll take I look.