Java Programming Problem

So I am importing a Program Folder from 2019 and I am getting an error in this part of my code.

Cannot invoke tankDrive(double, double) on the primitive type double

The goal of my program is when I Hold the a button on an xbox controller that the robot will approach the target.

if (auto) {

  if (m_LimelightHasValidTarget) {

    drive.tankDrive(m_LimelightDriveCommand, m_LimelightSteerCommand);

  } else {

    drive.tankDrive(0.0, 0.0);

  }

} else {

  drive.tankDrive(left, right);

}

The error’s outside the code the code you sent.

My guess is when you defined drive, you defined it as a double instead of (presumably) a DifferentialDrive.

This is how I named my “drive”

public class Robot extends TimedRobot {

// Naming Motor controllors

CANSparkMax leftFront = new CANSparkMax(RobotMap.leftFront, MotorType.kBrushless);

CANSparkMax leftRear = new CANSparkMax(RobotMap.leftRear, MotorType.kBrushless);

CANSparkMax rightFront = new CANSparkMax(RobotMap.rightFront, MotorType.kBrushless);

CANSparkMax rightRear = new CANSparkMax(RobotMap.rightRear, MotorType.kBrushless);

// Grouping motors

SpeedControllerGroup leftMotorGroup = new SpeedControllerGroup(leftFront, leftRear);

SpeedControllerGroup rightMotorGroup = new SpeedControllerGroup(rightFront, rightRear);

// Making motors into a drive system

DifferentialDrive drive = new DifferentialDrive(leftMotorGroup, rightMotorGroup);

Top tips:

  • Post ALL of your code
  • Copy and paste the ENTIRE error message and stack trace

Withholding information makes helping you a lot harder

2 Likes
package frc.robot;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;

import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.SpeedControllerGroup;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.GenericHID.Hand;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**

  • The VM is configured to automatically run this class, and to call the
  • functions corresponding to each mode, as described in the TimedRobot
  • documentation. If you change the name of this class or the package after
  • creating this project, you must also update the build.gradle file in the
  • project.
    */
    public class Robot extends TimedRobot {

CANSparkMax leftFront = new CANSparkMax(10, MotorType.kBrushless);
CANSparkMax leftRear = new CANSparkMax(11, MotorType.kBrushless);
CANSparkMax rightFront = new CANSparkMax(20, MotorType.kBrushless);
CANSparkMax rightRear = new CANSparkMax(21, MotorType.kBrushless);

SpeedControllerGroup leftMotorGroup = new SpeedControllerGroup(leftFront, leftRear);
SpeedControllerGroup rightMotorGroup = new SpeedControllerGroup(rightFront, rightRear);

DifferentialDrive drive = new DifferentialDrive(leftMotorGroup, rightMotorGroup);

XboxController controller = new XboxController(0);

Timer timer = new Timer();

//LimeLight
private boolean m_LimelightHasValidTarget = false;
private double m_LimelightDriveCommand = 0.0;
private double m_LimelightSteerCommand = 0.0;

/**

  • This function is run when the robot is first started up and should be
  • used for any initialization code.
    */
    @Override
    public void robotInit() {
//ShuffleBoard
SmartDashboard.putNumber("Joystick X value", controller.getX());
SmartDashboard.putNumber("RPM", leftFront.getAppliedOutput());
leftMotorGroup.setInverted(true);
rightMotorGroup.setInverted(true);

}

/**

  • This function is called every robot packet, no matter the mode. Use
  • this for items like diagnostics that you want ran during disabled,
  • autonomous, teleoperated and test.
  • This runs after the mode specific periodic functions, but before

  • LiveWindow and SmartDashboard integrated updating.
    */
    @Override
    public void robotPeriodic() {
    }

/**

  • This autonomous (along with the chooser code above) shows how to select
  • between different autonomous modes using the dashboard. The sendable
  • chooser code works with the Java SmartDashboard. If you prefer the
  • LabVIEW Dashboard, remove all of the chooser code and uncomment the
  • getString line to get the auto name from the text box below the Gyro
  • You can add additional auto modes by adding additional comparisons to

  • the switch structure below with additional strings. If using the
  • SendableChooser make sure to add them to the chooser code above as well.
    */
    @Override
    public void autonomousInit() {
    timer.reset();
    timer.start();
    }

/**

  • This function is called periodically during autonomous.
    */
    @Override
    public void autonomousPeriodic() {
    // Drive for 2 seconds
    if (timer.get() < 2.0) {
    drive.arcadeDrive(0.5, 0.0); // drive forwards half speed
    } else {
    drive.stopMotor(); // stop robot
    }

}

/**

  • This function is called periodically during operator control.
    */
    @Override
    public void teleopPeriodic() {
drive.tankDrive(controller.getRawAxis(1) , controller.getRawAxis(5));
//drive.arcadeDrive(controller.getRawAxis(1), controller.getRawAxis(5));

Update_Limelight_Tracking();

double left = controller.getY(Hand.kLeft);
double right = -controller.getY(Hand.kRight);
double drive = controller.getY(Hand.kLeft); //this will only be used for arcadeDrive
double steer = -controller.getX(Hand.kLeft);//this will only be used for arcadeDrive
final boolean auto = controller.getAButton();

left *= 0.70;
right *= 0.70;
drive *= 0.70; // this will only be used for arcadeDrive
steer *= 0.70; // this will only be used for arcadeDrive

if (auto) {
if (m_LimelightHasValidTarget) {

drive.tankDrive(m_LimelightDriveCommand, m_LimelightSteerCommand);
// drive.arcadeDrive(m_LimelightDriveCommand,m_LimelightSteerCommand); //this
// will only be used for arcadeDrive

} else {
drive.tankDrive(0.0, 0.0);
// drive.arcadeDrive(0.0,0.0); //this will only be used for arcadeDrive

}
} else {
drive.tankDrive(left, right);
// drive.arcadeDrive(drive,steer); //this will only be used for arcadeDrive
}

}
/**

  • This function is called periodically during test mode.
    */
    @Override
    public void testPeriodic() {
    teleopPeriodic();
    autonomousPeriodic();
    }
    public void Update_Limelight_Tracking() {
    // These numbers must be tuned for your Robot! Be careful!
    final double STEER_K = 0.03; // how hard to turn toward the target
    final double DRIVE_K = 0.26; // how hard to drive fwd toward the target
    final double DESIRED_TARGET_AREA = 13.0; // Area of the target when the robot reaches the wall
    final double MAX_DRIVE = 0.7; // Simple speed limit so we don’t drive too fast
final double tv = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tv").getDouble(0);
final double tx = NetworkTableInstance.getDefault().getTable("limelight").getEntry("tx").getDouble(0);
final double ty = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ty").getDouble(0);
final double ta = NetworkTableInstance.getDefault().getTable("limelight").getEntry("ta").getDouble(0);

if (tv < 1.0) {
  m_LimelightHasValidTarget = false;
  m_LimelightDriveCommand = 0.0;
  m_LimelightSteerCommand = 0.0;
  return;
}

m_LimelightHasValidTarget = true;

// Start with proportional steering
final double steer_cmd = tx * STEER_K;
m_LimelightSteerCommand = steer_cmd;

// try to drive forward until the target area reaches our desired area
double drive_cmd = (DESIRED_TARGET_AREA - ta) * DRIVE_K;

// don't let the robot drive too fast into the goal
if (drive_cmd > MAX_DRIVE) {
  drive_cmd = MAX_DRIVE;
}
m_LimelightDriveCommand = drive_cmd;

}

}

If you could, put the code in github, or somewhere more readable that here on CD and just link to it there.

Secondly, the error message should have a line number associated with it telling you which file, and which line where the error occurs.

1 Like

You’re defining a local double variable called drive which makes the DifferentialDrive instance variable of the same name inaccessible. Try changing the name of the drive double to something else.

2 Likes

Protip:

If you use only two grave marks (`), it will only use preformatted text for that one line. But if you use three grave marks, it will go for as long as you want until you close it with three more grave marks.

Like so
``` This will go on through paragraph breaks because I have THREE marks ```

``This will only go on for one line because there's only two``

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.