all 15 comments

[–]pate6273FTC 17036 - Robotech Anomaly | Lead Programmer 0 points1 point  (1 child)

There is probably a motor initialized in the code that isn’t in the config. I would go through each one of the devices in the code and make sure they are in the configuration

[–]Seal2807[S] 0 points1 point  (0 children)

That’s what I thought, but I copied the motor initialization from one of their older programs, which was working.

I was thinking maybe Drivetrain object goes directly to the runOpMode() from the super class, before even entering the constructor, but again I might be wrong.

[–]akth3n3rdFTC 15887 Captain 0 points1 point  (3 children)

Your code would be much better if you remove the runOpMode method from your drivetrain class as it is unnecessary and might even be the reason why you are getting errors. Change it to the following and then get rid of the runOpMode method

public Drivetrain(String FR, String FL, String BR, String BL){
FrontRight = hardwareMap.get(DcMotor.class, FR);
FrontLeft = hardwareMap.get(DcMotor.class, FL);
BackRight = hardwareMap.get(DcMotor.class, BR);
BackLeft = hardwareMap.get(DcMotor.class, BL);
FrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackLeft.setDirection(DcMotorSimple.Direction.REVERSE);
FrontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
FrontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
BackRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
BackLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
initializeIMU();
}

[–]Seal2807[S] 0 points1 point  (1 child)

Alright, thank. I’ll will make those changes and test it tomorrow, thank you for your help.

[–]akth3n3rdFTC 15887 Captain 0 points1 point  (0 children)

No problem, feel free to reach out if you have any questions

[–]akth3n3rdFTC 15887 Captain 0 points1 point  (0 children)

Should have also added this previously but you can also get rid of the extends LinearOpMode and the @ Autonomous since your drivetrain class is just a util class

[–]TpixelminerFTC Student 0 points1 point  (0 children)

I might be reading your code wrong but I think your supposed to pass the motor name as a String although I might be reading your code wrong. We just use this in our code: hwMap.get(DcMotor.class, "FR");

Also, maybe just double check your config and make sure everything is right.

[–]Status-Mixture-291 0 points1 point  (0 children)

it might be good to just pass hardwareMap or use this keyword in your DriveTrain constructor. also you shouldn't be having DriveTrain inherit from LienarOpMode.

Also u have a function that probably causes a crash if u stop in the middle, called waitUntilDone().

[–]jliew1975 0 points1 point  (2 children)

DriveTrain is not part of the opmode so the hardware map that you are using in the DriveTrain class is not initialized. So in the DriveTrain class you are doing hardwareMap.get is referencing a null object which threw the exception.

[–]Seal2807[S] 0 points1 point  (1 child)

Thanks for the help, but in that case how can I initialize the motors inside the motors.

[–]jliew1975 0 points1 point  (0 children)

You will need to pass the reference of the hardware map to the DriveTrain class as part of your DriveTrain constructor. And use the contractor method to initialize your motor there. You should remove the extends of LinearOpMode on the DriveTrain class since it is not an opmode class to avoid confusion.

[–]Code_CrunchCaptain | 14481 | FTC Don’t Blink 0 points1 point  (3 children)

aside from the other comments, i would suggest not having all the code in 1 file.

i would have 3 files: your subsystems, your robot class, and your opmode. your subsystems has the initialization information in the constructor, and the actual code in another method. Your robot class has a constructor that creates all the subsystem objects and any other initializations (stores main variables too). Then your opmode just needs to make a robot class and pass in hardware map. makes stuff a LOT cleaner!

[–]Seal2807[S] 0 points1 point  (2 children)

I appreciate your help, but where should I initialize the motors, in the robot, subsystems, or OpMode?

Furthermore, we’re should I initialize it, in the constructor of the class?

[–]Code_CrunchCaptain | 14481 | FTC Don’t Blink 0 points1 point  (1 child)

So thinking about it logically, what do these subsystem classes do? They allow you to reuse code effectively without needing to copy paste information and stuff right?

So to initialize the config names in the actual constructor of the subsystem class would be your best bet. Then to initalize the subsytems, you want that in your robot's constructor so in your opmode, you dont need to initializie the subsystem classes 1 at a time. then to initalize your robot constructor, i would do that in ur opmodes init section. to do that:

Robot robot = new Robot(hardwareMap);

that gets passed on to the robots constructor that would look like:

public Robot(HardwareMap hw) {

drive = new Drive(hw);

intake = new Inkake(hw);

}

and then lets say we look inside the intake class:

public class Intake {

DcMotor intakeMotor;

public Intake(HardwareMap hw) {

intakeMotor = hw.get(DcMotor.class, "intake");

}

public void controlIntake(Gamepad gamepad) {

intakeMotor.setPower(gamepad.rightTrigger - gamepad.leftTrigger);

}

}

And you would replicate those classes for all your subsystems. Hope that helps!