Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
all:
mkdir -p bin
g++ examples/llv3.cpp src/lidarlite_v3.cpp -I . -o bin/llv3.out
g++ examples/llv3_2.cpp src/lidarlite_v3.cpp -I . -o bin/llv3_2.out
g++ examples/llv3_stream_all.cpp src/lidarlite_v3.cpp -I . -o bin/llv3_stream_all.out
4 changes: 3 additions & 1 deletion examples/llv3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ LIDARLite_v3 myLidarLite;
int main()
{
__u16 distance;
__u16 signalstrength;
__u8 busyFlag;

// Initialize i2c peripheral in the cpu core
Expand All @@ -46,8 +47,9 @@ int main()
// This method will result in faster I2C rep rates.
myLidarLite.takeRange();
distance = myLidarLite.readDistance();
signalstrength = myLidarLite.readsignalstrength();

printf("%4d\n", distance);
printf("%4d,%4d\n", distance,signalstrength);
}
}
}
Expand Down
119 changes: 119 additions & 0 deletions examples/llv3_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*------------------------------------------------------------------------------
This example illustrates how to use the LIDAR-Lite library to gain quick
access to the basic functions of LIDAR-Lite via the Raspberry Pi interface.
Additionally, it provides users of any platform with a template for their
own application code.

Copyright (c) 2019 Garmin Ltd. or its subsidiaries.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
------------------------------------------------------------------------------*/

#include <linux/types.h>
#include <cstdio>

#include <include/lidarlite_v3.h>

LIDARLite_v3 myLidarLite;

int main()
{
__u16 distance;
__u16 signalstrength;
__u8 busyFlag;
//__u32 distance1;
//__u32 signalstrength1;
double distance1;
double signalstrength1;
double i_avg;
int i;
i_avg = 25;
i = -1;
distance1 = 0;
signalstrength1 = 0;

// Initialize i2c peripheral in the cpu core
myLidarLite.i2c_init();

// Optionally configure LIDAR-Lite
myLidarLite.configure(0);


while(1)
{
// Each time through the loop, check BUSY
busyFlag = myLidarLite.getBusyFlag();

if (busyFlag == 0x00)
{
i = i + 1;
// When no longer busy, immediately initialize another measurement
// and then read the distance data from the last measurement.
// This method will result in faster I2C rep rates.
myLidarLite.takeRange();
distance = myLidarLite.readDistance();
signalstrength = myLidarLite.readsignalstrength();
//distance1 = distance1 + (double)distance/100;
//signalstrength1 = signalstrength1 + (double)signalstrength/100;
//printf("%4d,%4d\n", distance, signalstrength);

distance1 = distance1 + ((double)distance)/i_avg;
signalstrength1 = signalstrength1 + ((double)signalstrength)/i_avg;
//printf("%d,%d\n", distance1, signalstrength1);

if (i>i_avg-1){
//printf("%d,%d\n", distance1, signalstrength1);
printf("%f,%f\n", distance1, signalstrength1);
fflush(stdout);
i = -1;

distance1 = 0;
signalstrength1 = 0;
}



}
}
}


/*
* ================================================================
* The set of instructions below illustrates one method of setting
* an alternate I2C device address in the LIDAR-Lite v3. See the
* operator manual and C++ libraries for further details.
* ================================================================
*/

/*
#define i2cSecondaryAddr 0x44 // Set I2C address of LIDAR-Lite v3 to 0x44

int main()
{
__u16 distance;

// Initialize i2c peripheral in the cpu core
myLidarLite.i2c_init();

// Set an alternate i2c address in the LIDAR-Lite
// The 2nd argument, if non-zero, disables the default addr 0x62
myLidarLite.setI2Caddr(i2cSecondaryAddr, true);

while(1)
{
myLidarLite.waitForBusy(i2cSecondaryAddr);
myLidarLite.takeRange(i2cSecondaryAddr);
distance = myLidarLite.readDistance(i2cSecondaryAddr);

printf("%4d\n", distance);
}
}
*/
59 changes: 59 additions & 0 deletions examples/llv3_stream_all.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*------------------------------------------------------------------------------
This example illustrates how to use the LIDAR-Lite library to gain quick
access to the basic functions of LIDAR-Lite via the Raspberry Pi interface.
Additionally, it provides users of any platform with a template for their
own application code.

Copyright (c) 2019 Garmin Ltd. or its subsidiaries.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
------------------------------------------------------------------------------*/

#include <linux/types.h>
#include <cstdio>

#include <include/lidarlite_v3.h>

LIDARLite_v3 myLidarLite;

int main()
{
__u16 distance;
__u16 signalstrength;
__u8 busyFlag;

// Initialize i2c peripheral in the cpu core
myLidarLite.i2c_init();

// Optionally configure LIDAR-Lite
myLidarLite.configure(0);


while(1)
{
// Each time through the loop, check BUSY
busyFlag = myLidarLite.getBusyFlag();

if (busyFlag == 0x00)
{
// When no longer busy, immediately initialize another measurement
// and then read the distance data from the last measurement.
// This method will result in faster I2C rep rates.
myLidarLite.takeRange();
distance = myLidarLite.readDistance();
signalstrength = myLidarLite.readsignalstrength();

printf("%d,%d\n", distance, signalstrength);
fflush(stdout);
}
}
}


2 changes: 2 additions & 0 deletions include/lidarlite_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define LLv3_STATUS 0x01
#define LLv3_SIG_CNT_VAL 0x02
#define LLv3_ACQ_CONFIG 0x04
#define LLv3_SIGNAL_STR 0x0e
#define LLv3_DISTANCE 0x0f
#define LLv3_REF_CNT_VAL 0x12
#define LLv3_UNIT_ID_HIGH 0x16
Expand All @@ -50,6 +51,7 @@ class LIDARLite_v3
void configure (__u8 configuration = 0, __u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
void setI2Caddr (__u8 newAddress, __u8 disableDefault, __u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
__u16 readDistance(__u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
__u16 readsignalstrength(__u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
void waitForBusy (__u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
__u8 getBusyFlag (__u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
void takeRange (__u8 lidarliteAddress = LIDARLITE_ADDR_DEFAULT);
Expand Down
21 changes: 21 additions & 0 deletions src/lidarlite_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ __u16 LIDARLite_v3::readDistance(__u8 lidarliteAddress)
return ((distBytes[0] << 8) | distBytes[1]);
} /* LIDARLite_v3::readDistance */

/*------------------------------------------------------------------------------
Read Signal Strength
Read and return result of signal strength measurement.

Parameters
------------------------------------------------------------------------------
lidarliteAddress: Default 0x62. Fill in new address here if changed. See
operating manual for instructions.
------------------------------------------------------------------------------*/
__u16 LIDARLite_v3::readsignalstrength(__u8 lidarliteAddress)
{
__u8 strengthBytes[2] = {0};

// Read two bytes from register 0x0f and 0x10 (autoincrement)
i2cRead((LLv3_SIGNAL_STR | 0x80), strengthBytes, 2, lidarliteAddress);

// Shift high byte and OR in low byte
return ((strengthBytes[0] << 8) | strengthBytes[1]);
} /* LIDARLite_v3::readsignalstrength */


/*------------------------------------------------------------------------------
Write
Perform I2C write to device.
Expand Down