Go to Post It will mean far more than you can imagine...and really, you can't lose. - David Kelso [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 01-04-2015, 03:53
2538Programming 2538Programming is offline
Registered User
FRC #2538
 
Join Date: Dec 2013
Location: Morris MN
Posts: 3
2538Programming is an unknown quantity at this point
I2C Rangefinders not working

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
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi