这是我第一次使用 Java,我似乎被卡住了。我正在尝试从命令 (DriveStraight) 中的子系统 (DriveTrain) 访问方法 (getHeading),但是当我尝试时,我不断收到“类型子系统的类型 getHeading(double) 未定义”的错误heading = Robot.DriveTrain.getHeading();
。这是命令:
public class DriveStraight extends Command {
private double speed;
private double duration;
private double heading;
public DriveStraight(float driveSpeed, float duration) {
requires(Robot.DriveTrain);
**heading = Robot.DriveTrain.getHeading();**
}
// Called just before this Command runs the first time
protected void initialize() {
setTimeout(duration);
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
**float currentheading = Robot.DriveTrain.getHeading();**
Robot.DriveTrain.arcadeDrive(speed, (heading - currentheading) * 0.08);
}
这是子系统:
public class DriveTrain extends Subsystem {
AnalogGyro gyro;
RobotDrive drive;
VictorSP frontLeftMotor, rearLeftMotor, frontRightMotor, rearRightMotor;
public DriveTrain() {
frontLeftMotor = new VictorSP(RobotMap.frontLeftMotor);
rearLeftMotor = new VictorSP(RobotMap.rearLeftMotor);
frontRightMotor = new VictorSP(RobotMap.frontRightMotor);
rearRightMotor = new VictorSP(RobotMap.rearRightMotor);
gyro = new AnalogGyro(RobotMap.analogGyro);
gyro.setSensitivity(0.00666);
gyro.calibrate();
}
public void arcadeDrive(float speed, float turn) {
drive.arcadeDrive(OI.joy.getRawAxis(OI.LEFT_Y_AXIS),
OI.joy.getRawAxis(OI.RIGHT_X_AXIS), true);
}
public void tankDrive(float leftValue, float rightValue) {
drive.tankDrive(OI.joy.getRawAxis(OI.LEFT_Y_AXIS),
OI.joy.getRawAxis(OI.RIGHT_Y_AXIS), true);
}
public double getHeading() {
return gyro.getAngle();
}
protected void initDefaultCommand() {
arcadeDrive(0, 0);
}
}
我刚开始使用 C++,所以我想我可能正在尝试使用指针,但我不确定。那么从子系统调用方法的正确方法是什么?
谢谢,塞思拉53