Help, pleeeease! #noob

Ah, yes. That makes a whole lot of sense.

Where do I need to move the requires method to?

Not going to worry with the print piece for now.

That requires method should be replace with the addRequirements method. See the link to the documentation above.

// Copyright © 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;

import edu.wpi.first.wpilibj2.command.CommandBase;

import frc.robot.Robot;

import frc.robot.RobotMap;

import frc.robot.subsystems.DriveTrain;

/** Add your docs here. */

public class TankDrive extends CommandBase {

public TankDrive() {

addRequirements(Robot.driveTrain);

}

private void addRequirements(DriveTrain driveTrain) {

}

@Override

public void initialize() {

}

@Override

public void execute() {

   

double leftStickY = Robot.oi.GetDriverRawAxis(RobotMap.LEFT_STICK_Y);

double rightStickY = Robot.oi.GetDriverRawAxis(RobotMap.RIGHT_STICK_Y);

Robot.driveTrain.setLeftMotors(leftStickY);

Robot.driveTrain.setRightMotors(rightStickY);

}

@Override

public boolean isFinished() {

return false;

}

}

Does the joystick button need to go under OI?

When you call addRequirements, it basically does nothing, as you are overriding it right below it. Is there a reason that function definition is there?

If you mean “where the controller is declared”, then yes. It should not go in the command.

:man_shrugging:

Again, I barely know what I am doing…

Could you perhaps send me your entire codebase?

What’d be your preferred method? Gist? Or like I did the last one?

That works fine, thank you. If you want, you can DM it to me.

// Copyright © 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.subsystems;

import com.ctre.phoenix.motorcontrol.ControlMode;

import com.ctre.phoenix.motorcontrol.can.TalonSRX;

import edu.wpi.first.wpilibj.Joystick;

import edu.wpi.first.wpilibj2.command.SubsystemBase;

import frc.robot.Robot;

import frc.robot.RobotMap;

import frc.robot.commands.TankDrive;

public class DriveTrain extends SubsystemBase {

private static final int LEFT_STICK_Y = 1;

private static final int RIGHT_STICK_Y = 5;

private TalonSRX motorLeft1 = new TalonSRX(RobotMap.Left_Motor_1);

private TalonSRX motorLeft2 = new TalonSRX(RobotMap.Left_Motor_2);

private TalonSRX motorRight1 = new TalonSRX(RobotMap.Right_Motor_1);

private TalonSRX motorRight2 = new TalonSRX(RobotMap.Right_Motor_2);

public void initDefaultCommand() {

setDefaultCommand(new TankDrive());

}

public void setLeftMotors(double speed) {

motorLeft1.set(ControlMode.PercentOutput, -speed);

motorLeft2.set(ControlMode.PercentOutput, -speed);

}

public void setRightMotors(double speed) {

motorRight1.set(ControlMode.PercentOutput, speed);

motorRight2.set(ControlMode.PercentOutput, speed);

}

public void driveWithJoysticks(Joystick controller, double speed) {

Robot.tankDrive(controller.getRawAxis(LEFT_STICK_Y));

Robot.tankDrive(controller.getRawAxis(RIGHT_STICK_Y));

}

}

How hot of a mess did I create?

Ok, so first off you are using an older version of Wpilib, since the newer versions have Constants and Robot Container instead of OI. This is why the addRequirements method probably gave you an error, since that is another thing that was updated. I am not sure if you need to update, but if I were you I would. Now, if you simply want to get something working, in your code change the addRequirements back to requires, and delete the method you made. Now the reason your code isn’t working is because your command is not being called from Robot.java. This basically means the code you wrote in your command is not running. To call your command, in the TeleopInit in Robot.java add the line “new TankDrive().schedule()”. This will call your command when the robot is enabled in teleop. Hope this helps!

1 Like

I don’t think it’s quite that - it looks like they’ve mixed the old and new command-based structures since RobotContainer is mentioned in Robot.java. (old command-based is technically still supported anyway but deprecated)

Could you link to the videos and examples you’ve been using? I have a feeling a few of them were outdated, as WPILib changed how command-based code is written relatively recently.

1 Like

But, you cannot use requires in the latest Wpilib, just tested it on this years robot project, updated to 2021 wpilib, and if I try to use requires instead of addRequirements, I get “error: cannot find symbol requires(m_CollatorSubsystem);” So possibly they are using the 2020 or 2019 version?

1 Like

Thank you for picking up where I left off; and yes, many guides are outdated. Porting them to Python have been quite the activity! I recommend giving us the version number of your libraries, as that will have a big impact on how you need to write this.

1 Like

Yes, this is most likely the most bastardized program one can create. It’s using both WPILIBs. I’ve got the old and new in addition to the CTRE.

Think I got the majority of the structure from this cool cat:

This is my first time posting on chiefdelphi and I cannot thank y’all enough for all the input! If y’all are able to help me resolve this mess and make the robot move, I will be thrilled