View Single Post
  #1   Spotlight this post!  
Unread 08-02-2015, 19:40
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 570
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
LIDAR-Lite Interfacing -- can't read distance

I'm having trouble getting the LIDAR-Lite interfaced to the roboRIO, and could use some input. My code is based on this Java class: https://gist.github.com/tech2077/c4ba2d344bdfcddd48d2.

For reference, here's the LIDAR-Lite manual: https://s3.amazonaws.com/cdn.freshde...lication%2Fpdf

Power is supplied via one of the prior year KOP 25w 12v-5v regulators, and I've verified that there's 5v on the output. The red wire (pin 1) from the LIDAR-Lite is connected to the yellow (+5) wire and pin 6 is connected to the black (-) wire on the regulator.

Pin 4 on the LIDAR-Lite (SCL) is connected to pin 32 on the MXP port, and pin 5 (SDA) is connected to pin 34.

Here's some code snippets -- initialization (from the constructor):

Code:
	this->Lidar = new I2C(port, LIDAR_ADDR);
	if (this->Lidar->AddressOnly())
	{
		printf("[LIDARLite] Device found.\n");
	}
	else
	{
		printf("[LIDARLite] Device not found.\n");
	}
My reading logic:

Code:
void LIDARLite::ReadValue() {
	bool ack = false;
	int count = 0;

	while (!ack && count++ < RETRIES)
	{
		ack = this->Lidar->Write(LIDAR_CONFIG_REGISTER, LIDAR_MEASURE);
		Sleep(10);
	}
	if (!ack)
	{
		printf("[LIDARLite] config failed after %d tries.\n", count);
		return;
	}

	ack = false;
	count = 0;
	while (!ack && count++ < RETRIES)
	{
		ack = this->Lidar->Read(LIDAR_DISTANCE_REGISTER, 2, this->readBytes);
		Sleep(10);
	}

	if (!ack)
	{
		printf("[LIDARLite] read failed after %d tries.\n", count);
		return;
	}
	printf("[LIDARLite] read completed.\n");


	CRITICAL_REGION(semaphore)
	{
		this->distance = this->readBytes[0] << 8 | this->readBytes[1];
	}
	END_REGION;
}
Useful values from the header:

Code:
	const int LIDAR_ADDR = 0x62;
	const int LIDAR_CONFIG_REGISTER = 0x00;
	const int LIDAR_DISTANCE_REGISTER = 0x8f;

	static const int NS_PER_MS = 1000000;
	const int RETRIES = 10;

	const int LIDAR_MEASURE = 0x04;
	I2C *Lidar;
	Notifier *updateNotifier;
	int distance = 0;
	unsigned char readBytes[2];
	MUTEX_ID semaphore;
The call to config succeeds after a couple retries, which I'm interpreting as telling me that the unit is on, but the calls to Read never return an ack. I've tried bumping up the timeout, but that doesn't seem to help. Any thoughts?
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote