I need alot of assistance!!! We spent up to 12 hours on Saturday figuring out code and staring at the same few lines fixing and fixing them and ended up at two points of needed help. One: with netbeans we could do a “System.out.println(String)” and it would appear on the console this year for (eclipse) debugging purposes we need that same type of thing. To be able to put in a variable or string and have it be able to print it as it changes any tips and where is the default system.out? 2: This year we are trying to do the same thing as last year. Last year we got an I2C sonar sensor working and able to send back distances through the I2C port. (Details on the sensor)We would like to use the same sensor again this year but the class we used last year was deleted! DANGIT FRC!
DigitalModule mod1 = DigitalModule.getIntance(1);
I2C sensor = mod1.getI2C(0xe0); //0xe0 8 it? // 0x70 7 bit
boolean rc=true;
boolean rc2=true;
sensor.write(0x0,0xe0);
//Timer.delay(.1);
//give the sensor the read command
rc=sensor.write(0x0,0x51);
Timer.delay(.05); //50ms
//read 2 bytes from the sensor, in hi, low
rc2sensor.read(0x0,0x02,bytes);
//convert signed 8bit value in quad word int to an unsigned value
high = (bytes[0] << 24) >>>24;
low = (bytes[1] << 24) >>>24;
inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
But… the DigitalModule class was deleted in the 2015 update. We started by copying the last years I2C code in a new document, found the missing class, and tried to adapt it from there… To create the /VERY/ long new document. Can someone look at our new code and understand why our runtime error is occurring? To make this more confusing the error is at the
sensor3.read(0x51, 0x02, mybytes);
line. We know this because we got the testPeriodic code to come back as true. Again /ANY/ help is wanted!!
package org.usfirst.frc.team4085.robot;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.I2C.Port;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.smartdashboard.*;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Robot extends IterativeRobot {
/*
DigitalModule mod1 = DigitalModule.getIntance(1);
I2C sensor = mod1.getI2C(0xe0); //0xe0 8 it? // 0x70 7 bit
boolean rc=true;
boolean rc2=true;
*/
//I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection
//I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port
byte] bytes = new byte[7];
CANTalon dmotor1 = new CANTalon(2);
CANTalon dmotor2 = new CANTalon(1);
Joystick lstick = new Joystick(0);
Joystick rstick = new Joystick(1);
RobotDrive moving = new RobotDrive(dmotor1,dmotor2);
SmartDashboard smart = new SmartDashboard();
//Port port = I2C.Port.valueOf("h");
//I2C sensor2 = new I2C(port, 0x0);
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
/*
sensor.write(0x0,0xe0);
//Timer.delay(.1);
//give the sensor the read command
rc=sensor.write(0x0,0x51);
Timer.delay(.05); //50ms
//read 2 bytes from the sensor, in hi, low
rc2sensor.read(0x0,0x02,bytes);
//convert signed 8bit value in quad word int to an unsigned value
high = (bytes[0] << 24) >>>24;
low = (bytes[1] << 24) >>>24;
inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
*/
I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection
I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port
sensor3.write(0,0xe0);
boolean rc5 = sensor3.write(0, 0x0);
rc5 = false;
System.out.println("Sensor 3 Returned " + rc5);
System.err.println("Test Here");
System.out.print("System out print here");
Timer.delay(.05); //50ms
//sensor2.read(0, 0x02, bytes);
byte] mybytes = new byte[8];
int count = 1, registerAddress = 0;
sensor3.read(0x51, 0x02, mybytes); // need to figure out the correct values that need to be passed in.
System.out.println("Test Here");
//sensor3.readOnly(bytes], count);
/*
try {
/*
sensor2.read(registerAddress, count, mybytes);
/*
} catch (java.nio.BufferUnderflowException e)
{
java.lang.Exception myexeception = new java.lang.Exception("my error message goes here");
e.printStackTrace();
//throw e;
//e.printStackTrace();
}
*/
//int high = 0, low = 0, inches = 0;
/*
int high = (bytes[0] << 24) >>>24;
int low = (bytes[1] << 24) >>>24;
int inches = (int) ( ((high*256)+low) * .393); //combine the high and low value, then convert to inches
*/
// print out inches
//System.out.println("real: high: " + high + " low: " + low + " inches: " + inches);
moving.tankDrive(lstick, rstick);
}
/**
* This function is called periodically during test mode
*/
public void testPeriodic() {
I2C sensor2 = new I2C(Port.kMXP,0); // for MXP port connection
I2C sensor3 = new I2C(Port.kOnboard,0); // for On Board port
byte] mybytes = new byte[8];
String displayme = "";
for(int i = 0; i<10; i++){
if(sensor3.verifySensor(0x51, i, mybytes))
{
System.out.println("Works" + i);
displayme = " good value " + i;
smart.putString("Works ", displayme);
}
}
}
}