Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Robot.java to with an attempted integration of robot code #4

Open
wants to merge 4 commits into
base: Autonomous_Motor
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 63 additions & 48 deletions src/main/java/frc/team7242/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

package frc.team7242.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.team7242.robot.subsystem.Drivetrain;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.CameraServer;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
Expand All @@ -29,22 +28,26 @@ public class Robot extends IterativeRobot {
private static final String kCustomAuto = "My Auto";
private String m_autoSelected;
private SendableChooser<String> m_chooser = new SendableChooser<>();

Joystick driverStick = new Joystick(0);
XboxController xboxdriver = new XboxController(1); //xbox controller in port 1

Drivetrain drivetrain = new Drivetrain();
Spark leftFront = new Spark(0);
Spark rightFront = new Spark(1);
Spark leftBack = new Spark(2);
Spark rightBack = new Spark(3);
//private static Drivetrain drivetrain = new Drivetrain();

public Spark leftFront = new Spark(0);
public Spark rightFront = new Spark(2);
public Spark leftBack = new Spark(1);
public Spark rightBack = new Spark(3);

double autonomousSpeed = 0.5;
double autonomousTime = 7;

double autonomousStartTime;






double autonomousStartTime;

/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
Expand All @@ -54,7 +57,7 @@ public void robotInit() {
m_chooser.addDefault("Default Auto", kDefaultAuto);
m_chooser.addObject("My Auto", kCustomAuto);
SmartDashboard.putData("Auto choices", m_chooser);

CameraServer.getInstance().startAutomaticCapture();
}

/**
Expand Down Expand Up @@ -84,41 +87,53 @@ public void autonomousInit() {
*/
@Override
public void autonomousPeriodic() {
double deltaTime = Timer.getFPGATimestamp() - autonomousStartTime;
if(deltaTime < autonomousTime){
drivetrain.drive(autonomousSpeed, 0.0);
}else{
drivetrain.drive(0.0, 0.0);
}

double deltaTime = Timer.getFPGATimestamp() - autonomousStartTime;
if(deltaTime < autonomousTime){
//drivetrain.drive(autonomousSpeed, 0.0);
}else{
//drivetrain.drive(0.0, 0.0);
}


}


}


/**
* This function is called periodically during operator control.
*/
@Override
public void teleopPeriodic() {

//if using joystick
double leftStickValue = driverStick.getRawAxis(1);
double rightStickValue = driverStick.getRawAxis(3);


//if using xbox, idk how to map xbox
// double leftStickvalue = xboxdriver.getX();
// double rightStickvalue = xboxdriver.getY();



// runs motors at speed
leftFront.set(leftStickValue);
leftBack.set(leftStickValue);
rightFront.set(rightStickValue);
rightBack.set(rightStickValue);

}

/**
public void teleopPeriodic() {


//if using joystick
double xvalue = driverStick.getX();
double yvalue = driverStick.getY();
double boost;

boolean trigger = driverStick.getRawButton(1);
if (trigger){
boost = 2.5;
}
else {
boost = 1;
}



//if using xbox, idk how to map xbox
// double leftStickvalue = xboxdriver.getX();
// double rightStickvalue = xboxdriver.getY();



// runs motors at speed
leftFront.set((yvalue+xvalue)*(-0.4)*boost);
leftBack.set((yvalue+xvalue)*(-0.4)*boost);
rightFront.set((yvalue-xvalue)*(0.4)*boost);
rightBack.set((yvalue-xvalue)*(0.4)*boost);

}}