Can't deploy robot code

When I try to deploy code to the robot, it deploys fully, but then in the RioLog, it says: "

  • Error at frc.robot.drivetrain.DriveSubsystem.( Unhandled exception: java.lang.NullPointerException: Cannot invoke “edu.wpi.first.math.geometry.Rotation2d.unaryMinus()” because “other” is null

  • at edu.wpi.first.math.geometry.Rotation2d.minus(

  • at edu.wpi.first.math.kinematics.Odometry.(

  • at edu.wpi.first.math.kinematics.SwerveDriveOdometry.(

  • at edu.wpi.first.math.estimator.SwerveDrivePoseEstimator.(

  • at edu.wpi.first.math.estimator.SwerveDrivePoseEstimator.(

  • at frc.robot.drivetrain.DriveSubsystem.(

  • at frc.robot.RobotContainer.(

  • at frc.robot.Robot.robotInit(

  • at edu.wpi.first.wpilibj.TimedRobot.startCompetition(

  • at edu.wpi.first.wpilibj.RobotBase.runRobot(

  • at edu.wpi.first.wpilibj.RobotBase.startRobot(

  • at frc.robot.Main.main("

how do i fix this??

its a error on your code. can you provide it so we can take a look ?

yeah sorry i completely forgot to link it: GitHub - Mateo-Johnson/RobustSturdy3

and this is the specific file referenced to

You need to initialize the getHeadingPose2d field. It is null by default, and is not initialized by the time it’s used when constructing the odometry object. You can either set it to zero, or set it to the gyro’s heading immediately before using it in the odometry object

wait so where and how would i do that? i don’t really understand.

and also, the getHeadingPose2d field is line 123, while the error it cites me is on line 126. is that just because thats the line where the constructor ends?

On line 120, set getHeadingPose2d = Rotation2d.fromDegrees(gyro.getHeading());

This will initialize the field before you pass it (erroneously, as null) to the odometry object. Line 123 uses the field, but if it’s not initialized it will be null, which causes the crash because the pose estimator expects it to be an actual value

that makes sense thank you so much!!

1 Like

do i need to use the gyro.getheading or can i use the drivesubsystem function getheading?

Wherever your gyro object lives, you want to getHeading() from that

wait so i cant use the direct method that gets it from the gyro in the subsystem?

You’d be able to use the getHeading() method from the subsystem. I misremembered your code when I wrote out the example

alright sounds good!!