Initial import of FaRui Campus ADS v3.2
@@ -0,0 +1,17 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 21
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 1
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
||||
@@ -0,0 +1,8 @@
|
||||
build
|
||||
Log/*.png
|
||||
Log/*.txt
|
||||
Log/*.csv
|
||||
Log/*.pdf
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/settings.json
|
||||
PCD/*.pcd
|
||||
@@ -0,0 +1,4 @@
|
||||
[submodule "include/ikd-Tree"]
|
||||
path = include/ikd-Tree
|
||||
url = https://github.com/hku-mars/ikd-Tree.git
|
||||
branch = fast_lio
|
||||
@@ -0,0 +1,128 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(fast_lio)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
ADD_COMPILE_OPTIONS(-std=c++17)
|
||||
ADD_COMPILE_OPTIONS(-std=c++17)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++17 -O3")
|
||||
|
||||
add_definitions(-DROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -std=c++0x -std=c++14 -fexceptions")
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
message("Current CPU archtecture: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
|
||||
include(ProcessorCount)
|
||||
ProcessorCount(N)
|
||||
message("Processer number: ${N}")
|
||||
|
||||
if(N GREATER 4)
|
||||
add_definitions(-DMP_EN)
|
||||
add_definitions(-DMP_PROC_NUM=3)
|
||||
message("core for MP: 3")
|
||||
elseif(N GREATER 3)
|
||||
add_definitions(-DMP_EN)
|
||||
add_definitions(-DMP_PROC_NUM=2)
|
||||
message("core for MP: 2")
|
||||
else()
|
||||
add_definitions(-DMP_PROC_NUM=1)
|
||||
endif()
|
||||
else()
|
||||
add_definitions(-DMP_PROC_NUM=1)
|
||||
endif()
|
||||
|
||||
find_package(OpenMP QUIET)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
|
||||
find_package(PythonLibs REQUIRED)
|
||||
find_path(MATPLOTLIB_CPP_INCLUDE_DIRS "matplotlibcpp.h")
|
||||
|
||||
# ROS dependencies
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(rclcpp_components REQUIRED)
|
||||
find_package(geometry_msgs REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
find_package(std_srvs REQUIRED)
|
||||
find_package(visualization_msgs REQUIRED)
|
||||
find_package(pcl_ros REQUIRED)
|
||||
find_package(pcl_conversions REQUIRED)
|
||||
find_package(livox_ros_driver2 REQUIRED)
|
||||
find_package(rosidl_default_generators REQUIRED)
|
||||
|
||||
set(dependencies
|
||||
rclcpp
|
||||
rclcpp_components
|
||||
geometry_msgs
|
||||
nav_msgs
|
||||
sensor_msgs
|
||||
std_msgs
|
||||
std_srvs
|
||||
visualization_msgs
|
||||
pcl_ros
|
||||
pcl_conversions
|
||||
livox_ros_driver2
|
||||
)
|
||||
|
||||
# Thirdparty libraries
|
||||
find_package(Eigen3 REQUIRED)
|
||||
find_package(PCL REQUIRED COMPONENTS common io)
|
||||
|
||||
message(Eigen: ${EIGEN3_INCLUDE_DIR})
|
||||
message(STATUS "PCL: ${PCL_INCLUDE_DIRS}")
|
||||
|
||||
set(msg_files
|
||||
"msg/Pose6D.msg"
|
||||
)
|
||||
|
||||
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||
${msg_files}
|
||||
)
|
||||
ament_export_dependencies(rosidl_default_runtime)
|
||||
|
||||
add_executable(fastlio_mapping src/laserMapping.cpp include/ikd-Tree/ikd_Tree.cpp src/preprocess.cpp)
|
||||
target_include_directories(fastlio_mapping PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
${PCL_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(fastlio_mapping ${PCL_LIBRARIES} ${PYTHON_LIBRARIES} Eigen3::Eigen)
|
||||
target_include_directories(fastlio_mapping PRIVATE ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
list(APPEND EOL_LIST "foxy" "galactic" "eloquent" "dashing" "crystal")
|
||||
|
||||
if($ENV{ROS_DISTRO} IN_LIST EOL_LIST)
|
||||
# Custommsg to support foxy & galactic
|
||||
rosidl_target_interfaces(fastlio_mapping
|
||||
${PROJECT_NAME} "rosidl_typesupport_cpp")
|
||||
else()
|
||||
rosidl_get_typesupport_target(cpp_typesupport_target
|
||||
${PROJECT_NAME} "rosidl_typesupport_cpp")
|
||||
target_link_libraries(fastlio_mapping ${cpp_typesupport_target})
|
||||
endif()
|
||||
|
||||
ament_target_dependencies(fastlio_mapping ${dependencies})
|
||||
|
||||
# ---------------- Install --------------- #
|
||||
install(TARGETS fastlio_mapping
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY config launch rviz
|
||||
DESTINATION share/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,135 @@
|
||||
clear
|
||||
close all
|
||||
|
||||
Color_red = [0.6350 0.0780 0.1840];
|
||||
Color_blue = [0 0.4470 0.7410];
|
||||
Color_orange = [0.8500 0.3250 0.0980];
|
||||
Color_green = [0.4660 0.6740 0.1880];
|
||||
Color_lightblue = [0.3010 0.7450 0.9330];
|
||||
Color_purple = [0.4940 0.1840 0.5560];
|
||||
Color_yellow = [0.9290 0.6940 0.1250];
|
||||
|
||||
fast_lio_ikdtree = csvread("./fast_lio_time_log.csv",1,0);
|
||||
timestamp_ikd = fast_lio_ikdtree(:,1);
|
||||
timestamp_ikd = timestamp_ikd - min(timestamp_ikd);
|
||||
total_time_ikd = fast_lio_ikdtree(:,2)*1e3;
|
||||
scan_num = fast_lio_ikdtree(:,3);
|
||||
incremental_time_ikd = fast_lio_ikdtree(:,4)*1e3;
|
||||
search_time_ikd = fast_lio_ikdtree(:,5)*1e3;
|
||||
delete_size_ikd = fast_lio_ikdtree(:,6);
|
||||
delete_time_ikd = fast_lio_ikdtree(:,7) * 1e3;
|
||||
tree_size_ikd_st = fast_lio_ikdtree(:,8);
|
||||
tree_size_ikd = fast_lio_ikdtree(:,9);
|
||||
add_points = fast_lio_ikdtree(:,10);
|
||||
|
||||
fast_lio_forest = csvread("fast_lio_time_log.csv",1,0);
|
||||
fov_check_time_forest = fast_lio_forest(:,5)*1e3;
|
||||
average_time_forest = fast_lio_forest(:,2)*1e3;
|
||||
total_time_forest = fast_lio_forest(:,6)*1e3;
|
||||
incremental_time_forest = fast_lio_forest(:,3)*1e3;
|
||||
search_time_forest = fast_lio_forest(:,4)*1e3;
|
||||
timestamp_forest = fast_lio_forest(:,1);
|
||||
|
||||
% Use slide window to calculate average
|
||||
L = 1; % Length of slide window
|
||||
for i = 1:length(timestamp_ikd)
|
||||
if (i<L)
|
||||
average_time_ikd(i) = mean(total_time_ikd(1:i));
|
||||
else
|
||||
average_time_ikd(i) = mean(total_time_ikd(i-L+1:i));
|
||||
end
|
||||
end
|
||||
for i = 1:length(timestamp_forest)
|
||||
if (i<L)
|
||||
average_time_forest(i) = mean(total_time_forest(1:i));
|
||||
else
|
||||
average_time_forest(i) = mean(total_time_forest(i-L+1:i));
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
f = figure;
|
||||
set(gcf,'Position',[80 433 600 640])
|
||||
tiled_handler = tiledlayout(3,1);
|
||||
tiled_handler.TileSpacing = 'compact';
|
||||
tiled_handler.Padding = 'compact';
|
||||
nexttile;
|
||||
hold on;
|
||||
set(gca,'FontSize',12,'FontName','Times New Roman')
|
||||
plot(timestamp_ikd, average_time_ikd,'-','Color',Color_blue,'LineWidth',1.2);
|
||||
plot(timestamp_forest, average_time_forest,'--','Color',Color_orange,'LineWidth',1.2);
|
||||
lg = legend("ikd-Tree", "ikd-Forest",'location',[0.1314 0.8559 0.2650 0.0789],'fontsize',14,'fontname','Times New Roman')
|
||||
title("Time Performance on FAST-LIO",'FontSize',16,'FontName','Times New Roman')
|
||||
xlabel("time/s",'FontSize',16,'FontName','Times New Roman')
|
||||
yl = ylabel("Run Time/ms",'FontSize',15,'Position',[285.7 5.5000 -1]);
|
||||
xlim([32,390]);
|
||||
ylim([0,23]);
|
||||
ax1 = gca;
|
||||
ax1.YAxis.FontSize = 12;
|
||||
ax1.XAxis.FontSize = 12;
|
||||
grid on
|
||||
box on
|
||||
% print('./Figures/fastlio_exp_average','-depsc','-r600')
|
||||
|
||||
|
||||
index_ikd = find(search_time_ikd > 0);
|
||||
search_time_ikd = search_time_ikd(index_ikd);
|
||||
index_forest = find(search_time_forest > 0);
|
||||
search_time_forest = search_time_forest(index_forest);
|
||||
|
||||
t = nexttile;
|
||||
hold on;
|
||||
boxplot_data_ikd = [incremental_time_ikd,total_time_ikd];
|
||||
boxplot_data_forest = [incremental_time_forest,total_time_forest];
|
||||
Colors_ikd = [Color_blue;Color_blue;Color_blue];
|
||||
Colors_forest = [Color_orange;Color_orange;Color_orange];
|
||||
% xticks([3,8,13])
|
||||
h_search_ikd = boxplot(search_time_ikd,'Whisker',50,'Positions',1,'Colors',Color_blue,'Widths',0.3);
|
||||
h_search_forest = boxplot(search_time_forest,'Whisker',50,'Positions',1.5,'Colors',Color_orange,'Widths',0.3);
|
||||
h_ikd = boxplot(boxplot_data_ikd,'Whisker',50,'Positions',[3,5],'Colors',Color_blue,'Widths',0.3);
|
||||
h_forest = boxplot(boxplot_data_forest,'Whisker',50,'Positions',[3.5,5.5],'Colors',Color_orange,'Widths',0.3);
|
||||
ax2 = gca;
|
||||
ax2.YAxis.Scale = 'log';
|
||||
xlim([0.5,6.0])
|
||||
ylim([0.0008,100])
|
||||
xticks([1.25 3.25 5.25])
|
||||
xticklabels({'Nearest Search',' Incremental Updates','Total Time'});
|
||||
yticks([1e-3,1e-2,1e-1,1e0,1e1,1e2])
|
||||
ax2.YAxis.FontSize = 12;
|
||||
ax2.XAxis.FontSize = 14.5;
|
||||
% ax.XAxis.FontWeight = 'bold';
|
||||
ylabel('Run Time/ms','FontSize',14,'FontName','Times New Roman')
|
||||
box_vars = [findall(h_search_ikd,'Tag','Box');findall(h_ikd,'Tag','Box');findall(h_search_forest,'Tag','Box');findall(h_forest,'Tag','Box')];
|
||||
for j=1:length(box_vars)
|
||||
if (j<=3)
|
||||
Color = Color_blue;
|
||||
else
|
||||
Color = Color_orange;
|
||||
end
|
||||
patch(get(box_vars(j),'XData'),get(box_vars(j),'YData'),Color,'FaceAlpha',0.25,'EdgeColor',Color);
|
||||
end
|
||||
Lg = legend(box_vars([1,4]), {'ikd-Tree','ikd-Forest'},'Location',[0.6707 0.4305 0.265 0.07891],'fontsize',14,'fontname','Times New Roman');
|
||||
grid on
|
||||
set(gca,'YMinorGrid','off')
|
||||
nexttile;
|
||||
hold on;
|
||||
grid on;
|
||||
box on;
|
||||
set(gca,'FontSize',12,'FontName','Times New Roman')
|
||||
plot(timestamp_ikd, alpha_bal_ikd,'-','Color',Color_blue,'LineWidth',1.2);
|
||||
plot(timestamp_ikd, alpha_del_ikd,'--','Color',Color_orange, 'LineWidth', 1.2);
|
||||
plot(timestamp_ikd, 0.6*ones(size(alpha_bal_ikd)), ':','Color','black','LineWidth',1.2);
|
||||
lg = legend("\alpha_{bal}", "\alpha_{del}",'location',[0.7871 0.1131 0.1433 0.069],'fontsize',14,'fontname','Times New Roman')
|
||||
title("Re-balancing Criterion",'FontSize',16,'FontName','Times New Roman')
|
||||
xlabel("time/s",'FontSize',16,'FontName','Times New Roman')
|
||||
yl = ylabel("\alpha",'FontSize',15, 'Position',[285.7 0.4250 -1])
|
||||
xlim([32,390]);
|
||||
ylim([0,0.85]);
|
||||
ax3 = gca;
|
||||
ax3.YAxis.FontSize = 12;
|
||||
ax3.XAxis.FontSize = 12;
|
||||
% print('./Figures/fastlio_exp_combine','-depsc','-r1200')
|
||||
% exportgraphics(f,'./Figures/fastlio_exp_combine_1.pdf','ContentType','vector')
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Here saved the debug records which can be drew by the ../Log/plot.py. The record function can be found frm the MACRO: DEBUG_FILE_DIR(name) in common_lib.h.
|
||||
@@ -0,0 +1,94 @@
|
||||
# import matplotlib
|
||||
# matplotlib.use('Agg')
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
#######for ikfom
|
||||
fig, axs = plt.subplots(4,2)
|
||||
lab_pre = ['', 'pre-x', 'pre-y', 'pre-z']
|
||||
lab_out = ['', 'out-x', 'out-y', 'out-z']
|
||||
plot_ind = range(7,10)
|
||||
a_pre=np.loadtxt('mat_pre.txt')
|
||||
a_out=np.loadtxt('mat_out.txt')
|
||||
time=a_pre[:,0]
|
||||
axs[0,0].set_title('Attitude')
|
||||
axs[1,0].set_title('Translation')
|
||||
axs[2,0].set_title('Extrins-R')
|
||||
axs[3,0].set_title('Extrins-T')
|
||||
axs[0,1].set_title('Velocity')
|
||||
axs[1,1].set_title('bg')
|
||||
axs[2,1].set_title('ba')
|
||||
axs[3,1].set_title('Gravity')
|
||||
for i in range(1,4):
|
||||
for j in range(8):
|
||||
axs[j%4, j/4].plot(time, a_pre[:,i+j*3],'.-', label=lab_pre[i])
|
||||
axs[j%4, j/4].plot(time, a_out[:,i+j*3],'.-', label=lab_out[i])
|
||||
for j in range(8):
|
||||
# axs[j].set_xlim(386,389)
|
||||
axs[j%4, j/4].grid()
|
||||
axs[j%4, j/4].legend()
|
||||
plt.grid()
|
||||
#######for ikfom#######
|
||||
|
||||
|
||||
#### Draw IMU data
|
||||
# fig, axs = plt.subplots(2)
|
||||
# imu=np.loadtxt('imu.txt')
|
||||
# time=imu[:,0]
|
||||
# axs[0].set_title('Gyroscope')
|
||||
# axs[1].set_title('Accelerameter')
|
||||
# lab_1 = ['gyr-x', 'gyr-y', 'gyr-z']
|
||||
# lab_2 = ['acc-x', 'acc-y', 'acc-z']
|
||||
# for i in range(3):
|
||||
# # if i==1:
|
||||
# axs[0].plot(time, imu[:,i+1],'.-', label=lab_1[i])
|
||||
# axs[1].plot(time, imu[:,i+4],'.-', label=lab_2[i])
|
||||
# for i in range(2):
|
||||
# # axs[i].set_xlim(386,389)
|
||||
# axs[i].grid()
|
||||
# axs[i].legend()
|
||||
# plt.grid()
|
||||
|
||||
# #### Draw time calculation
|
||||
# plt.figure(3)
|
||||
# fig = plt.figure()
|
||||
# font1 = {'family' : 'Times New Roman',
|
||||
# 'weight' : 'normal',
|
||||
# 'size' : 12,
|
||||
# }
|
||||
# c="red"
|
||||
# a_out1=np.loadtxt('Log/mat_out_time_indoor1.txt')
|
||||
# a_out2=np.loadtxt('Log/mat_out_time_indoor2.txt')
|
||||
# a_out3=np.loadtxt('Log/mat_out_time_outdoor.txt')
|
||||
# # n = a_out[:,1].size
|
||||
# # time_mean = a_out[:,1].mean()
|
||||
# # time_se = a_out[:,1].std() / np.sqrt(n)
|
||||
# # time_err = a_out[:,1] - time_mean
|
||||
# # feat_mean = a_out[:,2].mean()
|
||||
# # feat_err = a_out[:,2] - feat_mean
|
||||
# # feat_se = a_out[:,2].std() / np.sqrt(n)
|
||||
# ax1 = fig.add_subplot(111)
|
||||
# ax1.set_ylabel('Effective Feature Numbers',font1)
|
||||
# ax1.boxplot(a_out1[:,2], showfliers=False, positions=[0.9])
|
||||
# ax1.boxplot(a_out2[:,2], showfliers=False, positions=[1.9])
|
||||
# ax1.boxplot(a_out3[:,2], showfliers=False, positions=[2.9])
|
||||
# ax1.set_ylim([0, 3000])
|
||||
|
||||
# ax2 = ax1.twinx()
|
||||
# ax2.spines['right'].set_color('red')
|
||||
# ax2.set_ylabel('Compute Time (ms)',font1)
|
||||
# ax2.yaxis.label.set_color('red')
|
||||
# ax2.tick_params(axis='y', colors='red')
|
||||
# ax2.boxplot(a_out1[:,1]*1000, showfliers=False, positions=[1.1],boxprops=dict(color=c),capprops=dict(color=c),whiskerprops=dict(color=c))
|
||||
# ax2.boxplot(a_out2[:,1]*1000, showfliers=False, positions=[2.1],boxprops=dict(color=c),capprops=dict(color=c),whiskerprops=dict(color=c))
|
||||
# ax2.boxplot(a_out3[:,1]*1000, showfliers=False, positions=[3.1],boxprops=dict(color=c),capprops=dict(color=c),whiskerprops=dict(color=c))
|
||||
# ax2.set_xlim([0.5, 3.5])
|
||||
# ax2.set_ylim([0, 100])
|
||||
|
||||
# plt.xticks([1,2,3], ('Outdoor Scene', 'Indoor Scene 1', 'Indoor Scene 2'))
|
||||
# # # print(time_se)
|
||||
# # # print(a_out3[:,2])
|
||||
# plt.grid()
|
||||
# plt.savefig("time.pdf", dpi=1200)
|
||||
plt.show()
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,199 @@
|
||||
> ROS2 Fork repo maintainer: [Ericsiii](https://github.com/Ericsii)
|
||||
|
||||
## Related Works and Extended Application
|
||||
|
||||
**SLAM:**
|
||||
|
||||
1. [ikd-Tree](https://github.com/hku-mars/ikd-Tree): A state-of-art dynamic KD-Tree for 3D kNN search.
|
||||
2. [R2LIVE](https://github.com/hku-mars/r2live): A high-precision LiDAR-inertial-Vision fusion work using FAST-LIO as LiDAR-inertial front-end.
|
||||
3. [LI_Init](https://github.com/hku-mars/LiDAR_IMU_Init): A robust, real-time LiDAR-IMU extrinsic initialization and synchronization package..
|
||||
4. [FAST-LIO-LOCALIZATION](https://github.com/HViktorTsoi/FAST_LIO_LOCALIZATION): The integration of FAST-LIO with **Re-localization** function module.
|
||||
|
||||
**Control and Plan:**
|
||||
|
||||
1. [IKFOM](https://github.com/hku-mars/IKFoM): A Toolbox for fast and high-precision on-manifold Kalman filter.
|
||||
2. [UAV Avoiding Dynamic Obstacles](https://github.com/hku-mars/dyn_small_obs_avoidance): One of the implementation of FAST-LIO in robot's planning.
|
||||
3. [UGV Demo](https://www.youtube.com/watch?v=wikgrQbE6Cs): Model Predictive Control for Trajectory Tracking on Differentiable Manifolds.
|
||||
4. [Bubble Planner](https://arxiv.org/abs/2202.12177): Planning High-speed Smooth Quadrotor Trajectories using Receding Corridors.
|
||||
|
||||
<!-- 10. [**FAST-LIVO**](https://github.com/hku-mars/FAST-LIVO): Fast and Tightly-coupled Sparse-Direct LiDAR-Inertial-Visual Odometry. -->
|
||||
|
||||
## FAST-LIO
|
||||
**FAST-LIO** (Fast LiDAR-Inertial Odometry) is a computationally efficient and robust LiDAR-inertial odometry package. It fuses LiDAR feature points with IMU data using a tightly-coupled iterated extended Kalman filter to allow robust navigation in fast-motion, noisy or cluttered environments where degeneration occurs. Our package address many key issues:
|
||||
1. Fast iterated Kalman filter for odometry optimization;
|
||||
2. Automaticaly initialized at most steady environments;
|
||||
3. Parallel KD-Tree Search to decrease the computation;
|
||||
|
||||
## FAST-LIO 2.0 (2021-07-05 Update)
|
||||
<!--  -->
|
||||
<!-- [](https://youtu.be/2OvjGnxszf8) -->
|
||||
<div align="left">
|
||||
<img src="doc/real_experiment2.gif" width=49.6% />
|
||||
<img src="doc/ulhkwh_fastlio.gif" width = 49.6% >
|
||||
</div>
|
||||
|
||||
**Related video:** [FAST-LIO2](https://youtu.be/2OvjGnxszf8), [FAST-LIO1](https://youtu.be/iYCY6T79oNU)
|
||||
|
||||
**Pipeline:**
|
||||
<div align="center">
|
||||
<img src="doc/overview_fastlio2.svg" width=99% />
|
||||
</div>
|
||||
|
||||
**New Features:**
|
||||
1. Incremental mapping using [ikd-Tree](https://github.com/hku-mars/ikd-Tree), achieve faster speed and over 100Hz LiDAR rate.
|
||||
2. Direct odometry (scan to map) on Raw LiDAR points (feature extraction can be disabled), achieving better accuracy.
|
||||
3. Since no requirements for feature extraction, FAST-LIO2 can support many types of LiDAR including spinning (Velodyne, Ouster) and solid-state (Livox Avia, Horizon, MID-70) LiDARs, and can be easily extended to support more LiDARs.
|
||||
4. Support external IMU.
|
||||
5. Support ARM-based platforms including Khadas VIM3, Nivida TX2, Raspberry Pi 4B(8G RAM).
|
||||
|
||||
**Related papers**:
|
||||
|
||||
[FAST-LIO2: Fast Direct LiDAR-inertial Odometry](doc/Fast_LIO_2.pdf)
|
||||
|
||||
[FAST-LIO: A Fast, Robust LiDAR-inertial Odometry Package by Tightly-Coupled Iterated Kalman Filter](https://arxiv.org/abs/2010.08196)
|
||||
|
||||
**Contributors**
|
||||
|
||||
[Wei Xu 徐威](https://github.com/XW-HKU),[Yixi Cai 蔡逸熙](https://github.com/Ecstasy-EC),[Dongjiao He 贺东娇](https://github.com/Joanna-HE),[Fangcheng Zhu 朱方程](https://github.com/zfc-zfc),[Jiarong Lin 林家荣](https://github.com/ziv-lin),[Zheng Liu 刘政](https://github.com/Zale-Liu), [Borong Yuan](https://github.com/borongyuan)
|
||||
|
||||
<!-- <div align="center">
|
||||
<img src="doc/results/HKU_HW.png" width = 49% >
|
||||
<img src="doc/results/HKU_MB_001.png" width = 49% >
|
||||
</div> -->
|
||||
|
||||
## 1. Prerequisites
|
||||
### 1.1 **Ubuntu** and **ROS**
|
||||
**Ubuntu >= 20.04**
|
||||
|
||||
The **default from apt** PCL and Eigen is enough for FAST-LIO to work normally.
|
||||
|
||||
ROS >= Foxy (Recommend to use ROS-Humble). [ROS Installation](https://docs.ros.org/en/humble/Installation.html)
|
||||
|
||||
### 1.2. **PCL && Eigen**
|
||||
PCL >= 1.8, Follow [PCL Installation](https://pointclouds.org/downloads/#linux).
|
||||
|
||||
Eigen >= 3.3.4, Follow [Eigen Installation](http://eigen.tuxfamily.org/index.php?title=Main_Page).
|
||||
|
||||
### <span id="1.3">1.3. **livox_ros_driver2**</span>
|
||||
Follow [livox_ros_driver2 Installation](https://github.com/Livox-SDK/livox_ros_driver2).
|
||||
|
||||
You can also use the one I modified [livox_ros_driver2](https://github.com/Ericsii/livox_ros_driver2/tree/feature/use-standard-unit)
|
||||
|
||||
*Remarks:*
|
||||
- Since the FAST-LIO must support Livox serials LiDAR firstly, so the **livox_ros_driver** must be installed and **sourced** before run any FAST-LIO launch file.
|
||||
- How to source? The easiest way is add the line ``` source $Livox_ros_driver_dir$/devel/setup.bash ``` to the end of file ``` ~/.bashrc ```, where ``` $Livox_ros_driver_dir$ ``` is the directory of the livox ros driver workspace (should be the ``` ws_livox ``` directory if you completely followed the livox official document).
|
||||
|
||||
|
||||
## 2. Build
|
||||
Clone the repository and colcon build:
|
||||
|
||||
```bash
|
||||
cd <ros2_ws>/src # cd into a ros2 workspace folder
|
||||
git clone https://github.com/Ericsii/FAST_LIO_ROS2.git --recursive
|
||||
cd ..
|
||||
rosdepc install --from-paths src --ignore-src -y
|
||||
colcon build --symlink-install
|
||||
. ./install/setup.bash # use setup.zsh if use zsh
|
||||
```
|
||||
- **Remember to source the livox_ros_driver before build (follow [1.3 livox_ros_driver](#1.3))**
|
||||
- If you want to use a custom build of PCL, add the following line to ~/.bashrc
|
||||
```export PCL_ROOT={CUSTOM_PCL_PATH}```
|
||||
## 3. Directly run
|
||||
Noted:
|
||||
|
||||
A. Please make sure the IMU and LiDAR are **Synchronized**, that's important.
|
||||
|
||||
B. The warning message "Failed to find match for field 'time'." means the timestamps of each LiDAR points are missed in the rosbag file. That is important for the forward propagation and backwark propagation.
|
||||
|
||||
C. We recommend to set the **extrinsic_est_en** to false if the extrinsic is give. As for the extrinsic initiallization, please refer to our recent work: [**Robust Real-time LiDAR-inertial Initialization**](https://github.com/hku-mars/LiDAR_IMU_Init).
|
||||
|
||||
### 3.1 Run use ros launch
|
||||
Connect to your PC to Livox LiDAR by following [Livox-ros-driver2 installation](https://github.com/Livox-SDK/livox_ros_driver2), then
|
||||
```bash
|
||||
cd <ros2_ws>
|
||||
. install/setup.bash # use setup.zsh if use zsh
|
||||
ros2 launch fast_lio mapping.launch.py config_file:=avia.yaml
|
||||
```
|
||||
|
||||
Change `config_file` parameter to other yaml file under config directory as you need.
|
||||
|
||||
Launch livox ros driver. Use MID360 as an example.
|
||||
|
||||
```bash
|
||||
ros2 launch livox_ros_driver2 msg_MID360_launch.py
|
||||
```
|
||||
|
||||
- For livox serials, FAST-LIO only support the data collected by the ``` livox_lidar_msg.launch ``` since only its ``` livox_ros_driver2/CustomMsg ``` data structure produces the timestamp of each LiDAR point which is very important for the motion undistortion. ``` livox_lidar.launch ``` can not produce it right now.
|
||||
- If you want to change the frame rate, please modify the **publish_freq** parameter in the [livox_lidar_msg.launch](https://github.com/Livox-SDK/livox_ros_driver/blob/master/livox_ros_driver2/launch/livox_lidar_msg.launch) of [Livox-ros-driver](https://github.com/Livox-SDK/livox_ros_driver2) before make the livox_ros_driver pakage.
|
||||
|
||||
### 3.2 For Livox serials with external IMU
|
||||
|
||||
mapping_avia.launch theratically supports mid-70, mid-40 or other livox serial LiDAR, but need to setup some parameters befor run:
|
||||
|
||||
Edit ``` config/avia.yaml ``` to set the below parameters:
|
||||
|
||||
1. LiDAR point cloud topic name: ``` lid_topic ```
|
||||
2. IMU topic name: ``` imu_topic ```
|
||||
3. Translational extrinsic: ``` extrinsic_T ```
|
||||
4. Rotational extrinsic: ``` extrinsic_R ``` (only support rotation matrix)
|
||||
- The extrinsic parameters in FAST-LIO is defined as the LiDAR's pose (position and rotation matrix) in IMU body frame (i.e. the IMU is the base frame). They can be found in the official manual.
|
||||
- FAST-LIO produces a very simple software time sync for livox LiDAR, set parameter ```time_sync_en``` to ture to turn on. But turn on **ONLY IF external time synchronization is really not possible**, since the software time sync cannot make sure accuracy.
|
||||
|
||||
### 3.4 PCD file save
|
||||
|
||||
1. Enable `pcd_save.pcd_save_en` in the config file and set the `map_file_path` to the path where the map will be saved.
|
||||
2. Launch the fastlio2 according to README.
|
||||
3. Open RQt and switch to `Plugins->Services->Service Caller`. Trigger the service `/map_save`, then the pcd map file will be generated
|
||||
|
||||
```pcl_viewer scans.pcd``` can visualize the point clouds.
|
||||
|
||||
*Tips for pcl_viewer:*
|
||||
- change what to visualize/color by pressing keyboard 1,2,3,4,5 when pcl_viewer is running.
|
||||
```
|
||||
1 is all random
|
||||
2 is X values
|
||||
3 is Y values
|
||||
4 is Z values
|
||||
5 is intensity
|
||||
```
|
||||
|
||||
## 4. Rosbag Example
|
||||
### 4.1 Livox Avia Rosbag
|
||||
<div align="left">
|
||||
<img src="doc/results/HKU_LG_Indoor.png" width=47% />
|
||||
<img src="doc/results/HKU_MB_002.png" width = 51% >
|
||||
|
||||
Files: Can be downloaded from [google drive](https://drive.google.com/drive/folders/1CGYEJ9-wWjr8INyan6q1BZz_5VtGB-fP?usp=sharing)**!!!This ros1 bag should be convert to ros2!!!**
|
||||
|
||||
Run:
|
||||
```bash
|
||||
ros2 launch fast_lio mapping.launch.py config_path:=<path_to_your_config_file>
|
||||
ros2 bag play <your_bag_dir>
|
||||
|
||||
```
|
||||
|
||||
### 4.2 Velodyne HDL-32E Rosbag
|
||||
|
||||
**NCLT Dataset**: Original bin file can be found [here](http://robots.engin.umich.edu/nclt/).
|
||||
|
||||
We produce [Rosbag Files](https://drive.google.com/drive/folders/1VBK5idI1oyW0GC_I_Hxh63aqam3nocNK?usp=sharing) and [a python script](https://drive.google.com/file/d/1leh7DxbHx29DyS1NJkvEfeNJoccxH7XM/view) to generate Rosbag files: ```python3 sensordata_to_rosbag_fastlio.py bin_file_dir bag_name.bag```**!!!This ros1 bag should be convert to ros2!!!** To convert ros1 bag to ros2 bag, please follow the documentation [Convert rosbag versions](https://ternaris.gitlab.io/rosbags/topics/convert.html)
|
||||
|
||||
Run:
|
||||
```
|
||||
roslaunch fast_lio mapping_velodyne.launch
|
||||
rosbag play YOUR_DOWNLOADED.bag
|
||||
```
|
||||
|
||||
## 5.Implementation on UAV
|
||||
In order to validate the robustness and computational efficiency of FAST-LIO in actual mobile robots, we build a small-scale quadrotor which can carry a Livox Avia LiDAR with 70 degree FoV and a DJI Manifold 2-C onboard computer with a 1.8 GHz Intel i7-8550U CPU and 8 G RAM, as shown in below.
|
||||
|
||||
The main structure of this UAV is 3d printed (Aluminum or PLA), the .stl file will be open-sourced in the future.
|
||||
|
||||
<div align="center">
|
||||
<img src="doc/uav01.jpg" width=40.5% >
|
||||
<img src="doc/uav_system.png" width=57% >
|
||||
</div>
|
||||
|
||||
## 6.Acknowledgments
|
||||
|
||||
Thanks for LOAM(J. Zhang and S. Singh. LOAM: Lidar Odometry and Mapping in Real-time), [Livox_Mapping](https://github.com/Livox-SDK/livox_mapping), [LINS](https://github.com/ChaoqinRobotics/LINS---LiDAR-inertial-SLAM) and [Loam_Livox](https://github.com/hku-mars/loam_livox).
|
||||
@@ -0,0 +1,47 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 3
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "/home/nvidia/study/fast_lio/test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/livox/lidar"
|
||||
imu_topic: "/livox/imu"
|
||||
time_sync_en: false # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 1 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR,
|
||||
scan_line: 6
|
||||
blind: 4.0
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 90.0
|
||||
det_range: 450.0
|
||||
extrinsic_est_en: false # true: enable the online estimation of IMU-LiDAR extrinsic
|
||||
extrinsic_T: [-0.009, 0.0971, 0.9964]
|
||||
extrinsic_R: [0.9945, 0.0537, -0.0769,
|
||||
-0.0534, 0.9985, 0.0058,
|
||||
0.0772, 0.0006, 0.9970]
|
||||
|
||||
publish:
|
||||
path_en: false
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
map_en: true
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,49 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 4
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/carla/ego_vehicle/lidar"
|
||||
imu_topic: "/carla/ego_vehicle/imu"
|
||||
time_sync_en: true # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 2 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR,
|
||||
scan_line: 64
|
||||
scan_rate: 20 # only need to be set for velodyne, unit: Hz,
|
||||
timestamp_unit: 2 # the unit of time/t field in the PointCloud2 rostopic: 0-second, 1-milisecond, 2-microsecond, 3-nanosecond.
|
||||
blind: 2.0
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 360.0
|
||||
det_range: 100.0
|
||||
extrinsic_est_en: true # true: enable the online estimation of IMU-LiDAR extrinsic,
|
||||
extrinsic_T: [ 0., 0., 0.28]
|
||||
extrinsic_R: [ 1., 0., 0.,
|
||||
0., 1., 0.,
|
||||
0., 0., 1.]
|
||||
|
||||
publish:
|
||||
path_en: false
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
map_en: true
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,46 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 3
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/livox/lidar"
|
||||
imu_topic: "/livox/imu"
|
||||
time_sync_en: false # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 1 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR,
|
||||
scan_line: 6
|
||||
blind: 4.0
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 100.0
|
||||
det_range: 260.0
|
||||
extrinsic_est_en: true # true: enable the online estimation of IMU-LiDAR extrinsic
|
||||
extrinsic_T: [ 0.05512, 0.02226, -0.0297 ]
|
||||
extrinsic_R: [ 1., 0., 0.,
|
||||
0., 1., 0.,
|
||||
0., 0., 1.]
|
||||
|
||||
publish:
|
||||
path_en: false
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,50 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 3
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/livox/lidar"
|
||||
imu_topic: "/livox/imu"
|
||||
time_sync_en: false # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 1 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR, 4 for any other pointcloud input
|
||||
scan_line: 4
|
||||
blind: 0.5
|
||||
timestamp_unit: 3
|
||||
scan_rate: 10
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 360.0
|
||||
det_range: 100.0
|
||||
extrinsic_est_en: true # true: enable the online estimation of IMU-LiDAR extrinsic
|
||||
extrinsic_T: [ -0.011, -0.02329, 0.04412 ]
|
||||
extrinsic_R: [ 1., 0., 0.,
|
||||
0., 1., 0.,
|
||||
0., 0., 1.]
|
||||
|
||||
publish:
|
||||
path_en: true # true: publish Path
|
||||
effect_map_en: false # true: publish Effects
|
||||
map_en: true # true: publish Map cloud
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: false # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,47 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 3
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/os_cloud_node/points"
|
||||
imu_topic: "/os_cloud_node/imu"
|
||||
time_sync_en: false # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 3 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR,
|
||||
scan_line: 64
|
||||
timestamp_unit: 3 # 0-second, 1-milisecond, 2-microsecond, 3-nanosecond.
|
||||
blind: 4.0
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 360.0
|
||||
det_range: 150.0
|
||||
extrinsic_est_en: false # true: enable the online estimation of IMU-LiDAR extrinsic
|
||||
extrinsic_T: [ 0.0, 0.0, 0.0 ]
|
||||
extrinsic_R: [1., 0., 0.,
|
||||
0., 1., 0.,
|
||||
0., 0., 1.]
|
||||
|
||||
publish:
|
||||
path_en: false
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,49 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: true
|
||||
point_filter_num: 4
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: true
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/sensing/lidar/top/pointcloud"
|
||||
imu_topic: "/sensing/imu/tamagawa/imu_raw"
|
||||
time_sync_en: true # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 1.6 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 5 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR, 5 for hesai PANDAR64 LIDAR
|
||||
scan_line: 64
|
||||
scan_rate: 10 # only need to be set for velodyne, unit: Hz,
|
||||
timestamp_unit: 0 # the unit of time/t field in the PointCloud2 rostopic: 0-second, 1-milisecond, 2-microsecond, 3-nanosecond.
|
||||
blind: 2.0 # 盲距
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 360.0
|
||||
det_range: 200.0
|
||||
extrinsic_est_en: true # true: enable the online estimation of IMU-LiDAR extrinsic,
|
||||
extrinsic_T: [-0.009, 0.0971, 0.9964] # [-0.009, 0.0971, 0.9964]
|
||||
extrinsic_R: [0.9945, 0.0537, -0.0769,
|
||||
-0.0534, 0.9985, 0.0058,
|
||||
0.0772, 0.0006, 0.9970]
|
||||
|
||||
publish:
|
||||
path_en: true
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
map_en: true
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: 100 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
@@ -0,0 +1,49 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
feature_extract_enable: false
|
||||
point_filter_num: 4
|
||||
max_iteration: 3
|
||||
filter_size_surf: 0.5
|
||||
filter_size_map: 0.5
|
||||
cube_side_length: 1000.0
|
||||
runtime_pos_log_enable: false
|
||||
map_file_path: "./test.pcd"
|
||||
|
||||
common:
|
||||
lid_topic: "/velodyne_points"
|
||||
imu_topic: "/chcnav/imu/data"
|
||||
time_sync_en: false # ONLY turn on when external time synchronization is really not possible
|
||||
time_offset_lidar_to_imu: 0.0 # Time offset between lidar and IMU calibrated by other algorithms, e.g. LI-Init (can be found in README).
|
||||
# This param will take effect no matter what time_sync_en is. So if the time offset is not known exactly, please set as 0.0
|
||||
|
||||
preprocess:
|
||||
lidar_type: 2 # 1 for Livox serials LiDAR, 2 for Velodyne LiDAR, 3 for ouster LiDAR,
|
||||
scan_line: 32
|
||||
scan_rate: 10 # only need to be set for velodyne, unit: Hz,
|
||||
timestamp_unit: 2 # the unit of time/t field in the PointCloud2 rostopic: 0-second, 1-milisecond, 2-microsecond, 3-nanosecond.
|
||||
blind: 2.0
|
||||
|
||||
mapping:
|
||||
acc_cov: 0.1
|
||||
gyr_cov: 0.1
|
||||
b_acc_cov: 0.0001
|
||||
b_gyr_cov: 0.0001
|
||||
fov_degree: 360.0
|
||||
det_range: 100.0
|
||||
extrinsic_est_en: false # true: enable the online estimation of IMU-LiDAR extrinsic,
|
||||
extrinsic_T: [ 1.2, 0., 0.9]
|
||||
extrinsic_R: [ 1., 0., 0.,
|
||||
0., 1., 0.,
|
||||
0., 0., 1.]
|
||||
|
||||
publish:
|
||||
path_en: false
|
||||
scan_publish_en: true # false: close all the point cloud output
|
||||
dense_publish_en: true # false: low down the points number in a global-frame point clouds scan.
|
||||
scan_bodyframe_pub_en: true # true: output the point cloud scans in IMU-body-frame
|
||||
map_en: true
|
||||
|
||||
pcd_save:
|
||||
pcd_save_en: true
|
||||
interval: -1 # how many LiDAR frames saved in each pcd file;
|
||||
# -1 : all frames will be saved in ONE pcd file, may lead to memory crash when having too much frames.
|
||||
|
After Width: | Height: | Size: 323 KiB |
|
After Width: | Height: | Size: 244 KiB |
|
After Width: | Height: | Size: 401 KiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 50 MiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 4.9 MiB |
|
After Width: | Height: | Size: 3.1 MiB |
|
After Width: | Height: | Size: 962 KiB |
|
After Width: | Height: | Size: 580 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 774 KiB |
|
After Width: | Height: | Size: 698 KiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 549 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 434 KiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 333 KiB |
|
After Width: | Height: | Size: 421 KiB |
|
After Width: | Height: | Size: 34 MiB |
@@ -0,0 +1,103 @@
|
||||
#ifndef EXP_MAT_H
|
||||
#define EXP_MAT_H
|
||||
|
||||
#include <math.h>
|
||||
#include <Eigen/Core>
|
||||
#include <opencv2/core.hpp>
|
||||
// #include <common_lib.h>
|
||||
|
||||
#define SKEW_SYM_MATRX(v) 0.0,-v[2],v[1],v[2],0.0,-v[0],-v[1],v[0],0.0
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const Eigen::Matrix<T, 3, 1> &&ang)
|
||||
{
|
||||
T ang_norm = ang.norm();
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
if (ang_norm > 0.0000001)
|
||||
{
|
||||
Eigen::Matrix<T, 3, 1> r_axis = ang / ang_norm;
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
K << SKEW_SYM_MATRX(r_axis);
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(ang_norm) * K + (1.0 - std::cos(ang_norm)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Ts>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const Eigen::Matrix<T, 3, 1> &ang_vel, const Ts &dt)
|
||||
{
|
||||
T ang_vel_norm = ang_vel.norm();
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
|
||||
if (ang_vel_norm > 0.0000001)
|
||||
{
|
||||
Eigen::Matrix<T, 3, 1> r_axis = ang_vel / ang_vel_norm;
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
|
||||
K << SKEW_SYM_MATRX(r_axis);
|
||||
|
||||
T r_ang = ang_vel_norm * dt;
|
||||
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(r_ang) * K + (1.0 - std::cos(r_ang)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const T &v1, const T &v2, const T &v3)
|
||||
{
|
||||
T &&norm = sqrt(v1 * v1 + v2 * v2 + v3 * v3);
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
if (norm > 0.00001)
|
||||
{
|
||||
T r_ang[3] = {v1 / norm, v2 / norm, v3 / norm};
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
K << SKEW_SYM_MATRX(r_ang);
|
||||
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(norm) * K + (1.0 - std::cos(norm)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Logrithm of a Rotation Matrix */
|
||||
template<typename T>
|
||||
Eigen::Matrix<T,3,1> Log(const Eigen::Matrix<T, 3, 3> &R)
|
||||
{
|
||||
T &&theta = std::acos(0.5 * (R.trace() - 1));
|
||||
Eigen::Matrix<T,3,1> K(R(2,1) - R(1,2), R(0,2) - R(2,0), R(1,0) - R(0,1));
|
||||
return (std::abs(theta) < 0.001) ? (0.5 * K) : (0.5 * theta / std::sin(theta) * K);
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// cv::Mat Exp(const T &v1, const T &v2, const T &v3)
|
||||
// {
|
||||
|
||||
// T norm = sqrt(v1 * v1 + v2 * v2 + v3 * v3);
|
||||
// cv::Mat Eye3 = cv::Mat::eye(3, 3, CV_32F);
|
||||
// if (norm > 0.0000001)
|
||||
// {
|
||||
// T r_ang[3] = {v1 / norm, v2 / norm, v3 / norm};
|
||||
// cv::Mat K = (cv::Mat_<T>(3,3) << SKEW_SYM_MATRX(r_ang));
|
||||
|
||||
// /// Roderigous Tranformation
|
||||
// return Eye3 + std::sin(norm) * K + (1.0 - std::cos(norm)) * K * K;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return Eye3;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __MEKFOM_UTIL_HPP__
|
||||
#define __MEKFOM_UTIL_HPP__
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include "../mtk/src/mtkmath.hpp"
|
||||
namespace esekfom {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
class is_same {
|
||||
public:
|
||||
operator bool() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
template<typename T1>
|
||||
class is_same<T1, T1> {
|
||||
public:
|
||||
operator bool() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class is_double {
|
||||
public:
|
||||
operator bool() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class is_double<double> {
|
||||
public:
|
||||
operator bool() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static T
|
||||
id(const T &x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
} // namespace esekfom
|
||||
|
||||
#endif // __MEKFOM_UTIL_HPP__
|
||||
@@ -0,0 +1,229 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/build_manifold.hpp
|
||||
* @brief Macro to automatically construct compound manifolds.
|
||||
*
|
||||
*/
|
||||
#ifndef MTK_AUTOCONSTRUCT_HPP_
|
||||
#define MTK_AUTOCONSTRUCT_HPP_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/preprocessor/seq.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <Eigen/Core>
|
||||
|
||||
#include "src/SubManifold.hpp"
|
||||
#include "startIdx.hpp"
|
||||
|
||||
#ifndef PARSED_BY_DOXYGEN
|
||||
//////// internals //////
|
||||
|
||||
#define MTK_APPLY_MACRO_ON_TUPLE(r, macro, tuple) macro tuple
|
||||
|
||||
#define MTK_TRANSFORM_COMMA(macro, entries) BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM_S(1, MTK_APPLY_MACRO_ON_TUPLE, macro, entries))
|
||||
|
||||
#define MTK_TRANSFORM(macro, entries) BOOST_PP_SEQ_FOR_EACH_R(1, MTK_APPLY_MACRO_ON_TUPLE, macro, entries)
|
||||
|
||||
#define MTK_CONSTRUCTOR_ARG( type, id) const type& id = type()
|
||||
#define MTK_CONSTRUCTOR_COPY( type, id) id(id)
|
||||
#define MTK_BOXPLUS( type, id) id.boxplus(MTK::subvector(__vec, &self::id), __scale);
|
||||
#define MTK_OPLUS( type, id) id.oplus(MTK::subvector_(__vec, &self::id), __scale);
|
||||
#define MTK_BOXMINUS( type, id) id.boxminus(MTK::subvector(__res, &self::id), __oth.id);
|
||||
#define MTK_S2_hat( type, id) if(id.IDX == idx){id.S2_hat(res);}
|
||||
#define MTK_S2_Nx_yy( type, id) if(id.IDX == idx){id.S2_Nx_yy(res);}
|
||||
#define MTK_S2_Mx( type, id) if(id.IDX == idx){id.S2_Mx(res, dx);}
|
||||
#define MTK_OSTREAM( type, id) << __var.id << " "
|
||||
#define MTK_ISTREAM( type, id) >> __var.id
|
||||
#define MTK_S2_state( type, id) if(id.TYP == 1){S2_state.push_back(std::make_pair(id.IDX, id.DIM));}
|
||||
#define MTK_SO3_state( type, id) if(id.TYP == 2){(SO3_state).push_back(std::make_pair(id.IDX, id.DIM));}
|
||||
#define MTK_vect_state( type, id) if(id.TYP == 0){(vect_state).push_back(std::make_pair(std::make_pair(id.IDX, id.DIM), type::DOF));}
|
||||
|
||||
#define MTK_SUBVARLIST(seq, S2state, SO3state) \
|
||||
BOOST_PP_FOR_1( \
|
||||
( \
|
||||
BOOST_PP_SEQ_SIZE(seq), \
|
||||
BOOST_PP_SEQ_HEAD(seq), \
|
||||
BOOST_PP_SEQ_TAIL(seq) (~), \
|
||||
0,\
|
||||
0,\
|
||||
S2state,\
|
||||
SO3state ),\
|
||||
MTK_ENTRIES_TEST, MTK_ENTRIES_NEXT, MTK_ENTRIES_OUTPUT)
|
||||
|
||||
#define MTK_PUT_TYPE(type, id, dof, dim, S2state, SO3state) \
|
||||
MTK::SubManifold<type, dof, dim> id;
|
||||
#define MTK_PUT_TYPE_AND_ENUM(type, id, dof, dim, S2state, SO3state) \
|
||||
MTK_PUT_TYPE(type, id, dof, dim, S2state, SO3state) \
|
||||
enum {DOF = type::DOF + dof}; \
|
||||
enum {DIM = type::DIM+dim}; \
|
||||
typedef type::scalar scalar;
|
||||
|
||||
#define MTK_ENTRIES_OUTPUT(r, state) MTK_ENTRIES_OUTPUT_I state
|
||||
#define MTK_ENTRIES_OUTPUT_I(s, head, seq, dof, dim, S2state, SO3state) \
|
||||
MTK_APPLY_MACRO_ON_TUPLE(~, \
|
||||
BOOST_PP_IF(BOOST_PP_DEC(s), MTK_PUT_TYPE, MTK_PUT_TYPE_AND_ENUM), \
|
||||
( BOOST_PP_TUPLE_REM_2 head, dof, dim, S2state, SO3state))
|
||||
|
||||
#define MTK_ENTRIES_TEST(r, state) MTK_TUPLE_ELEM_4_0 state
|
||||
|
||||
//! this used to be BOOST_PP_TUPLE_ELEM_4_0:
|
||||
#define MTK_TUPLE_ELEM_4_0(a,b,c,d,e,f, g) a
|
||||
|
||||
#define MTK_ENTRIES_NEXT(r, state) MTK_ENTRIES_NEXT_I state
|
||||
#define MTK_ENTRIES_NEXT_I(len, head, seq, dof, dim, S2state, SO3state) ( \
|
||||
BOOST_PP_DEC(len), \
|
||||
BOOST_PP_SEQ_HEAD(seq), \
|
||||
BOOST_PP_SEQ_TAIL(seq), \
|
||||
dof + BOOST_PP_TUPLE_ELEM_2_0 head::DOF,\
|
||||
dim + BOOST_PP_TUPLE_ELEM_2_0 head::DIM,\
|
||||
S2state,\
|
||||
SO3state)
|
||||
|
||||
#endif /* not PARSED_BY_DOXYGEN */
|
||||
|
||||
|
||||
/**
|
||||
* Construct a manifold.
|
||||
* @param name is the class-name of the manifold,
|
||||
* @param entries is the list of sub manifolds
|
||||
*
|
||||
* Entries must be given in a list like this:
|
||||
* @code
|
||||
* typedef MTK::trafo<MTK::SO3<double> > Pose;
|
||||
* typedef MTK::vect<double, 3> Vec3;
|
||||
* MTK_BUILD_MANIFOLD(imu_state,
|
||||
* ((Pose, pose))
|
||||
* ((Vec3, vel))
|
||||
* ((Vec3, acc_bias))
|
||||
* )
|
||||
* @endcode
|
||||
* Whitespace is optional, but the double parentheses are necessary.
|
||||
* Construction is done entirely in preprocessor.
|
||||
* After construction @a name is also a manifold. Its members can be
|
||||
* accessed by names given in @a entries.
|
||||
*
|
||||
* @note Variable types are not allowed to have commas, thus types like
|
||||
* @c vect<double, 3> need to be typedef'ed ahead.
|
||||
*/
|
||||
#define MTK_BUILD_MANIFOLD(name, entries) \
|
||||
struct name { \
|
||||
typedef name self; \
|
||||
std::vector<std::pair<int, int> > S2_state;\
|
||||
std::vector<std::pair<int, int> > SO3_state;\
|
||||
std::vector<std::pair<std::pair<int, int>, int> > vect_state;\
|
||||
MTK_SUBVARLIST(entries, S2_state, SO3_state) \
|
||||
name ( \
|
||||
MTK_TRANSFORM_COMMA(MTK_CONSTRUCTOR_ARG, entries) \
|
||||
) : \
|
||||
MTK_TRANSFORM_COMMA(MTK_CONSTRUCTOR_COPY, entries) {}\
|
||||
int getDOF() const { return DOF; } \
|
||||
void boxplus(const MTK::vectview<const scalar, DOF> & __vec, scalar __scale = 1 ) { \
|
||||
MTK_TRANSFORM(MTK_BOXPLUS, entries)\
|
||||
} \
|
||||
void oplus(const MTK::vectview<const scalar, DIM> & __vec, scalar __scale = 1 ) { \
|
||||
MTK_TRANSFORM(MTK_OPLUS, entries)\
|
||||
} \
|
||||
void boxminus(MTK::vectview<scalar,DOF> __res, const name& __oth) const { \
|
||||
MTK_TRANSFORM(MTK_BOXMINUS, entries)\
|
||||
} \
|
||||
friend std::ostream& operator<<(std::ostream& __os, const name& __var){ \
|
||||
return __os MTK_TRANSFORM(MTK_OSTREAM, entries); \
|
||||
} \
|
||||
void build_S2_state(){\
|
||||
MTK_TRANSFORM(MTK_S2_state, entries)\
|
||||
}\
|
||||
void build_vect_state(){\
|
||||
MTK_TRANSFORM(MTK_vect_state, entries)\
|
||||
}\
|
||||
void build_SO3_state(){\
|
||||
MTK_TRANSFORM(MTK_SO3_state, entries)\
|
||||
}\
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res, int idx) {\
|
||||
MTK_TRANSFORM(MTK_S2_hat, entries)\
|
||||
}\
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res, int idx) {\
|
||||
MTK_TRANSFORM(MTK_S2_Nx_yy, entries)\
|
||||
}\
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, Eigen::Matrix<scalar, 2, 1> dx, int idx) {\
|
||||
MTK_TRANSFORM(MTK_S2_Mx, entries)\
|
||||
}\
|
||||
friend std::istream& operator>>(std::istream& __is, name& __var){ \
|
||||
return __is MTK_TRANSFORM(MTK_ISTREAM, entries); \
|
||||
} \
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /*MTK_AUTOCONSTRUCT_HPP_*/
|
||||
@@ -0,0 +1,123 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/src/SubManifold.hpp
|
||||
* @brief Defines the SubManifold class
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SUBMANIFOLD_HPP_
|
||||
#define SUBMANIFOLD_HPP_
|
||||
|
||||
|
||||
#include "vectview.hpp"
|
||||
|
||||
|
||||
namespace MTK {
|
||||
|
||||
/**
|
||||
* @ingroup SubManifolds
|
||||
* Helper class for compound manifolds.
|
||||
* This class wraps a manifold T and provides an enum IDX refering to the
|
||||
* index of the SubManifold within the compound manifold.
|
||||
*
|
||||
* Memberpointers to a submanifold can be used for @ref SubManifolds "functions accessing submanifolds".
|
||||
*
|
||||
* @tparam T The manifold type of the sub-type
|
||||
* @tparam idx The index of the sub-type within the compound manifold
|
||||
*/
|
||||
template<class T, int idx, int dim>
|
||||
struct SubManifold : public T
|
||||
{
|
||||
enum {IDX = idx, DIM = dim /*!< index of the sub-type within the compound manifold */ };
|
||||
//! manifold type
|
||||
typedef T type;
|
||||
|
||||
//! Construct from derived type
|
||||
template<class X>
|
||||
explicit
|
||||
SubManifold(const X& t) : T(t) {};
|
||||
|
||||
//! Construct from internal type
|
||||
//explicit
|
||||
SubManifold(const T& t) : T(t) {};
|
||||
|
||||
//! inherit assignment operator
|
||||
using T::operator=;
|
||||
|
||||
};
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
|
||||
#endif /* SUBMANIFOLD_HPP_ */
|
||||
@@ -0,0 +1,294 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/src/mtkmath.hpp
|
||||
* @brief several math utility functions.
|
||||
*/
|
||||
|
||||
#ifndef MTKMATH_H_
|
||||
#define MTKMATH_H_
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <boost/math/tools/precision.hpp>
|
||||
|
||||
#include "../types/vect.hpp"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
|
||||
|
||||
namespace MTK {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<class Manifold>
|
||||
struct traits {
|
||||
typedef typename Manifold::scalar scalar;
|
||||
enum {DOF = Manifold::DOF};
|
||||
typedef vect<DOF, scalar> vectorized_type;
|
||||
typedef Eigen::Matrix<scalar, DOF, DOF> matrix_type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct traits<float> : traits<Scalar<float> > {};
|
||||
template<>
|
||||
struct traits<double> : traits<Scalar<double> > {};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
/**
|
||||
* \defgroup MTKMath Mathematical helper functions
|
||||
*/
|
||||
//@{
|
||||
|
||||
//! constant @f$ \pi @f$
|
||||
const double pi = M_PI;
|
||||
|
||||
template<class scalar> inline scalar tolerance();
|
||||
|
||||
template<> inline float tolerance<float >() { return 1e-5f; }
|
||||
template<> inline double tolerance<double>() { return 1e-11; }
|
||||
|
||||
|
||||
/**
|
||||
* normalize @a x to @f$[-bound, bound] @f$.
|
||||
*
|
||||
* result for @f$ x = bound + 2\cdot n\cdot bound @f$ is arbitrary @f$\pm bound @f$.
|
||||
*/
|
||||
template<class scalar>
|
||||
inline scalar normalize(scalar x, scalar bound){ //not used
|
||||
if(std::fabs(x) <= bound) return x;
|
||||
int r = (int)(x *(scalar(1.0)/ bound));
|
||||
return x - ((r + (r>>31) + 1) & ~1)*bound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate cosine and sinc of sqrt(x2).
|
||||
* @param x2 the squared angle must be non-negative
|
||||
* @return a pair containing cos and sinc of sqrt(x2)
|
||||
*/
|
||||
template<class scalar>
|
||||
std::pair<scalar, scalar> cos_sinc_sqrt(const scalar &x2){
|
||||
using std::sqrt;
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
static scalar const taylor_0_bound = boost::math::tools::epsilon<scalar>();
|
||||
static scalar const taylor_2_bound = sqrt(taylor_0_bound);
|
||||
static scalar const taylor_n_bound = sqrt(taylor_2_bound);
|
||||
|
||||
assert(x2>=0 && "argument must be non-negative");
|
||||
|
||||
// FIXME check if bigger bounds are possible
|
||||
if(x2>=taylor_n_bound) {
|
||||
// slow fall-back solution
|
||||
scalar x = sqrt(x2);
|
||||
return std::make_pair(cos(x), sin(x)/x); // x is greater than 0.
|
||||
}
|
||||
|
||||
// FIXME Replace by Horner-Scheme (4 instead of 5 FLOP/term, numerically more stable, theoretically cos and sinc can be calculated in parallel using SSE2 mulpd/addpd)
|
||||
// TODO Find optimal coefficients using Remez algorithm
|
||||
static scalar const inv[] = {1/3., 1/4., 1/5., 1/6., 1/7., 1/8., 1/9.};
|
||||
scalar cosi = 1., sinc=1;
|
||||
scalar term = -1/2. * x2;
|
||||
for(int i=0; i<3; ++i) {
|
||||
cosi += term;
|
||||
term *= inv[2*i];
|
||||
sinc += term;
|
||||
term *= -inv[2*i+1] * x2;
|
||||
}
|
||||
|
||||
return std::make_pair(cosi, sinc);
|
||||
|
||||
}
|
||||
|
||||
template<typename Base>
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> hat(const Base& v) {
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> res;
|
||||
res << 0, -v[2], v[1],
|
||||
v[2], 0, -v[0],
|
||||
-v[1], v[0], 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename Base>
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> A_inv_trans(const Base& v){
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> res;
|
||||
if(v.norm() > MTK::tolerance<typename Base::scalar>())
|
||||
{
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity() + 0.5 * hat<Base>(v) + (1 - v.norm() * std::cos(v.norm() / 2) / 2 / std::sin(v.norm() / 2)) * hat(v) * hat(v) / v.squaredNorm();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename Base>
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> A_inv(const Base& v){
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> res;
|
||||
if(v.norm() > MTK::tolerance<typename Base::scalar>())
|
||||
{
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity() - 0.5 * hat<Base>(v) + (1 - v.norm() * std::cos(v.norm() / 2) / 2 / std::sin(v.norm() / 2)) * hat(v) * hat(v) / v.squaredNorm();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename scalar>
|
||||
Eigen::Matrix<scalar, 2, 3> S2_w_expw_( Eigen::Matrix<scalar, 2, 1> v, scalar length)
|
||||
{
|
||||
Eigen::Matrix<scalar, 2, 3> res;
|
||||
scalar norm = std::sqrt(v[0]*v[0] + v[1]*v[1]);
|
||||
if(norm < MTK::tolerance<scalar>()){
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
res(0, 1) = 1;
|
||||
res(1, 2) = 1;
|
||||
res /= length;
|
||||
}
|
||||
else{
|
||||
res << -v[0]*(1/norm-1/std::tan(norm))/std::sin(norm), norm/std::sin(norm), 0,
|
||||
-v[1]*(1/norm-1/std::tan(norm))/std::sin(norm), 0, norm/std::sin(norm);
|
||||
res /= length;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Base>
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> A_matrix(const Base & v){
|
||||
Eigen::Matrix<typename Base::scalar, 3, 3> res;
|
||||
double squaredNorm = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
||||
double norm = std::sqrt(squaredNorm);
|
||||
if(norm < MTK::tolerance<typename Base::scalar>()){
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity();
|
||||
}
|
||||
else{
|
||||
res = Eigen::Matrix<typename Base::scalar, 3, 3>::Identity() + (1 - std::cos(norm)) / squaredNorm * hat(v) + (1 - std::sin(norm) / norm) / squaredNorm * hat(v) * hat(v);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class scalar, int n>
|
||||
scalar exp(vectview<scalar, n> result, vectview<const scalar, n> vec, const scalar& scale = 1) {
|
||||
scalar norm2 = vec.squaredNorm();
|
||||
std::pair<scalar, scalar> cos_sinc = cos_sinc_sqrt(scale*scale * norm2);
|
||||
scalar mult = cos_sinc.second * scale;
|
||||
result = mult * vec;
|
||||
return cos_sinc.first;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inverse function to @c exp.
|
||||
*
|
||||
* @param result @c vectview to the result
|
||||
* @param w scalar part of input
|
||||
* @param vec vector part of input
|
||||
* @param scale scale result by this value
|
||||
* @param plus_minus_periodicity if true values @f$[w, vec]@f$ and @f$[-w, -vec]@f$ give the same result
|
||||
*/
|
||||
template<class scalar, int n>
|
||||
void log(vectview<scalar, n> result,
|
||||
const scalar &w, const vectview<const scalar, n> vec,
|
||||
const scalar &scale, bool plus_minus_periodicity)
|
||||
{
|
||||
// FIXME implement optimized case for vec.squaredNorm() <= tolerance() * (w*w) via Rational Remez approximation ~> only one division
|
||||
scalar nv = vec.norm();
|
||||
if(nv < tolerance<scalar>()) {
|
||||
if(!plus_minus_periodicity && w < 0) {
|
||||
// find the maximal entry:
|
||||
int i;
|
||||
nv = vec.cwiseAbs().maxCoeff(&i);
|
||||
result = scale * std::atan2(nv, w) * vect<n, scalar>::Unit(i);
|
||||
return;
|
||||
}
|
||||
nv = tolerance<scalar>();
|
||||
}
|
||||
scalar s = scale / nv * (plus_minus_periodicity ? std::atan(nv / w) : std::atan2(nv, w) );
|
||||
|
||||
result = s * vec;
|
||||
}
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
|
||||
#endif /* MTKMATH_H_ */
|
||||
@@ -0,0 +1,168 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/src/vectview.hpp
|
||||
* @brief Wrapper class around a pointer used as interface for plain vectors.
|
||||
*/
|
||||
|
||||
#ifndef VECTVIEW_HPP_
|
||||
#define VECTVIEW_HPP_
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
namespace MTK {
|
||||
|
||||
/**
|
||||
* A view to a vector.
|
||||
* Essentially, @c vectview is only a pointer to @c scalar but can be used directly in @c Eigen expressions.
|
||||
* The dimension of the vector is given as template parameter and type-checked when used in expressions.
|
||||
* Data has to be modifiable.
|
||||
*
|
||||
* @tparam scalar Scalar type of the vector.
|
||||
* @tparam dim Dimension of the vector.
|
||||
*
|
||||
* @todo @c vectview can be replaced by simple inheritance of @c Eigen::Map, as soon as they get const-correct
|
||||
*/
|
||||
namespace internal {
|
||||
template<class Base, class T1, class T2>
|
||||
struct CovBlock {
|
||||
typedef typename Eigen::Block<Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF>, T1::DOF, T2::DOF> Type;
|
||||
typedef typename Eigen::Block<const Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF>, T1::DOF, T2::DOF> ConstType;
|
||||
};
|
||||
|
||||
template<class Base, class T1, class T2>
|
||||
struct CovBlock_ {
|
||||
typedef typename Eigen::Block<Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM>, T1::DIM, T2::DIM> Type;
|
||||
typedef typename Eigen::Block<const Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM>, T1::DIM, T2::DIM> ConstType;
|
||||
};
|
||||
|
||||
template<typename Base1, typename Base2, typename T1, typename T2>
|
||||
struct CrossCovBlock {
|
||||
typedef typename Eigen::Block<Eigen::Matrix<typename Base1::scalar, Base1::DOF, Base2::DOF>, T1::DOF, T2::DOF> Type;
|
||||
typedef typename Eigen::Block<const Eigen::Matrix<typename Base1::scalar, Base1::DOF, Base2::DOF>, T1::DOF, T2::DOF> ConstType;
|
||||
};
|
||||
|
||||
template<typename Base1, typename Base2, typename T1, typename T2>
|
||||
struct CrossCovBlock_ {
|
||||
typedef typename Eigen::Block<Eigen::Matrix<typename Base1::scalar, Base1::DIM, Base2::DIM>, T1::DIM, T2::DIM> Type;
|
||||
typedef typename Eigen::Block<const Eigen::Matrix<typename Base1::scalar, Base1::DIM, Base2::DIM>, T1::DIM, T2::DIM> ConstType;
|
||||
};
|
||||
|
||||
template<class scalar, int dim>
|
||||
struct VectviewBase {
|
||||
typedef Eigen::Matrix<scalar, dim, 1> matrix_type;
|
||||
typedef typename matrix_type::MapType Type;
|
||||
typedef typename matrix_type::ConstMapType ConstType;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct UnalignedType {
|
||||
typedef T type;
|
||||
};
|
||||
}
|
||||
|
||||
template<class scalar, int dim>
|
||||
class vectview : public internal::VectviewBase<scalar, dim>::Type {
|
||||
typedef internal::VectviewBase<scalar, dim> VectviewBase;
|
||||
public:
|
||||
//! plain matrix type
|
||||
typedef typename VectviewBase::matrix_type matrix_type;
|
||||
//! base type
|
||||
typedef typename VectviewBase::Type base;
|
||||
//! construct from pointer
|
||||
explicit
|
||||
vectview(scalar* data, int dim_=dim) : base(data, dim_) {}
|
||||
//! construct from plain matrix
|
||||
vectview(matrix_type& m) : base(m.data(), m.size()) {}
|
||||
//! construct from another @c vectview
|
||||
vectview(const vectview &v) : base(v) {}
|
||||
//! construct from Eigen::Block:
|
||||
template<class Base>
|
||||
vectview(Eigen::VectorBlock<Base, dim> block) : base(&block.coeffRef(0), block.size()) {}
|
||||
template<class Base, bool PacketAccess>
|
||||
vectview(Eigen::Block<Base, dim, 1, PacketAccess> block) : base(&block.coeffRef(0), block.size()) {}
|
||||
|
||||
//! inherit assignment operator
|
||||
using base::operator=;
|
||||
//! data pointer
|
||||
scalar* data() {return const_cast<scalar*>(base::data());}
|
||||
};
|
||||
|
||||
/**
|
||||
* @c const version of @c vectview.
|
||||
* Compared to @c Eigen::Map this implementation is const correct, i.e.,
|
||||
* data will not be modifiable using this view.
|
||||
*
|
||||
* @tparam scalar Scalar type of the vector.
|
||||
* @tparam dim Dimension of the vector.
|
||||
*
|
||||
* @sa vectview
|
||||
*/
|
||||
template<class scalar, int dim>
|
||||
class vectview<const scalar, dim> : public internal::VectviewBase<scalar, dim>::ConstType {
|
||||
typedef internal::VectviewBase<scalar, dim> VectviewBase;
|
||||
public:
|
||||
//! plain matrix type
|
||||
typedef typename VectviewBase::matrix_type matrix_type;
|
||||
//! base type
|
||||
typedef typename VectviewBase::ConstType base;
|
||||
//! construct from const pointer
|
||||
explicit
|
||||
vectview(const scalar* data, int dim_ = dim) : base(data, dim_) {}
|
||||
//! construct from column vector
|
||||
template<int options>
|
||||
vectview(const Eigen::Matrix<scalar, dim, 1, options>& m) : base(m.data()) {}
|
||||
//! construct from row vector
|
||||
template<int options, int phony>
|
||||
vectview(const Eigen::Matrix<scalar, 1, dim, options, phony>& m) : base(m.data()) {}
|
||||
//! construct from another @c vectview
|
||||
vectview(vectview<scalar, dim> x) : base(x.data()) {}
|
||||
//! construct from base
|
||||
vectview(const base &x) : base(x) {}
|
||||
/**
|
||||
* Construct from Block
|
||||
* @todo adapt this, when Block gets const-correct
|
||||
*/
|
||||
template<class Base>
|
||||
vectview(Eigen::VectorBlock<Base, dim> block) : base(&block.coeffRef(0)) {}
|
||||
template<class Base, bool PacketAccess>
|
||||
vectview(Eigen::Block<Base, dim, 1, PacketAccess> block) : base(&block.coeffRef(0)) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
#endif /* VECTVIEW_HPP_ */
|
||||
@@ -0,0 +1,328 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/startIdx.hpp
|
||||
* @brief Tools to access sub-elements of compound manifolds.
|
||||
*/
|
||||
#ifndef GET_START_INDEX_H_
|
||||
#define GET_START_INDEX_H_
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
#include "src/SubManifold.hpp"
|
||||
#include "src/vectview.hpp"
|
||||
|
||||
namespace MTK {
|
||||
|
||||
|
||||
/**
|
||||
* \defgroup SubManifolds Accessing Submanifolds
|
||||
* For compound manifolds constructed using MTK_BUILD_MANIFOLD, member pointers
|
||||
* can be used to get sub-vectors or matrix-blocks of a corresponding big matrix.
|
||||
* E.g. for a type @a pose consisting of @a orient and @a trans the member pointers
|
||||
* @c &pose::orient and @c &pose::trans give all required information and are still
|
||||
* valid if the base type gets extended or the actual types of @a orient and @a trans
|
||||
* change (e.g. from 2D to 3D).
|
||||
*
|
||||
* @todo Maybe require manifolds to typedef MatrixType and VectorType, etc.
|
||||
*/
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Determine the index of a sub-variable within a compound variable.
|
||||
*/
|
||||
template<class Base, class T, int idx, int dim>
|
||||
int getStartIdx( MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return idx;
|
||||
}
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
int getStartIdx_( MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return dim;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the degrees of freedom of a sub-variable within a compound variable.
|
||||
*/
|
||||
template<class Base, class T, int idx, int dim>
|
||||
int getDof( MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return T::DOF;
|
||||
}
|
||||
template<class Base, class T, int idx, int dim>
|
||||
int getDim( MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return T::DIM;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the diagonal elements of a covariance matrix corresponding to a sub-variable
|
||||
*/
|
||||
template<class Base, class T, int idx, int dim>
|
||||
void setDiagonal(Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF> &cov,
|
||||
MTK::SubManifold<T, idx, dim> Base::*, const typename Base::scalar &val)
|
||||
{
|
||||
cov.diagonal().template segment<T::DOF>(idx).setConstant(val);
|
||||
}
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
void setDiagonal_(Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM> &cov,
|
||||
MTK::SubManifold<T, idx, dim> Base::*, const typename Base::scalar &val)
|
||||
{
|
||||
cov.diagonal().template segment<T::DIM>(dim).setConstant(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subblock of corresponding to two members, i.e.
|
||||
* \code
|
||||
* Eigen::Matrix<double, Pose::DOF, Pose::DOF> m;
|
||||
* MTK::subblock(m, &Pose::orient, &Pose::trans) = some_expression;
|
||||
* MTK::subblock(m, &Pose::trans, &Pose::orient) = some_expression.trans();
|
||||
* \endcode
|
||||
* lets you modify mixed covariance entries in a bigger covariance matrix.
|
||||
*/
|
||||
template<class Base, class T1, int idx1, int dim1, class T2, int idx2, int dim2>
|
||||
typename MTK::internal::CovBlock<Base, T1, T2>::Type
|
||||
subblock(Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF> &cov,
|
||||
MTK::SubManifold<T1, idx1, dim1> Base::*, MTK::SubManifold<T2, idx2, dim2> Base::*)
|
||||
{
|
||||
return cov.template block<T1::DOF, T2::DOF>(idx1, idx2);
|
||||
}
|
||||
|
||||
template<class Base, class T1, int idx1, int dim1, class T2, int idx2, int dim2>
|
||||
typename MTK::internal::CovBlock_<Base, T1, T2>::Type
|
||||
subblock_(Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM> &cov,
|
||||
MTK::SubManifold<T1, idx1, dim1> Base::*, MTK::SubManifold<T2, idx2, dim2> Base::*)
|
||||
{
|
||||
return cov.template block<T1::DIM, T2::DIM>(dim1, dim2);
|
||||
}
|
||||
|
||||
template<typename Base1, typename Base2, typename T1, typename T2, int idx1, int idx2, int dim1, int dim2>
|
||||
typename MTK::internal::CrossCovBlock<Base1, Base2, T1, T2>::Type
|
||||
subblock(Eigen::Matrix<typename Base1::scalar, Base1::DOF, Base2::DOF> &cov, MTK::SubManifold<T1, idx1, dim1> Base1::*, MTK::SubManifold<T2, idx2, dim2> Base2::*)
|
||||
{
|
||||
return cov.template block<T1::DOF, T2::DOF>(idx1, idx2);
|
||||
}
|
||||
|
||||
template<typename Base1, typename Base2, typename T1, typename T2, int idx1, int idx2, int dim1, int dim2>
|
||||
typename MTK::internal::CrossCovBlock_<Base1, Base2, T1, T2>::Type
|
||||
subblock_(Eigen::Matrix<typename Base1::scalar, Base1::DIM, Base2::DIM> &cov, MTK::SubManifold<T1, idx1, dim1> Base1::*, MTK::SubManifold<T2, idx2, dim2> Base2::*)
|
||||
{
|
||||
return cov.template block<T1::DIM, T2::DIM>(dim1, dim2);
|
||||
}
|
||||
/**
|
||||
* Get the subblock of corresponding to a member, i.e.
|
||||
* \code
|
||||
* Eigen::Matrix<double, Pose::DOF, Pose::DOF> m;
|
||||
* MTK::subblock(m, &Pose::orient) = some_expression;
|
||||
* \endcode
|
||||
* lets you modify covariance entries in a bigger covariance matrix.
|
||||
*/
|
||||
template<class Base, class T, int idx, int dim>
|
||||
typename MTK::internal::CovBlock_<Base, T, T>::Type
|
||||
subblock_(Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM> &cov,
|
||||
MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return cov.template block<T::DIM, T::DIM>(dim, dim);
|
||||
}
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
typename MTK::internal::CovBlock<Base, T, T>::Type
|
||||
subblock(Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF> &cov,
|
||||
MTK::SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return cov.template block<T::DOF, T::DOF>(idx, idx);
|
||||
}
|
||||
|
||||
template<typename Base>
|
||||
class get_cov {
|
||||
public:
|
||||
typedef Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF> type;
|
||||
typedef const Eigen::Matrix<typename Base::scalar, Base::DOF, Base::DOF> const_type;
|
||||
};
|
||||
|
||||
template<typename Base>
|
||||
class get_cov_ {
|
||||
public:
|
||||
typedef Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM> type;
|
||||
typedef const Eigen::Matrix<typename Base::scalar, Base::DIM, Base::DIM> const_type;
|
||||
};
|
||||
|
||||
template<typename Base1, typename Base2>
|
||||
class get_cross_cov {
|
||||
public:
|
||||
typedef Eigen::Matrix<typename Base1::scalar, Base1::DOF, Base2::DOF> type;
|
||||
typedef const type const_type;
|
||||
};
|
||||
|
||||
template<typename Base1, typename Base2>
|
||||
class get_cross_cov_ {
|
||||
public:
|
||||
typedef Eigen::Matrix<typename Base1::scalar, Base1::DIM, Base2::DIM> type;
|
||||
typedef const type const_type;
|
||||
};
|
||||
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
vectview<typename Base::scalar, T::DIM>
|
||||
subvector_impl_(vectview<typename Base::scalar, Base::DIM> vec, SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return vec.template segment<T::DIM>(dim);
|
||||
}
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
vectview<typename Base::scalar, T::DOF>
|
||||
subvector_impl(vectview<typename Base::scalar, Base::DOF> vec, SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return vec.template segment<T::DOF>(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subvector corresponding to a sub-manifold from a bigger vector.
|
||||
*/
|
||||
template<class Scalar, int BaseDIM, class Base, class T, int idx, int dim>
|
||||
vectview<Scalar, T::DIM>
|
||||
subvector_(vectview<Scalar, BaseDIM> vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl_(vec, ptr);
|
||||
}
|
||||
|
||||
template<class Scalar, int BaseDOF, class Base, class T, int idx, int dim>
|
||||
vectview<Scalar, T::DOF>
|
||||
subvector(vectview<Scalar, BaseDOF> vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl(vec, ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo This should be covered already by subvector(vectview<typename Base::scalar,Base::DOF> vec,SubManifold<T,idx> Base::*)
|
||||
*/
|
||||
template<class Scalar, int BaseDOF, class Base, class T, int idx, int dim>
|
||||
vectview<Scalar, T::DOF>
|
||||
subvector(Eigen::Matrix<Scalar, BaseDOF, 1>& vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl(vectview<Scalar, BaseDOF>(vec), ptr);
|
||||
}
|
||||
|
||||
template<class Scalar, int BaseDIM, class Base, class T, int idx, int dim>
|
||||
vectview<Scalar, T::DIM>
|
||||
subvector_(Eigen::Matrix<Scalar, BaseDIM, 1>& vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl_(vectview<Scalar, BaseDIM>(vec), ptr);
|
||||
}
|
||||
|
||||
template<class Scalar, int BaseDIM, class Base, class T, int idx, int dim>
|
||||
vectview<const Scalar, T::DIM>
|
||||
subvector_(const Eigen::Matrix<Scalar, BaseDIM, 1>& vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl_(vectview<const Scalar, BaseDIM>(vec), ptr);
|
||||
}
|
||||
|
||||
template<class Scalar, int BaseDOF, class Base, class T, int idx, int dim>
|
||||
vectview<const Scalar, T::DOF>
|
||||
subvector(const Eigen::Matrix<Scalar, BaseDOF, 1>& vec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl(vectview<const Scalar, BaseDOF>(vec), ptr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* const version of subvector(vectview<typename Base::scalar,Base::DOF> vec,SubManifold<T,idx> Base::*)
|
||||
*/
|
||||
template<class Base, class T, int idx, int dim>
|
||||
vectview<const typename Base::scalar, T::DOF>
|
||||
subvector_impl(const vectview<const typename Base::scalar, Base::DOF> cvec, SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return cvec.template segment<T::DOF>(idx);
|
||||
}
|
||||
|
||||
template<class Base, class T, int idx, int dim>
|
||||
vectview<const typename Base::scalar, T::DIM>
|
||||
subvector_impl_(const vectview<const typename Base::scalar, Base::DIM> cvec, SubManifold<T, idx, dim> Base::*)
|
||||
{
|
||||
return cvec.template segment<T::DIM>(dim);
|
||||
}
|
||||
|
||||
template<class Scalar, int BaseDOF, class Base, class T, int idx, int dim>
|
||||
vectview<const Scalar, T::DOF>
|
||||
subvector(const vectview<const Scalar, BaseDOF> cvec, SubManifold<T, idx, dim> Base::* ptr)
|
||||
{
|
||||
return subvector_impl(cvec, ptr);
|
||||
}
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
#endif // GET_START_INDEX_H_
|
||||
@@ -0,0 +1,316 @@
|
||||
// This is a NEW implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/types/S2.hpp
|
||||
* @brief Unit vectors on the sphere, or directions in 3D.
|
||||
*/
|
||||
#ifndef S2_H_
|
||||
#define S2_H_
|
||||
|
||||
|
||||
#include "vect.hpp"
|
||||
|
||||
#include "SOn.hpp"
|
||||
#include "../src/mtkmath.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
namespace MTK {
|
||||
|
||||
/**
|
||||
* Manifold representation of @f$ S^2 @f$.
|
||||
* Used for unit vectors on the sphere or directions in 3D.
|
||||
*
|
||||
* @todo add conversions from/to polar angles?
|
||||
*/
|
||||
template<class _scalar = double, int den = 1, int num = 1, int S2_typ = 3>
|
||||
struct S2 {
|
||||
|
||||
typedef _scalar scalar;
|
||||
typedef vect<3, scalar> vect_type;
|
||||
typedef SO3<scalar> SO3_type;
|
||||
typedef typename vect_type::base vec3;
|
||||
scalar length = scalar(den)/scalar(num);
|
||||
enum {DOF=2, TYP = 1, DIM = 3};
|
||||
|
||||
//private:
|
||||
/**
|
||||
* Unit vector on the sphere, or vector pointing in a direction
|
||||
*/
|
||||
vect_type vec;
|
||||
|
||||
public:
|
||||
S2() {
|
||||
if(S2_typ == 3) vec=length * vec3(0, 0, std::sqrt(1));
|
||||
if(S2_typ == 2) vec=length * vec3(0, std::sqrt(1), 0);
|
||||
if(S2_typ == 1) vec=length * vec3(std::sqrt(1), 0, 0);
|
||||
}
|
||||
S2(const scalar &x, const scalar &y, const scalar &z) : vec(vec3(x, y, z)) {
|
||||
vec.normalize();
|
||||
vec = vec * length;
|
||||
}
|
||||
|
||||
S2(const vect_type &_vec) : vec(_vec) {
|
||||
vec.normalize();
|
||||
vec = vec * length;
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, 3> delta, scalar scale = 1)
|
||||
{
|
||||
SO3_type res;
|
||||
res.w() = MTK::exp<scalar, 3>(res.vec(), delta, scalar(scale/2));
|
||||
vec = res.toRotationMatrix() * vec;
|
||||
}
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, 2> delta, scalar scale=1) {
|
||||
Eigen::Matrix<scalar, 3, 2> Bx;
|
||||
S2_Bx(Bx);
|
||||
vect_type Bu = Bx*delta;SO3_type res;
|
||||
res.w() = MTK::exp<scalar, 3>(res.vec(), Bu, scalar(scale/2));
|
||||
vec = res.toRotationMatrix() * vec;
|
||||
}
|
||||
|
||||
void boxminus(MTK::vectview<scalar, 2> res, const S2<scalar, den, num, S2_typ>& other) const {
|
||||
scalar v_sin = (MTK::hat(vec)*other.vec).norm();
|
||||
scalar v_cos = vec.transpose() * other.vec;
|
||||
scalar theta = std::atan2(v_sin, v_cos);
|
||||
if(v_sin < MTK::tolerance<scalar>())
|
||||
{
|
||||
if(std::fabs(theta) > MTK::tolerance<scalar>() )
|
||||
{
|
||||
res[0] = 3.1415926;
|
||||
res[1] = 0;
|
||||
}
|
||||
else{
|
||||
res[0] = 0;
|
||||
res[1] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
S2<scalar, den, num, S2_typ> other_copy = other;
|
||||
Eigen::Matrix<scalar, 3, 2>Bx;
|
||||
other_copy.S2_Bx(Bx);
|
||||
res = theta/v_sin * Bx.transpose() * MTK::hat(other.vec)*vec;
|
||||
}
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
Eigen::Matrix<scalar, 3, 3> skew_vec;
|
||||
skew_vec << scalar(0), -vec[2], vec[1],
|
||||
vec[2], scalar(0), -vec[0],
|
||||
-vec[1], vec[0], scalar(0);
|
||||
res = skew_vec;
|
||||
}
|
||||
|
||||
|
||||
void S2_Bx(Eigen::Matrix<scalar, 3, 2> &res)
|
||||
{
|
||||
if(S2_typ == 3)
|
||||
{
|
||||
if(vec[2] + length > tolerance<scalar>())
|
||||
{
|
||||
|
||||
res << length - vec[0]*vec[0]/(length+vec[2]), -vec[0]*vec[1]/(length+vec[2]),
|
||||
-vec[0]*vec[1]/(length+vec[2]), length-vec[1]*vec[1]/(length+vec[2]),
|
||||
-vec[0], -vec[1];
|
||||
res /= length;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
res(1, 1) = -1;
|
||||
res(2, 0) = 1;
|
||||
}
|
||||
}
|
||||
else if(S2_typ == 2)
|
||||
{
|
||||
if(vec[1] + length > tolerance<scalar>())
|
||||
{
|
||||
|
||||
res << length - vec[0]*vec[0]/(length+vec[1]), -vec[0]*vec[2]/(length+vec[1]),
|
||||
-vec[0], -vec[2],
|
||||
-vec[0]*vec[2]/(length+vec[1]), length-vec[2]*vec[2]/(length+vec[1]);
|
||||
res /= length;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
res(1, 1) = -1;
|
||||
res(2, 0) = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(vec[0] + length > tolerance<scalar>())
|
||||
{
|
||||
|
||||
res << -vec[1], -vec[2],
|
||||
length - vec[1]*vec[1]/(length+vec[0]), -vec[2]*vec[1]/(length+vec[0]),
|
||||
-vec[2]*vec[1]/(length+vec[0]), length-vec[2]*vec[2]/(length+vec[0]);
|
||||
res /= length;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
res(1, 1) = -1;
|
||||
res(2, 0) = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void S2_Nx(Eigen::Matrix<scalar, 2, 3> &res, S2<scalar, den, num, S2_typ>& subtrahend)
|
||||
{
|
||||
if((vec+subtrahend.vec).norm() > tolerance<scalar>())
|
||||
{
|
||||
Eigen::Matrix<scalar, 3, 2> Bx;
|
||||
S2_Bx(Bx);
|
||||
if((vec-subtrahend.vec).norm() > tolerance<scalar>())
|
||||
{
|
||||
scalar v_sin = (MTK::hat(vec)*subtrahend.vec).norm();
|
||||
scalar v_cos = vec.transpose() * subtrahend.vec;
|
||||
|
||||
res = Bx.transpose() * (std::atan2(v_sin, v_cos)/v_sin*MTK::hat(vec)+MTK::hat(vec)*subtrahend.vec*((-v_cos/v_sin/v_sin/length/length/length/length+std::atan2(v_sin, v_cos)/v_sin/v_sin/v_sin)*subtrahend.vec.transpose()*MTK::hat(vec)*MTK::hat(vec)-vec.transpose()/length/length/length/length));
|
||||
}
|
||||
else
|
||||
{
|
||||
res = 1/length/length*Bx.transpose()*MTK::hat(vec);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "No N(x, y) for x=-y" << std::endl;
|
||||
std::exit(100);
|
||||
}
|
||||
}
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
Eigen::Matrix<scalar, 3, 2> Bx;
|
||||
S2_Bx(Bx);
|
||||
res = 1/length/length*Bx.transpose()*MTK::hat(vec);
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
Eigen::Matrix<scalar, 3, 2> Bx;
|
||||
S2_Bx(Bx);
|
||||
if(delta.norm() < tolerance<scalar>())
|
||||
{
|
||||
res = -MTK::hat(vec)*Bx;
|
||||
}
|
||||
else{
|
||||
vect_type Bu = Bx*delta;
|
||||
SO3_type exp_delta;
|
||||
exp_delta.w() = MTK::exp<scalar, 3>(exp_delta.vec(), Bu, scalar(1/2));
|
||||
res = -exp_delta.toRotationMatrix()*MTK::hat(vec)*MTK::A_matrix(Bu).transpose()*Bx;
|
||||
}
|
||||
}
|
||||
|
||||
operator const vect_type&() const{
|
||||
return vec;
|
||||
}
|
||||
|
||||
const vect_type& get_vect() const {
|
||||
return vec;
|
||||
}
|
||||
|
||||
friend S2<scalar, den, num, S2_typ> operator*(const SO3<scalar>& rot, const S2<scalar, den, num, S2_typ>& dir)
|
||||
{
|
||||
S2<scalar, den, num, S2_typ> ret;
|
||||
ret.vec = rot * dir.vec;
|
||||
return ret;
|
||||
}
|
||||
|
||||
scalar operator[](int idx) const {return vec[idx]; }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &os, const S2<scalar, den, num, S2_typ>& vec){
|
||||
return os << vec.vec.transpose() << " ";
|
||||
}
|
||||
friend std::istream& operator>>(std::istream &is, S2<scalar, den, num, S2_typ>& vec){
|
||||
for(int i=0; i<3; ++i)
|
||||
is >> vec.vec[i];
|
||||
vec.vec.normalize();
|
||||
vec.vec = vec.vec * vec.length;
|
||||
return is;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
|
||||
#endif /*S2_H_*/
|
||||
@@ -0,0 +1,317 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/types/SOn.hpp
|
||||
* @brief Standard Orthogonal Groups i.e.\ rotatation groups.
|
||||
*/
|
||||
#ifndef SON_H_
|
||||
#define SON_H_
|
||||
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
#include "vect.hpp"
|
||||
#include "../src/mtkmath.hpp"
|
||||
|
||||
|
||||
namespace MTK {
|
||||
|
||||
|
||||
/**
|
||||
* Two-dimensional orientations represented as scalar.
|
||||
* There is no guarantee that the representing scalar is within any interval,
|
||||
* but the result of boxminus will always have magnitude @f$\le\pi @f$.
|
||||
*/
|
||||
template<class _scalar = double, int Options = Eigen::AutoAlign>
|
||||
struct SO2 : public Eigen::Rotation2D<_scalar> {
|
||||
enum {DOF = 1, DIM = 2, TYP = 3};
|
||||
|
||||
typedef _scalar scalar;
|
||||
typedef Eigen::Rotation2D<scalar> base;
|
||||
typedef vect<DIM, scalar, Options> vect_type;
|
||||
|
||||
//! Construct from angle
|
||||
SO2(const scalar& angle = 0) : base(angle) { }
|
||||
|
||||
//! Construct from Eigen::Rotation2D
|
||||
SO2(const base& src) : base(src) {}
|
||||
|
||||
/**
|
||||
* Construct from 2D vector.
|
||||
* Resulting orientation will rotate the first unit vector to point to vec.
|
||||
*/
|
||||
SO2(const vect_type &vec) : base(atan2(vec[1], vec[0])) {};
|
||||
|
||||
|
||||
//! Calculate @c this->inverse() * @c r
|
||||
SO2 operator%(const base &r) const {
|
||||
return base::inverse() * r;
|
||||
}
|
||||
|
||||
//! Calculate @c this->inverse() * @c r
|
||||
template<class Derived>
|
||||
vect_type operator%(const Eigen::MatrixBase<Derived> &vec) const {
|
||||
return base::inverse() * vec;
|
||||
}
|
||||
|
||||
//! Calculate @c *this * @c r.inverse()
|
||||
SO2 operator/(const SO2 &r) const {
|
||||
return *this * r.inverse();
|
||||
}
|
||||
|
||||
//! Gets the angle as scalar.
|
||||
operator scalar() const {
|
||||
return base::angle();
|
||||
}
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
//! @name Manifold requirements
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
base::angle() += scale * vec[0];
|
||||
}
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
base::angle() += scale * vec[0];
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const SO2<scalar>& other) const {
|
||||
res[0] = MTK::normalize(base::angle() - other.angle(), scalar(MTK::pi));
|
||||
}
|
||||
|
||||
friend std::istream& operator>>(std::istream &is, SO2<scalar>& ang){
|
||||
return is >> ang.angle();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Three-dimensional orientations represented as Quaternion.
|
||||
* It is assumed that the internal Quaternion always stays normalized,
|
||||
* should this not be the case, call inherited member function @c normalize().
|
||||
*/
|
||||
template<class _scalar = double, int Options = Eigen::AutoAlign>
|
||||
struct SO3 : public Eigen::Quaternion<_scalar, Options> {
|
||||
enum {DOF = 3, DIM = 3, TYP = 2};
|
||||
typedef _scalar scalar;
|
||||
typedef Eigen::Quaternion<scalar, Options> base;
|
||||
typedef Eigen::Quaternion<scalar> Quaternion;
|
||||
typedef vect<DIM, scalar, Options> vect_type;
|
||||
|
||||
//! Calculate @c this->inverse() * @c r
|
||||
template<class OtherDerived> EIGEN_STRONG_INLINE
|
||||
Quaternion operator%(const Eigen::QuaternionBase<OtherDerived> &r) const {
|
||||
return base::conjugate() * r;
|
||||
}
|
||||
|
||||
//! Calculate @c this->inverse() * @c r
|
||||
template<class Derived>
|
||||
vect_type operator%(const Eigen::MatrixBase<Derived> &vec) const {
|
||||
return base::conjugate() * vec;
|
||||
}
|
||||
|
||||
//! Calculate @c this * @c r.conjugate()
|
||||
template<class OtherDerived> EIGEN_STRONG_INLINE
|
||||
Quaternion operator/(const Eigen::QuaternionBase<OtherDerived> &r) const {
|
||||
return *this * r.conjugate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct from real part and three imaginary parts.
|
||||
* Quaternion is normalized after construction.
|
||||
*/
|
||||
SO3(const scalar& w, const scalar& x, const scalar& y, const scalar& z) : base(w, x, y, z) {
|
||||
base::normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct from Eigen::Quaternion.
|
||||
* @note Non-normalized input may result result in spurious behavior.
|
||||
*/
|
||||
SO3(const base& src = base::Identity()) : base(src) {}
|
||||
|
||||
/**
|
||||
* Construct from rotation matrix.
|
||||
* @note Invalid rotation matrices may lead to spurious behavior.
|
||||
*/
|
||||
template<class Derived>
|
||||
SO3(const Eigen::MatrixBase<Derived>& matrix) : base(matrix) {}
|
||||
|
||||
/**
|
||||
* Construct from arbitrary rotation type.
|
||||
* @note Invalid rotation matrices may lead to spurious behavior.
|
||||
*/
|
||||
template<class Derived>
|
||||
SO3(const Eigen::RotationBase<Derived, 3>& rotation) : base(rotation.derived()) {}
|
||||
|
||||
//! @name Manifold requirements
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale=1) {
|
||||
SO3 delta = exp(vec, scale);
|
||||
*this = *this * delta;
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const SO3<scalar>& other) const {
|
||||
res = SO3::log(other.conjugate() * *this);
|
||||
}
|
||||
//}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale=1) {
|
||||
SO3 delta = exp(vec, scale);
|
||||
*this = *this * delta;
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &os, const SO3<scalar, Options>& q){
|
||||
return os << q.coeffs().transpose() << " ";
|
||||
}
|
||||
|
||||
friend std::istream& operator>>(std::istream &is, SO3<scalar, Options>& q){
|
||||
vect<4,scalar> coeffs;
|
||||
is >> coeffs;
|
||||
q.coeffs() = coeffs.normalized();
|
||||
return is;
|
||||
}
|
||||
|
||||
//! @name Helper functions
|
||||
//{
|
||||
/**
|
||||
* Calculate the exponential map. In matrix terms this would correspond
|
||||
* to the Rodrigues formula.
|
||||
*/
|
||||
// FIXME vectview<> can't be constructed from every MatrixBase<>, use const Vector3x& as workaround
|
||||
// static SO3 exp(MTK::vectview<const scalar, 3> dvec, scalar scale = 1){
|
||||
static SO3 exp(const Eigen::Matrix<scalar, 3, 1>& dvec, scalar scale = 1){
|
||||
SO3 res;
|
||||
res.w() = MTK::exp<scalar, 3>(res.vec(), dvec, scalar(scale/2));
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Calculate the inverse of @c exp.
|
||||
* Only guarantees that <code>exp(log(x)) == x </code>
|
||||
*/
|
||||
static typename base::Vector3 log(const SO3 &orient){
|
||||
typename base::Vector3 res;
|
||||
MTK::log<scalar, 3>(res, orient.w(), orient.vec(), scalar(2), true);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
template<class Scalar, int Options>
|
||||
struct UnalignedType<SO2<Scalar, Options > >{
|
||||
typedef SO2<Scalar, Options | Eigen::DontAlign> type;
|
||||
};
|
||||
|
||||
template<class Scalar, int Options>
|
||||
struct UnalignedType<SO3<Scalar, Options > >{
|
||||
typedef SO3<Scalar, Options | Eigen::DontAlign> type;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
#endif /*SON_H_*/
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
// This is an advanced implementation of the algorithm described in the
|
||||
// following paper:
|
||||
// C. Hertzberg, R. Wagner, U. Frese, and L. Schroder. Integratinggeneric sensor fusion algorithms with sound state representationsthrough encapsulation of manifolds.
|
||||
// CoRR, vol. abs/1107.1119, 2011.[Online]. Available: http://arxiv.org/abs/1107.1119
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019--2023, The University of Hong Kong
|
||||
* All rights reserved.
|
||||
*
|
||||
* Modifier: Dongjiao HE <hdj65822@connect.hku.hk>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008--2011, Universitaet Bremen
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @file mtk/types/vect.hpp
|
||||
* @brief Basic vectors interpreted as manifolds.
|
||||
*
|
||||
* This file also implements a simple wrapper for matrices, for arbitrary scalars
|
||||
* and for positive scalars.
|
||||
*/
|
||||
#ifndef VECT_H_
|
||||
#define VECT_H_
|
||||
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "../src/vectview.hpp"
|
||||
|
||||
namespace MTK {
|
||||
|
||||
static const Eigen::IOFormat IO_no_spaces(Eigen::StreamPrecision, Eigen::DontAlignCols, ",", ",", "", "", "[", "]");
|
||||
|
||||
|
||||
/**
|
||||
* A simple vector class.
|
||||
* Implementation is basically a wrapper around Eigen::Matrix with manifold
|
||||
* requirements added.
|
||||
*/
|
||||
template<int D = 3, class _scalar = double, int _Options=Eigen::AutoAlign>
|
||||
struct vect : public Eigen::Matrix<_scalar, D, 1, _Options> {
|
||||
typedef Eigen::Matrix<_scalar, D, 1, _Options> base;
|
||||
enum {DOF = D, DIM = D, TYP = 0};
|
||||
typedef _scalar scalar;
|
||||
|
||||
//using base::operator=;
|
||||
|
||||
/** Standard constructor. Sets all values to zero. */
|
||||
vect(const base &src = base::Zero()) : base(src) {}
|
||||
|
||||
/** Constructor copying the value of the expression \a other */
|
||||
template<typename OtherDerived>
|
||||
EIGEN_STRONG_INLINE vect(const Eigen::DenseBase<OtherDerived>& other) : base(other) {}
|
||||
|
||||
/** Construct from memory. */
|
||||
vect(const scalar* src, int size = DOF) : base(base::Map(src, size)) { }
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, D> vec, scalar scale=1) {
|
||||
*this += scale * vec;
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, D> res, const vect<D, scalar>& other) const {
|
||||
res = *this - other;
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, D> vec, scalar scale=1) {
|
||||
*this += scale * vec;
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &os, const vect<D, scalar, _Options>& v){
|
||||
// Eigen sometimes messes with the streams flags, so output manually:
|
||||
for(int i=0; i<DOF; ++i)
|
||||
os << v(i) << " ";
|
||||
return os;
|
||||
}
|
||||
friend std::istream& operator>>(std::istream &is, vect<D, scalar, _Options>& v){
|
||||
char term=0;
|
||||
is >> std::ws; // skip whitespace
|
||||
switch(is.peek()) {
|
||||
case '(': term=')'; is.ignore(1); break;
|
||||
case '[': term=']'; is.ignore(1); break;
|
||||
case '{': term='}'; is.ignore(1); break;
|
||||
default: break;
|
||||
}
|
||||
if(D==Eigen::Dynamic) {
|
||||
assert(term !=0 && "Dynamic vectors must be embraced");
|
||||
std::vector<scalar> temp;
|
||||
while(is.good() && is.peek() != term) {
|
||||
scalar x;
|
||||
is >> x;
|
||||
temp.push_back(x);
|
||||
if(is.peek()==',') is.ignore(1);
|
||||
}
|
||||
v = vect::Map(temp.data(), temp.size());
|
||||
} else
|
||||
for(int i=0; i<v.size(); ++i){
|
||||
is >> v[i];
|
||||
if(is.peek()==',') { // ignore commas between values
|
||||
is.ignore(1);
|
||||
}
|
||||
}
|
||||
if(term!=0) {
|
||||
char x;
|
||||
is >> x;
|
||||
if(x!=term) {
|
||||
is.setstate(is.badbit);
|
||||
// assert(x==term && "start and end bracket do not match!");
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<int dim>
|
||||
vectview<scalar, dim> tail(){
|
||||
BOOST_STATIC_ASSERT(0< dim && dim <= DOF);
|
||||
return base::template tail<dim>();
|
||||
}
|
||||
template<int dim>
|
||||
vectview<const scalar, dim> tail() const{
|
||||
BOOST_STATIC_ASSERT(0< dim && dim <= DOF);
|
||||
return base::template tail<dim>();
|
||||
}
|
||||
template<int dim>
|
||||
vectview<scalar, dim> head(){
|
||||
BOOST_STATIC_ASSERT(0< dim && dim <= DOF);
|
||||
return base::template head<dim>();
|
||||
}
|
||||
template<int dim>
|
||||
vectview<const scalar, dim> head() const{
|
||||
BOOST_STATIC_ASSERT(0< dim && dim <= DOF);
|
||||
return base::template head<dim>();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A simple matrix class.
|
||||
* Implementation is basically a wrapper around Eigen::Matrix with manifold
|
||||
* requirements added, i.e., matrix is viewed as a plain vector for that.
|
||||
*/
|
||||
template<int M, int N, class _scalar = double, int _Options = Eigen::Matrix<_scalar, M, N>::Options>
|
||||
struct matrix : public Eigen::Matrix<_scalar, M, N, _Options> {
|
||||
typedef Eigen::Matrix<_scalar, M, N, _Options> base;
|
||||
enum {DOF = M * N, TYP = 4, DIM=0};
|
||||
typedef _scalar scalar;
|
||||
|
||||
using base::operator=;
|
||||
|
||||
/** Standard constructor. Sets all values to zero. */
|
||||
matrix() {
|
||||
base::setZero();
|
||||
}
|
||||
|
||||
/** Constructor copying the value of the expression \a other */
|
||||
template<typename OtherDerived>
|
||||
EIGEN_STRONG_INLINE matrix(const Eigen::MatrixBase<OtherDerived>& other) : base(other) {}
|
||||
|
||||
/** Construct from memory. */
|
||||
matrix(const scalar* src) : base(src) { }
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
*this += scale * base::Map(vec.data());
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const matrix& other) const {
|
||||
base::Map(res.data()) = *this - other;
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
*this += scale * base::Map(vec.data());
|
||||
}
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &os, const matrix<M, N, scalar, _Options>& mat){
|
||||
for(int i=0; i<DOF; ++i){
|
||||
os << mat.data()[i] << " ";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
friend std::istream& operator>>(std::istream &is, matrix<M, N, scalar, _Options>& mat){
|
||||
for(int i=0; i<DOF; ++i){
|
||||
is >> mat.data()[i];
|
||||
}
|
||||
return is;
|
||||
}
|
||||
};// @todo What if M / N = Eigen::Dynamic?
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A simple scalar type.
|
||||
*/
|
||||
template<class _scalar = double>
|
||||
struct Scalar {
|
||||
enum {DOF = 1, TYP = 5, DIM=0};
|
||||
typedef _scalar scalar;
|
||||
|
||||
scalar value;
|
||||
|
||||
Scalar(const scalar& value = scalar(0)) : value(value) {}
|
||||
operator const scalar&() const { return value; }
|
||||
operator scalar&() { return value; }
|
||||
Scalar& operator=(const scalar& val) { value = val; return *this; }
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale=1) {
|
||||
value += scale * vec[0];
|
||||
}
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale=1) {
|
||||
value += scale * vec[0];
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const Scalar& other) const {
|
||||
res[0] = *this - other;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Positive scalars.
|
||||
* Boxplus is implemented using multiplication by @f$x\boxplus\delta = x\cdot\exp(\delta) @f$.
|
||||
*/
|
||||
template<class _scalar = double>
|
||||
struct PositiveScalar {
|
||||
enum {DOF = 1, TYP = 6, DIM=0};
|
||||
typedef _scalar scalar;
|
||||
|
||||
scalar value;
|
||||
|
||||
PositiveScalar(const scalar& value = scalar(1)) : value(value) {
|
||||
assert(value > scalar(0));
|
||||
}
|
||||
operator const scalar&() const { return value; }
|
||||
PositiveScalar& operator=(const scalar& val) { assert(val>0); value = val; return *this; }
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
value *= std::exp(scale * vec[0]);
|
||||
}
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const PositiveScalar& other) const {
|
||||
res[0] = std::log(*this / other);
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
value *= std::exp(scale * vec[0]);
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
|
||||
friend std::istream& operator>>(std::istream &is, PositiveScalar<scalar>& s){
|
||||
is >> s.value;
|
||||
assert(s.value > 0);
|
||||
return is;
|
||||
}
|
||||
};
|
||||
|
||||
template<class _scalar = double>
|
||||
struct Complex : public std::complex<_scalar>{
|
||||
enum {DOF = 2, TYP = 7, DIM=0};
|
||||
typedef _scalar scalar;
|
||||
|
||||
typedef std::complex<scalar> Base;
|
||||
|
||||
Complex(const Base& value) : Base(value) {}
|
||||
Complex(const scalar& re = 0.0, const scalar& im = 0.0) : Base(re, im) {}
|
||||
Complex(const MTK::vectview<const scalar, 2> &in) : Base(in[0], in[1]) {}
|
||||
template<class Derived>
|
||||
Complex(const Eigen::DenseBase<Derived> &in) : Base(in[0], in[1]) {}
|
||||
|
||||
void boxplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
Base::real() += scale * vec[0];
|
||||
Base::imag() += scale * vec[1];
|
||||
};
|
||||
void boxminus(MTK::vectview<scalar, DOF> res, const Complex& other) const {
|
||||
Complex diff = *this - other;
|
||||
res << diff.real(), diff.imag();
|
||||
}
|
||||
|
||||
void S2_hat(Eigen::Matrix<scalar, 3, 3> &res)
|
||||
{
|
||||
res = Eigen::Matrix<scalar, 3, 3>::Zero();
|
||||
}
|
||||
|
||||
void oplus(MTK::vectview<const scalar, DOF> vec, scalar scale = 1) {
|
||||
Base::real() += scale * vec[0];
|
||||
Base::imag() += scale * vec[1];
|
||||
};
|
||||
|
||||
void S2_Nx_yy(Eigen::Matrix<scalar, 2, 3> &res)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 2, 3>::Zero();
|
||||
}
|
||||
|
||||
void S2_Mx(Eigen::Matrix<scalar, 3, 2> &res, MTK::vectview<const scalar, 2> delta)
|
||||
{
|
||||
std::cerr << "wrong idx for S2" << std::endl;
|
||||
std::exit(100);
|
||||
res = Eigen::Matrix<scalar, 3, 2>::Zero();
|
||||
}
|
||||
|
||||
scalar squaredNorm() const {
|
||||
return std::pow(Base::real(),2) + std::pow(Base::imag(),2);
|
||||
}
|
||||
|
||||
const scalar& operator()(int i) const {
|
||||
assert(0<=i && i<2 && "Index out of range");
|
||||
return i==0 ? Base::real() : Base::imag();
|
||||
}
|
||||
scalar& operator()(int i){
|
||||
assert(0<=i && i<2 && "Index out of range");
|
||||
return i==0 ? Base::real() : Base::imag();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<int dim, class Scalar, int Options>
|
||||
struct UnalignedType<vect<dim, Scalar, Options > >{
|
||||
typedef vect<dim, Scalar, Options | Eigen::DontAlign> type;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /*VECT_H_*/
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2010--2011, Universitaet Bremen and DFKI GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Rene Wagner <rene.wagner@dfki.de>
|
||||
* Christoph Hertzberg <chtz@informatik.uni-bremen.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Universitaet Bremen nor the DFKI GmbH
|
||||
* nor the names of its contributors may be used to endorse or
|
||||
* promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef WRAPPED_CV_MAT_HPP_
|
||||
#define WRAPPED_CV_MAT_HPP_
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <opencv/cv.h>
|
||||
|
||||
namespace MTK {
|
||||
|
||||
template<class f_type>
|
||||
struct cv_f_type;
|
||||
|
||||
template<>
|
||||
struct cv_f_type<double>
|
||||
{
|
||||
enum {value = CV_64F};
|
||||
};
|
||||
|
||||
template<>
|
||||
struct cv_f_type<float>
|
||||
{
|
||||
enum {value = CV_32F};
|
||||
};
|
||||
|
||||
/**
|
||||
* cv_mat wraps a CvMat around an Eigen Matrix
|
||||
*/
|
||||
template<int rows, int cols, class f_type = double>
|
||||
class cv_mat : public matrix<rows, cols, f_type, cols==1 ? Eigen::ColMajor : Eigen::RowMajor>
|
||||
{
|
||||
typedef matrix<rows, cols, f_type, cols==1 ? Eigen::ColMajor : Eigen::RowMajor> base_type;
|
||||
enum {type_ = cv_f_type<f_type>::value};
|
||||
CvMat cv_mat_;
|
||||
|
||||
public:
|
||||
cv_mat()
|
||||
{
|
||||
cv_mat_ = cvMat(rows, cols, type_, base_type::data());
|
||||
}
|
||||
|
||||
cv_mat(const cv_mat& oth) : base_type(oth)
|
||||
{
|
||||
cv_mat_ = cvMat(rows, cols, type_, base_type::data());
|
||||
}
|
||||
|
||||
template<class Derived>
|
||||
cv_mat(const Eigen::MatrixBase<Derived> &value) : base_type(value)
|
||||
{
|
||||
cv_mat_ = cvMat(rows, cols, type_, base_type::data());
|
||||
}
|
||||
|
||||
template<class Derived>
|
||||
cv_mat& operator=(const Eigen::MatrixBase<Derived> &value)
|
||||
{
|
||||
base_type::operator=(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv_mat& operator=(const cv_mat& value)
|
||||
{
|
||||
base_type::operator=(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// FIXME: Maybe overloading operator& is not a good idea ...
|
||||
CvMat* operator&()
|
||||
{
|
||||
return &cv_mat_;
|
||||
}
|
||||
const CvMat* operator&() const
|
||||
{
|
||||
return &cv_mat_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace MTK
|
||||
|
||||
#endif /* WRAPPED_CV_MAT_HPP_ */
|
||||
@@ -0,0 +1,270 @@
|
||||
#ifndef COMMON_LIB_H
|
||||
#define COMMON_LIB_H
|
||||
|
||||
#include <so3_math.h>
|
||||
#include <Eigen/Eigen>
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <fast_lio/msg/pose6_d.hpp>
|
||||
#include <sensor_msgs/msg/imu.hpp>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Eigen;
|
||||
|
||||
#define USE_IKFOM
|
||||
|
||||
#define PI_M (3.14159265358)
|
||||
#define G_m_s2 (9.81) // Gravaty const in GuangDong/China
|
||||
#define DIM_STATE (18) // Dimension of states (Let Dim(SO(3)) = 3)
|
||||
#define DIM_PROC_N (12) // Dimension of process noise (Let Dim(SO(3)) = 3)
|
||||
#define CUBE_LEN (6.0)
|
||||
#define LIDAR_SP_LEN (2)
|
||||
#define INIT_COV (1)
|
||||
#define NUM_MATCH_POINTS (5)
|
||||
#define MAX_MEAS_DIM (10000)
|
||||
|
||||
#define VEC_FROM_ARRAY(v) v[0],v[1],v[2]
|
||||
#define MAT_FROM_ARRAY(v) v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]
|
||||
#define CONSTRAIN(v,min,max) ((v>min)?((v<max)?v:max):min)
|
||||
#define ARRAY_FROM_EIGEN(mat) mat.data(), mat.data() + mat.rows() * mat.cols()
|
||||
#define STD_VEC_FROM_EIGEN(mat) vector<decltype(mat)::Scalar> (mat.data(), mat.data() + mat.rows() * mat.cols())
|
||||
#define DEBUG_FILE_DIR(name) (string(string(ROOT_DIR) + "Log/"+ name))
|
||||
|
||||
typedef fast_lio::msg::Pose6D Pose6D;
|
||||
typedef pcl::PointXYZINormal PointType;
|
||||
typedef pcl::PointCloud<PointType> PointCloudXYZI;
|
||||
typedef vector<PointType, Eigen::aligned_allocator<PointType>> PointVector;
|
||||
typedef Vector3d V3D;
|
||||
typedef Matrix3d M3D;
|
||||
typedef Vector3f V3F;
|
||||
typedef Matrix3f M3F;
|
||||
|
||||
#define MD(a,b) Matrix<double, (a), (b)>
|
||||
#define VD(a) Matrix<double, (a), 1>
|
||||
#define MF(a,b) Matrix<float, (a), (b)>
|
||||
#define VF(a) Matrix<float, (a), 1>
|
||||
|
||||
M3D Eye3d(M3D::Identity());
|
||||
M3F Eye3f(M3F::Identity());
|
||||
V3D Zero3d(0, 0, 0);
|
||||
V3F Zero3f(0, 0, 0);
|
||||
|
||||
struct MeasureGroup // Lidar data and imu dates for the curent process
|
||||
{
|
||||
MeasureGroup()
|
||||
{
|
||||
lidar_beg_time = 0.0;
|
||||
this->lidar.reset(new PointCloudXYZI());
|
||||
};
|
||||
double lidar_beg_time;
|
||||
double lidar_end_time;
|
||||
PointCloudXYZI::Ptr lidar;
|
||||
deque<sensor_msgs::msg::Imu::ConstSharedPtr> imu;
|
||||
};
|
||||
|
||||
struct StatesGroup
|
||||
{
|
||||
StatesGroup() {
|
||||
this->rot_end = M3D::Identity();
|
||||
this->pos_end = Zero3d;
|
||||
this->vel_end = Zero3d;
|
||||
this->bias_g = Zero3d;
|
||||
this->bias_a = Zero3d;
|
||||
this->gravity = Zero3d;
|
||||
this->cov = MD(DIM_STATE,DIM_STATE)::Identity() * INIT_COV;
|
||||
this->cov.block<9,9>(9,9) = MD(9,9)::Identity() * 0.00001;
|
||||
};
|
||||
|
||||
StatesGroup(const StatesGroup& b) {
|
||||
this->rot_end = b.rot_end;
|
||||
this->pos_end = b.pos_end;
|
||||
this->vel_end = b.vel_end;
|
||||
this->bias_g = b.bias_g;
|
||||
this->bias_a = b.bias_a;
|
||||
this->gravity = b.gravity;
|
||||
this->cov = b.cov;
|
||||
};
|
||||
|
||||
StatesGroup& operator=(const StatesGroup& b)
|
||||
{
|
||||
this->rot_end = b.rot_end;
|
||||
this->pos_end = b.pos_end;
|
||||
this->vel_end = b.vel_end;
|
||||
this->bias_g = b.bias_g;
|
||||
this->bias_a = b.bias_a;
|
||||
this->gravity = b.gravity;
|
||||
this->cov = b.cov;
|
||||
return *this;
|
||||
};
|
||||
|
||||
StatesGroup operator+(const Matrix<double, DIM_STATE, 1> &state_add)
|
||||
{
|
||||
StatesGroup a;
|
||||
a.rot_end = this->rot_end * Exp(state_add(0,0), state_add(1,0), state_add(2,0));
|
||||
a.pos_end = this->pos_end + state_add.block<3,1>(3,0);
|
||||
a.vel_end = this->vel_end + state_add.block<3,1>(6,0);
|
||||
a.bias_g = this->bias_g + state_add.block<3,1>(9,0);
|
||||
a.bias_a = this->bias_a + state_add.block<3,1>(12,0);
|
||||
a.gravity = this->gravity + state_add.block<3,1>(15,0);
|
||||
a.cov = this->cov;
|
||||
return a;
|
||||
};
|
||||
|
||||
StatesGroup& operator+=(const Matrix<double, DIM_STATE, 1> &state_add)
|
||||
{
|
||||
this->rot_end = this->rot_end * Exp(state_add(0,0), state_add(1,0), state_add(2,0));
|
||||
this->pos_end += state_add.block<3,1>(3,0);
|
||||
this->vel_end += state_add.block<3,1>(6,0);
|
||||
this->bias_g += state_add.block<3,1>(9,0);
|
||||
this->bias_a += state_add.block<3,1>(12,0);
|
||||
this->gravity += state_add.block<3,1>(15,0);
|
||||
return *this;
|
||||
};
|
||||
|
||||
Matrix<double, DIM_STATE, 1> operator-(const StatesGroup& b)
|
||||
{
|
||||
Matrix<double, DIM_STATE, 1> a;
|
||||
M3D rotd(b.rot_end.transpose() * this->rot_end);
|
||||
a.block<3,1>(0,0) = Log(rotd);
|
||||
a.block<3,1>(3,0) = this->pos_end - b.pos_end;
|
||||
a.block<3,1>(6,0) = this->vel_end - b.vel_end;
|
||||
a.block<3,1>(9,0) = this->bias_g - b.bias_g;
|
||||
a.block<3,1>(12,0) = this->bias_a - b.bias_a;
|
||||
a.block<3,1>(15,0) = this->gravity - b.gravity;
|
||||
return a;
|
||||
};
|
||||
|
||||
void resetpose()
|
||||
{
|
||||
this->rot_end = M3D::Identity();
|
||||
this->pos_end = Zero3d;
|
||||
this->vel_end = Zero3d;
|
||||
}
|
||||
|
||||
M3D rot_end; // the estimated attitude (rotation matrix) at the end lidar point
|
||||
V3D pos_end; // the estimated position at the end lidar point (world frame)
|
||||
V3D vel_end; // the estimated velocity at the end lidar point (world frame)
|
||||
V3D bias_g; // gyroscope bias
|
||||
V3D bias_a; // accelerator bias
|
||||
V3D gravity; // the estimated gravity acceleration
|
||||
Matrix<double, DIM_STATE, DIM_STATE> cov; // states covariance
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T rad2deg(T radians)
|
||||
{
|
||||
return radians * 180.0 / PI_M;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T deg2rad(T degrees)
|
||||
{
|
||||
return degrees * PI_M / 180.0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto set_pose6d(const double t, const Matrix<T, 3, 1> &a, const Matrix<T, 3, 1> &g, \
|
||||
const Matrix<T, 3, 1> &v, const Matrix<T, 3, 1> &p, const Matrix<T, 3, 3> &R)
|
||||
{
|
||||
Pose6D rot_kp;
|
||||
rot_kp.offset_time = t;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
rot_kp.acc[i] = a(i);
|
||||
rot_kp.gyr[i] = g(i);
|
||||
rot_kp.vel[i] = v(i);
|
||||
rot_kp.pos[i] = p(i);
|
||||
for (int j = 0; j < 3; j++) rot_kp.rot[i*3+j] = R(i,j);
|
||||
}
|
||||
return move(rot_kp);
|
||||
}
|
||||
|
||||
/* comment
|
||||
plane equation: Ax + By + Cz + D = 0
|
||||
convert to: A/D*x + B/D*y + C/D*z = -1
|
||||
solve: A0*x0 = b0
|
||||
where A0_i = [x_i, y_i, z_i], x0 = [A/D, B/D, C/D]^T, b0 = [-1, ..., -1]^T
|
||||
normvec: normalized x0
|
||||
*/
|
||||
template<typename T>
|
||||
bool esti_normvector(Matrix<T, 3, 1> &normvec, const PointVector &point, const T &threshold, const int &point_num)
|
||||
{
|
||||
MatrixXf A(point_num, 3);
|
||||
MatrixXf b(point_num, 1);
|
||||
b.setOnes();
|
||||
b *= -1.0f;
|
||||
|
||||
for (int j = 0; j < point_num; j++)
|
||||
{
|
||||
A(j,0) = point[j].x;
|
||||
A(j,1) = point[j].y;
|
||||
A(j,2) = point[j].z;
|
||||
}
|
||||
normvec = A.colPivHouseholderQr().solve(b);
|
||||
|
||||
for (int j = 0; j < point_num; j++)
|
||||
{
|
||||
if (fabs(normvec(0) * point[j].x + normvec(1) * point[j].y + normvec(2) * point[j].z + 1.0f) > threshold)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
normvec.normalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
float calc_dist(PointType p1, PointType p2){
|
||||
float d = (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z);
|
||||
return d;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool esti_plane(Matrix<T, 4, 1> &pca_result, const PointVector &point, const T &threshold)
|
||||
{
|
||||
Matrix<T, NUM_MATCH_POINTS, 3> A;
|
||||
Matrix<T, NUM_MATCH_POINTS, 1> b;
|
||||
A.setZero();
|
||||
b.setOnes();
|
||||
b *= -1.0f;
|
||||
|
||||
for (int j = 0; j < NUM_MATCH_POINTS; j++)
|
||||
{
|
||||
A(j,0) = point[j].x;
|
||||
A(j,1) = point[j].y;
|
||||
A(j,2) = point[j].z;
|
||||
}
|
||||
|
||||
Matrix<T, 3, 1> normvec = A.colPivHouseholderQr().solve(b);
|
||||
|
||||
T n = normvec.norm();
|
||||
pca_result(0) = normvec(0) / n;
|
||||
pca_result(1) = normvec(1) / n;
|
||||
pca_result(2) = normvec(2) / n;
|
||||
pca_result(3) = 1.0 / n;
|
||||
|
||||
for (int j = 0; j < NUM_MATCH_POINTS; j++)
|
||||
{
|
||||
if (fabs(pca_result(0) * point[j].x + pca_result(1) * point[j].y + pca_result(2) * point[j].z + pca_result(3)) > threshold)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
double get_time_sec(const builtin_interfaces::msg::Time &time)
|
||||
{
|
||||
return rclcpp::Time(time).seconds();
|
||||
}
|
||||
|
||||
rclcpp::Time get_ros_time(double timestamp)
|
||||
{
|
||||
int32_t sec = std::floor(timestamp);
|
||||
auto nanosec_d = (timestamp - std::floor(timestamp)) * 1e9;
|
||||
uint32_t nanosec = nanosec_d;
|
||||
return rclcpp::Time(sec, nanosec);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
# ikd-Tree
|
||||
ikd-Tree is an incremental k-d tree for robotic applications.
|
||||
@@ -0,0 +1,344 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <queue>
|
||||
#include <pthread.h>
|
||||
#include <chrono>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <memory.h>
|
||||
#include <pcl/point_types.h>
|
||||
|
||||
#define EPSS 1e-6
|
||||
#define Minimal_Unbalanced_Tree_Size 10
|
||||
#define Multi_Thread_Rebuild_Point_Num 1500
|
||||
#define DOWNSAMPLE_SWITCH true
|
||||
#define ForceRebuildPercentage 0.2
|
||||
#define Q_LEN 1000000
|
||||
|
||||
using namespace std;
|
||||
|
||||
// typedef pcl::PointXYZINormal PointType;
|
||||
// typedef vector<PointType, Eigen::aligned_allocator<PointType>> PointVector;
|
||||
|
||||
struct BoxPointType
|
||||
{
|
||||
float vertex_min[3];
|
||||
float vertex_max[3];
|
||||
};
|
||||
|
||||
enum operation_set
|
||||
{
|
||||
ADD_POINT,
|
||||
DELETE_POINT,
|
||||
DELETE_BOX,
|
||||
ADD_BOX,
|
||||
DOWNSAMPLE_DELETE,
|
||||
PUSH_DOWN
|
||||
};
|
||||
|
||||
enum delete_point_storage_set
|
||||
{
|
||||
NOT_RECORD,
|
||||
DELETE_POINTS_REC,
|
||||
MULTI_THREAD_REC
|
||||
};
|
||||
|
||||
template <typename PointType>
|
||||
class KD_TREE
|
||||
{
|
||||
// using MANUAL_Q_ = MANUAL_Q<typename PointType>;
|
||||
// using PointVector = std::vector<PointType>;
|
||||
|
||||
// using MANUAL_Q_ = MANUAL_Q<typename PointType>;
|
||||
public:
|
||||
using PointVector = std::vector<PointType, Eigen::aligned_allocator<PointType>>;
|
||||
using Ptr = std::shared_ptr<KD_TREE<PointType>>;
|
||||
|
||||
struct KD_TREE_NODE
|
||||
{
|
||||
PointType point;
|
||||
int division_axis;
|
||||
int TreeSize = 1;
|
||||
int invalid_point_num = 0;
|
||||
int down_del_num = 0;
|
||||
bool point_deleted = false;
|
||||
bool tree_deleted = false;
|
||||
bool point_downsample_deleted = false;
|
||||
bool tree_downsample_deleted = false;
|
||||
bool need_push_down_to_left = false;
|
||||
bool need_push_down_to_right = false;
|
||||
bool working_flag = false;
|
||||
pthread_mutex_t push_down_mutex_lock;
|
||||
float node_range_x[2], node_range_y[2], node_range_z[2];
|
||||
float radius_sq;
|
||||
KD_TREE_NODE *left_son_ptr = nullptr;
|
||||
KD_TREE_NODE *right_son_ptr = nullptr;
|
||||
KD_TREE_NODE *father_ptr = nullptr;
|
||||
// For paper data record
|
||||
float alpha_del;
|
||||
float alpha_bal;
|
||||
};
|
||||
|
||||
struct Operation_Logger_Type
|
||||
{
|
||||
PointType point;
|
||||
BoxPointType boxpoint;
|
||||
bool tree_deleted, tree_downsample_deleted;
|
||||
operation_set op;
|
||||
};
|
||||
// static const PointType zeroP;
|
||||
|
||||
struct PointType_CMP
|
||||
{
|
||||
PointType point;
|
||||
float dist = 0.0;
|
||||
PointType_CMP(PointType p = PointType(), float d = INFINITY)
|
||||
{
|
||||
this->point = p;
|
||||
this->dist = d;
|
||||
};
|
||||
bool operator<(const PointType_CMP &a) const
|
||||
{
|
||||
if (fabs(dist - a.dist) < 1e-10)
|
||||
return point.x < a.point.x;
|
||||
else
|
||||
return dist < a.dist;
|
||||
}
|
||||
};
|
||||
|
||||
class MANUAL_HEAP
|
||||
{
|
||||
|
||||
public:
|
||||
MANUAL_HEAP(int max_capacity = 100)
|
||||
|
||||
{
|
||||
cap = max_capacity;
|
||||
heap = new PointType_CMP[max_capacity];
|
||||
heap_size = 0;
|
||||
}
|
||||
|
||||
~MANUAL_HEAP()
|
||||
{
|
||||
delete[] heap;
|
||||
}
|
||||
void pop()
|
||||
{
|
||||
if (heap_size == 0)
|
||||
return;
|
||||
heap[0] = heap[heap_size - 1];
|
||||
heap_size--;
|
||||
MoveDown(0);
|
||||
return;
|
||||
}
|
||||
PointType_CMP top()
|
||||
{
|
||||
return heap[0];
|
||||
}
|
||||
void push(PointType_CMP point)
|
||||
{
|
||||
if (heap_size >= cap)
|
||||
return;
|
||||
heap[heap_size] = point;
|
||||
FloatUp(heap_size);
|
||||
heap_size++;
|
||||
return;
|
||||
}
|
||||
int size()
|
||||
{
|
||||
return heap_size;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
heap_size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
PointType_CMP *heap;
|
||||
void MoveDown(int heap_index)
|
||||
{
|
||||
int l = heap_index * 2 + 1;
|
||||
PointType_CMP tmp = heap[heap_index];
|
||||
while (l < heap_size)
|
||||
{
|
||||
if (l + 1 < heap_size && heap[l] < heap[l + 1])
|
||||
l++;
|
||||
if (tmp < heap[l])
|
||||
{
|
||||
heap[heap_index] = heap[l];
|
||||
heap_index = l;
|
||||
l = heap_index * 2 + 1;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
heap[heap_index] = tmp;
|
||||
return;
|
||||
}
|
||||
void FloatUp(int heap_index)
|
||||
{
|
||||
int ancestor = (heap_index - 1) / 2;
|
||||
PointType_CMP tmp = heap[heap_index];
|
||||
while (heap_index > 0)
|
||||
{
|
||||
if (heap[ancestor] < tmp)
|
||||
{
|
||||
heap[heap_index] = heap[ancestor];
|
||||
heap_index = ancestor;
|
||||
ancestor = (heap_index - 1) / 2;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
heap[heap_index] = tmp;
|
||||
return;
|
||||
}
|
||||
int heap_size = 0;
|
||||
int cap = 0;
|
||||
};
|
||||
|
||||
class MANUAL_Q
|
||||
{
|
||||
private:
|
||||
int head = 0, tail = 0, counter = 0;
|
||||
Operation_Logger_Type q[Q_LEN];
|
||||
bool is_empty;
|
||||
|
||||
public:
|
||||
void pop()
|
||||
{
|
||||
if (counter == 0)
|
||||
return;
|
||||
head++;
|
||||
head %= Q_LEN;
|
||||
counter--;
|
||||
if (counter == 0)
|
||||
is_empty = true;
|
||||
return;
|
||||
}
|
||||
Operation_Logger_Type front()
|
||||
{
|
||||
return q[head];
|
||||
}
|
||||
Operation_Logger_Type back()
|
||||
{
|
||||
return q[tail];
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
head = 0;
|
||||
tail = 0;
|
||||
counter = 0;
|
||||
is_empty = true;
|
||||
return;
|
||||
}
|
||||
void push(Operation_Logger_Type op)
|
||||
{
|
||||
q[tail] = op;
|
||||
counter++;
|
||||
if (is_empty)
|
||||
is_empty = false;
|
||||
tail++;
|
||||
tail %= Q_LEN;
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
return is_empty;
|
||||
}
|
||||
int size()
|
||||
{
|
||||
return counter;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
// Multi-thread Tree Rebuild
|
||||
bool termination_flag = false;
|
||||
bool rebuild_flag = false;
|
||||
pthread_t rebuild_thread;
|
||||
pthread_mutex_t termination_flag_mutex_lock, rebuild_ptr_mutex_lock, working_flag_mutex, search_flag_mutex;
|
||||
pthread_mutex_t rebuild_logger_mutex_lock, points_deleted_rebuild_mutex_lock;
|
||||
// queue<Operation_Logger_Type> Rebuild_Logger;
|
||||
MANUAL_Q Rebuild_Logger;
|
||||
PointVector Rebuild_PCL_Storage;
|
||||
KD_TREE_NODE **Rebuild_Ptr = nullptr;
|
||||
int search_mutex_counter = 0;
|
||||
static void *multi_thread_ptr(void *arg);
|
||||
void multi_thread_rebuild();
|
||||
void start_thread();
|
||||
void stop_thread();
|
||||
void run_operation(KD_TREE_NODE **root, Operation_Logger_Type operation);
|
||||
// KD Tree Functions and augmented variables
|
||||
int Treesize_tmp = 0, Validnum_tmp = 0;
|
||||
float alpha_bal_tmp = 0.5, alpha_del_tmp = 0.0;
|
||||
float delete_criterion_param = 0.5f;
|
||||
float balance_criterion_param = 0.7f;
|
||||
float downsample_size = 0.2f;
|
||||
bool Delete_Storage_Disabled = false;
|
||||
KD_TREE_NODE *STATIC_ROOT_NODE = nullptr;
|
||||
PointVector Points_deleted;
|
||||
PointVector Downsample_Storage;
|
||||
PointVector Multithread_Points_deleted;
|
||||
void InitTreeNode(KD_TREE_NODE *root);
|
||||
void Test_Lock_States(KD_TREE_NODE *root);
|
||||
void BuildTree(KD_TREE_NODE **root, int l, int r, PointVector &Storage);
|
||||
void Rebuild(KD_TREE_NODE **root);
|
||||
int Delete_by_range(KD_TREE_NODE **root, BoxPointType boxpoint, bool allow_rebuild, bool is_downsample);
|
||||
void Delete_by_point(KD_TREE_NODE **root, PointType point, bool allow_rebuild);
|
||||
void Add_by_point(KD_TREE_NODE **root, PointType point, bool allow_rebuild, int father_axis);
|
||||
void Add_by_range(KD_TREE_NODE **root, BoxPointType boxpoint, bool allow_rebuild);
|
||||
void Search(KD_TREE_NODE *root, int k_nearest, PointType point, MANUAL_HEAP &q, float max_dist); //priority_queue<PointType_CMP>
|
||||
void Search_by_range(KD_TREE_NODE *root, BoxPointType boxpoint, PointVector &Storage);
|
||||
void Search_by_radius(KD_TREE_NODE *root, PointType point, float radius, PointVector &Storage);
|
||||
bool Criterion_Check(KD_TREE_NODE *root);
|
||||
void Push_Down(KD_TREE_NODE *root);
|
||||
void Update(KD_TREE_NODE *root);
|
||||
void delete_tree_nodes(KD_TREE_NODE **root);
|
||||
void downsample(KD_TREE_NODE **root);
|
||||
bool same_point(PointType a, PointType b);
|
||||
float calc_dist(PointType a, PointType b);
|
||||
float calc_box_dist(KD_TREE_NODE *node, PointType point);
|
||||
static bool point_cmp_x(PointType a, PointType b);
|
||||
static bool point_cmp_y(PointType a, PointType b);
|
||||
static bool point_cmp_z(PointType a, PointType b);
|
||||
|
||||
public:
|
||||
KD_TREE(float delete_param = 0.5, float balance_param = 0.6, float box_length = 0.2);
|
||||
~KD_TREE();
|
||||
void Set_delete_criterion_param(float delete_param)
|
||||
{
|
||||
delete_criterion_param = delete_param;
|
||||
}
|
||||
void Set_balance_criterion_param(float balance_param)
|
||||
{
|
||||
balance_criterion_param = balance_param;
|
||||
}
|
||||
void set_downsample_param(float downsample_param)
|
||||
{
|
||||
downsample_size = downsample_param;
|
||||
}
|
||||
void InitializeKDTree(float delete_param = 0.5, float balance_param = 0.7, float box_length = 0.2);
|
||||
int size();
|
||||
int validnum();
|
||||
void root_alpha(float &alpha_bal, float &alpha_del);
|
||||
void Build(PointVector point_cloud);
|
||||
void Nearest_Search(PointType point, int k_nearest, PointVector &Nearest_Points, vector<float> &Point_Distance, float max_dist = INFINITY);
|
||||
void Box_Search(const BoxPointType &Box_of_Point, PointVector &Storage);
|
||||
void Radius_Search(PointType point, const float radius, PointVector &Storage);
|
||||
int Add_Points(PointVector &PointToAdd, bool downsample_on);
|
||||
void Add_Point_Boxes(vector<BoxPointType> &BoxPoints);
|
||||
void Delete_Points(PointVector &PointToDel);
|
||||
int Delete_Point_Boxes(vector<BoxPointType> &BoxPoints);
|
||||
void flatten(KD_TREE_NODE *root, PointVector &Storage, delete_point_storage_set storage_type);
|
||||
void acquire_removed_points(PointVector &removed_points);
|
||||
BoxPointType tree_range();
|
||||
PointVector PCL_Storage;
|
||||
KD_TREE_NODE *Root_Node = nullptr;
|
||||
int max_queue_size = 0;
|
||||
};
|
||||
|
||||
// template <typename PointType>
|
||||
// PointType KD_TREE<PointType>::zeroP = PointType(0,0,0);
|
||||
@@ -0,0 +1,111 @@
|
||||
#ifndef SO3_MATH_H
|
||||
#define SO3_MATH_H
|
||||
|
||||
#include <math.h>
|
||||
#include <Eigen/Core>
|
||||
|
||||
#define SKEW_SYM_MATRX(v) 0.0,-v[2],v[1],v[2],0.0,-v[0],-v[1],v[0],0.0
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 3> skew_sym_mat(const Eigen::Matrix<T, 3, 1> &v)
|
||||
{
|
||||
Eigen::Matrix<T, 3, 3> skew_sym_mat;
|
||||
skew_sym_mat<<0.0,-v[2],v[1],v[2],0.0,-v[0],-v[1],v[0],0.0;
|
||||
return skew_sym_mat;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const Eigen::Matrix<T, 3, 1> &&ang)
|
||||
{
|
||||
T ang_norm = ang.norm();
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
if (ang_norm > 0.0000001)
|
||||
{
|
||||
Eigen::Matrix<T, 3, 1> r_axis = ang / ang_norm;
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
K << SKEW_SYM_MATRX(r_axis);
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(ang_norm) * K + (1.0 - std::cos(ang_norm)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Ts>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const Eigen::Matrix<T, 3, 1> &ang_vel, const Ts &dt)
|
||||
{
|
||||
T ang_vel_norm = ang_vel.norm();
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
|
||||
if (ang_vel_norm > 0.0000001)
|
||||
{
|
||||
Eigen::Matrix<T, 3, 1> r_axis = ang_vel / ang_vel_norm;
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
|
||||
K << SKEW_SYM_MATRX(r_axis);
|
||||
|
||||
T r_ang = ang_vel_norm * dt;
|
||||
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(r_ang) * K + (1.0 - std::cos(r_ang)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 3> Exp(const T &v1, const T &v2, const T &v3)
|
||||
{
|
||||
T &&norm = sqrt(v1 * v1 + v2 * v2 + v3 * v3);
|
||||
Eigen::Matrix<T, 3, 3> Eye3 = Eigen::Matrix<T, 3, 3>::Identity();
|
||||
if (norm > 0.00001)
|
||||
{
|
||||
T r_ang[3] = {v1 / norm, v2 / norm, v3 / norm};
|
||||
Eigen::Matrix<T, 3, 3> K;
|
||||
K << SKEW_SYM_MATRX(r_ang);
|
||||
|
||||
/// Roderigous Tranformation
|
||||
return Eye3 + std::sin(norm) * K + (1.0 - std::cos(norm)) * K * K;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Eye3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Logrithm of a Rotation Matrix */
|
||||
template<typename T>
|
||||
Eigen::Matrix<T,3,1> Log(const Eigen::Matrix<T, 3, 3> &R)
|
||||
{
|
||||
T theta = (R.trace() > 3.0 - 1e-6) ? 0.0 : std::acos(0.5 * (R.trace() - 1));
|
||||
Eigen::Matrix<T,3,1> K(R(2,1) - R(1,2), R(0,2) - R(2,0), R(1,0) - R(0,1));
|
||||
return (std::abs(theta) < 0.001) ? (0.5 * K) : (0.5 * theta / std::sin(theta) * K);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Eigen::Matrix<T, 3, 1> RotMtoEuler(const Eigen::Matrix<T, 3, 3> &rot)
|
||||
{
|
||||
T sy = sqrt(rot(0,0)*rot(0,0) + rot(1,0)*rot(1,0));
|
||||
bool singular = sy < 1e-6;
|
||||
T x, y, z;
|
||||
if(!singular)
|
||||
{
|
||||
x = atan2(rot(2, 1), rot(2, 2));
|
||||
y = atan2(-rot(2, 0), sy);
|
||||
z = atan2(rot(1, 0), rot(0, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
x = atan2(-rot(1, 2), rot(1, 1));
|
||||
y = atan2(-rot(2, 0), sy);
|
||||
z = 0;
|
||||
}
|
||||
Eigen::Matrix<T, 3, 1> ang(x, y, z);
|
||||
return ang;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
#ifndef USE_IKFOM_H
|
||||
#define USE_IKFOM_H
|
||||
|
||||
#include <IKFoM_toolkit/esekfom/esekfom.hpp>
|
||||
|
||||
typedef MTK::vect<3, double> vect3;
|
||||
typedef MTK::SO3<double> SO3;
|
||||
typedef MTK::S2<double, 98090, 10000, 1> S2;
|
||||
typedef MTK::vect<1, double> vect1;
|
||||
typedef MTK::vect<2, double> vect2;
|
||||
|
||||
MTK_BUILD_MANIFOLD(state_ikfom,
|
||||
((vect3, pos))
|
||||
((SO3, rot))
|
||||
((SO3, offset_R_L_I))
|
||||
((vect3, offset_T_L_I))
|
||||
((vect3, vel))
|
||||
((vect3, bg))
|
||||
((vect3, ba))
|
||||
((S2, grav))
|
||||
);
|
||||
|
||||
MTK_BUILD_MANIFOLD(input_ikfom,
|
||||
((vect3, acc))
|
||||
((vect3, gyro))
|
||||
);
|
||||
|
||||
MTK_BUILD_MANIFOLD(process_noise_ikfom,
|
||||
((vect3, ng))
|
||||
((vect3, na))
|
||||
((vect3, nbg))
|
||||
((vect3, nba))
|
||||
);
|
||||
|
||||
MTK::get_cov<process_noise_ikfom>::type process_noise_cov()
|
||||
{
|
||||
MTK::get_cov<process_noise_ikfom>::type cov = MTK::get_cov<process_noise_ikfom>::type::Zero();
|
||||
MTK::setDiagonal<process_noise_ikfom, vect3, 0>(cov, &process_noise_ikfom::ng, 0.0001);// 0.03
|
||||
MTK::setDiagonal<process_noise_ikfom, vect3, 3>(cov, &process_noise_ikfom::na, 0.0001); // *dt 0.01 0.01 * dt * dt 0.05
|
||||
MTK::setDiagonal<process_noise_ikfom, vect3, 6>(cov, &process_noise_ikfom::nbg, 0.00001); // *dt 0.00001 0.00001 * dt *dt 0.3 //0.001 0.0001 0.01
|
||||
MTK::setDiagonal<process_noise_ikfom, vect3, 9>(cov, &process_noise_ikfom::nba, 0.00001); //0.001 0.05 0.0001/out 0.01
|
||||
return cov;
|
||||
}
|
||||
|
||||
//double L_offset_to_I[3] = {0.04165, 0.02326, -0.0284}; // Avia
|
||||
//vect3 Lidar_offset_to_IMU(L_offset_to_I, 3);
|
||||
Eigen::Matrix<double, 24, 1> get_f(state_ikfom &s, const input_ikfom &in)
|
||||
{
|
||||
Eigen::Matrix<double, 24, 1> res = Eigen::Matrix<double, 24, 1>::Zero();
|
||||
vect3 omega;
|
||||
in.gyro.boxminus(omega, s.bg);
|
||||
vect3 a_inertial = s.rot * (in.acc-s.ba);
|
||||
for(int i = 0; i < 3; i++ ){
|
||||
res(i) = s.vel[i];
|
||||
res(i + 3) = omega[i];
|
||||
res(i + 12) = a_inertial[i] + s.grav[i];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Eigen::Matrix<double, 24, 23> df_dx(state_ikfom &s, const input_ikfom &in)
|
||||
{
|
||||
Eigen::Matrix<double, 24, 23> cov = Eigen::Matrix<double, 24, 23>::Zero();
|
||||
cov.template block<3, 3>(0, 12) = Eigen::Matrix3d::Identity();
|
||||
vect3 acc_;
|
||||
in.acc.boxminus(acc_, s.ba);
|
||||
vect3 omega;
|
||||
in.gyro.boxminus(omega, s.bg);
|
||||
cov.template block<3, 3>(12, 3) = -s.rot.toRotationMatrix()*MTK::hat(acc_);
|
||||
cov.template block<3, 3>(12, 18) = -s.rot.toRotationMatrix();
|
||||
Eigen::Matrix<state_ikfom::scalar, 2, 1> vec = Eigen::Matrix<state_ikfom::scalar, 2, 1>::Zero();
|
||||
Eigen::Matrix<state_ikfom::scalar, 3, 2> grav_matrix;
|
||||
s.S2_Mx(grav_matrix, vec, 21);
|
||||
cov.template block<3, 2>(12, 21) = grav_matrix;
|
||||
cov.template block<3, 3>(3, 15) = -Eigen::Matrix3d::Identity();
|
||||
return cov;
|
||||
}
|
||||
|
||||
|
||||
Eigen::Matrix<double, 24, 12> df_dw(state_ikfom &s, const input_ikfom &in)
|
||||
{
|
||||
Eigen::Matrix<double, 24, 12> cov = Eigen::Matrix<double, 24, 12>::Zero();
|
||||
cov.template block<3, 3>(12, 3) = -s.rot.toRotationMatrix();
|
||||
cov.template block<3, 3>(3, 0) = -Eigen::Matrix3d::Identity();
|
||||
cov.template block<3, 3>(15, 6) = Eigen::Matrix3d::Identity();
|
||||
cov.template block<3, 3>(18, 9) = Eigen::Matrix3d::Identity();
|
||||
return cov;
|
||||
}
|
||||
|
||||
vect3 SO3ToEuler(const SO3 &orient)
|
||||
{
|
||||
Eigen::Matrix<double, 3, 1> _ang;
|
||||
Eigen::Vector4d q_data = orient.coeffs().transpose();
|
||||
//scalar w=orient.coeffs[3], x=orient.coeffs[0], y=orient.coeffs[1], z=orient.coeffs[2];
|
||||
double sqw = q_data[3]*q_data[3];
|
||||
double sqx = q_data[0]*q_data[0];
|
||||
double sqy = q_data[1]*q_data[1];
|
||||
double sqz = q_data[2]*q_data[2];
|
||||
double unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise is correction factor
|
||||
double test = q_data[3]*q_data[1] - q_data[2]*q_data[0];
|
||||
|
||||
if (test > 0.49999*unit) { // singularity at north pole
|
||||
|
||||
_ang << 2 * std::atan2(q_data[0], q_data[3]), M_PI/2, 0;
|
||||
double temp[3] = {_ang[0] * 57.3, _ang[1] * 57.3, _ang[2] * 57.3};
|
||||
vect3 euler_ang(temp, 3);
|
||||
return euler_ang;
|
||||
}
|
||||
if (test < -0.49999*unit) { // singularity at south pole
|
||||
_ang << -2 * std::atan2(q_data[0], q_data[3]), -M_PI/2, 0;
|
||||
double temp[3] = {_ang[0] * 57.3, _ang[1] * 57.3, _ang[2] * 57.3};
|
||||
vect3 euler_ang(temp, 3);
|
||||
return euler_ang;
|
||||
}
|
||||
|
||||
_ang <<
|
||||
std::atan2(2*q_data[0]*q_data[3]+2*q_data[1]*q_data[2] , -sqx - sqy + sqz + sqw),
|
||||
std::asin (2*test/unit),
|
||||
std::atan2(2*q_data[2]*q_data[3]+2*q_data[1]*q_data[0] , sqx - sqy - sqz + sqw);
|
||||
double temp[3] = {_ang[0] * 57.3, _ang[1] * 57.3, _ang[2] * 57.3};
|
||||
vect3 euler_ang(temp, 3);
|
||||
// euler_ang[0] = roll, euler_ang[1] = pitch, euler_ang[2] = yaw
|
||||
return euler_ang;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
import os.path
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
||||
from launch.conditions import IfCondition
|
||||
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
package_path = get_package_share_directory('fast_lio')
|
||||
default_config_path = os.path.join(package_path, 'config')
|
||||
default_rviz_config_path = os.path.join(
|
||||
package_path, 'rviz', 'fastlio.rviz')
|
||||
|
||||
use_sim_time = LaunchConfiguration('use_sim_time')
|
||||
config_path = LaunchConfiguration('config_path')
|
||||
config_file = LaunchConfiguration('config_file')
|
||||
rviz_use = LaunchConfiguration('rviz')
|
||||
rviz_cfg = LaunchConfiguration('rviz_cfg')
|
||||
|
||||
declare_use_sim_time_cmd = DeclareLaunchArgument(
|
||||
'use_sim_time', default_value='true',
|
||||
description='Use simulation (Gazebo) clock if true'
|
||||
)
|
||||
declare_config_path_cmd = DeclareLaunchArgument(
|
||||
'config_path', default_value=default_config_path,
|
||||
description='Yaml config file path'
|
||||
)
|
||||
decalre_config_file_cmd = DeclareLaunchArgument(
|
||||
'config_file', default_value='carla.yaml',
|
||||
description='Config file'
|
||||
)
|
||||
declare_rviz_cmd = DeclareLaunchArgument(
|
||||
'rviz', default_value='true',
|
||||
description='Use RViz to monitor results'
|
||||
)
|
||||
declare_rviz_config_path_cmd = DeclareLaunchArgument(
|
||||
'rviz_cfg', default_value=default_rviz_config_path,
|
||||
description='RViz config file path'
|
||||
)
|
||||
|
||||
fast_lio_node = Node(
|
||||
package='fast_lio',
|
||||
executable='fastlio_mapping',
|
||||
parameters=[PathJoinSubstitution([config_path, config_file]),
|
||||
{'use_sim_time': use_sim_time}],
|
||||
output='screen'
|
||||
)
|
||||
rviz_node = Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
arguments=['-d', rviz_cfg],
|
||||
condition=IfCondition(rviz_use)
|
||||
)
|
||||
|
||||
ld = LaunchDescription()
|
||||
ld.add_action(declare_use_sim_time_cmd)
|
||||
ld.add_action(declare_config_path_cmd)
|
||||
ld.add_action(decalre_config_file_cmd)
|
||||
ld.add_action(declare_rviz_cmd)
|
||||
ld.add_action(declare_rviz_config_path_cmd)
|
||||
|
||||
ld.add_action(fast_lio_node)
|
||||
ld.add_action(rviz_node)
|
||||
|
||||
return ld
|
||||
@@ -0,0 +1,22 @@
|
||||
<launch>
|
||||
|
||||
<arg name="rviz" default="true" />
|
||||
|
||||
<node pkg="fast_lio" type="fastlio_mapping" name="laserMapping" output="screen" required="true" launch-prefix="gdb -ex run --args">
|
||||
<param name="imu_topic" type="string" value="/livox/imu" />
|
||||
<param name="map_file_path" type="string" value=" " />
|
||||
<param name="max_iteration" type="int" value="4" />
|
||||
<param name="dense_map_enable" type="bool" value="1" />
|
||||
<param name="fov_degree" type="double" value="75" />
|
||||
<param name="filter_size_corner" type="double" value="0.2" />
|
||||
<param name="filter_size_surf" type="double" value="0.2" />
|
||||
<param name="filter_size_map" type="double" value="0.5" />
|
||||
<param name="runtime_pos_log_enable" type="bool" value="1" />
|
||||
<param name="cube_side_length" type="double" value="2000" />
|
||||
</node>
|
||||
|
||||
<!-- <group if="$(arg rviz)">
|
||||
<node launch-prefix="nice" pkg="rviz" type="rviz" name="rviz" args="-d $(find fast_lio)/rviz_cfg/loam_livox.rviz" />
|
||||
</group> -->
|
||||
|
||||
</launch>
|
||||
@@ -0,0 +1,70 @@
|
||||
import os.path
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
|
||||
from launch.conditions import IfCondition
|
||||
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
package_path = get_package_share_directory('fast_lio')
|
||||
default_config_path = os.path.join(package_path, 'config')
|
||||
default_rviz_config_path = os.path.join(
|
||||
package_path, 'rviz', 'fastlio.rviz')
|
||||
|
||||
use_sim_time = LaunchConfiguration('use_sim_time')
|
||||
config_path = LaunchConfiguration('config_path')
|
||||
config_file = LaunchConfiguration('config_file')
|
||||
rviz_use = LaunchConfiguration('rviz')
|
||||
rviz_cfg = LaunchConfiguration('rviz_cfg')
|
||||
|
||||
declare_use_sim_time_cmd = DeclareLaunchArgument(
|
||||
'use_sim_time', default_value='false',
|
||||
description='Use simulation (Gazebo) clock if true'
|
||||
)
|
||||
declare_config_path_cmd = DeclareLaunchArgument(
|
||||
'config_path', default_value=default_config_path,
|
||||
description='Yaml config file path'
|
||||
)
|
||||
decalre_config_file_cmd = DeclareLaunchArgument(
|
||||
'config_file', default_value='pandar64.yaml',
|
||||
description='Config file'
|
||||
)
|
||||
declare_rviz_cmd = DeclareLaunchArgument(
|
||||
'rviz', default_value='true',
|
||||
description='Use RViz to monitor results'
|
||||
)
|
||||
declare_rviz_config_path_cmd = DeclareLaunchArgument(
|
||||
'rviz_cfg', default_value=default_rviz_config_path,
|
||||
description='RViz config file path'
|
||||
)
|
||||
|
||||
fast_lio_node = Node(
|
||||
package='fast_lio',
|
||||
executable='fastlio_mapping',
|
||||
parameters=[PathJoinSubstitution([config_path, config_file]),
|
||||
{'use_sim_time': use_sim_time}],
|
||||
output='screen'
|
||||
)
|
||||
rviz_node = Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
arguments=['-d', rviz_cfg],
|
||||
condition=IfCondition(rviz_use)
|
||||
)
|
||||
|
||||
ld = LaunchDescription()
|
||||
ld.add_action(declare_use_sim_time_cmd)
|
||||
ld.add_action(declare_config_path_cmd)
|
||||
ld.add_action(decalre_config_file_cmd)
|
||||
ld.add_action(declare_rviz_cmd)
|
||||
ld.add_action(declare_rviz_config_path_cmd)
|
||||
|
||||
ld.add_action(fast_lio_node)
|
||||
ld.add_action(rviz_node)
|
||||
|
||||
return ld
|
||||
@@ -0,0 +1,7 @@
|
||||
# the preintegrated Lidar states at the time of IMU measurements in a frame
|
||||
float64 offset_time # the offset time of IMU measurement w.r.t the first lidar point
|
||||
float64[3] acc # the preintegrated total acceleration (global frame) at the Lidar origin
|
||||
float64[3] gyr # the unbiased angular velocity (body frame) at the Lidar origin
|
||||
float64[3] vel # the preintegrated velocity (global frame) at the Lidar origin
|
||||
float64[3] pos # the preintegrated position (global frame) at the Lidar origin
|
||||
float64[9] rot # the preintegrated rotation (global frame) at the Lidar origin
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0"?>
|
||||
<package format="3">
|
||||
<name>fast_lio</name>
|
||||
<version>0.0.0</version>
|
||||
|
||||
<description>
|
||||
This is a modified version of LOAM which is original algorithm
|
||||
is described in the following paper:
|
||||
J. Zhang and S. Singh. LOAM: Lidar Odometry and Mapping in Real-time.
|
||||
Robotics: Science and Systems Conference (RSS). Berkeley, CA, July 2014.
|
||||
</description>
|
||||
|
||||
<maintainer email="dev@livoxtech.com">claydergc</maintainer>
|
||||
|
||||
<license>BSD</license>
|
||||
|
||||
<author email="zhangji@cmu.edu">Ji Zhang</author>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
<buildtool_depend>rosidl_default_generators</buildtool_depend>
|
||||
<depend>geometry_msgs</depend>
|
||||
<depend>nav_msgs</depend>
|
||||
<depend>rclcpp</depend>
|
||||
<depend>std_msgs</depend>
|
||||
<depend>sensor_msgs</depend>
|
||||
<depend>common_interfaces</depend>
|
||||
<depend>tf2</depend>
|
||||
<depend>pcl_ros</depend>
|
||||
<depend>pcl_conversions</depend>
|
||||
<depend>livox_ros_driver2</depend>
|
||||
|
||||
<exec_depend>rosidl_default_runtime</exec_depend>
|
||||
<member_of_group>rosidl_interface_packages</member_of_group>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
@@ -0,0 +1,304 @@
|
||||
Panels:
|
||||
- Class: rviz_common/Displays
|
||||
Help Height: 78
|
||||
Name: Displays
|
||||
Property Tree Widget:
|
||||
Expanded:
|
||||
- /Global Options1
|
||||
- /Status1
|
||||
Splitter Ratio: 0.5
|
||||
Tree Height: 549
|
||||
- Class: rviz_common/Selection
|
||||
Name: Selection
|
||||
- Class: rviz_common/Tool Properties
|
||||
Expanded:
|
||||
- /2D Goal Pose1
|
||||
- /Publish Point1
|
||||
Name: Tool Properties
|
||||
Splitter Ratio: 0.5886790156364441
|
||||
- Class: rviz_common/Views
|
||||
Expanded:
|
||||
- /Current View1
|
||||
Name: Views
|
||||
Splitter Ratio: 0.5
|
||||
- Class: rviz_common/Time
|
||||
Experimental: false
|
||||
Name: Time
|
||||
SyncMode: 0
|
||||
SyncSource: CloudRegistered
|
||||
Visualization Manager:
|
||||
Class: ""
|
||||
Displays:
|
||||
- Class: rviz_default_plugins/TF
|
||||
Enabled: true
|
||||
Frame Timeout: 15
|
||||
Frames:
|
||||
All Enabled: true
|
||||
body:
|
||||
Value: true
|
||||
camera_init:
|
||||
Value: true
|
||||
Marker Scale: 1
|
||||
Name: TF
|
||||
Show Arrows: true
|
||||
Show Axes: true
|
||||
Show Names: false
|
||||
Tree:
|
||||
camera_init:
|
||||
body:
|
||||
{}
|
||||
Update Interval: 0
|
||||
Value: true
|
||||
- Angle Tolerance: 0.10000000149011612
|
||||
Class: rviz_default_plugins/Odometry
|
||||
Covariance:
|
||||
Orientation:
|
||||
Alpha: 0.5
|
||||
Color: 255; 255; 127
|
||||
Color Style: Unique
|
||||
Frame: Local
|
||||
Offset: 1
|
||||
Scale: 1
|
||||
Value: true
|
||||
Position:
|
||||
Alpha: 0.30000001192092896
|
||||
Color: 204; 51; 204
|
||||
Scale: 1
|
||||
Value: true
|
||||
Value: true
|
||||
Enabled: true
|
||||
Keep: 100
|
||||
Name: Odometry
|
||||
Position Tolerance: 0.10000000149011612
|
||||
Shape:
|
||||
Alpha: 1
|
||||
Axes Length: 1
|
||||
Axes Radius: 0.10000000149011612
|
||||
Color: 255; 25; 0
|
||||
Head Length: 0.30000001192092896
|
||||
Head Radius: 0.10000000149011612
|
||||
Shaft Length: 1
|
||||
Shaft Radius: 0.05000000074505806
|
||||
Value: Arrow
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
Filter size: 10
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /Odometry
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Buffer Length: 1
|
||||
Class: rviz_default_plugins/Path
|
||||
Color: 25; 255; 0
|
||||
Enabled: true
|
||||
Head Diameter: 0.30000001192092896
|
||||
Head Length: 0.20000000298023224
|
||||
Length: 0.30000001192092896
|
||||
Line Style: Lines
|
||||
Line Width: 0.029999999329447746
|
||||
Name: Path
|
||||
Offset:
|
||||
X: 0
|
||||
Y: 0
|
||||
Z: 0
|
||||
Pose Color: 255; 85; 255
|
||||
Pose Style: None
|
||||
Radius: 0.029999999329447746
|
||||
Shaft Diameter: 0.10000000149011612
|
||||
Shaft Length: 0.10000000149011612
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
Filter size: 10
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /path
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 11.062739372253418
|
||||
Min Value: -13.864188194274902
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz_default_plugins/PointCloud2
|
||||
Color: 255; 255; 255
|
||||
Color Transformer: AxisColor
|
||||
Decay Time: 30
|
||||
Enabled: true
|
||||
Invert Rainbow: false
|
||||
Max Color: 255; 255; 255
|
||||
Max Intensity: 186
|
||||
Min Color: 0; 0; 0
|
||||
Min Intensity: 0
|
||||
Name: CloudRegistered
|
||||
Position Transformer: XYZ
|
||||
Selectable: true
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.05000000074505806
|
||||
Style: Flat Squares
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
Filter size: 10
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /cloud_registered
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 10
|
||||
Min Value: -10
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz_default_plugins/PointCloud2
|
||||
Color: 255; 255; 255
|
||||
Color Transformer: Intensity
|
||||
Decay Time: 0
|
||||
Enabled: true
|
||||
Invert Rainbow: false
|
||||
Max Color: 255; 255; 255
|
||||
Max Intensity: 184
|
||||
Min Color: 0; 0; 0
|
||||
Min Intensity: 0
|
||||
Name: CloudEffected
|
||||
Position Transformer: XYZ
|
||||
Selectable: true
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.10000000149011612
|
||||
Style: Flat Squares
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
Filter size: 10
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /cloud_effected
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: -9999
|
||||
Min Value: 9999
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz_default_plugins/PointCloud2
|
||||
Color: 255; 255; 255
|
||||
Color Transformer: AxisColor
|
||||
Decay Time: 0
|
||||
Enabled: true
|
||||
Invert Rainbow: false
|
||||
Max Color: 255; 255; 255
|
||||
Max Intensity: 255
|
||||
Min Color: 0; 0; 0
|
||||
Min Intensity: 0
|
||||
Name: CloudMap
|
||||
Position Transformer: XYZ
|
||||
Selectable: true
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.05000000074505806
|
||||
Style: Flat Squares
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
Filter size: 10
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /Laser_map
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: true
|
||||
Enabled: true
|
||||
Global Options:
|
||||
Background Color: 0; 0; 0
|
||||
Fixed Frame: camera_init
|
||||
Frame Rate: 30
|
||||
Name: root
|
||||
Tools:
|
||||
- Class: rviz_default_plugins/Interact
|
||||
Hide Inactive Objects: true
|
||||
- Class: rviz_default_plugins/MoveCamera
|
||||
- Class: rviz_default_plugins/Select
|
||||
- Class: rviz_default_plugins/FocusCamera
|
||||
- Class: rviz_default_plugins/Measure
|
||||
Line color: 128; 128; 0
|
||||
- Class: rviz_default_plugins/SetInitialPose
|
||||
Covariance x: 0.25
|
||||
Covariance y: 0.25
|
||||
Covariance yaw: 0.06853891909122467
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /initialpose
|
||||
- Class: rviz_default_plugins/SetGoal
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /goal_pose
|
||||
- Class: rviz_default_plugins/PublishPoint
|
||||
Single click: true
|
||||
Topic:
|
||||
Depth: 5
|
||||
Durability Policy: Volatile
|
||||
History Policy: Keep Last
|
||||
Reliability Policy: Reliable
|
||||
Value: /clicked_point
|
||||
Transformation:
|
||||
Current:
|
||||
Class: rviz_default_plugins/TF
|
||||
Value: true
|
||||
Views:
|
||||
Current:
|
||||
Class: rviz_default_plugins/Orbit
|
||||
Distance: 216.99887084960938
|
||||
Enable Stereo Rendering:
|
||||
Stereo Eye Separation: 0.05999999865889549
|
||||
Stereo Focal Distance: 1
|
||||
Swap Stereo Eyes: false
|
||||
Value: false
|
||||
Focal Point:
|
||||
X: -0.008504047989845276
|
||||
Y: -0.0005770106799900532
|
||||
Z: 0.034441977739334106
|
||||
Focal Shape Fixed Size: true
|
||||
Focal Shape Size: 0.05000000074505806
|
||||
Invert Z Axis: false
|
||||
Name: Current View
|
||||
Near Clip Distance: 0.009999999776482582
|
||||
Pitch: 1.5697963237762451
|
||||
Target Frame: <Fixed Frame>
|
||||
Value: Orbit (rviz_default_plugins)
|
||||
Yaw: 4.88355827331543
|
||||
Saved: ~
|
||||
Window Geometry:
|
||||
Displays:
|
||||
collapsed: false
|
||||
Height: 846
|
||||
Hide Left Dock: false
|
||||
Hide Right Dock: false
|
||||
QMainWindow State: 000000ff00000000fd000000040000000000000156000002b0fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002b0000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002b0fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000003d000002b0000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000005ad0000003efc0100000002fb0000000800540069006d00650100000000000005ad000002fb00fffffffb0000000800540069006d0065010000000000000450000000000000000000000451000002b000000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
|
||||
Selection:
|
||||
collapsed: false
|
||||
Time:
|
||||
collapsed: false
|
||||
Tool Properties:
|
||||
collapsed: false
|
||||
Views:
|
||||
collapsed: false
|
||||
Width: 1453
|
||||
X: 368
|
||||
Y: 104
|
||||
@@ -0,0 +1,358 @@
|
||||
Panels:
|
||||
- Class: rviz/Displays
|
||||
Help Height: 0
|
||||
Name: Displays
|
||||
Property Tree Widget:
|
||||
Expanded:
|
||||
- /Global Options1
|
||||
- /mapping1
|
||||
- /mapping1/surround1
|
||||
- /mapping1/currPoints1
|
||||
- /mapping1/currPoints1/Autocompute Value Bounds1
|
||||
- /Odometry1/Odometry1
|
||||
- /Odometry1/Odometry1/Shape1
|
||||
- /Odometry1/Odometry1/Covariance1
|
||||
- /Odometry1/Odometry1/Covariance1/Position1
|
||||
- /Odometry1/Odometry1/Covariance1/Orientation1
|
||||
- /MarkerArray1/Namespaces1
|
||||
Splitter Ratio: 0.6432291865348816
|
||||
Tree Height: 811
|
||||
- Class: rviz/Selection
|
||||
Name: Selection
|
||||
- Class: rviz/Tool Properties
|
||||
Expanded:
|
||||
- /2D Pose Estimate1
|
||||
- /2D Nav Goal1
|
||||
- /Publish Point1
|
||||
Name: Tool Properties
|
||||
Splitter Ratio: 0.5886790156364441
|
||||
- Class: rviz/Views
|
||||
Expanded:
|
||||
- /Current View1
|
||||
Name: Views
|
||||
Splitter Ratio: 0.5
|
||||
- Class: rviz/Time
|
||||
Experimental: false
|
||||
Name: Time
|
||||
SyncMode: 0
|
||||
SyncSource: surround
|
||||
Preferences:
|
||||
PromptSaveOnExit: true
|
||||
Toolbars:
|
||||
toolButtonStyle: 2
|
||||
Visualization Manager:
|
||||
Class: ""
|
||||
Displays:
|
||||
- Alpha: 1
|
||||
Cell Size: 1000
|
||||
Class: rviz/Grid
|
||||
Color: 160; 160; 164
|
||||
Enabled: false
|
||||
Line Style:
|
||||
Line Width: 0.029999999329447746
|
||||
Value: Lines
|
||||
Name: Grid
|
||||
Normal Cell Count: 0
|
||||
Offset:
|
||||
X: 0
|
||||
Y: 0
|
||||
Z: 0
|
||||
Plane: XY
|
||||
Plane Cell Count: 40
|
||||
Reference Frame: <Fixed Frame>
|
||||
Value: false
|
||||
- Class: rviz/Axes
|
||||
Enabled: false
|
||||
Length: 0.699999988079071
|
||||
Name: Axes
|
||||
Radius: 0.05999999865889549
|
||||
Reference Frame: <Fixed Frame>
|
||||
Value: false
|
||||
- Class: rviz/Group
|
||||
Displays:
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 10
|
||||
Min Value: -10
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz/PointCloud2
|
||||
Color: 238; 238; 236
|
||||
Color Transformer: Intensity
|
||||
Decay Time: 0
|
||||
Enabled: true
|
||||
Invert Rainbow: false
|
||||
Max Color: 255; 255; 255
|
||||
Min Color: 238; 238; 236
|
||||
Name: surround
|
||||
Position Transformer: XYZ
|
||||
Queue Size: 1
|
||||
Selectable: false
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.05000000074505806
|
||||
Style: Points
|
||||
Topic: /cloud_registered
|
||||
Unreliable: false
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: true
|
||||
- Alpha: 0.10000000149011612
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 15
|
||||
Min Value: -5
|
||||
Value: false
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz/PointCloud2
|
||||
Color: 255; 255; 255
|
||||
Color Transformer: Intensity
|
||||
Decay Time: 1000
|
||||
Enabled: true
|
||||
Invert Rainbow: true
|
||||
Max Color: 255; 255; 255
|
||||
Min Color: 0; 0; 0
|
||||
Name: currPoints
|
||||
Position Transformer: XYZ
|
||||
Queue Size: 100000
|
||||
Selectable: true
|
||||
Size (Pixels): 1
|
||||
Size (m): 0.009999999776482582
|
||||
Style: Points
|
||||
Topic: /cloud_registered
|
||||
Unreliable: false
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 10
|
||||
Min Value: -10
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz/PointCloud2
|
||||
Color: 255; 0; 0
|
||||
Color Transformer: FlatColor
|
||||
Decay Time: 0
|
||||
Enabled: false
|
||||
Invert Rainbow: false
|
||||
Max Color: 255; 255; 255
|
||||
Min Color: 0; 0; 0
|
||||
Name: PointCloud2
|
||||
Position Transformer: XYZ
|
||||
Queue Size: 10
|
||||
Selectable: true
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.10000000149011612
|
||||
Style: Flat Squares
|
||||
Topic: /Laser_map
|
||||
Unreliable: false
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: false
|
||||
Enabled: true
|
||||
Name: mapping
|
||||
- Class: rviz/Group
|
||||
Displays:
|
||||
- Angle Tolerance: 0.009999999776482582
|
||||
Class: rviz/Odometry
|
||||
Covariance:
|
||||
Orientation:
|
||||
Alpha: 0.5
|
||||
Color: 255; 255; 127
|
||||
Color Style: Unique
|
||||
Frame: Local
|
||||
Offset: 1
|
||||
Scale: 1
|
||||
Value: true
|
||||
Position:
|
||||
Alpha: 0.30000001192092896
|
||||
Color: 204; 51; 204
|
||||
Scale: 1
|
||||
Value: true
|
||||
Value: true
|
||||
Enabled: true
|
||||
Keep: 1
|
||||
Name: Odometry
|
||||
Position Tolerance: 0.0010000000474974513
|
||||
Shape:
|
||||
Alpha: 1
|
||||
Axes Length: 1
|
||||
Axes Radius: 0.20000000298023224
|
||||
Color: 255; 85; 0
|
||||
Head Length: 0
|
||||
Head Radius: 0
|
||||
Shaft Length: 0.05000000074505806
|
||||
Shaft Radius: 0.05000000074505806
|
||||
Value: Axes
|
||||
Topic: /Odometry
|
||||
Unreliable: false
|
||||
Value: true
|
||||
Enabled: true
|
||||
Name: Odometry
|
||||
- Class: rviz/Axes
|
||||
Enabled: true
|
||||
Length: 0.699999988079071
|
||||
Name: Axes
|
||||
Radius: 0.10000000149011612
|
||||
Reference Frame: <Fixed Frame>
|
||||
Value: true
|
||||
- Alpha: 0
|
||||
Buffer Length: 2
|
||||
Class: rviz/Path
|
||||
Color: 25; 255; 255
|
||||
Enabled: true
|
||||
Head Diameter: 0
|
||||
Head Length: 0
|
||||
Length: 0.30000001192092896
|
||||
Line Style: Billboards
|
||||
Line Width: 0.20000000298023224
|
||||
Name: Path
|
||||
Offset:
|
||||
X: 0
|
||||
Y: 0
|
||||
Z: 0
|
||||
Pose Color: 25; 255; 255
|
||||
Pose Style: None
|
||||
Radius: 0.029999999329447746
|
||||
Shaft Diameter: 0.4000000059604645
|
||||
Shaft Length: 0.4000000059604645
|
||||
Topic: /path
|
||||
Unreliable: false
|
||||
Value: true
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: false
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 10
|
||||
Min Value: -10
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz/PointCloud2
|
||||
Color: 255; 255; 255
|
||||
Color Transformer: Intensity
|
||||
Decay Time: 0
|
||||
Enabled: false
|
||||
Invert Rainbow: false
|
||||
Max Color: 239; 41; 41
|
||||
Max Intensity: 0
|
||||
Min Color: 239; 41; 41
|
||||
Min Intensity: 0
|
||||
Name: PointCloud2
|
||||
Position Transformer: XYZ
|
||||
Queue Size: 10
|
||||
Selectable: true
|
||||
Size (Pixels): 4
|
||||
Size (m): 0.30000001192092896
|
||||
Style: Spheres
|
||||
Topic: /cloud_effected
|
||||
Unreliable: false
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: false
|
||||
- Alpha: 1
|
||||
Autocompute Intensity Bounds: true
|
||||
Autocompute Value Bounds:
|
||||
Max Value: 13.139549255371094
|
||||
Min Value: -32.08251953125
|
||||
Value: true
|
||||
Axis: Z
|
||||
Channel Name: intensity
|
||||
Class: rviz/PointCloud2
|
||||
Color: 138; 226; 52
|
||||
Color Transformer: FlatColor
|
||||
Decay Time: 0
|
||||
Enabled: false
|
||||
Invert Rainbow: false
|
||||
Max Color: 138; 226; 52
|
||||
Min Color: 138; 226; 52
|
||||
Name: PointCloud2
|
||||
Position Transformer: XYZ
|
||||
Queue Size: 10
|
||||
Selectable: true
|
||||
Size (Pixels): 3
|
||||
Size (m): 0.10000000149011612
|
||||
Style: Flat Squares
|
||||
Topic: /Laser_map
|
||||
Unreliable: false
|
||||
Use Fixed Frame: true
|
||||
Use rainbow: true
|
||||
Value: false
|
||||
- Class: rviz/MarkerArray
|
||||
Enabled: false
|
||||
Marker Topic: /MarkerArray
|
||||
Name: MarkerArray
|
||||
Namespaces:
|
||||
{}
|
||||
Queue Size: 100
|
||||
Value: false
|
||||
Enabled: true
|
||||
Global Options:
|
||||
Background Color: 0; 0; 0
|
||||
Default Light: true
|
||||
Fixed Frame: camera_init
|
||||
Frame Rate: 10
|
||||
Name: root
|
||||
Tools:
|
||||
- Class: rviz/Interact
|
||||
Hide Inactive Objects: true
|
||||
- Class: rviz/MoveCamera
|
||||
- Class: rviz/Select
|
||||
- Class: rviz/FocusCamera
|
||||
- Class: rviz/Measure
|
||||
- Class: rviz/SetInitialPose
|
||||
Theta std deviation: 0.2617993950843811
|
||||
Topic: /initialpose
|
||||
X std deviation: 0.5
|
||||
Y std deviation: 0.5
|
||||
- Class: rviz/SetGoal
|
||||
Topic: /move_base_simple/goal
|
||||
- Class: rviz/PublishPoint
|
||||
Single click: true
|
||||
Topic: /clicked_point
|
||||
Value: true
|
||||
Views:
|
||||
Current:
|
||||
Class: rviz/Orbit
|
||||
Distance: 46.0853271484375
|
||||
Enable Stereo Rendering:
|
||||
Stereo Eye Separation: 0.05999999865889549
|
||||
Stereo Focal Distance: 1
|
||||
Swap Stereo Eyes: false
|
||||
Value: false
|
||||
Focal Point:
|
||||
X: -4.982542037963867
|
||||
Y: -15.83572006225586
|
||||
Z: -3.063523054122925
|
||||
Focal Shape Fixed Size: true
|
||||
Focal Shape Size: 0.05000000074505806
|
||||
Invert Z Axis: false
|
||||
Name: Current View
|
||||
Near Clip Distance: 0.009999999776482582
|
||||
Pitch: 0.399796724319458
|
||||
Target Frame: global
|
||||
Value: Orbit (rviz)
|
||||
Yaw: 1.277182698249817
|
||||
Saved: ~
|
||||
Window Geometry:
|
||||
Displays:
|
||||
collapsed: false
|
||||
Height: 1028
|
||||
Hide Left Dock: false
|
||||
Hide Right Dock: true
|
||||
QMainWindow State: 000000ff00000000fd0000000400000000000001c800000368fc020000000dfb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000002700000368000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000000a0049006d0061006700650000000297000001dc0000000000000000fb0000000a0049006d0061006700650000000394000001600000000000000000fb0000000a0049006d00610067006501000002c5000000c70000000000000000fb0000000a0049006d00610067006501000002c5000000c70000000000000000fb0000000a0049006d00610067006501000002c5000000c700000000000000000000000100000152000004b7fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000003d000004b7000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000061f00000052fc0100000002fb0000000800540069006d006501000000000000061f000002eb00fffffffb0000000800540069006d00650100000000000004500000000000000000000004510000036800000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
|
||||
Selection:
|
||||
collapsed: false
|
||||
Time:
|
||||
collapsed: false
|
||||
Tool Properties:
|
||||
collapsed: false
|
||||
Views:
|
||||
collapsed: true
|
||||
Width: 1567
|
||||
X: 67
|
||||
Y: 24
|
||||
@@ -0,0 +1,128 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(fast_lio)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
ADD_COMPILE_OPTIONS(-std=c++17)
|
||||
ADD_COMPILE_OPTIONS(-std=c++17)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++17 -O3")
|
||||
|
||||
add_definitions(-DROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -std=c++0x -std=c++14 -fexceptions")
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
message("Current CPU archtecture: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
|
||||
include(ProcessorCount)
|
||||
ProcessorCount(N)
|
||||
message("Processer number: ${N}")
|
||||
|
||||
if(N GREATER 4)
|
||||
add_definitions(-DMP_EN)
|
||||
add_definitions(-DMP_PROC_NUM=3)
|
||||
message("core for MP: 3")
|
||||
elseif(N GREATER 3)
|
||||
add_definitions(-DMP_EN)
|
||||
add_definitions(-DMP_PROC_NUM=2)
|
||||
message("core for MP: 2")
|
||||
else()
|
||||
add_definitions(-DMP_PROC_NUM=1)
|
||||
endif()
|
||||
else()
|
||||
add_definitions(-DMP_PROC_NUM=1)
|
||||
endif()
|
||||
|
||||
find_package(OpenMP QUIET)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
|
||||
find_package(PythonLibs REQUIRED)
|
||||
find_path(MATPLOTLIB_CPP_INCLUDE_DIRS "matplotlibcpp.h")
|
||||
|
||||
# ROS dependencies
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(rclcpp_components REQUIRED)
|
||||
find_package(geometry_msgs REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
find_package(std_srvs REQUIRED)
|
||||
find_package(visualization_msgs REQUIRED)
|
||||
find_package(pcl_ros REQUIRED)
|
||||
find_package(pcl_conversions REQUIRED)
|
||||
find_package(livox_ros_driver2 REQUIRED)
|
||||
find_package(rosidl_default_generators REQUIRED)
|
||||
|
||||
set(dependencies
|
||||
rclcpp
|
||||
rclcpp_components
|
||||
geometry_msgs
|
||||
nav_msgs
|
||||
sensor_msgs
|
||||
std_msgs
|
||||
std_srvs
|
||||
visualization_msgs
|
||||
pcl_ros
|
||||
pcl_conversions
|
||||
livox_ros_driver2
|
||||
)
|
||||
|
||||
# Thirdparty libraries
|
||||
find_package(Eigen3 REQUIRED)
|
||||
find_package(PCL REQUIRED COMPONENTS common io)
|
||||
|
||||
message(Eigen: ${EIGEN3_INCLUDE_DIR})
|
||||
message(STATUS "PCL: ${PCL_INCLUDE_DIRS}")
|
||||
|
||||
set(msg_files
|
||||
"msg/Pose6D.msg"
|
||||
)
|
||||
|
||||
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||
${msg_files}
|
||||
)
|
||||
ament_export_dependencies(rosidl_default_runtime)
|
||||
|
||||
add_executable(fastlio_mapping src/laserMapping.cpp include/ikd-Tree/ikd_Tree.cpp src/preprocess.cpp)
|
||||
target_include_directories(fastlio_mapping PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
${PCL_INCLUDE_DIRS}
|
||||
)
|
||||
target_link_libraries(fastlio_mapping ${PCL_LIBRARIES} ${PYTHON_LIBRARIES} Eigen3::Eigen)
|
||||
target_include_directories(fastlio_mapping PRIVATE ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
list(APPEND EOL_LIST "foxy" "galactic" "eloquent" "dashing" "crystal")
|
||||
|
||||
if($ENV{ROS_DISTRO} IN_LIST EOL_LIST)
|
||||
# Custommsg to support foxy & galactic
|
||||
rosidl_target_interfaces(fastlio_mapping
|
||||
${PROJECT_NAME} "rosidl_typesupport_cpp")
|
||||
else()
|
||||
rosidl_get_typesupport_target(cpp_typesupport_target
|
||||
${PROJECT_NAME} "rosidl_typesupport_cpp")
|
||||
target_link_libraries(fastlio_mapping ${cpp_typesupport_target})
|
||||
endif()
|
||||
|
||||
ament_target_dependencies(fastlio_mapping ${dependencies})
|
||||
|
||||
# ---------------- Install --------------- #
|
||||
install(TARGETS fastlio_mapping
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY config launch rviz
|
||||
DESTINATION share/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
ament_package()
|
||||
@@ -0,0 +1,379 @@
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include <csignal>
|
||||
#include <so3_math.h>
|
||||
#include <Eigen/Eigen>
|
||||
#include <common_lib.h>
|
||||
#include <pcl/common/io.h>
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <pcl/point_types.h>
|
||||
#include <condition_variable>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <pcl/common/transforms.h>
|
||||
#include <pcl/kdtree/kdtree_flann.h>
|
||||
#include <pcl_conversions/pcl_conversions.h>
|
||||
#include <sensor_msgs/msg/imu.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <geometry_msgs/msg/vector3.hpp>
|
||||
#include "use-ikfom.hpp"
|
||||
|
||||
/// *************Preconfiguration
|
||||
|
||||
#define MAX_INI_COUNT (10)
|
||||
|
||||
const bool time_list(PointType &x, PointType &y) {return (x.curvature < y.curvature);};
|
||||
|
||||
/// *************IMU Process and undistortion
|
||||
class ImuProcess
|
||||
{
|
||||
public:
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
|
||||
ImuProcess();
|
||||
~ImuProcess();
|
||||
|
||||
void Reset();
|
||||
// void Reset(double start_timestamp, const sensor_msgs::ImuConstPtr &lastimu);
|
||||
void Reset(double start_timestamp, const sensor_msgs::msg::Imu::ConstSharedPtr &lastimu);
|
||||
void set_extrinsic(const V3D &transl, const M3D &rot);
|
||||
void set_extrinsic(const V3D &transl);
|
||||
void set_extrinsic(const MD(4,4) &T);
|
||||
void set_gyr_cov(const V3D &scaler);
|
||||
void set_acc_cov(const V3D &scaler);
|
||||
void set_gyr_bias_cov(const V3D &b_g);
|
||||
void set_acc_bias_cov(const V3D &b_a);
|
||||
Eigen::Matrix<double, 12, 12> Q;
|
||||
void Process(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, PointCloudXYZI::Ptr pcl_un_);
|
||||
|
||||
ofstream fout_imu;
|
||||
V3D cov_acc;
|
||||
V3D cov_gyr;
|
||||
V3D cov_acc_scale;
|
||||
V3D cov_gyr_scale;
|
||||
V3D cov_bias_gyr;
|
||||
V3D cov_bias_acc;
|
||||
double first_lidar_time;
|
||||
|
||||
private:
|
||||
void IMU_init(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, int &N);
|
||||
void UndistortPcl(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, PointCloudXYZI &pcl_in_out);
|
||||
|
||||
PointCloudXYZI::Ptr cur_pcl_un_;
|
||||
// sensor_msgs::ImuConstPtr last_imu_;
|
||||
sensor_msgs::msg::Imu::ConstSharedPtr last_imu_;
|
||||
deque<sensor_msgs::msg::Imu::ConstSharedPtr> v_imu_;
|
||||
vector<Pose6D> IMUpose;
|
||||
vector<M3D> v_rot_pcl_;
|
||||
M3D Lidar_R_wrt_IMU;
|
||||
V3D Lidar_T_wrt_IMU;
|
||||
V3D mean_acc;
|
||||
V3D mean_gyr;
|
||||
V3D angvel_last;
|
||||
V3D acc_s_last;
|
||||
double start_timestamp_;
|
||||
double last_lidar_end_time_;
|
||||
int init_iter_num = 1;
|
||||
bool b_first_frame_ = true;
|
||||
bool imu_need_init_ = true;
|
||||
};
|
||||
|
||||
ImuProcess::ImuProcess()
|
||||
: b_first_frame_(true), imu_need_init_(true), start_timestamp_(-1)
|
||||
{
|
||||
init_iter_num = 1;
|
||||
Q = process_noise_cov();
|
||||
cov_acc = V3D(0.1, 0.1, 0.1);
|
||||
cov_gyr = V3D(0.1, 0.1, 0.1);
|
||||
cov_bias_gyr = V3D(0.0001, 0.0001, 0.0001);
|
||||
cov_bias_acc = V3D(0.0001, 0.0001, 0.0001);
|
||||
mean_acc = V3D(0, 0, -1.0);
|
||||
mean_gyr = V3D(0, 0, 0);
|
||||
angvel_last = Zero3d;
|
||||
Lidar_T_wrt_IMU = Zero3d;
|
||||
Lidar_R_wrt_IMU = Eye3d;
|
||||
last_imu_.reset(new sensor_msgs::msg::Imu());
|
||||
}
|
||||
|
||||
ImuProcess::~ImuProcess() {}
|
||||
|
||||
void ImuProcess::Reset()
|
||||
{
|
||||
// ROS_WARN("Reset ImuProcess");
|
||||
mean_acc = V3D(0, 0, -1.0);
|
||||
mean_gyr = V3D(0, 0, 0);
|
||||
angvel_last = Zero3d;
|
||||
imu_need_init_ = true;
|
||||
start_timestamp_ = -1;
|
||||
init_iter_num = 1;
|
||||
v_imu_.clear();
|
||||
IMUpose.clear();
|
||||
last_imu_.reset(new sensor_msgs::msg::Imu());
|
||||
cur_pcl_un_.reset(new PointCloudXYZI());
|
||||
}
|
||||
|
||||
void ImuProcess::set_extrinsic(const MD(4,4) &T)
|
||||
{
|
||||
Lidar_T_wrt_IMU = T.block<3,1>(0,3);
|
||||
Lidar_R_wrt_IMU = T.block<3,3>(0,0);
|
||||
}
|
||||
|
||||
void ImuProcess::set_extrinsic(const V3D &transl)
|
||||
{
|
||||
Lidar_T_wrt_IMU = transl;
|
||||
Lidar_R_wrt_IMU.setIdentity();
|
||||
}
|
||||
|
||||
void ImuProcess::set_extrinsic(const V3D &transl, const M3D &rot)
|
||||
{
|
||||
Lidar_T_wrt_IMU = transl;
|
||||
Lidar_R_wrt_IMU = rot;
|
||||
}
|
||||
|
||||
void ImuProcess::set_gyr_cov(const V3D &scaler)
|
||||
{
|
||||
cov_gyr_scale = scaler;
|
||||
}
|
||||
|
||||
void ImuProcess::set_acc_cov(const V3D &scaler)
|
||||
{
|
||||
cov_acc_scale = scaler;
|
||||
}
|
||||
|
||||
void ImuProcess::set_gyr_bias_cov(const V3D &b_g)
|
||||
{
|
||||
cov_bias_gyr = b_g;
|
||||
}
|
||||
|
||||
void ImuProcess::set_acc_bias_cov(const V3D &b_a)
|
||||
{
|
||||
cov_bias_acc = b_a;
|
||||
}
|
||||
|
||||
void ImuProcess::IMU_init(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, int &N)
|
||||
{
|
||||
/** 1. initializing the gravity, gyro bias, acc and gyro covariance
|
||||
** 2. normalize the acceleration measurenments to unit gravity **/
|
||||
|
||||
V3D cur_acc, cur_gyr;
|
||||
|
||||
if (b_first_frame_)
|
||||
{
|
||||
Reset();
|
||||
N = 1;
|
||||
b_first_frame_ = false;
|
||||
const auto &imu_acc = meas.imu.front()->linear_acceleration;
|
||||
const auto &gyr_acc = meas.imu.front()->angular_velocity;
|
||||
mean_acc << imu_acc.x, imu_acc.y, imu_acc.z;
|
||||
mean_gyr << gyr_acc.x, gyr_acc.y, gyr_acc.z;
|
||||
first_lidar_time = meas.lidar_beg_time;
|
||||
}
|
||||
|
||||
for (const auto &imu : meas.imu)
|
||||
{
|
||||
const auto &imu_acc = imu->linear_acceleration;
|
||||
const auto &gyr_acc = imu->angular_velocity;
|
||||
cur_acc << imu_acc.x, imu_acc.y, imu_acc.z;
|
||||
cur_gyr << gyr_acc.x, gyr_acc.y, gyr_acc.z;
|
||||
|
||||
mean_acc += (cur_acc - mean_acc) / N;
|
||||
mean_gyr += (cur_gyr - mean_gyr) / N;
|
||||
|
||||
cov_acc = cov_acc * (N - 1.0) / N + (cur_acc - mean_acc).cwiseProduct(cur_acc - mean_acc) * (N - 1.0) / (N * N);
|
||||
cov_gyr = cov_gyr * (N - 1.0) / N + (cur_gyr - mean_gyr).cwiseProduct(cur_gyr - mean_gyr) * (N - 1.0) / (N * N);
|
||||
|
||||
// cout<<"acc norm: "<<cur_acc.norm()<<" "<<mean_acc.norm()<<endl;
|
||||
|
||||
N ++;
|
||||
}
|
||||
state_ikfom init_state = kf_state.get_x();
|
||||
init_state.grav = S2(- mean_acc / mean_acc.norm() * G_m_s2);
|
||||
|
||||
//state_inout.rot = Eye3d; // Exp(mean_acc.cross(V3D(0, 0, -1 / scale_gravity)));
|
||||
init_state.bg = mean_gyr;
|
||||
init_state.offset_T_L_I = Lidar_T_wrt_IMU;
|
||||
init_state.offset_R_L_I = Lidar_R_wrt_IMU;
|
||||
kf_state.change_x(init_state);
|
||||
|
||||
esekfom::esekf<state_ikfom, 12, input_ikfom>::cov init_P = kf_state.get_P();
|
||||
init_P.setIdentity();
|
||||
init_P(6,6) = init_P(7,7) = init_P(8,8) = 0.00001;
|
||||
init_P(9,9) = init_P(10,10) = init_P(11,11) = 0.00001;
|
||||
init_P(15,15) = init_P(16,16) = init_P(17,17) = 0.0001;
|
||||
init_P(18,18) = init_P(19,19) = init_P(20,20) = 0.001;
|
||||
init_P(21,21) = init_P(22,22) = 0.00001;
|
||||
kf_state.change_P(init_P);
|
||||
last_imu_ = meas.imu.back();
|
||||
|
||||
}
|
||||
|
||||
void ImuProcess::UndistortPcl(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, PointCloudXYZI &pcl_out)
|
||||
{
|
||||
/*** add the imu of the last frame-tail to the of current frame-head ***/
|
||||
auto v_imu = meas.imu;
|
||||
v_imu.push_front(last_imu_);
|
||||
const double &imu_beg_time = rclcpp::Time(v_imu.front()->header.stamp).seconds();
|
||||
const double &imu_end_time = rclcpp::Time(v_imu.back()->header.stamp).seconds();
|
||||
const double &pcl_beg_time = meas.lidar_beg_time;
|
||||
const double &pcl_end_time = meas.lidar_end_time;
|
||||
|
||||
/*** sort point clouds by offset time ***/
|
||||
pcl_out = *(meas.lidar);
|
||||
sort(pcl_out.points.begin(), pcl_out.points.end(), time_list);
|
||||
// cout<<"[ IMU Process ]: Process lidar from "<<pcl_beg_time<<" to "<<pcl_end_time<<", " \
|
||||
// <<meas.imu.size()<<" imu msgs from "<<imu_beg_time<<" to "<<imu_end_time<<endl;
|
||||
|
||||
/*** Initialize IMU pose ***/
|
||||
state_ikfom imu_state = kf_state.get_x();
|
||||
IMUpose.clear();
|
||||
IMUpose.push_back(set_pose6d(0.0, acc_s_last, angvel_last, imu_state.vel, imu_state.pos, imu_state.rot.toRotationMatrix()));
|
||||
|
||||
/*** forward propagation at each imu point ***/
|
||||
V3D angvel_avr, acc_avr, acc_imu, vel_imu, pos_imu;
|
||||
M3D R_imu;
|
||||
|
||||
double dt = 0;
|
||||
|
||||
input_ikfom in;
|
||||
for (auto it_imu = v_imu.begin(); it_imu < (v_imu.end() - 1); it_imu++)
|
||||
{
|
||||
auto &&head = *(it_imu);
|
||||
auto &&tail = *(it_imu + 1);
|
||||
|
||||
double tail_stamp = rclcpp::Time(tail->header.stamp).seconds();
|
||||
double head_stamp = rclcpp::Time(head->header.stamp).seconds();
|
||||
|
||||
if (tail_stamp < last_lidar_end_time_) continue;
|
||||
|
||||
angvel_avr<<0.5 * (head->angular_velocity.x + tail->angular_velocity.x),
|
||||
0.5 * (head->angular_velocity.y + tail->angular_velocity.y),
|
||||
0.5 * (head->angular_velocity.z + tail->angular_velocity.z);
|
||||
acc_avr <<0.5 * (head->linear_acceleration.x + tail->linear_acceleration.x),
|
||||
0.5 * (head->linear_acceleration.y + tail->linear_acceleration.y),
|
||||
0.5 * (head->linear_acceleration.z + tail->linear_acceleration.z);
|
||||
|
||||
// fout_imu << setw(10) << head->header.stamp.toSec() - first_lidar_time << " " << angvel_avr.transpose() << " " << acc_avr.transpose() << endl;
|
||||
|
||||
acc_avr = acc_avr * G_m_s2 / mean_acc.norm(); // - state_inout.ba;
|
||||
|
||||
if(head_stamp < last_lidar_end_time_)
|
||||
{
|
||||
dt = tail_stamp - last_lidar_end_time_;
|
||||
// dt = tail->header.stamp.toSec() - pcl_beg_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = tail_stamp - head_stamp;
|
||||
}
|
||||
|
||||
in.acc = acc_avr;
|
||||
in.gyro = angvel_avr;
|
||||
Q.block<3, 3>(0, 0).diagonal() = cov_gyr;
|
||||
Q.block<3, 3>(3, 3).diagonal() = cov_acc;
|
||||
Q.block<3, 3>(6, 6).diagonal() = cov_bias_gyr;
|
||||
Q.block<3, 3>(9, 9).diagonal() = cov_bias_acc;
|
||||
kf_state.predict(dt, Q, in);
|
||||
|
||||
/* save the poses at each IMU measurements */
|
||||
imu_state = kf_state.get_x();
|
||||
angvel_last = angvel_avr - imu_state.bg;
|
||||
acc_s_last = imu_state.rot * (acc_avr - imu_state.ba);
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
acc_s_last[i] += imu_state.grav[i];
|
||||
}
|
||||
double &&offs_t = tail_stamp - pcl_beg_time;
|
||||
IMUpose.push_back(set_pose6d(offs_t, acc_s_last, angvel_last, imu_state.vel, imu_state.pos, imu_state.rot.toRotationMatrix()));
|
||||
}
|
||||
|
||||
/*** calculated the pos and attitude prediction at the frame-end ***/
|
||||
double note = pcl_end_time > imu_end_time ? 1.0 : -1.0;
|
||||
dt = note * (pcl_end_time - imu_end_time);
|
||||
kf_state.predict(dt, Q, in);
|
||||
|
||||
imu_state = kf_state.get_x();
|
||||
last_imu_ = meas.imu.back();
|
||||
last_lidar_end_time_ = pcl_end_time;
|
||||
|
||||
/*** undistort each lidar point (backward propagation) ***/
|
||||
if (pcl_out.points.begin() == pcl_out.points.end()) return;
|
||||
auto it_pcl = pcl_out.points.end() - 1;
|
||||
for (auto it_kp = IMUpose.end() - 1; it_kp != IMUpose.begin(); it_kp--)
|
||||
{
|
||||
auto head = it_kp - 1;
|
||||
auto tail = it_kp;
|
||||
R_imu<<MAT_FROM_ARRAY(head->rot);
|
||||
// cout<<"head imu acc: "<<acc_imu.transpose()<<endl;
|
||||
vel_imu<<VEC_FROM_ARRAY(head->vel);
|
||||
pos_imu<<VEC_FROM_ARRAY(head->pos);
|
||||
acc_imu<<VEC_FROM_ARRAY(tail->acc);
|
||||
angvel_avr<<VEC_FROM_ARRAY(tail->gyr);
|
||||
|
||||
for(; it_pcl->curvature / double(1000) > head->offset_time; it_pcl --)
|
||||
{
|
||||
dt = it_pcl->curvature / double(1000) - head->offset_time;
|
||||
|
||||
/* Transform to the 'end' frame, using only the rotation
|
||||
* Note: Compensation direction is INVERSE of Frame's moving direction
|
||||
* So if we want to compensate a point at timestamp-i to the frame-e
|
||||
* P_compensate = R_imu_e ^ T * (R_i * P_i + T_ei) where T_ei is represented in global frame */
|
||||
M3D R_i(R_imu * Exp(angvel_avr, dt));
|
||||
|
||||
V3D P_i(it_pcl->x, it_pcl->y, it_pcl->z);
|
||||
V3D T_ei(pos_imu + vel_imu * dt + 0.5 * acc_imu * dt * dt - imu_state.pos);
|
||||
V3D P_compensate = imu_state.offset_R_L_I.conjugate() * (imu_state.rot.conjugate() * (R_i * (imu_state.offset_R_L_I * P_i + imu_state.offset_T_L_I) + T_ei) - imu_state.offset_T_L_I);// not accurate!
|
||||
|
||||
// save Undistorted points and their rotation
|
||||
it_pcl->x = P_compensate(0);
|
||||
it_pcl->y = P_compensate(1);
|
||||
it_pcl->z = P_compensate(2);
|
||||
|
||||
if (it_pcl == pcl_out.points.begin()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImuProcess::Process(const MeasureGroup &meas, esekfom::esekf<state_ikfom, 12, input_ikfom> &kf_state, PointCloudXYZI::Ptr cur_pcl_un_)
|
||||
{
|
||||
double t1,t2,t3;
|
||||
t1 = omp_get_wtime();
|
||||
|
||||
if(meas.imu.empty()) {return;};
|
||||
assert(meas.lidar != nullptr);
|
||||
|
||||
if (imu_need_init_)
|
||||
{
|
||||
/// The very first lidar frame
|
||||
IMU_init(meas, kf_state, init_iter_num);
|
||||
|
||||
imu_need_init_ = true;
|
||||
|
||||
last_imu_ = meas.imu.back();
|
||||
|
||||
state_ikfom imu_state = kf_state.get_x();
|
||||
if (init_iter_num > MAX_INI_COUNT)
|
||||
{
|
||||
cov_acc *= pow(G_m_s2 / mean_acc.norm(), 2);
|
||||
imu_need_init_ = false;
|
||||
|
||||
cov_acc = cov_acc_scale;
|
||||
cov_gyr = cov_gyr_scale;
|
||||
std::cout << "IMU Initial Done" << std::endl;
|
||||
// ROS_INFO("IMU Initial Done: Gravity: %.4f %.4f %.4f %.4f; state.bias_g: %.4f %.4f %.4f; acc covarience: %.8f %.8f %.8f; gry covarience: %.8f %.8f %.8f",\
|
||||
// imu_state.grav[0], imu_state.grav[1], imu_state.grav[2], mean_acc.norm(), cov_bias_gyr[0], cov_bias_gyr[1], cov_bias_gyr[2], cov_acc[0], cov_acc[1], cov_acc[2], cov_gyr[0], cov_gyr[1], cov_gyr[2]);
|
||||
fout_imu.open(DEBUG_FILE_DIR("imu.txt"),ios::out);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
UndistortPcl(meas, kf_state, *cur_pcl_un_);
|
||||
|
||||
t2 = omp_get_wtime();
|
||||
t3 = omp_get_wtime();
|
||||
|
||||
// cout<<"[ IMU Process ]: Time: "<<t3 - t1<<endl;
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
// #include <ros/ros.h>
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
#include <pcl_conversions/pcl_conversions.h>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <livox_ros_driver2/msg/custom_msg.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define IS_VALID(a) ((abs(a) > 1e8) ? true : false)
|
||||
|
||||
typedef pcl::PointXYZINormal PointType;
|
||||
typedef pcl::PointCloud<PointType> PointCloudXYZI;
|
||||
|
||||
enum LID_TYPE
|
||||
{
|
||||
AVIA = 1,
|
||||
VELO16,
|
||||
OUST64,
|
||||
MID360,
|
||||
Pandar64
|
||||
}; //{1, 2, 3}
|
||||
enum TIME_UNIT
|
||||
{
|
||||
SEC = 0,
|
||||
MS = 1,
|
||||
US = 2,
|
||||
NS = 3
|
||||
};
|
||||
enum Feature
|
||||
{
|
||||
Nor,
|
||||
Poss_Plane,
|
||||
Real_Plane,
|
||||
Edge_Jump,
|
||||
Edge_Plane,
|
||||
Wire,
|
||||
ZeroPoint
|
||||
};
|
||||
enum Surround
|
||||
{
|
||||
Prev,
|
||||
Next
|
||||
};
|
||||
enum E_jump
|
||||
{
|
||||
Nr_nor,
|
||||
Nr_zero,
|
||||
Nr_180,
|
||||
Nr_inf,
|
||||
Nr_blind
|
||||
};
|
||||
|
||||
struct orgtype
|
||||
{
|
||||
double range;
|
||||
double dista;
|
||||
double angle[2];
|
||||
double intersect;
|
||||
E_jump edj[2];
|
||||
Feature ftype;
|
||||
orgtype()
|
||||
{
|
||||
range = 0;
|
||||
edj[Prev] = Nr_nor;
|
||||
edj[Next] = Nr_nor;
|
||||
ftype = Nor;
|
||||
intersect = 2;
|
||||
}
|
||||
};
|
||||
|
||||
namespace velodyne_ros
|
||||
{
|
||||
struct EIGEN_ALIGN16 Point
|
||||
{
|
||||
PCL_ADD_POINT4D;
|
||||
float intensity;
|
||||
float time;
|
||||
uint8_t ring;
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
};
|
||||
} // namespace velodyne_ros
|
||||
POINT_CLOUD_REGISTER_POINT_STRUCT(velodyne_ros::Point,
|
||||
(float, x, x)(float, y, y)(float, z, z)(float, intensity,
|
||||
intensity)(float, time, time)(uint8_t, ring,
|
||||
|
||||
ring))
|
||||
namespace pandar_ros
|
||||
{
|
||||
struct EIGEN_ALIGN16 Point
|
||||
{
|
||||
PCL_ADD_POINT4D;
|
||||
float intensity;
|
||||
uint8_t ring;
|
||||
double timestamp;
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
};
|
||||
} // namespace pandar_ros
|
||||
POINT_CLOUD_REGISTER_POINT_STRUCT(
|
||||
pandar_ros::Point,
|
||||
(float, x, x)
|
||||
(float, y, y)
|
||||
(float, z, z)
|
||||
(float, intensity,intensity)
|
||||
(uint16_t, ring, ring)
|
||||
(double, timestamp, timestamp)
|
||||
)
|
||||
|
||||
namespace ouster_ros
|
||||
{
|
||||
struct EIGEN_ALIGN16 Point
|
||||
{
|
||||
PCL_ADD_POINT4D;
|
||||
float intensity;
|
||||
uint32_t t;
|
||||
uint16_t reflectivity;
|
||||
uint8_t ring;
|
||||
uint16_t ambient;
|
||||
uint32_t range;
|
||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
};
|
||||
} // namespace ouster_ros
|
||||
|
||||
// clang-format off
|
||||
POINT_CLOUD_REGISTER_POINT_STRUCT(ouster_ros::Point,
|
||||
(float, x, x)
|
||||
(float, y, y)
|
||||
(float, z, z)
|
||||
(float, intensity, intensity)
|
||||
// use std::uint32_t to avoid conflicting with pcl::uint32_t
|
||||
(std::uint32_t, t, t)
|
||||
(std::uint16_t, reflectivity, reflectivity)
|
||||
(std::uint8_t, ring, ring)
|
||||
(std::uint16_t, ambient, ambient)
|
||||
(std::uint32_t, range, range)
|
||||
)
|
||||
|
||||
namespace livox_ros
|
||||
{
|
||||
typedef struct {
|
||||
float x; /**< X axis, Unit:m */
|
||||
float y; /**< Y axis, Unit:m */
|
||||
float z; /**< Z axis, Unit:m */
|
||||
float reflectivity; /**< Reflectivity */
|
||||
uint8_t tag; /**< Livox point tag */
|
||||
uint8_t line; /**< Laser line id */
|
||||
} LivoxPointXyzrtl;
|
||||
|
||||
typedef struct {
|
||||
float x; /**< X axis, Unit:m */
|
||||
float y; /**< Y axis, Unit:m */
|
||||
float z; /**< Z axis, Unit:m */
|
||||
float intensity; /**< Intensity */
|
||||
uint8_t tag; /**< Livox point tag */
|
||||
uint8_t line; /**< Laser line id */
|
||||
} LivoxPointXyzitl;
|
||||
}
|
||||
POINT_CLOUD_REGISTER_POINT_STRUCT(livox_ros::LivoxPointXyzrtl,
|
||||
(float, x, x)
|
||||
(float, y, y)
|
||||
(float, z, z)
|
||||
(float, reflectivity, reflectivity)
|
||||
(uint8_t, tag, tag)
|
||||
(uint8_t, line, line)
|
||||
)
|
||||
|
||||
POINT_CLOUD_REGISTER_POINT_STRUCT(livox_ros::LivoxPointXyzitl,
|
||||
(float, x, x)
|
||||
(float, y, y)
|
||||
(float, z, z)
|
||||
(float, intensity, intensity)
|
||||
(uint8_t, tag, tag)
|
||||
(uint8_t, line, line)
|
||||
)
|
||||
|
||||
class Preprocess
|
||||
{
|
||||
public:
|
||||
// EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||
|
||||
Preprocess();
|
||||
~Preprocess();
|
||||
|
||||
void process(const livox_ros_driver2::msg::CustomMsg::UniquePtr &msg, PointCloudXYZI::Ptr &pcl_out);
|
||||
void process(const sensor_msgs::msg::PointCloud2::UniquePtr &msg, PointCloudXYZI::Ptr &pcl_out);
|
||||
void set(bool feat_en, int lid_type, double bld, int pfilt_num);
|
||||
|
||||
// sensor_msgs::PointCloud2::ConstPtr pointcloud;
|
||||
PointCloudXYZI pl_full, pl_corn, pl_surf;
|
||||
PointCloudXYZI pl_buff[128]; //maximum 128 line lidar
|
||||
vector<orgtype> typess[128]; //maximum 128 line lidar
|
||||
float time_unit_scale;
|
||||
int lidar_type, point_filter_num, N_SCANS, SCAN_RATE, time_unit;
|
||||
double blind;
|
||||
bool feature_enabled, given_offset_time;
|
||||
// ros::Publisher pub_full, pub_surf, pub_corn;
|
||||
|
||||
private:
|
||||
void avia_handler(const livox_ros_driver2::msg::CustomMsg::UniquePtr &msg);
|
||||
void oust64_handler(const sensor_msgs::msg::PointCloud2::UniquePtr &msg);
|
||||
void velodyne_handler(const sensor_msgs::msg::PointCloud2::UniquePtr &msg);
|
||||
void mid360_handler(const sensor_msgs::msg::PointCloud2::UniquePtr &msg);
|
||||
void default_handler(const sensor_msgs::msg::PointCloud2::UniquePtr &msg);
|
||||
void pandar64_handler(const sensor_msgs::msg::PointCloud2::UniquePtr &msg);
|
||||
void give_feature(PointCloudXYZI &pl, vector<orgtype> &types);
|
||||
void pub_func(PointCloudXYZI &pl, const rclcpp::Time &ct);
|
||||
int plane_judge(const PointCloudXYZI &pl, vector<orgtype> &types, uint i, uint &i_nex, Eigen::Vector3d &curr_direct);
|
||||
bool small_plane(const PointCloudXYZI &pl, vector<orgtype> &types, uint i_cur, uint &i_nex, Eigen::Vector3d &curr_direct);
|
||||
bool edge_jump_judge(const PointCloudXYZI &pl, vector<orgtype> &types, uint i, Surround nor_dir);
|
||||
|
||||
int group_size;
|
||||
double disA, disB, inf_bound;
|
||||
double limit_maxmid, limit_midmin, limit_maxmin;
|
||||
double p2l_ratio;
|
||||
double jump_up_limit, jump_down_limit;
|
||||
double cos160;
|
||||
double edgea, edgeb;
|
||||
double smallp_intersect, smallp_ratio;
|
||||
double vx, vy, vz;
|
||||
};
|
||||
@@ -0,0 +1,175 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(liorf)
|
||||
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -pthread")
|
||||
|
||||
# ============================================
|
||||
# 强制使用 TBB 2.x 版本(修复冲突)
|
||||
# ============================================
|
||||
|
||||
# 直接使用完整路径
|
||||
set(TBB_2_LIBRARY /usr/lib/aarch64-linux-gnu/libtbb.so.2)
|
||||
|
||||
# 验证文件存在
|
||||
if(NOT EXISTS ${TBB_2_LIBRARY})
|
||||
message(FATAL_ERROR "libtbb.so.2 not found at ${TBB_2_LIBRARY}")
|
||||
endif()
|
||||
|
||||
message(STATUS "==========================================")
|
||||
message(STATUS "Forced TBB library: ${TBB_2_LIBRARY}")
|
||||
message(STATUS "==========================================")
|
||||
|
||||
# 创建导入目标
|
||||
add_library(TBB::tbb_2 SHARED IMPORTED)
|
||||
set_target_properties(TBB::tbb_2 PROPERTIES
|
||||
IMPORTED_LOCATION ${TBB_2_LIBRARY}
|
||||
INTERFACE_INCLUDE_DIRECTORIES /usr/include
|
||||
)
|
||||
|
||||
# 强制链接器选项
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/lib/x86_64-linux-gnu")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,/usr/lib/x86_64-linux-gnu")
|
||||
|
||||
# 优先搜索路径
|
||||
link_directories(BEFORE /usr/lib/x86_64-linux-gnu)
|
||||
# ============================================
|
||||
|
||||
include(cmake/rosidl_get_typesupport_target.cmake)
|
||||
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rosidl_default_generators REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(rclpy REQUIRED)
|
||||
find_package(cv_bridge REQUIRED)
|
||||
find_package(std_msgs REQUIRED)
|
||||
find_package(sensor_msgs REQUIRED)
|
||||
find_package(geometry_msgs REQUIRED)
|
||||
find_package(nav_msgs REQUIRED)
|
||||
find_package(visualization_msgs REQUIRED)
|
||||
find_package(pcl_msgs REQUIRED)
|
||||
find_package(pcl_conversions REQUIRED)
|
||||
find_package(tf2 REQUIRED)
|
||||
find_package(tf2_geometry_msgs REQUIRED)
|
||||
find_package(tf2_sensor_msgs REQUIRED)
|
||||
find_package(tf2_eigen REQUIRED)
|
||||
find_package(tf2_ros REQUIRED)
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
find_package(PCL REQUIRED)
|
||||
find_package(GTSAM REQUIRED)
|
||||
find_package(Eigen REQUIRED)
|
||||
find_package(OpenMP REQUIRED)
|
||||
find_package(Boost REQUIRED COMPONENTS timer)
|
||||
|
||||
set(ros2_lib "rclcpp;rclpy;std_msgs;sensor_msgs;geometry_msgs;nav_msgs;cv_bridge;pcl_msgs;pcl_conversions;visualization_msgs;tf2;tf2_ros;tf2_eigen;tf2_sensor_msgs;tf2_geometry_msgs")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/share/cmake/geographiclib/")
|
||||
find_package(GeographicLib REQUIRED)
|
||||
|
||||
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||
"msg/CloudInfo.msg"
|
||||
"srv/SaveMap.srv"
|
||||
DEPENDENCIES std_msgs sensor_msgs
|
||||
)
|
||||
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} rosidl_typesupport_cpp)
|
||||
|
||||
include_directories(
|
||||
lib
|
||||
include
|
||||
${PCL_INCLUDE_DIRS}
|
||||
${OpenCV_INCLUDE_DIRS}
|
||||
${GTSAM_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
lib
|
||||
include
|
||||
${PCL_LIBRARY_DIRS}
|
||||
${OpenCV_LIBRARY_DIRS}
|
||||
${GTSAM_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
file(GLOB common_lib "lib/*.cpp")
|
||||
|
||||
###########
|
||||
## Build ##
|
||||
###########
|
||||
|
||||
# Range Image Projection
|
||||
add_executable(${PROJECT_NAME}_imageProjection src/imageProjection.cpp ${common_lib})
|
||||
ament_target_dependencies(${PROJECT_NAME}_imageProjection ${ros2_lib})
|
||||
target_link_libraries(${PROJECT_NAME}_imageProjection
|
||||
"${cpp_typesupport_target}"
|
||||
${PCL_LIBRARIES}
|
||||
${OpenCV_LIBRARIES}
|
||||
TBB::tbb_2
|
||||
)
|
||||
|
||||
# Mapping Optimization
|
||||
add_executable(${PROJECT_NAME}_mapOptmization src/mapOptmization.cpp ${common_lib} include/Scancontext.cpp)
|
||||
target_compile_options(${PROJECT_NAME}_mapOptmization PRIVATE ${OpenMP_CXX_FLAGS})
|
||||
ament_target_dependencies(${PROJECT_NAME}_mapOptmization ${ros2_lib})
|
||||
target_link_libraries(${PROJECT_NAME}_mapOptmization
|
||||
Boost::timer
|
||||
"${cpp_typesupport_target}"
|
||||
${PCL_LIBRARIES}
|
||||
${OpenCV_LIBRARIES}
|
||||
${OpenMP_CXX_FLAGS}
|
||||
${GeographicLib_LIBRARIES}
|
||||
gtsam
|
||||
TBB::tbb_2
|
||||
)
|
||||
|
||||
# IMU Preintegration
|
||||
add_executable(${PROJECT_NAME}_imuPreintegration src/imuPreintegration.cpp ${common_lib})
|
||||
ament_target_dependencies(${PROJECT_NAME}_imuPreintegration ${ros2_lib})
|
||||
target_link_libraries(${PROJECT_NAME}_imuPreintegration
|
||||
Boost::timer
|
||||
"${cpp_typesupport_target}"
|
||||
${PCL_LIBRARIES}
|
||||
${OpenCV_LIBRARIES}
|
||||
gtsam
|
||||
TBB::tbb_2
|
||||
)
|
||||
|
||||
# 设置 RPATH
|
||||
set_target_properties(${PROJECT_NAME}_imageProjection PROPERTIES
|
||||
INSTALL_RPATH "/usr/lib/x86_64-linux-gnu"
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
)
|
||||
set_target_properties(${PROJECT_NAME}_mapOptmization PROPERTIES
|
||||
INSTALL_RPATH "/usr/lib/x86_64-linux-gnu"
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
)
|
||||
set_target_properties(${PROJECT_NAME}_imuPreintegration PROPERTIES
|
||||
INSTALL_RPATH "/usr/lib/x86_64-linux-gnu"
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY launch config rviz
|
||||
DESTINATION share/${PROJECT_NAME}/
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
${PROJECT_NAME}_imageProjection
|
||||
${PROJECT_NAME}_imuPreintegration
|
||||
${PROJECT_NAME}_mapOptmization
|
||||
DESTINATION lib/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY "include/"
|
||||
DESTINATION include
|
||||
)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
find_package(ament_lint_auto REQUIRED)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
ament_export_include_directories(include)
|
||||
ament_package()
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 YJZ_Lucky_Boy
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,144 @@
|
||||
# New Feature
|
||||
------------------- Update Date: 2022-11-20 -------------------
|
||||
- This version has removed the feature extraction module, making it easier to adapt to different lidars;
|
||||
|
||||
- Support 'robosense' lidar and Mulran datasets, make the following changes in "*.yaml":
|
||||
- sensor: “robosense” or sensor: “mulran”
|
||||
|
||||
- Support 6-axis IMU, make the following changes in "*.yaml":
|
||||
- imuType: 0 # 0: 6-axis IMU, 1: 9-axis IMU
|
||||
|
||||
- Support low frequency IMU(50HZ、100HZ), make the following changes in "*.yaml":
|
||||
- imuRate: 500
|
||||
|
||||
------------------- Update Date: 2022-12-13 -------------------
|
||||
- Re-derivation the LM optimization, don't need coordinate transformation.
|
||||
|
||||
------------------- Update Date: 2022-12-24 -------------------
|
||||
- Modified gps factor, no longer depending on the 'robot_localization' package, and make it easier to adapt to different gnss device(RTK/GPS).
|
||||
|
||||
- The gps factor is modified to make it easier to adapt to gnss devices with different frequencies(10HZ~500HZ).
|
||||
|
||||
------------------- Update Date: 2023-02-11 -------------------
|
||||
- Add scancontext loop closure detection;
|
||||
|
||||
- Support M2DGR dataset.
|
||||
|
||||
------------------- Update Date: 2024-04-29 -------------------
|
||||
- Add [liorf ROS2](https://github.com/YJZLuckyBoy/liorf/tree/liorf-ros2) version (Foxy、Galactic).
|
||||
|
||||
Blog:[LIO-SAM:配置环境、安装测试、适配自己采集数据集](https://blog.csdn.net/qq_42938987/article/details/108434290)
|
||||
|
||||
Video:[基于LIO-SAM框架SLAM算法开发系列视频](https://space.bilibili.com/327643131/channel/collectiondetail?sid=945184&ctype=0)
|
||||
|
||||
## Dependency
|
||||
- [gtsam](https://gtsam.org/get_started/)(Georgia Tech Smoothing and Mapping library)
|
||||
```
|
||||
sudo add-apt-repository ppa:borglab/gtsam-release-4.0
|
||||
sudo apt install libgtsam-dev libgtsam-unstable-dev
|
||||
```
|
||||
- Others
|
||||
```
|
||||
sudo apt install libgeographic-dev
|
||||
```
|
||||
|
||||
## Install
|
||||
1. Use the following commands to download and compile the package.
|
||||
```
|
||||
mkdir -p ~/liorf-ros2/src && cd ~/liorf-ros2/src
|
||||
git clone https://github.com/YJZLuckyBoy/liorf.git
|
||||
cd liorf && git checkout liorf-ros2
|
||||
cd ../../
|
||||
colcon build
|
||||
```
|
||||
|
||||
## Run the package
|
||||
1. Run the launch file
|
||||
```
|
||||
source install/setup.bash
|
||||
ros2 launch liorf run_lio_sam_default.launch.py
|
||||
```
|
||||
|
||||
2. Play existing bag files. Example data in ROS2 format can be downloaded here ([lio-sam-dataset with ros2 format](https://drive.google.com/drive/folders/1n2AZC7GPpUMoW0K4nFGOI6vVjQcuxPru?usp=sharing))
|
||||
```
|
||||
ros2 bag play casual_walk/
|
||||
```
|
||||
|
||||
## For fusion gps factor
|
||||
- Make sure your gnss topic type is 'sensor_msgs::msg::NavSatFix';
|
||||
|
||||
- Modify 'gpsTopic' paramter in '*.yaml' with yourself gnss topic;
|
||||
```
|
||||
gpsTopic: "gps/fix" # GPS topic
|
||||
```
|
||||
- If you want to use liorf with integrated gps factor in kitti dataset, you can use the modified python script in "config/doc/kitti2bag" to obtain high-frequency gps data(Rate: 100HZ, Topic: '/gps/fix/correct'). About how to use "[kitti2bag.py](https://github.com/YJZLuckyBoy/liorf/blob/main/config/doc/kitti2bag/kitti2bag.py)", please refer to [doc/kitti2bag](https://github.com/TixiaoShan/LIO-SAM/tree/master/config/doc/kitti2bag).
|
||||
This will generate a BAG package in ROS1 format, You need to convert it to the BAG package in ROS2 format, Please refer to the conversion method [ros2 to ros1](https://ternaris.gitlab.io/rosbags/index.html).
|
||||
|
||||
<!-- - For more details, please check the demo video: [基于LIO-SAM框架SLAM算法开发(六):建图之快速适配多雷达及GNSS设备](https://www.bilibili.com/video/BV1ZD4y177ut/?spm_id_from=333.999.0.0&vd_source=fb7f82fee1e57e882c6174174ad2fa11) -->
|
||||
|
||||
## Mapping
|
||||
<!-- 1. lio-sam dataset
|
||||
<p align='center'>
|
||||
<img src="./demo/lio_sam_livox_data.gif" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
|
||||
2. M2DGR dataset
|
||||
<p align='center'>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/M2DGR/gate_01.png" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
|
||||
3. kitti-05 dataset
|
||||
<p align='center'>
|
||||
<img src="./demo/kitti.gif" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
|
||||
4. ubran_hongkong dataset
|
||||
<p align='center'>
|
||||
<img src="./demo/ubran_hongkong.gif" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
|
||||
5. MulRan dataset
|
||||
<p align='center'>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/mulran/mulran_00.png" alt="drawing" width="400"/>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/mulran/mulran_01.png" alt="drawing" width="400"/>
|
||||
</p>
|
||||
|
||||
6. Multiple Lidar
|
||||
<p align='center'>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/multiple_lidar/multiple_lidar_00.png" alt="drawing" width="400"/>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/multiple_lidar/multiple_lidar_01.png" alt="drawing" width="400"/>
|
||||
</p>
|
||||
|
||||
6. r3live dataset
|
||||
<p align='center'>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/r3live/r3live_data_00.png" alt="drawing" width="266"/>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/r3live/r3live_data_01.png" alt="drawing" width="266"/>
|
||||
<img src="https://github.com/YJZLuckyBoy/pic/blob/master/liorf/r3live/r3live_data_02.png" alt="drawing" width="266"/>
|
||||
</p> -->
|
||||
|
||||
## Performance
|
||||
<!-- 1. MulRan
|
||||
<p align='center'>
|
||||
<img src="./demo/mulran_traj.png" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
|
||||
2. Kitti 01
|
||||
<p align='center'>
|
||||
<img src="./demo/kitti01_trajec.png" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
<p align='center'>
|
||||
<img src="./demo/kitti01_ape.png" alt="drawing" width="400"/>
|
||||
<img src="./demo/kitti01_rpe.png" alt="drawing" width="400"/>
|
||||
</p>
|
||||
|
||||
3. Kitti 05
|
||||
<p align='center'>
|
||||
<img src="./demo/kitti05_trajec.png" alt="drawing" width="800" height = "400"/>
|
||||
</p>
|
||||
<p align='center'>
|
||||
<img src="./demo/kitti05_ape.png" alt="drawing" width="400"/>
|
||||
<img src="./demo/kitti05_rpe.png" alt="drawing" width="400"/>
|
||||
</p> -->
|
||||
|
||||
## Acknowledgments
|
||||
Thanks for [LIO-SAM](https://github.com/TixiaoShan/LIO-SAM), [FAST_LIO2](https://github.com/hku-mars/FAST_LIO), [UrbanNavDataset](https://github.com/weisongwen/UrbanNavDataset), [M2DGR](https://github.com/SJTU-ViSYS/M2DGR) and [MulRanDataset](https://sites.google.com/view/mulran-pr/?pli=1).
|
||||
@@ -0,0 +1,41 @@
|
||||
# Copyright 2021 Open Source Robotics Foundation, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Get the name of a Typesupport target so it can be used to depend on
|
||||
# generated messages in the same package that generated them.
|
||||
#
|
||||
# :param var: A name of a variable to store the typesupport target name
|
||||
# :param generate_interfaces_target: the target name passed to
|
||||
# rosidl_generate_interfaces
|
||||
# :type generate_interfaces_target: string
|
||||
# :param typesupport_name: the package name of the type support
|
||||
# :type typesupport_name: string
|
||||
#
|
||||
# @public
|
||||
#
|
||||
function(rosidl_get_typesupport_target var generate_interfaces_target typesupport_name)
|
||||
if(NOT TARGET ${generate_interfaces_target})
|
||||
message(FATAL_ERROR
|
||||
"${generate_interfaces_target} is not a CMake target. Maybe rosidl_generate_interfaces was given a different target name?")
|
||||
endif()
|
||||
|
||||
set(output_target "${generate_interfaces_target}__${typesupport_name}")
|
||||
|
||||
if(NOT TARGET ${output_target})
|
||||
# CMake if() evaluates strings ending in `-NOTFOUND` as false
|
||||
set(output_target "${output_target}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set("${var}" "${output_target}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "velodyne_points" # Point cloud data
|
||||
imuTopic: "handsfree/imu" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: velodyne # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 32 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 1 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 5 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 2.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 100.0
|
||||
imuAccNoise: 3.7686306102624571e-02
|
||||
imuGyrNoise: 2.3417543020438883e-03
|
||||
imuAccBiasN: 1.1416642385952368e-03
|
||||
imuGyrBiasN: 1.4428407712885209e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.27255, -0.00053,0.17954]
|
||||
extrinsicRot: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,17 @@
|
||||
# kitti2bag
|
||||
|
||||
## How to run it?
|
||||
|
||||
```bash
|
||||
wget https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data/2011_09_26_drive_0084/2011_09_26_drive_0084_sync.zip
|
||||
wget https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data/2011_09_26_drive_0084/2011_09_26_drive_0084_extract.zip
|
||||
wget https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data/2011_09_26_calib.zip
|
||||
unzip 2011_09_26_drive_0084_sync.zip
|
||||
unzip 2011_09_26_drive_0084_extract.zip
|
||||
unzip 2011_09_26_calib.zip
|
||||
python kitti2bag.py -t 2011_09_26 -r 0084 raw_synced .
|
||||
```
|
||||
|
||||
That's it. You have a bag that contains your data.
|
||||
|
||||
Other source files can be found at [KITTI raw data](http://www.cvlibs.net/datasets/kitti/raw_data.php) page.
|
||||
@@ -0,0 +1,484 @@
|
||||
#!env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
import pykitti
|
||||
except ImportError as e:
|
||||
print('Could not load module \'pykitti\'. Please run `pip install pykitti`')
|
||||
sys.exit(1)
|
||||
|
||||
import tf
|
||||
import os
|
||||
import cv2
|
||||
import rospy
|
||||
import rosbag
|
||||
from tqdm import tqdm
|
||||
from tf2_msgs.msg import TFMessage
|
||||
from datetime import datetime
|
||||
from std_msgs.msg import Header
|
||||
from sensor_msgs.msg import CameraInfo, Imu, PointField, NavSatFix
|
||||
import sensor_msgs.point_cloud2 as pcl2
|
||||
from geometry_msgs.msg import TransformStamped, TwistStamped, Transform
|
||||
from cv_bridge import CvBridge
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
def save_imu_data(bag, kitti, imu_frame_id, topic):
|
||||
print("Exporting IMU")
|
||||
for timestamp, oxts in zip(kitti.timestamps, kitti.oxts):
|
||||
q = tf.transformations.quaternion_from_euler(oxts.packet.roll, oxts.packet.pitch, oxts.packet.yaw)
|
||||
imu = Imu()
|
||||
imu.header.frame_id = imu_frame_id
|
||||
imu.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f")))
|
||||
imu.orientation.x = q[0]
|
||||
imu.orientation.y = q[1]
|
||||
imu.orientation.z = q[2]
|
||||
imu.orientation.w = q[3]
|
||||
imu.linear_acceleration.x = oxts.packet.af
|
||||
imu.linear_acceleration.y = oxts.packet.al
|
||||
imu.linear_acceleration.z = oxts.packet.au
|
||||
imu.angular_velocity.x = oxts.packet.wf
|
||||
imu.angular_velocity.y = oxts.packet.wl
|
||||
imu.angular_velocity.z = oxts.packet.wu
|
||||
bag.write(topic, imu, t=imu.header.stamp)
|
||||
|
||||
def save_imu_data_raw(bag, kitti, imu_frame_id, topic, gps_correct_topic):
|
||||
print("Exporting IMU Raw")
|
||||
synced_path = kitti.data_path
|
||||
unsynced_path = synced_path.replace('sync', 'extract')
|
||||
imu_path = os.path.join(unsynced_path, 'oxts')
|
||||
|
||||
# read time stamp (convert to ros seconds format)
|
||||
with open(os.path.join(imu_path, 'timestamps.txt')) as f:
|
||||
lines = f.readlines()
|
||||
imu_datetimes = []
|
||||
for line in lines:
|
||||
if len(line) == 1:
|
||||
continue
|
||||
timestamp = datetime.strptime(line[:-4], '%Y-%m-%d %H:%M:%S.%f')
|
||||
imu_datetimes.append(float(timestamp.strftime("%s.%f")))
|
||||
|
||||
# fix imu time using a linear model (may not be ideal, ^_^)
|
||||
imu_index = np.asarray(range(len(imu_datetimes)), dtype=np.float64)
|
||||
z = np.polyfit(imu_index, imu_datetimes, 1)
|
||||
imu_datetimes_new = z[0] * imu_index + z[1]
|
||||
imu_datetimes = imu_datetimes_new.tolist()
|
||||
|
||||
# get all imu data
|
||||
imu_data_dir = os.path.join(imu_path, 'data')
|
||||
imu_filenames = sorted(os.listdir(imu_data_dir))
|
||||
imu_data = [None] * len(imu_filenames)
|
||||
for i, imu_file in enumerate(imu_filenames):
|
||||
imu_data_file = open(os.path.join(imu_data_dir, imu_file), "r")
|
||||
for line in imu_data_file:
|
||||
if len(line) == 1:
|
||||
continue
|
||||
stripped_line = line.strip()
|
||||
line_list = stripped_line.split()
|
||||
imu_data[i] = line_list
|
||||
|
||||
assert len(imu_datetimes) == len(imu_data)
|
||||
|
||||
for timestamp, data in zip(imu_datetimes, imu_data):
|
||||
roll, pitch, yaw = float(data[3]), float(data[4]), float(data[5]),
|
||||
q = tf.transformations.quaternion_from_euler(roll, pitch, yaw)
|
||||
imu = Imu()
|
||||
imu.header.frame_id = imu_frame_id
|
||||
imu.header.stamp = rospy.Time.from_sec(timestamp)
|
||||
imu.orientation.x = q[0]
|
||||
imu.orientation.y = q[1]
|
||||
imu.orientation.z = q[2]
|
||||
imu.orientation.w = q[3]
|
||||
imu.linear_acceleration.x = float(data[11])
|
||||
imu.linear_acceleration.y = float(data[12])
|
||||
imu.linear_acceleration.z = float(data[13])
|
||||
imu.angular_velocity.x = float(data[17])
|
||||
imu.angular_velocity.y = float(data[18])
|
||||
imu.angular_velocity.z = float(data[19])
|
||||
bag.write(topic, imu, t=imu.header.stamp)
|
||||
|
||||
imu.header.frame_id = 'imu_enu_link'
|
||||
bag.write('/imu_correct', imu, t=imu.header.stamp) # for LIO-SAM GPS
|
||||
|
||||
# For GPS 100HZ
|
||||
navsatfix_msg = NavSatFix()
|
||||
navsatfix_msg.header.frame_id = imu_frame_id
|
||||
navsatfix_msg.header.stamp = rospy.Time.from_sec(timestamp)
|
||||
navsatfix_msg.latitude = float(data[0])
|
||||
navsatfix_msg.longitude = float(data[1])
|
||||
navsatfix_msg.altitude = float(data[2])
|
||||
navsatfix_msg.status.service = 1
|
||||
bag.write(gps_correct_topic, navsatfix_msg, t=navsatfix_msg.header.stamp)
|
||||
|
||||
def save_dynamic_tf(bag, kitti, kitti_type, initial_time):
|
||||
print("Exporting time dependent transformations")
|
||||
if kitti_type.find("raw") != -1:
|
||||
for timestamp, oxts in zip(kitti.timestamps, kitti.oxts):
|
||||
tf_oxts_msg = TFMessage()
|
||||
tf_oxts_transform = TransformStamped()
|
||||
tf_oxts_transform.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f")))
|
||||
tf_oxts_transform.header.frame_id = 'world'
|
||||
tf_oxts_transform.child_frame_id = 'base_link'
|
||||
|
||||
transform = (oxts.T_w_imu)
|
||||
t = transform[0:3, 3]
|
||||
q = tf.transformations.quaternion_from_matrix(transform)
|
||||
oxts_tf = Transform()
|
||||
|
||||
oxts_tf.translation.x = t[0]
|
||||
oxts_tf.translation.y = t[1]
|
||||
oxts_tf.translation.z = t[2]
|
||||
|
||||
oxts_tf.rotation.x = q[0]
|
||||
oxts_tf.rotation.y = q[1]
|
||||
oxts_tf.rotation.z = q[2]
|
||||
oxts_tf.rotation.w = q[3]
|
||||
|
||||
tf_oxts_transform.transform = oxts_tf
|
||||
tf_oxts_msg.transforms.append(tf_oxts_transform)
|
||||
|
||||
bag.write('/tf', tf_oxts_msg, tf_oxts_msg.transforms[0].header.stamp)
|
||||
|
||||
elif kitti_type.find("odom") != -1:
|
||||
timestamps = map(lambda x: initial_time + x.total_seconds(), kitti.timestamps)
|
||||
for timestamp, tf_matrix in zip(timestamps, kitti.T_w_cam0):
|
||||
tf_msg = TFMessage()
|
||||
tf_stamped = TransformStamped()
|
||||
tf_stamped.header.stamp = rospy.Time.from_sec(timestamp)
|
||||
tf_stamped.header.frame_id = 'world'
|
||||
tf_stamped.child_frame_id = 'camera_left'
|
||||
|
||||
t = tf_matrix[0:3, 3]
|
||||
q = tf.transformations.quaternion_from_matrix(tf_matrix)
|
||||
transform = Transform()
|
||||
|
||||
transform.translation.x = t[0]
|
||||
transform.translation.y = t[1]
|
||||
transform.translation.z = t[2]
|
||||
|
||||
transform.rotation.x = q[0]
|
||||
transform.rotation.y = q[1]
|
||||
transform.rotation.z = q[2]
|
||||
transform.rotation.w = q[3]
|
||||
|
||||
tf_stamped.transform = transform
|
||||
tf_msg.transforms.append(tf_stamped)
|
||||
|
||||
bag.write('/tf', tf_msg, tf_msg.transforms[0].header.stamp)
|
||||
|
||||
def save_camera_data(bag, kitti_type, kitti, util, bridge, camera, camera_frame_id, topic, initial_time):
|
||||
print("Exporting camera {}".format(camera))
|
||||
if kitti_type.find("raw") != -1:
|
||||
camera_pad = '{0:02d}'.format(camera)
|
||||
image_dir = os.path.join(kitti.data_path, 'image_{}'.format(camera_pad))
|
||||
image_path = os.path.join(image_dir, 'data')
|
||||
image_filenames = sorted(os.listdir(image_path))
|
||||
with open(os.path.join(image_dir, 'timestamps.txt')) as f:
|
||||
image_datetimes = map(lambda x: datetime.strptime(x[:-4], '%Y-%m-%d %H:%M:%S.%f'), f.readlines())
|
||||
|
||||
calib = CameraInfo()
|
||||
calib.header.frame_id = camera_frame_id
|
||||
calib.width, calib.height = tuple(util['S_rect_{}'.format(camera_pad)].tolist())
|
||||
calib.distortion_model = 'plumb_bob'
|
||||
calib.K = util['K_{}'.format(camera_pad)]
|
||||
calib.R = util['R_rect_{}'.format(camera_pad)]
|
||||
calib.D = util['D_{}'.format(camera_pad)]
|
||||
calib.P = util['P_rect_{}'.format(camera_pad)]
|
||||
|
||||
elif kitti_type.find("odom") != -1:
|
||||
camera_pad = '{0:01d}'.format(camera)
|
||||
image_path = os.path.join(kitti.sequence_path, 'image_{}'.format(camera_pad))
|
||||
image_filenames = sorted(os.listdir(image_path))
|
||||
image_datetimes = map(lambda x: initial_time + x.total_seconds(), kitti.timestamps)
|
||||
|
||||
calib = CameraInfo()
|
||||
calib.header.frame_id = camera_frame_id
|
||||
calib.P = util['P{}'.format(camera_pad)]
|
||||
|
||||
iterable = zip(image_datetimes, image_filenames)
|
||||
for dt, filename in tqdm(iterable, total=len(image_filenames)):
|
||||
image_filename = os.path.join(image_path, filename)
|
||||
cv_image = cv2.imread(image_filename)
|
||||
calib.height, calib.width = cv_image.shape[:2]
|
||||
if camera in (0, 1):
|
||||
cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BGR2GRAY)
|
||||
encoding = "mono8" if camera in (0, 1) else "bgr8"
|
||||
image_message = bridge.cv2_to_imgmsg(cv_image, encoding=encoding)
|
||||
image_message.header.frame_id = camera_frame_id
|
||||
if kitti_type.find("raw") != -1:
|
||||
image_message.header.stamp = rospy.Time.from_sec(float(datetime.strftime(dt, "%s.%f")))
|
||||
topic_ext = "/image_raw"
|
||||
elif kitti_type.find("odom") != -1:
|
||||
image_message.header.stamp = rospy.Time.from_sec(dt)
|
||||
topic_ext = "/image_rect"
|
||||
calib.header.stamp = image_message.header.stamp
|
||||
bag.write(topic + topic_ext, image_message, t = image_message.header.stamp)
|
||||
bag.write(topic + '/camera_info', calib, t = calib.header.stamp)
|
||||
|
||||
def save_velo_data(bag, kitti, velo_frame_id, topic):
|
||||
print("Exporting velodyne data")
|
||||
velo_path = os.path.join(kitti.data_path, 'velodyne_points')
|
||||
velo_data_dir = os.path.join(velo_path, 'data')
|
||||
velo_filenames = sorted(os.listdir(velo_data_dir))
|
||||
with open(os.path.join(velo_path, 'timestamps.txt')) as f:
|
||||
lines = f.readlines()
|
||||
velo_datetimes = []
|
||||
for line in lines:
|
||||
if len(line) == 1:
|
||||
continue
|
||||
dt = datetime.strptime(line[:-4], '%Y-%m-%d %H:%M:%S.%f')
|
||||
velo_datetimes.append(dt)
|
||||
|
||||
iterable = zip(velo_datetimes, velo_filenames)
|
||||
|
||||
count = 0
|
||||
|
||||
for dt, filename in tqdm(iterable, total=len(velo_filenames)):
|
||||
if dt is None:
|
||||
continue
|
||||
|
||||
velo_filename = os.path.join(velo_data_dir, filename)
|
||||
|
||||
# read binary data
|
||||
scan = (np.fromfile(velo_filename, dtype=np.float32)).reshape(-1, 4)
|
||||
|
||||
# get ring channel
|
||||
depth = np.linalg.norm(scan, 2, axis=1)
|
||||
pitch = np.arcsin(scan[:, 2] / depth) # arcsin(z, depth)
|
||||
fov_down = -24.8 / 180.0 * np.pi
|
||||
fov = (abs(-24.8) + abs(2.0)) / 180.0 * np.pi
|
||||
proj_y = (pitch + abs(fov_down)) / fov # in [0.0, 1.0]
|
||||
proj_y *= 64 # in [0.0, H]
|
||||
proj_y = np.floor(proj_y)
|
||||
proj_y = np.minimum(64 - 1, proj_y)
|
||||
proj_y = np.maximum(0, proj_y).astype(np.int32) # in [0,H-1]
|
||||
proj_y = proj_y.reshape(-1, 1)
|
||||
scan = np.concatenate((scan,proj_y), axis=1)
|
||||
scan = scan.tolist()
|
||||
for i in range(len(scan)):
|
||||
scan[i][-1] = int(scan[i][-1])
|
||||
|
||||
# create header
|
||||
header = Header()
|
||||
header.frame_id = velo_frame_id
|
||||
header.stamp = rospy.Time.from_sec(float(datetime.strftime(dt, "%s.%f")))
|
||||
|
||||
# fill pcl msg
|
||||
fields = [PointField('x', 0, PointField.FLOAT32, 1),
|
||||
PointField('y', 4, PointField.FLOAT32, 1),
|
||||
PointField('z', 8, PointField.FLOAT32, 1),
|
||||
PointField('intensity', 12, PointField.FLOAT32, 1),
|
||||
PointField('ring', 16, PointField.UINT16, 1)]
|
||||
pcl_msg = pcl2.create_cloud(header, fields, scan)
|
||||
pcl_msg.is_dense = True
|
||||
# print(pcl_msg)
|
||||
|
||||
bag.write(topic, pcl_msg, t=pcl_msg.header.stamp)
|
||||
|
||||
# count += 1
|
||||
# if count > 200:
|
||||
# break
|
||||
|
||||
def get_static_transform(from_frame_id, to_frame_id, transform):
|
||||
t = transform[0:3, 3]
|
||||
q = tf.transformations.quaternion_from_matrix(transform)
|
||||
tf_msg = TransformStamped()
|
||||
tf_msg.header.frame_id = from_frame_id
|
||||
tf_msg.child_frame_id = to_frame_id
|
||||
tf_msg.transform.translation.x = float(t[0])
|
||||
tf_msg.transform.translation.y = float(t[1])
|
||||
tf_msg.transform.translation.z = float(t[2])
|
||||
tf_msg.transform.rotation.x = float(q[0])
|
||||
tf_msg.transform.rotation.y = float(q[1])
|
||||
tf_msg.transform.rotation.z = float(q[2])
|
||||
tf_msg.transform.rotation.w = float(q[3])
|
||||
return tf_msg
|
||||
|
||||
|
||||
def inv(transform):
|
||||
"Invert rigid body transformation matrix"
|
||||
R = transform[0:3, 0:3]
|
||||
t = transform[0:3, 3]
|
||||
t_inv = -1 * R.T.dot(t)
|
||||
transform_inv = np.eye(4)
|
||||
transform_inv[0:3, 0:3] = R.T
|
||||
transform_inv[0:3, 3] = t_inv
|
||||
return transform_inv
|
||||
|
||||
|
||||
def save_static_transforms(bag, transforms, timestamps):
|
||||
print("Exporting static transformations")
|
||||
tfm = TFMessage()
|
||||
for transform in transforms:
|
||||
t = get_static_transform(from_frame_id=transform[0], to_frame_id=transform[1], transform=transform[2])
|
||||
tfm.transforms.append(t)
|
||||
for timestamp in timestamps:
|
||||
time = rospy.Time.from_sec(float(timestamp.strftime("%s.%f")))
|
||||
for i in range(len(tfm.transforms)):
|
||||
tfm.transforms[i].header.stamp = time
|
||||
bag.write('/tf_static', tfm, t=time)
|
||||
|
||||
|
||||
def save_gps_fix_data(bag, kitti, gps_frame_id, topic):
|
||||
for timestamp, oxts in zip(kitti.timestamps, kitti.oxts):
|
||||
navsatfix_msg = NavSatFix()
|
||||
navsatfix_msg.header.frame_id = gps_frame_id
|
||||
navsatfix_msg.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f")))
|
||||
navsatfix_msg.latitude = oxts.packet.lat
|
||||
navsatfix_msg.longitude = oxts.packet.lon
|
||||
navsatfix_msg.altitude = oxts.packet.alt
|
||||
navsatfix_msg.status.service = 1
|
||||
bag.write(topic, navsatfix_msg, t=navsatfix_msg.header.stamp)
|
||||
|
||||
|
||||
def save_gps_vel_data(bag, kitti, gps_frame_id, topic):
|
||||
for timestamp, oxts in zip(kitti.timestamps, kitti.oxts):
|
||||
twist_msg = TwistStamped()
|
||||
twist_msg.header.frame_id = gps_frame_id
|
||||
twist_msg.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f")))
|
||||
twist_msg.twist.linear.x = oxts.packet.vf
|
||||
twist_msg.twist.linear.y = oxts.packet.vl
|
||||
twist_msg.twist.linear.z = oxts.packet.vu
|
||||
twist_msg.twist.angular.x = oxts.packet.wf
|
||||
twist_msg.twist.angular.y = oxts.packet.wl
|
||||
twist_msg.twist.angular.z = oxts.packet.wu
|
||||
bag.write(topic, twist_msg, t=twist_msg.header.stamp)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description = "Convert KITTI dataset to ROS bag file the easy way!")
|
||||
# Accepted argument values
|
||||
kitti_types = ["raw_synced", "odom_color", "odom_gray"]
|
||||
odometry_sequences = []
|
||||
for s in range(22):
|
||||
odometry_sequences.append(str(s).zfill(2))
|
||||
|
||||
parser.add_argument("kitti_type", choices = kitti_types, help = "KITTI dataset type")
|
||||
parser.add_argument("dir", nargs = "?", default = os.getcwd(), help = "base directory of the dataset, if no directory passed the deafult is current working directory")
|
||||
parser.add_argument("-t", "--date", help = "date of the raw dataset (i.e. 2011_09_26), option is only for RAW datasets.")
|
||||
parser.add_argument("-r", "--drive", help = "drive number of the raw dataset (i.e. 0001), option is only for RAW datasets.")
|
||||
parser.add_argument("-s", "--sequence", choices = odometry_sequences,help = "sequence of the odometry dataset (between 00 - 21), option is only for ODOMETRY datasets.")
|
||||
args = parser.parse_args()
|
||||
|
||||
bridge = CvBridge()
|
||||
compression = rosbag.Compression.NONE
|
||||
# compression = rosbag.Compression.BZ2
|
||||
# compression = rosbag.Compression.LZ4
|
||||
|
||||
# CAMERAS
|
||||
cameras = [
|
||||
(0, 'camera_gray_left', '/kitti/camera_gray_left'),
|
||||
(1, 'camera_gray_right', '/kitti/camera_gray_right'),
|
||||
(2, 'camera_color_left', '/kitti/camera_color_left'),
|
||||
(3, 'camera_color_right', '/kitti/camera_color_right')
|
||||
]
|
||||
|
||||
if args.kitti_type.find("raw") != -1:
|
||||
|
||||
if args.date == None:
|
||||
print("Date option is not given. It is mandatory for raw dataset.")
|
||||
print("Usage for raw dataset: kitti2bag raw_synced [dir] -t <date> -r <drive>")
|
||||
sys.exit(1)
|
||||
elif args.drive == None:
|
||||
print("Drive option is not given. It is mandatory for raw dataset.")
|
||||
print("Usage for raw dataset: kitti2bag raw_synced [dir] -t <date> -r <drive>")
|
||||
sys.exit(1)
|
||||
|
||||
bag = rosbag.Bag("kitti_{}_drive_{}_{}.bag".format(args.date, args.drive, args.kitti_type[4:]), 'w', compression=compression)
|
||||
kitti = pykitti.raw(args.dir, args.date, args.drive)
|
||||
if not os.path.exists(kitti.data_path):
|
||||
print('Path {} does not exists. Exiting.'.format(kitti.data_path))
|
||||
sys.exit(1)
|
||||
|
||||
if len(kitti.timestamps) == 0:
|
||||
print('Dataset is empty? Exiting.')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
# IMU
|
||||
imu_frame_id = 'imu_link'
|
||||
imu_topic = '/kitti/oxts/imu'
|
||||
imu_raw_topic = '/imu_raw'
|
||||
gps_fix_topic = '/gps/fix'
|
||||
gps_fix_correct_topic = '/gps/fix/correct'
|
||||
gps_vel_topic = '/gps/vel'
|
||||
velo_frame_id = 'velodyne'
|
||||
velo_topic = '/points_raw'
|
||||
|
||||
T_base_link_to_imu = np.eye(4, 4)
|
||||
T_base_link_to_imu[0:3, 3] = [-2.71/2.0-0.05, 0.32, 0.93]
|
||||
|
||||
# tf_static
|
||||
transforms = [
|
||||
('base_link', imu_frame_id, T_base_link_to_imu),
|
||||
(imu_frame_id, velo_frame_id, inv(kitti.calib.T_velo_imu)),
|
||||
(imu_frame_id, cameras[0][1], inv(kitti.calib.T_cam0_imu)),
|
||||
(imu_frame_id, cameras[1][1], inv(kitti.calib.T_cam1_imu)),
|
||||
(imu_frame_id, cameras[2][1], inv(kitti.calib.T_cam2_imu)),
|
||||
(imu_frame_id, cameras[3][1], inv(kitti.calib.T_cam3_imu))
|
||||
]
|
||||
|
||||
util = pykitti.utils.read_calib_file(os.path.join(kitti.calib_path, 'calib_cam_to_cam.txt'))
|
||||
|
||||
# Export
|
||||
# save_static_transforms(bag, transforms, kitti.timestamps)
|
||||
# save_dynamic_tf(bag, kitti, args.kitti_type, initial_time=None)
|
||||
# save_imu_data(bag, kitti, imu_frame_id, imu_topic)
|
||||
save_imu_data_raw(bag, kitti, imu_frame_id, imu_raw_topic, gps_fix_correct_topic)
|
||||
save_gps_fix_data(bag, kitti, imu_frame_id, gps_fix_topic)
|
||||
save_gps_vel_data(bag, kitti, imu_frame_id, gps_vel_topic)
|
||||
for camera in cameras:
|
||||
save_camera_data(bag, args.kitti_type, kitti, util, bridge, camera=camera[0], camera_frame_id=camera[1], topic=camera[2], initial_time=None)
|
||||
break
|
||||
save_velo_data(bag, kitti, velo_frame_id, velo_topic)
|
||||
|
||||
finally:
|
||||
print("## OVERVIEW ##")
|
||||
print(bag)
|
||||
bag.close()
|
||||
|
||||
elif args.kitti_type.find("odom") != -1:
|
||||
|
||||
if args.sequence == None:
|
||||
print("Sequence option is not given. It is mandatory for odometry dataset.")
|
||||
print("Usage for odometry dataset: kitti2bag {odom_color, odom_gray} [dir] -s <sequence>")
|
||||
sys.exit(1)
|
||||
|
||||
bag = rosbag.Bag("kitti_data_odometry_{}_sequence_{}.bag".format(args.kitti_type[5:],args.sequence), 'w', compression=compression)
|
||||
|
||||
kitti = pykitti.odometry(args.dir, args.sequence)
|
||||
if not os.path.exists(kitti.sequence_path):
|
||||
print('Path {} does not exists. Exiting.'.format(kitti.sequence_path))
|
||||
sys.exit(1)
|
||||
|
||||
kitti.load_calib()
|
||||
kitti.load_timestamps()
|
||||
|
||||
if len(kitti.timestamps) == 0:
|
||||
print('Dataset is empty? Exiting.')
|
||||
sys.exit(1)
|
||||
|
||||
if args.sequence in odometry_sequences[:11]:
|
||||
print("Odometry dataset sequence {} has ground truth information (poses).".format(args.sequence))
|
||||
kitti.load_poses()
|
||||
|
||||
try:
|
||||
util = pykitti.utils.read_calib_file(os.path.join(args.dir,'sequences',args.sequence, 'calib.txt'))
|
||||
current_epoch = (datetime.utcnow() - datetime(1970, 1, 1)).total_seconds()
|
||||
# Export
|
||||
if args.kitti_type.find("gray") != -1:
|
||||
used_cameras = cameras[:2]
|
||||
elif args.kitti_type.find("color") != -1:
|
||||
used_cameras = cameras[-2:]
|
||||
|
||||
save_dynamic_tf(bag, kitti, args.kitti_type, initial_time=current_epoch)
|
||||
for camera in used_cameras:
|
||||
save_camera_data(bag, args.kitti_type, kitti, util, bridge, camera=camera[0], camera_frame_id=camera[1], topic=camera[2], initial_time=current_epoch)
|
||||
|
||||
finally:
|
||||
print("## OVERVIEW ##")
|
||||
print(bag)
|
||||
bag.close()
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "/sensing/lidar/top/pointcloud" # Point cloud data
|
||||
imuTopic: "/sensing/imu/tamagawa/imu_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "/sensing/gnss/ublox/nav_sat_fix" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Documents/map/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: robosense # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 64 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 2 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 1 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 100.0
|
||||
imuAccNoise: 0.0001
|
||||
imuGyrNoise: 0.0001
|
||||
imuAccBiasN: 0.00001
|
||||
imuGyrBiasN: 0.00001
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.019973, 0.01783, -0.895085]
|
||||
extrinsicRot: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.3 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "points_raw" # Point cloud data
|
||||
imuTopic: "imu_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: velodyne # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 64 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 2 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 5 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 100.0
|
||||
imuAccNoise: 3.9939570888238808e-03
|
||||
imuGyrNoise: 1.5636343949698187e-03
|
||||
imuAccBiasN: 6.4356659353532566e-05
|
||||
imuGyrBiasN: 3.5640318696367613e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [-8.086759e-01, 3.195559e-01, -7.997231e-01]
|
||||
extrinsicRot: [9.999976e-01, 7.553071e-04, -2.035826e-03,
|
||||
-7.854027e-04, 9.998898e-01, -1.482298e-02,
|
||||
2.024406e-03, 1.482454e-02, 9.998881e-01]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [9.999976e-01, 7.553071e-04, -2.035826e-03,
|
||||
-7.854027e-04, 9.998898e-01, -1.482298e-02,
|
||||
2.024406e-03, 1.482454e-02, 9.998881e-01]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,89 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
history_policy: "history_keep_last"
|
||||
reliability_policy: "reliability_reliable"
|
||||
|
||||
# Topics
|
||||
pointCloudTopic: "points_raw" # Point cloud data
|
||||
imuTopic: "imu_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: velodyne # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 16 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 1 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 1 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 500.0
|
||||
imuAccNoise: 3.9939570888238808e-03
|
||||
imuGyrNoise: 1.5636343949698187e-03
|
||||
imuAccBiasN: 6.4356659353532566e-05
|
||||
imuGyrBiasN: 3.5640318696367613e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.0, 0.0, 0.0]
|
||||
extrinsicRot: [-1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, -1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [0.0, -1.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "points_raw" # Point cloud data
|
||||
imuTopic: "imu_correct" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: velodyne # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 16 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 1 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 1 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 1 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 500.0
|
||||
imuAccNoise: 3.9939570888238808e-03
|
||||
imuGyrNoise: 1.5636343949698187e-03
|
||||
imuAccBiasN: 6.4356659353532566e-05
|
||||
imuGyrBiasN: 3.5640318696367613e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.0, 0.0, 0.0]
|
||||
extrinsicRot: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "points_raw" # Point cloud data
|
||||
imuTopic: "imu_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "odometry/gpsz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: false # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: livox # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 6 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 4000 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 1 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 3 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 500.0
|
||||
imuAccNoise: 3.9939570888238808e-03
|
||||
imuGyrNoise: 1.5636343949698187e-03
|
||||
imuAccBiasN: 6.4356659353532566e-05
|
||||
imuGyrBiasN: 3.5640318696367613e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.0, 0.0, 0.0]
|
||||
extrinsicRot: [-1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, -1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [0.0, -1.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.15 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 0.5 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.3 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.3 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "points_raw" # Point cloud data
|
||||
imuTopic: "imu_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "odometry/gpsz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: false # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: ouster # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 128 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1024 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 2 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 5 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 500.0
|
||||
imuAccNoise: 3.9939570888238808e-03
|
||||
imuGyrNoise: 1.5636343949698187e-03
|
||||
imuAccBiasN: 6.4356659353532566e-05
|
||||
imuGyrBiasN: 3.5640318696367613e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.0, 0.0, 0.0]
|
||||
extrinsicRot: [-1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, -1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "/os1_points" # Point cloud data
|
||||
imuTopic: "/imu/data_raw" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: ouster # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 128 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1024 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 2 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 1 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 100.0
|
||||
imuAccNoise: 0.009939570888238808e+02
|
||||
imuGyrNoise: 0.005636343949698187e+02
|
||||
imuAccBiasN: 0.64356659353532566e-03
|
||||
imuGyrBiasN: 0.35640318696367613e-03
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [1.77, -0.00, -0.05]
|
||||
extrinsicRot: [-1.0, 0.0, 0.0,
|
||||
0.0, -1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.3 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,89 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics - Aligned with current drivers
|
||||
pointCloudTopic: "/sensing/lidar/top/liorf/pointcloud" # LIO-RF formatted point cloud from pointcloud_process
|
||||
imuTopic: "/sensing/imu/hipnuc/imu_raw" # HI13R4 IMU raw data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry
|
||||
gpsTopic: "/sensing/gnss/fix" # Wheeltec Dual RTK GPS
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Documents/map/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: robosense # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 64 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 1800 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 2 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 1 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 1.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings - HI13R4
|
||||
imuType: 0 # 0: 6-axis (HI13R4 without magnetic heading)
|
||||
imuRate: 100.0 # HI13R4 supports up to 1000Hz, 100Hz is recommended for LIO
|
||||
# Noise parameters from HI13R4 datasheet:
|
||||
# Accel Random Walk: 0.04 mg/sqrt(h) = 0.00004 * 9.81 / sqrt(3600) m/s^2/sqrt(s)
|
||||
# Gyro Random Walk: 0.25 deg/sqrt(h) = 0.25 * pi/180 / sqrt(3600) rad/s/sqrt(s)
|
||||
imuAccNoise: 0.00016 # [m/s^2/sqrt(Hz)] accelerometer white noise
|
||||
imuGyrNoise: 0.000036 # [rad/s/sqrt(Hz)] gyroscope white noise
|
||||
imuAccBiasN: 0.00035 # [m/s^2] accel bias (0.35mg from datasheet stability)
|
||||
imuGyrBiasN: 0.00015 # [rad/s] gyro bias (max 0.05deg/s from datasheet)
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.019973, 0.01783, -0.895085]
|
||||
extrinsicRot: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.3 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,86 @@
|
||||
/**:
|
||||
ros__parameters:
|
||||
# Topics
|
||||
pointCloudTopic: "/velodyne_points" # Point cloud data
|
||||
imuTopic: "/imu/data" # IMU data
|
||||
odomTopic: "odometry/imu" # IMU pre-preintegration odometry, same frequency as IMU
|
||||
gpsTopic: "gps/fixz" # GPS odometry topic from navsat, see module_navsat.launch file
|
||||
|
||||
# Frames
|
||||
lidarFrame: "base_link"
|
||||
baselinkFrame: "base_link"
|
||||
odometryFrame: "odom"
|
||||
mapFrame: "map"
|
||||
|
||||
# GPS Settings
|
||||
useImuHeadingInitialization: true # if using GPS data, set to "true"
|
||||
useGpsElevation: true # if GPS elevation is bad, set to "false"
|
||||
gpsCovThreshold: 2.0 # m^2, threshold for using GPS data
|
||||
poseCovThreshold: 25.0 # m^2, threshold for using GPS data
|
||||
|
||||
# Export settings
|
||||
savePCD: false # https://github.com/TixiaoShan/LIO-SAM/issues/3
|
||||
savePCDDirectory: "/Downloads/LOAM/" # in your home folder, starts and ends with "/". Warning: the code deletes "LOAM" folder then recreates it. See "mapOptimization" for implementation
|
||||
|
||||
# Sensor Settings
|
||||
sensor: velodyne # lidar sensor type, 'velodyne' or 'ouster' or 'livox' or 'robosense'
|
||||
N_SCAN: 32 # number of lidar channel (i.e., Velodyne/Ouster: 16, 32, 64, 128, Livox Horizon: 6)
|
||||
Horizon_SCAN: 2000 # lidar horizontal resolution (Velodyne:1800, Ouster:512,1024,2048, Livox Horizon: 4000)
|
||||
downsampleRate: 1 # default: 1. Downsample your data if too many points(line). i.e., 16 = 64 / 4, 16 = 16 / 1
|
||||
point_filter_num: 5 # default: 3. Downsample your data if too many points(point). e.g., 16: 1, 32: 5, 64: 8
|
||||
lidarMinRange: 3.0 # default: 1.0, minimum lidar range to be used
|
||||
lidarMaxRange: 1000.0 # default: 1000.0, maximum lidar range to be used
|
||||
|
||||
# IMU Settings
|
||||
imuType: 0 # 0: 6-axis 1: 9-axis
|
||||
imuRate: 100.0
|
||||
imuAccNoise: 8.1330537434371481e-03
|
||||
imuGyrNoise: 7.4266825125507141e-03
|
||||
imuAccBiasN: 1.2123362494392119e-04
|
||||
imuGyrBiasN: 8.6572985145653080e-05
|
||||
imuGravity: 9.80511
|
||||
imuRPYWeight: 0.01
|
||||
|
||||
# Extrinsics: T_lb (lidar -> imu)
|
||||
extrinsicTrans: [0.0, 0.0, 0.0]
|
||||
extrinsicRot: [1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# This parameter is set only when the 9-axis IMU is used, but it must be a high-precision IMU. e.g. MTI-680
|
||||
extrinsicRPY: [0.0, -1.0, 0.0,
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0]
|
||||
|
||||
# voxel filter paprams
|
||||
mappingSurfLeafSize: 0.4 # default: 0.4 - outdoor, 0.2 - indoor
|
||||
|
||||
# robot motion constraint (in case you are using a 2D robot)
|
||||
z_tollerance: 1000.0 # meters
|
||||
rotation_tollerance: 1000.0 # radians
|
||||
|
||||
# CPU Params
|
||||
numberOfCores: 4 # number of cores for mapping optimization
|
||||
mappingProcessInterval: 0.0 # seconds, regulate mapping frequency
|
||||
|
||||
# Surrounding map
|
||||
surroundingkeyframeAddingDistThreshold: 1.0 # meters, regulate keyframe adding threshold
|
||||
surroundingkeyframeAddingAngleThreshold: 0.2 # radians, regulate keyframe adding threshold
|
||||
surroundingKeyframeDensity: 2.0 # meters, downsample surrounding keyframe poses
|
||||
surroundingKeyframeSearchRadius: 50.0 # meters, within n meters scan-to-map optimization (when loop closure disabled)
|
||||
surroundingKeyframeMapLeafSize: 0.5 # downsample local map point cloud
|
||||
|
||||
# Loop closure
|
||||
loopClosureEnableFlag: true
|
||||
loopClosureFrequency: 1.0 # Hz, regulate loop closure constraint add frequency
|
||||
surroundingKeyframeSize: 50 # submap size (when loop closure enabled)
|
||||
historyKeyframeSearchRadius: 15.0 # meters, key frame that is within n meters from current pose will be considerd for loop closure
|
||||
historyKeyframeSearchTimeDiff: 30.0 # seconds, key frame that is n seconds older will be considered for loop closure
|
||||
historyKeyframeSearchNum: 25 # number of hostory key frames will be fused into a submap for loop closure
|
||||
loopClosureICPSurfLeafSize: 0.5 # downsample icp point cloud
|
||||
historyKeyframeFitnessScore: 0.3 # icp threshold, the smaller the better alignment
|
||||
|
||||
# Visualization
|
||||
globalMapVisualizationSearchRadius: 1000.0 # meters, global map visualization radius
|
||||
globalMapVisualizationPoseDensity: 1.0 # meters, global map visualization keyframe density
|
||||
globalMapVisualizationLeafSize: 0.5 # meters, global map visualization cloud density
|
||||
@@ -0,0 +1,117 @@
|
||||
/***********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright 2011-16 Jose Luis Blanco (joseluisblancoc@gmail.com).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nanoflann.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
// ===== This example shows how to use nanoflann with these types of containers: =======
|
||||
//typedef std::vector<std::vector<double> > my_vector_of_vectors_t;
|
||||
//typedef std::vector<Eigen::VectorXd> my_vector_of_vectors_t; // This requires #include <Eigen/Dense>
|
||||
// =====================================================================================
|
||||
|
||||
|
||||
/** A simple vector-of-vectors adaptor for nanoflann, without duplicating the storage.
|
||||
* The i'th vector represents a point in the state space.
|
||||
*
|
||||
* \tparam DIM If set to >0, it specifies a compile-time fixed dimensionality for the points in the data set, allowing more compiler optimizations.
|
||||
* \tparam num_t The type of the point coordinates (typically, double or float).
|
||||
* \tparam Distance The distance metric to use: nanoflann::metric_L1, nanoflann::metric_L2, nanoflann::metric_L2_Simple, etc.
|
||||
* \tparam IndexType The type for indices in the KD-tree index (typically, size_t of int)
|
||||
*/
|
||||
template <class VectorOfVectorsType, typename num_t = double, int DIM = -1, class Distance = nanoflann::metric_L2, typename IndexType = size_t>
|
||||
struct KDTreeVectorOfVectorsAdaptor
|
||||
{
|
||||
typedef KDTreeVectorOfVectorsAdaptor<VectorOfVectorsType,num_t,DIM,Distance> self_t;
|
||||
typedef typename Distance::template traits<num_t,self_t>::distance_t metric_t;
|
||||
typedef nanoflann::KDTreeSingleIndexAdaptor< metric_t,self_t,DIM,IndexType> index_t;
|
||||
|
||||
index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index.
|
||||
|
||||
/// Constructor: takes a const ref to the vector of vectors object with the data points
|
||||
KDTreeVectorOfVectorsAdaptor(const size_t /* dimensionality */, const VectorOfVectorsType &mat, const int leaf_max_size = 10) : m_data(mat)
|
||||
{
|
||||
assert(mat.size() != 0 && mat[0].size() != 0);
|
||||
const size_t dims = mat[0].size();
|
||||
if (DIM>0 && static_cast<int>(dims) != DIM)
|
||||
throw std::runtime_error("Data set dimensionality does not match the 'DIM' template argument");
|
||||
index = new index_t( static_cast<int>(dims), *this /* adaptor */, nanoflann::KDTreeSingleIndexAdaptorParams(leaf_max_size ) );
|
||||
index->buildIndex();
|
||||
}
|
||||
|
||||
~KDTreeVectorOfVectorsAdaptor() {
|
||||
delete index;
|
||||
}
|
||||
|
||||
const VectorOfVectorsType &m_data;
|
||||
|
||||
/** Query for the \a num_closest closest points to a given point (entered as query_point[0:dim-1]).
|
||||
* Note that this is a short-cut method for index->findNeighbors().
|
||||
* The user can also call index->... methods as desired.
|
||||
* \note nChecks_IGNORED is ignored but kept for compatibility with the original FLANN interface.
|
||||
*/
|
||||
inline void query(const num_t *query_point, const size_t num_closest, IndexType *out_indices, num_t *out_distances_sq, const int nChecks_IGNORED = 10) const
|
||||
{
|
||||
nanoflann::KNNResultSet<num_t,IndexType> resultSet(num_closest);
|
||||
resultSet.init(out_indices, out_distances_sq);
|
||||
index->findNeighbors(resultSet, query_point, nanoflann::SearchParams());
|
||||
}
|
||||
|
||||
/** @name Interface expected by KDTreeSingleIndexAdaptor
|
||||
* @{ */
|
||||
|
||||
const self_t & derived() const {
|
||||
return *this;
|
||||
}
|
||||
self_t & derived() {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Must return the number of data points
|
||||
inline size_t kdtree_get_point_count() const {
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
// Returns the dim'th component of the idx'th point in the class:
|
||||
inline num_t kdtree_get_pt(const size_t idx, const size_t dim) const {
|
||||
return m_data[idx][dim];
|
||||
}
|
||||
|
||||
// Optional bounding-box computation: return false to default to a standard bbox computation loop.
|
||||
// Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again.
|
||||
// Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds)
|
||||
template <class BBOX>
|
||||
bool kdtree_get_bbox(BBOX & /*bb*/) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
}; // end of KDTreeVectorOfVectorsAdaptor
|
||||
@@ -0,0 +1,346 @@
|
||||
#include "Scancontext.h"
|
||||
|
||||
// namespace SC2
|
||||
// {
|
||||
|
||||
void coreImportTest (void)
|
||||
{
|
||||
cout << "scancontext lib is successfully imported." << endl;
|
||||
} // coreImportTest
|
||||
|
||||
|
||||
float rad2deg(float radians)
|
||||
{
|
||||
return radians * 180.0 / M_PI;
|
||||
}
|
||||
|
||||
float deg2rad(float degrees)
|
||||
{
|
||||
return degrees * M_PI / 180.0;
|
||||
}
|
||||
|
||||
|
||||
float xy2theta( const float & _x, const float & _y )
|
||||
{
|
||||
if ( (_x >= 0) & (_y >= 0))
|
||||
return (180/M_PI) * atan(_y / _x);
|
||||
|
||||
if ( (_x < 0) & (_y >= 0))
|
||||
return 180 - ( (180/M_PI) * atan(_y / (-_x)) );
|
||||
|
||||
if ( (_x < 0) & (_y < 0))
|
||||
return 180 + ( (180/M_PI) * atan(_y / _x) );
|
||||
|
||||
if ( (_x >= 0) & (_y < 0))
|
||||
return 360 - ( (180/M_PI) * atan((-_y) / _x) );
|
||||
} // xy2theta
|
||||
|
||||
|
||||
MatrixXd circshift( MatrixXd &_mat, int _num_shift )
|
||||
{
|
||||
// shift columns to right direction
|
||||
assert(_num_shift >= 0);
|
||||
|
||||
if( _num_shift == 0 )
|
||||
{
|
||||
MatrixXd shifted_mat( _mat );
|
||||
return shifted_mat; // Early return
|
||||
}
|
||||
|
||||
MatrixXd shifted_mat = MatrixXd::Zero( _mat.rows(), _mat.cols() );
|
||||
for ( int col_idx = 0; col_idx < _mat.cols(); col_idx++ )
|
||||
{
|
||||
int new_location = (col_idx + _num_shift) % _mat.cols();
|
||||
shifted_mat.col(new_location) = _mat.col(col_idx);
|
||||
}
|
||||
|
||||
return shifted_mat;
|
||||
|
||||
} // circshift
|
||||
|
||||
|
||||
std::vector<float> eig2stdvec( MatrixXd _eigmat )
|
||||
{
|
||||
std::vector<float> vec( _eigmat.data(), _eigmat.data() + _eigmat.size() );
|
||||
return vec;
|
||||
} // eig2stdvec
|
||||
|
||||
|
||||
double SCManager::distDirectSC ( MatrixXd &_sc1, MatrixXd &_sc2 )
|
||||
{
|
||||
int num_eff_cols = 0; // i.e., to exclude all-nonzero sector
|
||||
double sum_sector_similarity = 0;
|
||||
for ( int col_idx = 0; col_idx < _sc1.cols(); col_idx++ )
|
||||
{
|
||||
VectorXd col_sc1 = _sc1.col(col_idx);
|
||||
VectorXd col_sc2 = _sc2.col(col_idx);
|
||||
|
||||
if( (col_sc1.norm() == 0) | (col_sc2.norm() == 0) )
|
||||
continue; // don't count this sector pair.
|
||||
|
||||
double sector_similarity = col_sc1.dot(col_sc2) / (col_sc1.norm() * col_sc2.norm());
|
||||
|
||||
sum_sector_similarity = sum_sector_similarity + sector_similarity;
|
||||
num_eff_cols = num_eff_cols + 1;
|
||||
}
|
||||
|
||||
double sc_sim = sum_sector_similarity / num_eff_cols;
|
||||
return 1.0 - sc_sim;
|
||||
|
||||
} // distDirectSC
|
||||
|
||||
|
||||
int SCManager::fastAlignUsingVkey( MatrixXd & _vkey1, MatrixXd & _vkey2)
|
||||
{
|
||||
int argmin_vkey_shift = 0;
|
||||
double min_veky_diff_norm = 10000000;
|
||||
for ( int shift_idx = 0; shift_idx < _vkey1.cols(); shift_idx++ )
|
||||
{
|
||||
MatrixXd vkey2_shifted = circshift(_vkey2, shift_idx);
|
||||
|
||||
MatrixXd vkey_diff = _vkey1 - vkey2_shifted;
|
||||
|
||||
double cur_diff_norm = vkey_diff.norm();
|
||||
if( cur_diff_norm < min_veky_diff_norm )
|
||||
{
|
||||
argmin_vkey_shift = shift_idx;
|
||||
min_veky_diff_norm = cur_diff_norm;
|
||||
}
|
||||
}
|
||||
|
||||
return argmin_vkey_shift;
|
||||
|
||||
} // fastAlignUsingVkey
|
||||
|
||||
|
||||
std::pair<double, int> SCManager::distanceBtnScanContext( MatrixXd &_sc1, MatrixXd &_sc2 )
|
||||
{
|
||||
// 1. fast align using variant key (not in original IROS18)
|
||||
MatrixXd vkey_sc1 = makeSectorkeyFromScancontext( _sc1 );
|
||||
MatrixXd vkey_sc2 = makeSectorkeyFromScancontext( _sc2 );
|
||||
int argmin_vkey_shift = fastAlignUsingVkey( vkey_sc1, vkey_sc2 );
|
||||
|
||||
const int SEARCH_RADIUS = round( 0.5 * SEARCH_RATIO * _sc1.cols() ); // a half of search range
|
||||
std::vector<int> shift_idx_search_space { argmin_vkey_shift };
|
||||
for ( int ii = 1; ii < SEARCH_RADIUS + 1; ii++ )
|
||||
{
|
||||
shift_idx_search_space.push_back( (argmin_vkey_shift + ii + _sc1.cols()) % _sc1.cols() );
|
||||
shift_idx_search_space.push_back( (argmin_vkey_shift - ii + _sc1.cols()) % _sc1.cols() );
|
||||
}
|
||||
std::sort(shift_idx_search_space.begin(), shift_idx_search_space.end());
|
||||
|
||||
// 2. fast columnwise diff
|
||||
int argmin_shift = 0;
|
||||
double min_sc_dist = 10000000;
|
||||
for ( int num_shift: shift_idx_search_space )
|
||||
{
|
||||
MatrixXd sc2_shifted = circshift(_sc2, num_shift);
|
||||
double cur_sc_dist = distDirectSC( _sc1, sc2_shifted );
|
||||
if( cur_sc_dist < min_sc_dist )
|
||||
{
|
||||
argmin_shift = num_shift;
|
||||
min_sc_dist = cur_sc_dist;
|
||||
}
|
||||
}
|
||||
|
||||
return make_pair(min_sc_dist, argmin_shift);
|
||||
|
||||
} // distanceBtnScanContext
|
||||
|
||||
|
||||
MatrixXd SCManager::makeScancontext( pcl::PointCloud<SCPointType> & _scan_down )
|
||||
{
|
||||
TicToc t_making_desc;
|
||||
|
||||
int num_pts_scan_down = _scan_down.points.size();
|
||||
|
||||
// main
|
||||
const int NO_POINT = -1000;
|
||||
MatrixXd desc = NO_POINT * MatrixXd::Ones(PC_NUM_RING, PC_NUM_SECTOR);
|
||||
|
||||
SCPointType pt;
|
||||
float azim_angle, azim_range; // wihtin 2d plane
|
||||
int ring_idx, sctor_idx;
|
||||
for (int pt_idx = 0; pt_idx < num_pts_scan_down; pt_idx++)
|
||||
{
|
||||
pt.x = _scan_down.points[pt_idx].x;
|
||||
pt.y = _scan_down.points[pt_idx].y;
|
||||
pt.z = _scan_down.points[pt_idx].z + LIDAR_HEIGHT; // naive adding is ok (all points should be > 0).
|
||||
|
||||
// xyz to ring, sector
|
||||
azim_range = sqrt(pt.x * pt.x + pt.y * pt.y);
|
||||
azim_angle = xy2theta(pt.x, pt.y);
|
||||
|
||||
// if range is out of roi, pass
|
||||
if( azim_range > PC_MAX_RADIUS )
|
||||
continue;
|
||||
|
||||
ring_idx = std::max( std::min( PC_NUM_RING, int(ceil( (azim_range / PC_MAX_RADIUS) * PC_NUM_RING )) ), 1 );
|
||||
sctor_idx = std::max( std::min( PC_NUM_SECTOR, int(ceil( (azim_angle / 360.0) * PC_NUM_SECTOR )) ), 1 );
|
||||
|
||||
// taking maximum z
|
||||
if ( desc(ring_idx-1, sctor_idx-1) < pt.z ) // -1 means cpp starts from 0
|
||||
desc(ring_idx-1, sctor_idx-1) = pt.z; // update for taking maximum value at that bin
|
||||
}
|
||||
|
||||
// reset no points to zero (for cosine dist later)
|
||||
for ( int row_idx = 0; row_idx < desc.rows(); row_idx++ )
|
||||
for ( int col_idx = 0; col_idx < desc.cols(); col_idx++ )
|
||||
if( desc(row_idx, col_idx) == NO_POINT )
|
||||
desc(row_idx, col_idx) = 0;
|
||||
|
||||
t_making_desc.toc("PolarContext making");
|
||||
|
||||
return desc;
|
||||
} // SCManager::makeScancontext
|
||||
|
||||
|
||||
MatrixXd SCManager::makeRingkeyFromScancontext( Eigen::MatrixXd &_desc )
|
||||
{
|
||||
/*
|
||||
* summary: rowwise mean vector
|
||||
*/
|
||||
Eigen::MatrixXd invariant_key(_desc.rows(), 1);
|
||||
for ( int row_idx = 0; row_idx < _desc.rows(); row_idx++ )
|
||||
{
|
||||
Eigen::MatrixXd curr_row = _desc.row(row_idx);
|
||||
invariant_key(row_idx, 0) = curr_row.mean();
|
||||
}
|
||||
|
||||
return invariant_key;
|
||||
} // SCManager::makeRingkeyFromScancontext
|
||||
|
||||
|
||||
MatrixXd SCManager::makeSectorkeyFromScancontext( Eigen::MatrixXd &_desc )
|
||||
{
|
||||
/*
|
||||
* summary: columnwise mean vector
|
||||
*/
|
||||
Eigen::MatrixXd variant_key(1, _desc.cols());
|
||||
for ( int col_idx = 0; col_idx < _desc.cols(); col_idx++ )
|
||||
{
|
||||
Eigen::MatrixXd curr_col = _desc.col(col_idx);
|
||||
variant_key(0, col_idx) = curr_col.mean();
|
||||
}
|
||||
|
||||
return variant_key;
|
||||
} // SCManager::makeSectorkeyFromScancontext
|
||||
|
||||
|
||||
const Eigen::MatrixXd& SCManager::getConstRefRecentSCD(void)
|
||||
{
|
||||
return polarcontexts_.back();
|
||||
}
|
||||
|
||||
|
||||
void SCManager::makeAndSaveScancontextAndKeys( pcl::PointCloud<SCPointType> & _scan_down )
|
||||
{
|
||||
Eigen::MatrixXd sc = makeScancontext(_scan_down); // v1
|
||||
Eigen::MatrixXd ringkey = makeRingkeyFromScancontext( sc );
|
||||
Eigen::MatrixXd sectorkey = makeSectorkeyFromScancontext( sc );
|
||||
std::vector<float> polarcontext_invkey_vec = eig2stdvec( ringkey );
|
||||
|
||||
polarcontexts_.push_back( sc );
|
||||
polarcontext_invkeys_.push_back( ringkey );
|
||||
polarcontext_vkeys_.push_back( sectorkey );
|
||||
polarcontext_invkeys_mat_.push_back( polarcontext_invkey_vec );
|
||||
|
||||
// cout <<polarcontext_vkeys_.size() << endl;
|
||||
|
||||
} // SCManager::makeAndSaveScancontextAndKeys
|
||||
|
||||
|
||||
std::pair<int, float> SCManager::detectLoopClosureID ( void )
|
||||
{
|
||||
int loop_id { -1 }; // init with -1, -1 means no loop (== LeGO-LOAM's variable "closestHistoryFrameID")
|
||||
|
||||
auto curr_key = polarcontext_invkeys_mat_.back(); // current observation (query)
|
||||
auto curr_desc = polarcontexts_.back(); // current observation (query)
|
||||
|
||||
/*
|
||||
* step 1: candidates from ringkey tree_
|
||||
*/
|
||||
if( (int)polarcontext_invkeys_mat_.size() < NUM_EXCLUDE_RECENT + 1)
|
||||
{
|
||||
std::pair<int, float> result {loop_id, 0.0};
|
||||
return result; // Early return
|
||||
}
|
||||
|
||||
// tree_ reconstruction (not mandatory to make everytime)
|
||||
if( tree_making_period_conter % TREE_MAKING_PERIOD_ == 0) // to save computation cost
|
||||
{
|
||||
TicToc t_tree_construction;
|
||||
|
||||
polarcontext_invkeys_to_search_.clear();
|
||||
polarcontext_invkeys_to_search_.assign( polarcontext_invkeys_mat_.begin(), polarcontext_invkeys_mat_.end() - NUM_EXCLUDE_RECENT ) ;
|
||||
|
||||
polarcontext_tree_.reset();
|
||||
polarcontext_tree_ = std::make_unique<InvKeyTree>(PC_NUM_RING /* dim */, polarcontext_invkeys_to_search_, 10 /* max leaf */ );
|
||||
// tree_ptr_->index->buildIndex(); // inernally called in the constructor of InvKeyTree (for detail, refer the nanoflann and KDtreeVectorOfVectorsAdaptor)
|
||||
t_tree_construction.toc("Tree construction");
|
||||
}
|
||||
tree_making_period_conter = tree_making_period_conter + 1;
|
||||
|
||||
double min_dist = 10000000; // init with somthing large
|
||||
int nn_align = 0;
|
||||
int nn_idx = 0;
|
||||
|
||||
// knn search
|
||||
std::vector<size_t> candidate_indexes( NUM_CANDIDATES_FROM_TREE );
|
||||
std::vector<float> out_dists_sqr( NUM_CANDIDATES_FROM_TREE );
|
||||
|
||||
TicToc t_tree_search;
|
||||
nanoflann::KNNResultSet<float> knnsearch_result( NUM_CANDIDATES_FROM_TREE );
|
||||
knnsearch_result.init( &candidate_indexes[0], &out_dists_sqr[0] );
|
||||
polarcontext_tree_->index->findNeighbors( knnsearch_result, &curr_key[0] /* query */, nanoflann::SearchParams(10) );
|
||||
t_tree_search.toc("Tree search");
|
||||
|
||||
/*
|
||||
* step 2: pairwise distance (find optimal columnwise best-fit using cosine distance)
|
||||
*/
|
||||
TicToc t_calc_dist;
|
||||
for ( int candidate_iter_idx = 0; candidate_iter_idx < NUM_CANDIDATES_FROM_TREE; candidate_iter_idx++ )
|
||||
{
|
||||
MatrixXd polarcontext_candidate = polarcontexts_[ candidate_indexes[candidate_iter_idx] ];
|
||||
std::pair<double, int> sc_dist_result = distanceBtnScanContext( curr_desc, polarcontext_candidate );
|
||||
|
||||
double candidate_dist = sc_dist_result.first;
|
||||
int candidate_align = sc_dist_result.second;
|
||||
|
||||
if( candidate_dist < min_dist )
|
||||
{
|
||||
min_dist = candidate_dist;
|
||||
nn_align = candidate_align;
|
||||
|
||||
nn_idx = candidate_indexes[candidate_iter_idx];
|
||||
}
|
||||
}
|
||||
t_calc_dist.toc("Distance calc");
|
||||
|
||||
/*
|
||||
* loop threshold check
|
||||
*/
|
||||
if( min_dist < SC_DIST_THRES )
|
||||
{
|
||||
loop_id = nn_idx;
|
||||
|
||||
// std::cout.precision(3);
|
||||
// cout << "[Loop found] Nearest distance: " << min_dist << " btn " << polarcontexts_.size()-1 << " and " << nn_idx << "." << endl;
|
||||
// cout << "[Loop found] yaw diff: " << nn_align * PC_UNIT_SECTORANGLE << " deg." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout.precision(3);
|
||||
// cout << "[Not loop] Nearest distance: " << min_dist << " btn " << polarcontexts_.size()-1 << " and " << nn_idx << "." << endl;
|
||||
// cout << "[Not loop] yaw diff: " << nn_align * PC_UNIT_SECTORANGLE << " deg." << endl;
|
||||
}
|
||||
|
||||
// To do: return also nn_align (i.e., yaw diff)
|
||||
float yaw_diff_rad = deg2rad(nn_align * PC_UNIT_SECTORANGLE);
|
||||
std::pair<int, float> result {loop_id, yaw_diff_rad};
|
||||
|
||||
return result;
|
||||
|
||||
} // SCManager::detectLoopClosureID
|
||||
|
||||
// } // namespace SC2
|
||||
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/core/eigen.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <cv_bridge/cv_bridge.h>
|
||||
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/filters/voxel_grid.h>
|
||||
#include <pcl_conversions/pcl_conversions.h>
|
||||
|
||||
#include "nanoflann.hpp"
|
||||
#include "KDTreeVectorOfVectorsAdaptor.h"
|
||||
|
||||
#include "tictoc.h"
|
||||
|
||||
using namespace Eigen;
|
||||
using namespace nanoflann;
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::make_pair;
|
||||
|
||||
using std::atan2;
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
|
||||
using SCPointType = pcl::PointXYZI; // using xyz only. but a user can exchange the original bin encoding function (i.e., max hegiht) to max intensity (for detail, refer 20 ICRA Intensity Scan Context)
|
||||
using KeyMat = std::vector<std::vector<float> >;
|
||||
using InvKeyTree = KDTreeVectorOfVectorsAdaptor< KeyMat, float >;
|
||||
|
||||
|
||||
// namespace SC2
|
||||
// {
|
||||
|
||||
void coreImportTest ( void );
|
||||
|
||||
|
||||
// sc param-independent helper functions
|
||||
float xy2theta( const float & _x, const float & _y );
|
||||
MatrixXd circshift( MatrixXd &_mat, int _num_shift );
|
||||
std::vector<float> eig2stdvec( MatrixXd _eigmat );
|
||||
|
||||
|
||||
class SCManager
|
||||
{
|
||||
public:
|
||||
SCManager( ) = default; // reserving data space (of std::vector) could be considered. but the descriptor is lightweight so don't care.
|
||||
|
||||
Eigen::MatrixXd makeScancontext( pcl::PointCloud<SCPointType> & _scan_down );
|
||||
Eigen::MatrixXd makeRingkeyFromScancontext( Eigen::MatrixXd &_desc );
|
||||
Eigen::MatrixXd makeSectorkeyFromScancontext( Eigen::MatrixXd &_desc );
|
||||
|
||||
int fastAlignUsingVkey ( MatrixXd & _vkey1, MatrixXd & _vkey2 );
|
||||
double distDirectSC ( MatrixXd &_sc1, MatrixXd &_sc2 ); // "d" (eq 5) in the original paper (IROS 18)
|
||||
std::pair<double, int> distanceBtnScanContext ( MatrixXd &_sc1, MatrixXd &_sc2 ); // "D" (eq 6) in the original paper (IROS 18)
|
||||
|
||||
// User-side API
|
||||
void makeAndSaveScancontextAndKeys( pcl::PointCloud<SCPointType> & _scan_down );
|
||||
std::pair<int, float> detectLoopClosureID( void ); // int: nearest node index, float: relative yaw
|
||||
|
||||
// for ltmapper
|
||||
const Eigen::MatrixXd& getConstRefRecentSCD(void);
|
||||
|
||||
public:
|
||||
// hyper parameters ()
|
||||
const double LIDAR_HEIGHT = 2.0; // lidar height : add this for simply directly using lidar scan in the lidar local coord (not robot base coord) / if you use robot-coord-transformed lidar scans, just set this as 0.
|
||||
|
||||
const int PC_NUM_RING = 20; // 20 in the original paper (IROS 18)
|
||||
const int PC_NUM_SECTOR = 60; // 60 in the original paper (IROS 18)
|
||||
const double PC_MAX_RADIUS = 80.0; // 80 meter max in the original paper (IROS 18)
|
||||
const double PC_UNIT_SECTORANGLE = 360.0 / double(PC_NUM_SECTOR);
|
||||
const double PC_UNIT_RINGGAP = PC_MAX_RADIUS / double(PC_NUM_RING);
|
||||
|
||||
// tree
|
||||
const int NUM_EXCLUDE_RECENT = 30; // simply just keyframe gap (related with loopClosureFrequency in yaml), but node position distance-based exclusion is ok.
|
||||
const int NUM_CANDIDATES_FROM_TREE = 3; // 10 is enough. (refer the IROS 18 paper)
|
||||
|
||||
// loop thres
|
||||
const double SEARCH_RATIO = 0.1; // for fast comparison, no Brute-force, but search 10 % is okay. // not was in the original conf paper, but improved ver.
|
||||
// const double SC_DIST_THRES = 0.13; // empirically 0.1-0.2 is fine (rare false-alarms) for 20x60 polar context (but for 0.15 <, DCS or ICP fit score check (e.g., in LeGO-LOAM) should be required for robustness)
|
||||
const double SC_DIST_THRES = 0.3; // 0.4-0.6 is good choice for using with robust kernel (e.g., Cauchy, DCS) + icp fitness threshold / if not, recommend 0.1-0.15
|
||||
// const double SC_DIST_THRES = 0.7; // 0.4-0.6 is good choice for using with robust kernel (e.g., Cauchy, DCS) + icp fitness threshold / if not, recommend 0.1-0.15
|
||||
|
||||
// config
|
||||
const int TREE_MAKING_PERIOD_ = 10; // i.e., remaking tree frequency, to avoid non-mandatory every remaking, to save time cost / in the LeGO-LOAM integration, it is synchronized with the loop detection callback (which is 1Hz) so it means the tree is updated evrey 10 sec. But you can use the smaller value because it is enough fast ~ 5-50ms wrt N.
|
||||
int tree_making_period_conter = 0;
|
||||
|
||||
// data
|
||||
std::vector<double> polarcontexts_timestamp_; // optional.
|
||||
std::vector<Eigen::MatrixXd> polarcontexts_;
|
||||
std::vector<Eigen::MatrixXd> polarcontext_invkeys_;
|
||||
std::vector<Eigen::MatrixXd> polarcontext_vkeys_;
|
||||
|
||||
KeyMat polarcontext_invkeys_mat_;
|
||||
KeyMat polarcontext_invkeys_to_search_;
|
||||
std::unique_ptr<InvKeyTree> polarcontext_tree_;
|
||||
|
||||
}; // SCManager
|
||||
|
||||
// } // namespace SC2
|
||||
@@ -0,0 +1,47 @@
|
||||
// Author: Tong Qin qintonguav@gmail.com
|
||||
// Shaozu Cao saozu.cao@connect.ust.hk
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
|
||||
class TicToc
|
||||
{
|
||||
public:
|
||||
TicToc()
|
||||
{
|
||||
tic();
|
||||
}
|
||||
|
||||
TicToc( bool _disp )
|
||||
{
|
||||
disp_ = _disp;
|
||||
tic();
|
||||
}
|
||||
|
||||
void tic()
|
||||
{
|
||||
start = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
void toc( std::string _about_task )
|
||||
{
|
||||
end = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||
double elapsed_ms = elapsed_seconds.count() * 1000;
|
||||
|
||||
if( disp_ )
|
||||
{
|
||||
std::cout.precision(3); // 10 for sec, 3 for ms
|
||||
std::cout << _about_task << ": " << elapsed_ms << " msec." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
bool disp_ = false;
|
||||
};
|
||||
@@ -0,0 +1,436 @@
|
||||
#pragma once
|
||||
#ifndef _UTILITY_LIDAR_ODOMETRY_H_
|
||||
#define _UTILITY_LIDAR_ODOMETRY_H_
|
||||
#define PCL_NO_PRECOMPILE
|
||||
// <!-- liorf_yjz_lucky_boy -->
|
||||
#include <rclcpp/rclcpp.hpp>
|
||||
|
||||
#include <std_msgs/msg/header.hpp>
|
||||
#include <std_msgs/msg/string.hpp>
|
||||
#include <std_msgs/msg/float64_multi_array.hpp>
|
||||
#include <sensor_msgs/msg/imu.hpp>
|
||||
#include <sensor_msgs/msg/point_cloud2.hpp>
|
||||
#include <sensor_msgs/msg/nav_sat_fix.hpp>
|
||||
#include <nav_msgs/msg/odometry.hpp>
|
||||
#include <nav_msgs/msg/path.hpp>
|
||||
#include <common_lib.h>
|
||||
#include <visualization_msgs/msg/marker.hpp>
|
||||
#include <visualization_msgs/msg/marker_array.hpp>
|
||||
|
||||
#include <pcl/point_cloud.h>
|
||||
#include <pcl/point_types.h>
|
||||
#include <pcl/search/impl/search.hpp>
|
||||
#include <pcl/range_image/range_image.h>
|
||||
#include <pcl/kdtree/kdtree_flann.h>
|
||||
#include <pcl/common/common.h>
|
||||
#include <pcl/common/transforms.h>
|
||||
#include <pcl/registration/icp.h>
|
||||
#include <pcl/io/pcd_io.h>
|
||||
#include <pcl/filters/filter.h>
|
||||
#include <pcl/filters/voxel_grid.h>
|
||||
#include <pcl/filters/crop_box.h>
|
||||
#include <pcl_conversions/pcl_conversions.h>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
// #include <opencv/cv.h>
|
||||
|
||||
#include <tf2/LinearMath/Quaternion.h>
|
||||
#include <tf2_ros/transform_listener.h>
|
||||
#include <tf2_ros/transform_broadcaster.h>
|
||||
#include <tf2_eigen/tf2_eigen.h>
|
||||
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
|
||||
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <cfloat>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <iomanip>
|
||||
#include <array>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef pcl::PointXYZI PointType;
|
||||
|
||||
// <!-- liorf_localization_yjz_lucky_boy -->
|
||||
std::shared_ptr<CommonLib::common_lib> common_lib_;
|
||||
|
||||
enum class SensorType { VELODYNE, OUSTER, LIVOX, ROBOSENSE, MULRAN};
|
||||
|
||||
class ParamServer : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
string history_policy;
|
||||
string reliability_policy;
|
||||
|
||||
std::string robot_id;
|
||||
|
||||
//Topics
|
||||
string pointCloudTopic;
|
||||
string imuTopic;
|
||||
string odomTopic;
|
||||
string gpsTopic;
|
||||
|
||||
//Frames
|
||||
string lidarFrame;
|
||||
string baselinkFrame;
|
||||
string odometryFrame;
|
||||
string mapFrame;
|
||||
|
||||
// GPS Settings
|
||||
bool useImuHeadingInitialization;
|
||||
bool useGpsElevation;
|
||||
float gpsCovThreshold;
|
||||
float poseCovThreshold;
|
||||
|
||||
// Save pcd
|
||||
bool savePCD;
|
||||
string savePCDDirectory;
|
||||
|
||||
// Lidar Sensor Configuration
|
||||
SensorType sensor;
|
||||
int N_SCAN;
|
||||
int Horizon_SCAN;
|
||||
int downsampleRate;
|
||||
int point_filter_num;
|
||||
float lidarMinRange;
|
||||
float lidarMaxRange;
|
||||
|
||||
// IMU
|
||||
int imuType;
|
||||
float imuRate;
|
||||
float imuAccNoise;
|
||||
float imuGyrNoise;
|
||||
float imuAccBiasN;
|
||||
float imuGyrBiasN;
|
||||
float imuGravity;
|
||||
float imuRPYWeight;
|
||||
vector<double> extRotV;
|
||||
vector<double> extRPYV;
|
||||
vector<double> extTransV;
|
||||
Eigen::Matrix3d extRot;
|
||||
Eigen::Matrix3d extRPY;
|
||||
Eigen::Vector3d extTrans;
|
||||
Eigen::Quaterniond extQRPY;
|
||||
|
||||
// voxel filter paprams
|
||||
float mappingSurfLeafSize ;
|
||||
float surroundingKeyframeMapLeafSize;
|
||||
float loopClosureICPSurfLeafSize ;
|
||||
|
||||
float z_tollerance;
|
||||
float rotation_tollerance;
|
||||
|
||||
// CPU Params
|
||||
int numberOfCores;
|
||||
double mappingProcessInterval;
|
||||
|
||||
// Surrounding map
|
||||
float surroundingkeyframeAddingDistThreshold;
|
||||
float surroundingkeyframeAddingAngleThreshold;
|
||||
float surroundingKeyframeDensity;
|
||||
float surroundingKeyframeSearchRadius;
|
||||
|
||||
// Loop closure
|
||||
bool loopClosureEnableFlag;
|
||||
float loopClosureFrequency;
|
||||
int surroundingKeyframeSize;
|
||||
float historyKeyframeSearchRadius;
|
||||
float historyKeyframeSearchTimeDiff;
|
||||
int historyKeyframeSearchNum;
|
||||
float historyKeyframeFitnessScore;
|
||||
|
||||
// global map visualization radius
|
||||
float globalMapVisualizationSearchRadius;
|
||||
float globalMapVisualizationPoseDensity;
|
||||
float globalMapVisualizationLeafSize;
|
||||
|
||||
ParamServer(std::string node_name, const rclcpp::NodeOptions & options) : Node(node_name, options)
|
||||
{
|
||||
declare_parameter<string>("history_policy", "history_keep_last");
|
||||
get_parameter("history_policy", history_policy);
|
||||
declare_parameter<string>("reliability_policy", "reliability_reliable");
|
||||
get_parameter("reliability_policy", reliability_policy);
|
||||
|
||||
declare_parameter<string>("pointCloudTopic", "/points_raw");
|
||||
get_parameter("pointCloudTopic", pointCloudTopic);
|
||||
declare_parameter<string>("imuTopic", "/imu_correct");
|
||||
get_parameter("imuTopic", imuTopic);
|
||||
declare_parameter<string>("odomTopic", "/odometry/imu");
|
||||
get_parameter("odomTopic", odomTopic);
|
||||
declare_parameter<string>("gpsTopic", "/odometry/gps");
|
||||
get_parameter("gpsTopic", gpsTopic);
|
||||
|
||||
declare_parameter<string>("lidarFrame", "base_link");
|
||||
get_parameter("lidarFrame", lidarFrame);
|
||||
declare_parameter<string>("baselinkFrame", "base_link");
|
||||
get_parameter("baselinkFrame", baselinkFrame);
|
||||
declare_parameter<string>("odometryFrame", "odom");
|
||||
get_parameter("odometryFrame", odometryFrame);
|
||||
declare_parameter<string>("mapFrame", "map");
|
||||
get_parameter("mapFrame", mapFrame);
|
||||
|
||||
declare_parameter<bool>("useImuHeadingInitialization", false);
|
||||
get_parameter("useImuHeadingInitialization", useImuHeadingInitialization);
|
||||
declare_parameter<bool>("useGpsElevation", false);
|
||||
get_parameter("useGpsElevation", useGpsElevation);
|
||||
declare_parameter<float>("gpsCovThreshold", 2.0f);
|
||||
get_parameter("gpsCovThreshold", gpsCovThreshold);
|
||||
declare_parameter<float>("poseCovThreshold", 25.0f);
|
||||
get_parameter("poseCovThreshold", poseCovThreshold);
|
||||
|
||||
declare_parameter<bool>("savePCD", false);
|
||||
get_parameter("savePCD", savePCD);
|
||||
declare_parameter<string>("savePCDDirectory", "/Downloads/LOAM/");
|
||||
get_parameter("savePCDDirectory", savePCDDirectory);
|
||||
|
||||
std::string sensorStr;
|
||||
declare_parameter<string>("sensor", " ");
|
||||
get_parameter("sensor", sensorStr);
|
||||
if (sensorStr == "velodyne")
|
||||
{
|
||||
sensor = SensorType::VELODYNE;
|
||||
}
|
||||
else if (sensorStr == "ouster")
|
||||
{
|
||||
sensor = SensorType::OUSTER;
|
||||
}
|
||||
else if (sensorStr == "livox")
|
||||
{
|
||||
sensor = SensorType::LIVOX;
|
||||
} else if (sensorStr == "robosense") {
|
||||
sensor = SensorType::ROBOSENSE;
|
||||
}
|
||||
else if (sensorStr == "mulran")
|
||||
{
|
||||
sensor = SensorType::MULRAN;
|
||||
}
|
||||
else {
|
||||
RCLCPP_ERROR_STREAM(
|
||||
get_logger(),
|
||||
"Invalid sensor type (must be either 'velodyne' or 'ouster' or 'livox' or 'robosense' or 'mulran'): " << sensorStr);
|
||||
rclcpp::shutdown();
|
||||
}
|
||||
|
||||
declare_parameter<int>("N_SCAN", 16);
|
||||
get_parameter("N_SCAN", N_SCAN);
|
||||
declare_parameter<int>("Horizon_SCAN", 1800);
|
||||
get_parameter("Horizon_SCAN", Horizon_SCAN);
|
||||
declare_parameter<int>("downsampleRate", 1);
|
||||
get_parameter("downsampleRate", downsampleRate);
|
||||
declare_parameter<int>("point_filter_num", 3);
|
||||
get_parameter("point_filter_num", point_filter_num);
|
||||
declare_parameter<float>("lidarMinRange", 1.0f);
|
||||
get_parameter("lidarMinRange", lidarMinRange);
|
||||
declare_parameter<float>("lidarMaxRange", 1000.0f);
|
||||
get_parameter("lidarMaxRange", lidarMaxRange);
|
||||
|
||||
declare_parameter<int>("imuType", 0);
|
||||
get_parameter("imuType", imuType);
|
||||
declare_parameter<float>("imuRate", 500.0f);
|
||||
get_parameter("imuRate", imuRate);
|
||||
declare_parameter<float>("imuAccNoise", 0.01f);
|
||||
get_parameter("imuAccNoise", imuAccNoise);
|
||||
declare_parameter<float>("imuGyrNoise", 0.001f);
|
||||
get_parameter("imuGyrNoise", imuGyrNoise);
|
||||
declare_parameter<float>("imuAccBiasN", 0.0002f);
|
||||
get_parameter("imuAccBiasN", imuAccBiasN);
|
||||
declare_parameter<float>("imuGyrBiasN", 0.00003f);
|
||||
get_parameter("imuGyrBiasN", imuGyrBiasN);
|
||||
declare_parameter<float>("imuGravity", 9.80511f);
|
||||
get_parameter("imuGravity", imuGravity);
|
||||
declare_parameter<float>("imuRPYWeight", 0.01f);
|
||||
get_parameter("imuRPYWeight", imuRPYWeight);
|
||||
|
||||
double ida[] = { 1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0};
|
||||
std::vector < double > id(ida, std::end(ida));
|
||||
declare_parameter("extrinsicRot", id);
|
||||
get_parameter("extrinsicRot", extRotV);
|
||||
declare_parameter("extrinsicRPY", id);
|
||||
get_parameter("extrinsicRPY", extRPYV);
|
||||
double zea[] = {0.0, 0.0, 0.0};
|
||||
std::vector < double > ze(zea, std::end(zea));
|
||||
declare_parameter("extrinsicTrans", ze);
|
||||
get_parameter("extrinsicTrans", extTransV);
|
||||
|
||||
extRot = Eigen::Map<const Eigen::Matrix<double, -1, -1, Eigen::RowMajor>>(extRotV.data(), 3, 3);
|
||||
extRPY = Eigen::Map<const Eigen::Matrix<double, -1, -1, Eigen::RowMajor>>(extRPYV.data(), 3, 3);
|
||||
extTrans = Eigen::Map<const Eigen::Matrix<double, -1, -1, Eigen::RowMajor>>(extTransV.data(), 3, 1);
|
||||
extQRPY = Eigen::Quaterniond(extRPY).inverse();
|
||||
|
||||
declare_parameter<float>("mappingSurfLeafSize", 0.2f);
|
||||
get_parameter("mappingSurfLeafSize", mappingSurfLeafSize);
|
||||
declare_parameter<float>("surroundingKeyframeMapLeafSize", 0.2f);
|
||||
get_parameter("surroundingKeyframeMapLeafSize", surroundingKeyframeMapLeafSize);
|
||||
declare_parameter<float>("z_tollerance", 1000.0f);
|
||||
get_parameter("z_tollerance", z_tollerance);
|
||||
declare_parameter<float>("rotation_tollerance", 1000.0f);
|
||||
get_parameter("rotation_tollerance", rotation_tollerance);
|
||||
|
||||
declare_parameter<int>("numberOfCores", 2);
|
||||
get_parameter("numberOfCores", numberOfCores);
|
||||
declare_parameter<double>("mappingProcessInterval", 0.15f);
|
||||
get_parameter("mappingProcessInterval", mappingProcessInterval);
|
||||
|
||||
declare_parameter<float>("surroundingkeyframeAddingDistThreshold", 1.0f);
|
||||
get_parameter("surroundingkeyframeAddingDistThreshold", surroundingkeyframeAddingDistThreshold);
|
||||
declare_parameter<float>("surroundingkeyframeAddingAngleThreshold", 0.2f);
|
||||
get_parameter("surroundingkeyframeAddingAngleThreshold", surroundingkeyframeAddingAngleThreshold);
|
||||
declare_parameter<float>("surroundingKeyframeDensity", 1.0f);
|
||||
get_parameter("surroundingKeyframeDensity", surroundingKeyframeDensity);
|
||||
declare_parameter<float>("loopClosureICPSurfLeafSize", 0.3f);
|
||||
get_parameter("loopClosureICPSurfLeafSize", loopClosureICPSurfLeafSize);
|
||||
declare_parameter<float>("surroundingKeyframeSearchRadius", 50.0f);
|
||||
get_parameter("surroundingKeyframeSearchRadius", surroundingKeyframeSearchRadius);
|
||||
|
||||
declare_parameter<bool>("loopClosureEnableFlag", false);
|
||||
get_parameter("loopClosureEnableFlag", loopClosureEnableFlag);
|
||||
declare_parameter<float>("loopClosureFrequency", 1.0f);
|
||||
get_parameter("loopClosureFrequency", loopClosureFrequency);
|
||||
declare_parameter<int>("surroundingKeyframeSize", 50);
|
||||
get_parameter("surroundingKeyframeSize", surroundingKeyframeSize);
|
||||
declare_parameter<float>("historyKeyframeSearchRadius", 10.0f);
|
||||
get_parameter("historyKeyframeSearchRadius", historyKeyframeSearchRadius);
|
||||
declare_parameter<float>("historyKeyframeSearchTimeDiff", 30.0f);
|
||||
get_parameter("historyKeyframeSearchTimeDiff", historyKeyframeSearchTimeDiff);
|
||||
declare_parameter<int>("historyKeyframeSearchNum", 25);
|
||||
get_parameter("historyKeyframeSearchNum", historyKeyframeSearchNum);
|
||||
declare_parameter<float>("historyKeyframeFitnessScore", 0.3f);
|
||||
get_parameter("historyKeyframeFitnessScore", historyKeyframeFitnessScore);
|
||||
|
||||
|
||||
declare_parameter<float>("globalMapVisualizationSearchRadius", 1e3f);
|
||||
get_parameter("globalMapVisualizationSearchRadius", globalMapVisualizationSearchRadius);
|
||||
declare_parameter<float>("globalMapVisualizationPoseDensity", 10.0);
|
||||
get_parameter("globalMapVisualizationPoseDensity", globalMapVisualizationPoseDensity);
|
||||
declare_parameter<float>("globalMapVisualizationLeafSize", 1.0f);
|
||||
get_parameter("globalMapVisualizationLeafSize", globalMapVisualizationLeafSize);
|
||||
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
sensor_msgs::msg::Imu imuConverter(const sensor_msgs::msg::Imu& imu_in)
|
||||
{
|
||||
sensor_msgs::msg::Imu imu_out = imu_in;
|
||||
// rotate acceleration
|
||||
Eigen::Vector3d acc(imu_in.linear_acceleration.x, imu_in.linear_acceleration.y, imu_in.linear_acceleration.z);
|
||||
acc = extRot * acc;
|
||||
imu_out.linear_acceleration.x = acc.x();
|
||||
imu_out.linear_acceleration.y = acc.y();
|
||||
imu_out.linear_acceleration.z = acc.z();
|
||||
// rotate gyroscope
|
||||
Eigen::Vector3d gyr(imu_in.angular_velocity.x, imu_in.angular_velocity.y, imu_in.angular_velocity.z);
|
||||
gyr = extRot * gyr;
|
||||
imu_out.angular_velocity.x = gyr.x();
|
||||
imu_out.angular_velocity.y = gyr.y();
|
||||
imu_out.angular_velocity.z = gyr.z();
|
||||
|
||||
if (imuType) {
|
||||
// rotate roll pitch yaw
|
||||
Eigen::Quaterniond q_from(imu_in.orientation.w, imu_in.orientation.x, imu_in.orientation.y, imu_in.orientation.z);
|
||||
Eigen::Quaterniond q_final = q_from * extQRPY;
|
||||
imu_out.orientation.x = q_final.x();
|
||||
imu_out.orientation.y = q_final.y();
|
||||
imu_out.orientation.z = q_final.z();
|
||||
imu_out.orientation.w = q_final.w();
|
||||
|
||||
if (sqrt(q_final.x()*q_final.x() + q_final.y()*q_final.y() + q_final.z()*q_final.z() + q_final.w()*q_final.w()) < 0.1)
|
||||
{
|
||||
RCLCPP_ERROR(get_logger(), "Invalid quaternion, please use a 9-axis IMU!");
|
||||
rclcpp::shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
return imu_out;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
sensor_msgs::msg::PointCloud2 publishCloud(const rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr &thisPub, const T& thisCloud, rclcpp::Time thisStamp, std::string thisFrame)
|
||||
{
|
||||
sensor_msgs::msg::PointCloud2 tempCloud;
|
||||
pcl::toROSMsg(*thisCloud, tempCloud);
|
||||
tempCloud.header.stamp = thisStamp;
|
||||
tempCloud.header.frame_id = thisFrame;
|
||||
if (thisPub->get_subscription_count() != 0)
|
||||
thisPub->publish(tempCloud);
|
||||
|
||||
return tempCloud;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double ROS_TIME(T msg)
|
||||
{
|
||||
return rclcpp::Time(msg).seconds();
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void imuAngular2rosAngular(sensor_msgs::msg::Imu *thisImuMsg, T *angular_x, T *angular_y, T *angular_z)
|
||||
{
|
||||
*angular_x = thisImuMsg->angular_velocity.x;
|
||||
*angular_y = thisImuMsg->angular_velocity.y;
|
||||
*angular_z = thisImuMsg->angular_velocity.z;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void imuAccel2rosAccel(sensor_msgs::msg::Imu *thisImuMsg, T *acc_x, T *acc_y, T *acc_z)
|
||||
{
|
||||
*acc_x = thisImuMsg->linear_acceleration.x;
|
||||
*acc_y = thisImuMsg->linear_acceleration.y;
|
||||
*acc_z = thisImuMsg->linear_acceleration.z;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void imuRPY2rosRPY(sensor_msgs::msg::Imu *thisImuMsg, T *rosRoll, T *rosPitch, T *rosYaw)
|
||||
{
|
||||
double imuRoll, imuPitch, imuYaw;
|
||||
tf2::Quaternion orientation;
|
||||
tf2::fromMsg(thisImuMsg->orientation, orientation);
|
||||
tf2::Matrix3x3(orientation).getRPY(imuRoll, imuPitch, imuYaw);
|
||||
|
||||
*rosRoll = imuRoll;
|
||||
*rosPitch = imuPitch;
|
||||
*rosYaw = imuYaw;
|
||||
}
|
||||
|
||||
rclcpp::QoS QosPolicy(const string &history_policy, const string &reliability_policy)
|
||||
{
|
||||
rmw_qos_profile_t qos_profile;
|
||||
if (history_policy == "history_keep_last")
|
||||
qos_profile.history = rmw_qos_history_policy_t::RMW_QOS_POLICY_HISTORY_KEEP_LAST;
|
||||
else if (history_policy == "history_keep_all")
|
||||
qos_profile.history = rmw_qos_history_policy_t::RMW_QOS_POLICY_HISTORY_KEEP_ALL;
|
||||
|
||||
if (reliability_policy == "reliability_reliable")
|
||||
qos_profile.reliability = rmw_qos_reliability_policy_t::RMW_QOS_POLICY_RELIABILITY_RELIABLE;
|
||||
else if (reliability_policy == "reliability_best_effort")
|
||||
qos_profile.reliability = rmw_qos_reliability_policy_t::RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
|
||||
|
||||
qos_profile.depth = 2000;
|
||||
|
||||
qos_profile.durability = rmw_qos_durability_policy_t::RMW_QOS_POLICY_DURABILITY_VOLATILE;
|
||||
qos_profile.deadline = RMW_QOS_DEADLINE_DEFAULT;
|
||||
qos_profile.lifespan = RMW_QOS_LIFESPAN_DEFAULT;
|
||||
qos_profile.liveliness = rmw_qos_liveliness_policy_t::RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT;
|
||||
qos_profile.liveliness_lease_duration = RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT;
|
||||
qos_profile.avoid_ros_namespace_conventions = false;
|
||||
|
||||
return rclcpp::QoS(rclcpp::QoSInitialization(qos_profile.history, qos_profile.depth), qos_profile);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration, Command
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
|
||||
share_dir = get_package_share_directory('liorf')
|
||||
parameter_file = LaunchConfiguration('params_file')
|
||||
rviz_config_file = os.path.join(share_dir, 'rviz', 'mapping.rviz')
|
||||
|
||||
params_declare = DeclareLaunchArgument(
|
||||
'params_file',
|
||||
default_value=os.path.join(
|
||||
share_dir, 'config', 'hesai.yaml'),
|
||||
description='FPath to the ROS2 parameters file to use.')
|
||||
|
||||
return LaunchDescription([
|
||||
params_declare,
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
arguments='0.0 0.0 0.0 0.0 0.0 0.0 map odom'.split(' '),
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_imuPreintegration',
|
||||
name='liorf_imuPreintegration',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_imageProjection',
|
||||
name='liorf_imageProjection',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_mapOptmization',
|
||||
name='liorf_mapOptmization',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
name='rviz2',
|
||||
arguments=['-d', rviz_config_file],
|
||||
output='screen'
|
||||
)
|
||||
])
|
||||
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument
|
||||
from launch.substitutions import LaunchConfiguration, Command
|
||||
from launch_ros.actions import Node
|
||||
|
||||
|
||||
def generate_launch_description():
|
||||
|
||||
share_dir = get_package_share_directory('liorf')
|
||||
parameter_file = LaunchConfiguration('params_file')
|
||||
rviz_config_file = os.path.join(share_dir, 'rviz', 'mapping.rviz')
|
||||
|
||||
params_declare = DeclareLaunchArgument(
|
||||
'params_file',
|
||||
default_value=os.path.join(
|
||||
share_dir, 'config', 'M2DGR.yaml'),
|
||||
description='FPath to the ROS2 parameters file to use.')
|
||||
|
||||
return LaunchDescription([
|
||||
params_declare,
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
arguments='0.0 0.0 0.0 0.0 0.0 0.0 map odom'.split(' '),
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_imuPreintegration',
|
||||
name='liorf_imuPreintegration',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_imageProjection',
|
||||
name='liorf_imageProjection',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='liorf',
|
||||
executable='liorf_mapOptmization',
|
||||
name='liorf_mapOptmization',
|
||||
parameters=[parameter_file],
|
||||
output='screen'
|
||||
),
|
||||
Node(
|
||||
package='rviz2',
|
||||
executable='rviz2',
|
||||
name='rviz2',
|
||||
arguments=['-d', rviz_config_file],
|
||||
output='screen'
|
||||
)
|
||||
])
|
||||