We are using maxbotics mb1212 I2C rangefinders and we have tested our rangefinders on an arduino but for some reason, the same approach to reading off the sensors seems to fail. I think our issue may be that it can't find the sensors, which it should totally be able to do, or that it has trouble accessing the command on the sensors. The documentation for the rangefinders is right here
http://www.maxbotix.com/documents/I2..._Datasheet.pdf
,as well our Rangefinder code:
Quote:
package org.usfirst.frc2538.RecycleRush2538.subsystems;
import edu.wpi.first.wpilibj.I2C;
public class RangeFinder {
private I2C newRangeFinder;
private byte[] buffer = new byte[2];
private static int count = 2;
private static long echoTime = 0;
private int rangeCM;
// diagnostic
public boolean successfulWrite;
public boolean successfulRead;
// register addresses, must be in hexadecimle
private static int writeRegisterAddress = 0xE0; //224
private static int readRegisterAddress = 0xE1; //225
// write commands
private static int writeData = 81;
private static int writeDataHex = 0x51;
public RangeFinder(int hexAddress) {
newRangeFinder = new I2C(I2C.Port.kOnboard, hexAddress);
}
public void startSensor() {
successfulWrite = !newRangeFinder.write(writeRegisterAddress, writeDataHex);
echoTime = System.currentTimeMillis() + 100;
}
public int getRangeCM() {
if (System.currentTimeMillis() >= echoTime) {
successfulRead = !newRangeFinder.read(readRegisterAddress, count, buffer);
successfulWrite = !newRangeFinder.write(writeRegisterAddress, writeDataHex);
rangeCM = buffer[0] * 256 + buffer[1];
echoTime = System.currentTimeMillis() + 100;
}
return rangeCM;
}
}
|
Any help we can get is much appreciated, thanks