Go to Post FRC is a game of mentors. The best teams are guided by mentors who know how to balance on the knife edge of pushing the envelope and achieving success. - Mr. Van [more]
Home
Go Back   Chief Delphi > Technical > Control System > Sensors
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #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: 573
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
  #2   Spotlight this post!  
Unread 22-02-2015, 19:54
FlyOldPlanes FlyOldPlanes is offline
Registered User
FRC #1592
 
Join Date: Feb 2015
Location: Titusville, FL
Posts: 6
FlyOldPlanes is an unknown quantity at this point
Re: LIDAR-Lite Interfacing -- can't read distance

We had issues as well. We ended up putting a pull-up resistor on the SCL pin. Here is our example:http://www.chiefdelphi.com/forums/sh...d.php?t=135043

It is Java, but the look will be similar.
Reply With Quote
Reply


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 02:31.

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