Hey everyone,
So my team followed the documentation WPI to code a single ultrasonic to the smartdashboard.
We did that with success, but now find ourselves with a problem.
We want two to show, but for some reason… The console throws an “Illegal exception” error every time we now push code. (Which means no robot code on the driverstation)
It appears that the “error” conflicts on the lines where our naming conventions are the same, but we clearly put “ultra1” and “ultra2” to be different variables.
Furthermore, we looked into another solution that said it may be the setAutomaticMode being used twice and causing the problem…
We removed that in our second sensor class, but that did not help either.
Any suggestions help! We need this issue fixed asap.
Here is the code:
package org.usfirst.frc253.Code2016.commands;
import com.ni.vision.NIVision.Image;
import edu.wpi.first.wpilibj.Ultrasonic;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
i
/**
*
*/
public class Ultrasonic1 extends Command {
Ultrasonic ultra1;
int session;
Image frame;
AxisCamera camera;
public Ultrasonic1() {
ultra1 = new Ultrasonic(0,1);
ultra1.setAutomaticMode(true);
// turns on automatic mode
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
//accelerationX = accel.getX();
//accelerationY = accel.getY();
//accelerationZ = accel.getZ();
double range1 = ultra1.getRangeInches();
//String stringTEST = ultra.getSmartDashboardType();
//System.out.println(accelerationX + " " + accelerationY + " " + accelerationZ + ".");
//SmartDashboard.putNumber("Accelometer X", accel.getX());
//SmartDashboard.putNumber("Accelometer Y", accel.getY());
//SmartDashboard.putNumber("Accelometer Z", accel.getZ());
SmartDashboard.putNumber("Ultrasonic", range1);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
Ultrasonic Sensor 2:
package org.usfirst.frc253.Code2016.commands;
import com.ni.vision.NIVision.Image;
import edu.wpi.first.wpilibj.Ultrasonic;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.vision.AxisCamera;
/**
*
*/
public class Ultrasonic2 extends Command {
Ultrasonic ultra2;
int session;
Image frame;
AxisCamera camera;
public Ultrasonic2() {
ultra2 = new Ultrasonic(2,3);
// turns on automatic mode
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
//accelerationX = accel.getX();
//accelerationY = accel.getY();
//accelerationZ = accel.getZ();
double range2 = ultra2.getRangeInches();
//String stringTEST = ultra.getSmartDashboardType();
//System.out.println(accelerationX + " " + accelerationY + " " + accelerationZ + ".");
//SmartDashboard.putNumber("Accelometer X", accel.getX());
//SmartDashboard.putNumber("Accelometer Y", accel.getY());
//SmartDashboard.putNumber("Accelometer Z", accel.getZ());
SmartDashboard.putNumber("Ultrasonic 2", range2);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}