I am very new to programming for an FRC. We currently do not have a controller to test the Code I wrote but I was hoping somebody could tell me if I was on the right track.
Any Feedback is appreciated, Thanks!
// Copyright (c) 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;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX;
public class Robot extends TimedRobot {
//Me
private static final int kFrontLeftChannel = 6;
private static final int kFrontRightChannel = 7;
private static final int kRearRightChannel = 8;
private static final int kRearLeftChannel = 9;
private static final int kJoystickChannel = 0;
private MecanumDrive m_robotDrive;
private Joystick m_stick;
@Override
public void robotInit() {
PWMVictorSPX frontLeft = new PWMVictorSPX(kFrontLeftChannel);
PWMVictorSPX rearLeft = new PWMVictorSPX(kRearLeftChannel);
PWMVictorSPX frontRight = new PWMVictorSPX(kFrontRightChannel);
PWMVictorSPX rearRight = new PWMVictorSPX(kRearRightChannel);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_stick = new Joystick(kJoystickChannel);
}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {
//Updates Stick Position
double xAxis = m_stick.getRawAxis(0);
double yAxis = m_stick.getRawAxis(1);
double zAxis = m_stick.getRawAxis(4);
// Converts Axis values to speed the drive is set to
m_robotDrive.driveCartesian(xAxis, yAxis, zAxis, 0.0);}
}
If your robot is using a mecanum drivetrain then this seems good to me (although I would confirm with your mechanical team whether this is the case; it is rather unusual for rookie teams, or any FRC team for that matter, to use a mecanum drive).
I will point out two things just as a nitpick:
1.) You seem to use two spaces for indentation, which is fine, although the standard in most projects seems to be four spaces as it’s more readable that way. Establish consensus with your programming team before changing this.
2.) At the end of your teleopPeriodic() method, you have the end curly brace in a weird position:
public void teleopPeriodic() {
...
m_robotDrive.driveCartesian(xAxis, yAxis, zAxis, 0.0);}
}
The code will run just the same in any case, but you should move the curly brace to a new line:
I am unfamiliar with Commands. I began programming in the “recommended” template by the tutorial I was following. Could you explain what Commands are and how to use them? or linking to any resources explaining this?