From 2acf3439842fa73f1294ed5236322dd790894928 Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 11:59:34 -0400 Subject: [PATCH 1/8] include signal strength --- examples/llv3.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/llv3.cpp b/examples/llv3.cpp index 515ff08..a398157 100644 --- a/examples/llv3.cpp +++ b/examples/llv3.cpp @@ -26,6 +26,7 @@ LIDARLite_v3 myLidarLite; int main() { __u16 distance; + __u16 signalstrength; __u8 busyFlag; // Initialize i2c peripheral in the cpu core @@ -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); } } } From 575b74d0e13aff1ad6535a66da905fc35d2e1483 Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 11:59:54 -0400 Subject: [PATCH 2/8] include signal strength --- include/lidarlite_v3.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/lidarlite_v3.h b/include/lidarlite_v3.h index 6bcadb6..f171d7e 100644 --- a/include/lidarlite_v3.h +++ b/include/lidarlite_v3.h @@ -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 @@ -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); From a1263368342b650bd90aa04b1b0b4ff4f71cdec4 Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 12:00:12 -0400 Subject: [PATCH 3/8] include signal strength --- src/lidarlite_v3.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lidarlite_v3.cpp b/src/lidarlite_v3.cpp index f8397a6..beaa83b 100644 --- a/src/lidarlite_v3.cpp +++ b/src/lidarlite_v3.cpp @@ -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. From 8cd8c6030e74f26c4fd59ab6220cc5805220637e Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 12:00:31 -0400 Subject: [PATCH 4/8] more examples --- examples/llv3_2.cpp | 119 +++++++++++++++++++++++++++++++++++ examples/llv3_stream_all.cpp | 59 +++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 examples/llv3_2.cpp create mode 100644 examples/llv3_stream_all.cpp diff --git a/examples/llv3_2.cpp b/examples/llv3_2.cpp new file mode 100644 index 0000000..7a54d66 --- /dev/null +++ b/examples/llv3_2.cpp @@ -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 +#include + +#include + +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); + } +} +*/ diff --git a/examples/llv3_stream_all.cpp b/examples/llv3_stream_all.cpp new file mode 100644 index 0000000..8b0372a --- /dev/null +++ b/examples/llv3_stream_all.cpp @@ -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 +#include + +#include + +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); + } + } +} + + From 726f0f8b883796e9fbeb03e4c4f877f08dcb38f0 Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 12:02:54 -0400 Subject: [PATCH 5/8] Delete llv3_2.cpp --- examples/llv3_2.cpp | 119 -------------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 examples/llv3_2.cpp diff --git a/examples/llv3_2.cpp b/examples/llv3_2.cpp deleted file mode 100644 index 7a54d66..0000000 --- a/examples/llv3_2.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*------------------------------------------------------------------------------ - 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 -#include - -#include - -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); - } -} -*/ From af72909f8ac5fb614952725a534bc00cb104f5d0 Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Wed, 4 May 2022 12:03:00 -0400 Subject: [PATCH 6/8] Delete llv3_stream_all.cpp --- examples/llv3_stream_all.cpp | 59 ------------------------------------ 1 file changed, 59 deletions(-) delete mode 100644 examples/llv3_stream_all.cpp diff --git a/examples/llv3_stream_all.cpp b/examples/llv3_stream_all.cpp deleted file mode 100644 index 8b0372a..0000000 --- a/examples/llv3_stream_all.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/*------------------------------------------------------------------------------ - 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 -#include - -#include - -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); - } - } -} - - From 8ceb444c5b0b51957affc6656ed1c7ad34e8b55c Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Fri, 6 May 2022 13:32:57 -0400 Subject: [PATCH 7/8] Add files via upload --- examples/llv3_2.cpp | 119 +++++++++++++++++++++++++++++++++++ examples/llv3_stream_all.cpp | 59 +++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 examples/llv3_2.cpp create mode 100644 examples/llv3_stream_all.cpp diff --git a/examples/llv3_2.cpp b/examples/llv3_2.cpp new file mode 100644 index 0000000..7a54d66 --- /dev/null +++ b/examples/llv3_2.cpp @@ -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 +#include + +#include + +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); + } +} +*/ diff --git a/examples/llv3_stream_all.cpp b/examples/llv3_stream_all.cpp new file mode 100644 index 0000000..8b0372a --- /dev/null +++ b/examples/llv3_stream_all.cpp @@ -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 +#include + +#include + +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); + } + } +} + + From 91d7a185fb4f3a5c9fd3c2493490d0222188210b Mon Sep 17 00:00:00 2001 From: Douglas Cahl <48590543+dougcahl@users.noreply.github.com> Date: Fri, 6 May 2022 14:07:39 -0400 Subject: [PATCH 8/8] Add files via upload --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index ffdd45c..4592e0c 100644 --- a/Makefile +++ b/Makefile @@ -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