I am new to coding with Java and I would like to know where I can find a basic code to run my bot. it has four jaguar motors and our drve station has dual joystics to operate it. Any help will be greatly appreciated
Well first off here are some links to get you started.
WPI Robotics Library Users Guide (PDF) This explains the general use of the library and include examples, though some are missing Java examples C++ is very similar to Java.
Java Getting Started Guide (PDF) Contains infomation of Netbeans, the templates, and java in general. Also has sample source code.
If you have netbeans and the FRC Java updates installed already then you also have examples too. Here is a picture showing how to access the samples.
If you just want to see source code, and dont want to download a PDF or make a sample project, here is the exact example out of the Java getting Started Guide.
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
public class RobotTemplate extends SimpleRobot {
RobotDrive drive = new RobotDrive(1, 2);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
public void autonomous() {
for (int i = 0; i < 4; i++) {
drive.drive(0.5, 0.0); // drive 50% forward speed with 0% turn
Timer.delay(2.0);
// wait 2 seconds
drive.drive(0.0, 0.75); // drive 0% forward speed with 75% turn
Timer.delay(0.75);
// wait for the 90 degree turn to complete
}
drive.drive(0.0, 0.0);
// drive 0% forward speed with 0% turn (stop)
}
public void operatorControl() {
while (isOperatorControl() && isEnabled())
// loop during enabled teleop mode
{
drive.tankDrive(leftStick, rightStick);
// drive with the joysticks
Timer.delay(0.005);
}
}
}