Commit 6ff0d32d authored by Your Name's avatar Your Name
Browse files

added lsllidar and LIDARLITE library

parent cdcb79c1
LSLBASE=../labstreaminglayer/build/install
CPPFLAGS+=-Wall -Wno-sign-compare -I$(LSLBASE)/include -I.
LDFLAGS+=-L$(LSLBASE)/lib
CXX=g++
CC=g++
LDLIBS+=-llsl32 -lboost_program_options
#LDLIBS+=-lzmq -lboost_program_options -lpigpio -llsl32
#LDLIBS+=-lzmq -lpthread -lboost_system -lboost_regex -lboost_program_options
#INCLUDE+=RS-232
CXXFLAGS+=-Wall -std=c++11
all: lsllidar
lsllidar: lsllidar.o lidarlite_v3.o
lsllidar.o: lsllidar.cc include/lidarlite_v3.h
lidarlite_v3.o: lidarlite_v3.cpp include/lidarlite_v3.h
../../LIDARLite_RaspberryPi_Library/include/lidarlite_v3.h
\ No newline at end of file
../LIDARLite_RaspberryPi_Library/src/lidarlite_v3.cpp
\ No newline at end of file
/*------------------------------------------------------------------------------
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;
__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();
printf("%4d\n", distance);
}
}
}
/*
* ================================================================
* 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);
}
}
*/
#include <linux/types.h>
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <lsl_cpp.h>
#include <boost/program_options.hpp>
#include <include/lidarlite_v3.h>
using namespace std;
using namespace boost;
using namespace lsl;
LIDARLite_v3 myLidarLite;
stream_outlet *outlet;
string info_name, info_type, info_sourceid;
static int verbose = 0;
void parse_options(int argc, const char *argv[]) {
namespace po = boost::program_options;
// Declare the supported options.
po::options_description desc("Usage:");
desc.add_options()("help,h", "show this message")(
"lsl-name", po::value<string>(), "set the name of the LSL stream")(
"lsl-type", po::value<string>(), "set the type of the LSL stream")(
"lsl-sourceid", po::value<string>(),
"set the sourceid of the LSL stream")("verbose,v",
"enable verbose output");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
exit(0);
}
if (vm.count("verbose")) {
verbose = 1;
}
if (vm.count("lsl-name"))
info_name = vm["lsl-name"].as<string>();
else
info_name = "Raspberry Pi LIDAR Events";
if (verbose)
cout << "LSL name is: " << info_name << endl;
if (vm.count("lsl-type"))
info_type = vm["lsl-type"].as<string>();
else {
char hostname[255];
gethostname(hostname, 255);
ostringstream s;
s << "LIDAR Events @ " << hostname;
info_type = s.str();
}
if (verbose)
cout << "LSL type is: " << info_type << endl;
if (vm.count("lsl-sourceid"))
info_sourceid = vm["lsl-sourceid"].as<string>();
else {
char hostname[255];
gethostname(hostname, 255);
ostringstream s;
s << argv[0] << "@" << hostname;
info_sourceid = s.str();
}
if (verbose)
cout << "LSL sourceid is: " << info_sourceid << endl;
}
int main(int argc, const char *argv[])
{
int16_t distance;
__u8 busyFlag;
parse_options(argc, argv);
// Initialize i2c peripheral in the cpu core
myLidarLite.i2c_init();
// Optionally configure LIDAR-Lite
myLidarLite.configure(0);
// make a new stream_info and open an outlet with it
stream_info info(info_name.c_str(), info_type.c_str(), 1,
lsl::IRREGULAR_RATE, lsl::cf_int16,
info_sourceid.c_str());
outlet = new stream_outlet(info);
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();
outlet->push_sample(&distance);
printf("%4d\n", distance);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment