|
Re: GRIP and NetworkTables settings for use with a co-processor
This is our entire Robot.java class. NetworkTables related code is bolded.
package org.usfirst.frc.team4541.robot;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.SPI;
import com.kauailabs.navx.frc.AHRS;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.I2C.Port;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SendableChoos er;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;
public class Robot extends SampleRobot {
Joystick stick;
TankDrive drive;
CANTalon t1, t2, t3, t4, t5, t6, t7, t8, t9;
MotorManip m1, m2, m3, m4, m5;
Shooter shooter;
Intake intake;
Climber climber;
LIDAR lidar;
final String defaultAuto = "Default";
final String customAuto = "My Auto";
SendableChooser chooser;
AHRS gyro;
NetworkTable table;
CameraServer server;
double targetWidthPx;
double targetDistanceIn;
double desiredX;
double targetOffsetIn;
double targetOffsetDegrees;
// Port port = I2C.Port.kOnboard;
public Robot() {
stick = new Joystick(0);
t1 = new CANTalon(0);
t2 = new CANTalon(1);
t3 = new CANTalon(2);
t4 = new CANTalon(3);
t5 = new CANTalon(4);
t6 = new CANTalon(5);
t7 = new CANTalon(6);
t8 = new CANTalon(7);
t9 = new CANTalon(8);
m1 = new MotorManip(t5);
m2 = new MotorManip(t6);
m3 = new MotorManip(t7);
m4 = new MotorManip(t8);
climber = new Climber(t9);
drive = new TankDrive(t1,t2,t3,t4);
shooter = new Shooter(m1, m2);
intake = new Intake(m3, m4);
// lidar = new LIDAR(port);
gyro = new AHRS(SPI.Port.kMXP);
server = CameraServer.getInstance();
server.setQuality(50);
server.startAutomaticCapture("cam0");
}
public void robotInit() {
chooser = new SendableChooser();
chooser.addDefault("Default Auto", defaultAuto);
chooser.addObject("My Auto", customAuto);
SmartDashboard.putData("Auto modes", chooser);
table = NetworkTable.getTable("GRIP/myContoursReport");
}
public void autonomous() {
// String autoSelected = (String) chooser.getSelected();
// String autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);
// System.out.println("Auto selected: " + autoSelected);
//
// switch(autoSelected) {
// case customAuto:
// break;
// case defaultAuto:
// default:
// break;
// }
}
public void operatorControl() {
gyro.reset();
while (isOperatorControl() && isEnabled()) {
// lidar.begin(100, 0xff);
// lidar.start(100);
// SmartDashboard.putNumber("Distance", lidar.getDistance());
targetWidthPx = table.getNumber("width", 0);
targetDistanceIn = 3200/(2 * targetWidthPx * Math.tan(25));
desiredX = 0;
targetOffsetIn = (desiredX -table.getNumber("centerX", 0)) * 20/targetWidthPx;
targetOffsetDegrees = Math.tan(targetOffsetIn/targetDistanceIn);
SmartDashboard.putNumber("angle", gyro.getAngle());
SmartDashboard.putNumber("output", Math.abs(.0035*(90-gyro.getAngle())));
SmartDashboard.putNumber("target width", targetWidthPx);
SmartDashboard.putNumber("target distance", targetDistanceIn);
drive.arcadeDrive(drive.modStickIn(stick,1),drive. modStickIn(stick, 4));
if(stick.getRawButton(1)){
drive.rotateToAngle(90, gyro);
}
else if(stick.getRawButton(5)){
drive.speedUp();
}
else if(stick.getRawButton(6)){
drive.slowDown();
}
// else if(stick.getRawButton(2)){
// drive.rotateToAngle(targetOffsetDegrees, gyro);
// shooter.shoot(1,1);
// }
// else if(stick.getRawButton(4)){
// intake.pickUp(1);
// }
//
// else if(stick.getRawButton(5)){
// climber.extend(.5);
// }
//
// else if(stick.getRawButton(6)){
// climber.retract(.5);
// }
}
}
public void test() {
}
}
|