Skip to content
Snippets Groups Projects
Commit 7f01c0e3 authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

first commit. work in progress

parents
No related branches found
No related tags found
No related merge requests found
Showing with 875 additions and 0 deletions
SUBSYSTEM=="usb|usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A700evSl", RUN+="/bin/sh -c 'echo $kernel > /sys/bus/usb/drivers/ftdi_sio/unbind'"
SUBSYSTEM=="usb|usb_device", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A700evSl", MODE="0666"
\ No newline at end of file
# Pre-requisites about cmake itself
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0005 NEW)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
# The project name and the type of project
PROJECT(lidar-lite)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
SET(CMAKE_INSTALL_PREFIX /usr/local)
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
ENDIF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -D_REENTRANT")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_REENTRANT")
ADD_SUBDIRECTORY(src)
FIND_PACKAGE(Doxygen)
ADD_CUSTOM_TARGET (doc ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/doxygen.conf)
ADD_CUSTOM_TARGET (distclean @echo cleaning cmake files)
IF (UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "distribution clean"
COMMAND make ARGS clean
COMMAND rm ARGS -rf ${CMAKE_SOURCE_DIR}/build/*
TARGET distclean
)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "distclean only implemented in unix"
TARGET distclean
)
ENDIF(UNIX)
ADD_CUSTOM_TARGET (uninstall @echo uninstall package)
IF (UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "uninstall package"
COMMAND xargs ARGS rm < install_manifest.txt
TARGET uninstall
)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "uninstall only implemented in unix"
TARGET uninstall
)
ENDIF(UNIX)
#edit the following line to add the librarie's header files
FIND_PATH(lidar_lite_INCLUDE_DIR lidar_lite.h /usr/include/iridrivers /usr/local/include/iridrivers)
FIND_LIBRARY(lidar_lite_LIBRARY
NAMES lidar_lite
PATHS /usr/lib /usr/local/lib /usr/local/lib/iridrivers)
IF (lidar_lite_INCLUDE_DIR AND lidar_lite_LIBRARY)
SET(lidar_lite_FOUND TRUE)
ENDIF (lidar_lite_INCLUDE_DIR AND lidar_lite_LIBRARY)
IF (lidar_lite_FOUND)
IF (NOT lidar_lite_FIND_QUIETLY)
MESSAGE(STATUS "Found lidar_lite: ${lidar_lite_LIBRARY}")
ENDIF (NOT lidar_lite_FIND_QUIETLY)
ELSE (lidar_lite_FOUND)
IF (lidar_lite_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find lidar_lite")
ENDIF (lidar_lite_FIND_REQUIRED)
ENDIF (lidar_lite_FOUND)
Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
Author asantamaria (asantamaria@iri.upc.edu)
All rights reserved.
This file is part of lidar_lite library
lidar_lite library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
# Ignore everything
*
# But not these files...
!.gitignore
# ...even if they are in subdirectories
!*/
# Ignore everything
*
# But not these files...
!.gitignore
# ...even if they are in subdirectories
!*/
# Doxyfile 1.5.5
@INCLUDE_PATH = ../doc/
@INCLUDE = doxygen_project_name.conf
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NUMBER =
OUTPUT_DIRECTORY = ../doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = NO
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
TYPEDEF_HIDES_STRUCT = NO
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = NO
SORT_BRIEF_DOCS = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = ../src \
../doc/main.dox
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.c \
*.h \
*.cpp
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = *.tab.c \
*.tab.h \
lex* \
*glr.h \
*llr.h \
*glr.c \
*llr.c \
*general.h
EXCLUDE_SYMBOLS =
EXAMPLE_PATH = ../src/examples
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH = ../doc/images
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
HTML_DYNAMIC_SECTIONS = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = _USE_MPI=1
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = NO
CALL_GRAPH = YES
CALLER_GRAPH = YES
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = NO
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 2
DOT_TRANSPARENT = YES
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO
PROJECT_NAME = "lidar_lite"
/*! \mainpage lidar_lite
\section Introduction
\subsection Pre-Requisites
This package requires of the following libraries and packages
- <A href="http://www.cmake.org">cmake</A>, a cross-platform build system.
- <A href="http://www.doxygen.org">doxygen</a> and
<A href="http://www.graphviz.org">graphviz</a> to generate the documentation.
- stdc++,
.
Under linux all of these utilities are available in ready-to-use packages.
Under MacOS most of the packages are available via <a href="http://www.finkproject.org/">fink</a>. <br>
\subsection Compilation
Just download this package, uncompress it, and execute
- cd build
- cmake ..
.
to generate the makefile and then
- make
.
to obtain the shared library (in this case called <em>iriutils.so</em>) and
also all the example programs.
The <em>cmake</em> only need to be executed once (make will automatically call
<em>cmake</em> if you modify one of the <em>CMakeList.txt</em> files).
To generate this documentation type
- make doc
.
The files in the <em>build</em> directory are genetated by <em>cmake</em>
and <em>make</em> and can be safely removed.
After doing so you will need to call cmake manually again.
\subsection Configuration
The default build mode is DEBUG. That is, objects and executables
include debug information.
The RELEASE build mode optimizes for speed. To build in this mode
execute
- cmake .. -DCMAKE_BUILD_TYPE=RELEASE
.
The release mode will be kept until next time cmake is executed.
\subsection Installation
In order to be able to use the library, it it necessary to copy it into the system.
To do that, execute
- make install
.
as root and the shared libraries will be copied to <em>/usr/local/lib/iriutils</em> directory
and the header files will be copied to <em>/usr/local/include/iriutils</em> dierctory. At
this point, the library may be used by any user.
To remove the library from the system, exceute
- make uninstall
.
as root, and all the associated files will be removed from the system.
\section Customization
To build a new application using these library, first it is necessary to locate if the library
has been installed or not using the following command
- FIND_PACKAGE(lidar_lite REQUIRED)
In the case that the package is present, it is necessary to add the header files directory to
the include directory path by using
- INCLUDE_DIRECTORIES(${lidar_lite_INCLUDE_DIR})
Finally, it is also nevessary to link with the desired libraries by using the following command
- TARGET_LINK_LIBRARIES(<executable name> ${lidar_lite_LIBRARY})
.
\section License
This package is licensed under a
<a href="http://www.gnu.org/licenses/lgpl.html">
LGPL 3.0 License</a>.
\section Disclaimer
This is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# Ignore everything
*
# But not these files...
!.gitignore
# ...even if they are in subdirectories
!*/
# driver source files
SET(sources lidar_lite.cpp exceptions/exceptions.cpp exceptions/lidar_lite_exceptions.cpp)
# application header files
SET(headers lidar_lite.h exceptions/exceptions.h exceptions/lidar_lite_exceptions.h)
# locate the necessary dependencies
FIND_PACKAGE(usb_i2c_adapter REQUIRED)
# add the necessary include directories
INCLUDE_DIRECTORIES(. ${usb_i2c_adapter_INCLUDE_DIR})
# create the shared library
ADD_LIBRARY(lidar_lite SHARED ${sources})
# link necessary libraries
TARGET_LINK_LIBRARIES(lidar_lite ${usb_i2c_adapter_LIBRARY})
# Check G++ compiler version
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# install
INSTALL(TARGETS lidar_lite
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib/iridrivers
ARCHIVE DESTINATION lib/iridrivers)
INSTALL(FILES ${headers} DESTINATION include/iridrivers)
INSTALL(FILES ../Findlidar_lite.cmake DESTINATION ${CMAKE_ROOT}/Modules/)
INSTALL(FILES ../99-lidar_lite.rules DESTINATION /etc/udev/rules.d/)
# Restart UDEV to account for new rules.d
execute_process(COMMAND sudo service udev restart)
ADD_SUBDIRECTORY(examples)
# create an example application
ADD_EXECUTABLE(lidar_lite_test lidar_lite_test.cpp)
# link necessary libraries
TARGET_LINK_LIBRARIES(lidar_lite_test lidar_lite)
#include "lidar_lite.h"
int main(int argc, char *argv[])
{
std::string serial="A700evSl";
CLidarLite* laser_ptr = new CLidarLite();
try
{
laser_ptr->open(serial);
laser_ptr->close();
}catch(CLidarLiteException &e)
{
std::cout << e.what() << std::endl;
}
if(laser_ptr != NULL)
delete laser_ptr;
}
// Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Author Sergi Hernandez (shernand@iri.upc.edu)
// All rights reserved.
//
// This file is part of iriutils
// iriutils is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "exceptions.h"
#include <string.h>
#include <stdio.h>
const std::string exception_msg="[Exception caught] - ";
CException::CException(const std::string& where, const std::string& error_msg)
{
this->error_msg=exception_msg;
this->error_msg+=where;
this->error_msg+="\nError: ";
this->error_msg+=error_msg;
}
const std::string& CException::what(void)
{
return this->error_msg;
}
CException::~CException() throw()
{
/* the error message is destroyed by its own destructor */
}
// Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
// Author Sergi Hernandez (shernand@iri.upc.edu)
// All rights reserved.
//
// This file is part of iriutils
// iriutils is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _EXCEPTIONS
#define _EXCEPTIONS
#include <exception>
#include <sstream>
#include <string>
template <typename T_>
inline std::string tostring (const T_ & src)
{
std::ostringstream out;
out << src;
return out.str();
}
#define _HERE_ (std::string(__PRETTY_FUNCTION__) + " at " + \
std::string(__FILE__) + ":" +tostring(__LINE__))
/**
* \brief Generic exception
*
* This class inherits from the std::exception class to provide generic
* exceptions for for all classes. The error message is provided at
* construction time with all the necessary information about the error
* that has generated the exception. When the exception is caught, the
* what() function may be used to get the error message.
*
* This class should be used as a base class for all other exception
* classes in any program. This way it will be simple to distinguish
* between system exceptions and application exceptions.
*
* When throwing exceptions, it is important to free all allocated
* resources and also to set all the class attributes and variables to a
* known state. Otherwise the behavior of the program after an exception
* is thrown could be unpredictible.
*
* Next there is a scketch of a program to catch exceptions:
*
* \verbatim
* try{
* user code here
* }catch(CException &e){
* handle the exception
* }
* \endverbatim
*
* There exist no copy constructor, so if it is necessary to rethrow an
* exception just use throw; instead of throw e;, because the later tries
* to create a new CException object and initialize it with the information
* of the original one.
*
* This code will catch any exception of this class or any inherited class.
* Several catch statements can be used to catch exceptions of different
* classes separatelly and handle them in different ways.
*
*/
class CException : public std::exception
{
protected:
/**
* \brief Exception error message.
*
* This attribute is a string which contains the error message with the
* information about the error that has generated the exception. This
* message is allocated and initialized at construction time and can not
* be modified afterwards.
*
* When the exception is caught, the what() function must be used to get
* the contents of this error message.
*/
std::string error_msg;
public:
/**
* \brief Class constructor
*
* The constructor of this class allocates the necessary memory to store
* the error message. In addition to the error message provided to the
* constructor, the name of the function, filename and line where the error
* has ocurred, as well as the text "[Exception caught] - " is pre-appended
* to label the message as an exception.
*
* \param where a null terminated string with the information about the name
* of the function, the source code filename and the line where
* the exception was generated. This string must be generated
* by the _HERE_ macro.
*
* \param error_msg a null terminated string that contains the error message.
* This string may have any valid character and there is no
* limit on its length.
*/
CException(const std::string& where, const std::string& error_msg);
/**
* \brief Function to get the error message
*
* This function is used to get the error message with the information about
* the error that has generated the exception.
*
* \return the error message as a constant string to prevent external
* modifications of the private attributes of the class.
*/
virtual const std::string& what(void);
/**
* \brief Class destructor
*
* This destructor just frees all the memory allocated to store the error
* message.
*/
virtual ~CException() throw();
};
#endif
#include "lidar_lite_exceptions.h"
#include <sstream>
#include <string.h>
#include <stdio.h>
#include "exceptions/lidar_lite_exceptions.h"
const std::string lidar_lite_error_message="LidarLite error - ";
CLidarLiteException::CLidarLiteException(const std::string& where,const std::string &error_msg):CException(where,lidar_lite_error_message)
{
std::stringstream text;
this->error_msg+=error_msg;
}
#ifndef _LIDAR_LITE_EXCEPTIONS
#define _LIDAR_LITE_EXCEPTIONS
#include "exceptions.h"
/**
* \brief Lidar Lite exception
*
* This class is used to report general errors of the Lidar Lite devices. These
* errors are normally caused by invalid parameters passed to the functions.
* In this case the error message is used to identify which error has ocuurred.
*
*/
class CLidarLiteException : public CException
{
public:
/**
* \brief
*/
CLidarLiteException(const std::string& where,const std::string &error_msg);
};
#endif
#include "lidar_lite.h"
CLidarLite::CLidarLite(void)
{
}
CLidarLite::~CLidarLite(void)
{
close();
if(this->adapter_ != NULL)
delete this->adapter_;
}
void CLidarLite::blink_led(void)
{
try
{
for (int ii = 0; ii < 2; ++ii)
{
this->adapter_->turn_led_off();
usleep(200000);
this->adapter_->turn_led_on();
usleep(200000);
}
}catch(CException &e)
{
throw CLidarLiteException(_HERE_, e.what());
}
}
void CLidarLite::open(const std::string& serial)
{
this->adapter_ = new CUSBI2C("adapter");
try
{
// open serial port
std::cout << "[CLidarLite] Opening Lidar Lite. " << std::endl;
this->adapter_->open(serial);
std::cout << " - Serial number: " << serial << std::endl;
std::cout << " - Firmware revision: " << (int)this->adapter_->get_revision() << std::endl;
// blink led
blink_led();
// Setup gpio 2 as i2c
this->adapter_->config_gpio(gpio2,i2c);
// Test
// unsigned char param1 = 0x00;
unsigned char data = 0x04;
this->adapter_->write_reg(gpio2, 0x00, &data, 1);
// this->adapter_->write(0x00, &data, 1);
//int CUSBI2C::write_reg(unsigned char dev_id, short int address, unsigned char *data, int len)
//Write 0x04 to register 0x00.
//Read register 0x01. Repeat until bit 0 (LSB) goes low.
//Read two bytes from 0x8f (High byte 0x0f then low byte 0x10) to obtain the 16-bit measured distance in centimeter
}catch(CException &e)
{
throw CLidarLiteException(_HERE_, e.what());
}
}
void CLidarLite::close(void)
{
try
{
this->adapter_->close();
}catch(CException &e)
{
throw CLidarLiteException(_HERE_, e.what());
}
}
#ifndef _LIDAR_LITE_H
#define _LIDAR_LITE_H
#include <iostream>
#include "usb_i2c.h"
#include "exceptions/lidar_lite_exceptions.h"
class CLidarLite
{
private:
std::string serial_; // Serial port
CUSBI2C* adapter_; // Device object
void blink_led(void);
public:
CLidarLite(void);
~CLidarLite(void);
void open(const std::string& serial);
void close(void);
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment