├── karto_slam.png
├── slam_karto
├── maps
│ └── willow-full-0.05.pgm
├── config
│ ├── recovery_behaviors.yaml
│ ├── global_costmap_params.yaml
│ ├── local_costmap_params.yaml
│ ├── base_local_planner_params.yaml
│ ├── explore_costmap_params.yaml
│ ├── costmap_common_params.yaml
│ ├── move_base.xml
│ └── mapper_params.yaml
├── launch
│ ├── build_map_w_params.launch
│ ├── karto_slam.launch
│ ├── karto_stage.launch
│ └── karto_slam.rviz
├── CMakeLists.txt
├── package.xml
├── worlds
│ └── willow-pr2-5cm.world
├── CHANGELOG.rst
└── src
│ ├── spa_solver.h
│ └── spa_solver.cpp
├── sparse_bundle_adjustment
├── README.txt
├── include
│ └── sparse_bundle_adjustment
│ │ ├── visualization.h
│ │ ├── sba_setup.h
│ │ ├── read_spa.h
│ │ ├── sba_file_io.h
│ │ ├── node.h
│ │ ├── proj.h
│ │ ├── csparse.h
│ │ ├── spa2d.h
│ │ ├── bpcg
│ │ └── bpcg.h
│ │ └── sba.h
├── package.xml
├── CMakeLists.txt
├── CHANGELOG.rst
└── src
│ ├── cholmod_timing.cpp
│ ├── visualization.cpp
│ ├── node.cpp
│ ├── nodes
│ └── sba_node.cpp
│ └── proj.cpp
├── open_karto
├── Authors
├── samples
│ ├── README.txt
│ ├── SpaSolver.h
│ ├── CMakeLists.txt
│ ├── SpaSolver.cpp
│ ├── tutorial1.cpp
│ └── tutorial2.cpp
├── README.md
├── package.xml
├── CMakeLists.txt
├── include
│ └── open_karto
│ │ ├── Types.h
│ │ ├── Macros.h
│ │ └── Math.h
├── CHANGELOG.rst
├── LICENSE
└── src
│ └── Karto.cpp
└── README.md
/karto_slam.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lausen001/Karto-Note/HEAD/karto_slam.png
--------------------------------------------------------------------------------
/slam_karto/maps/willow-full-0.05.pgm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lausen001/Karto-Note/HEAD/slam_karto/maps/willow-full-0.05.pgm
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/README.txt:
--------------------------------------------------------------------------------
1 | Sparse Bundle Adjustment Library
2 | ================================
3 |
4 | Originally developed at Willow Garage as part of the vslam stack.
5 |
--------------------------------------------------------------------------------
/open_karto/Authors:
--------------------------------------------------------------------------------
1 | Karto Open Source Library 1.0
2 |
3 | Contributors:
4 | -------------------------------
5 | Michael A. Eriksen (eriksen@ai.sri.com)
6 | Benson Limketkai (bensonl@ai.sri.com)
7 |
--------------------------------------------------------------------------------
/slam_karto/config/recovery_behaviors.yaml:
--------------------------------------------------------------------------------
1 | recovery_behaviors: [{name: conservative_clear, type: ClearCostmapRecovery}, {name: aggressive_clear, type: ClearCostmapRecovery}]
2 |
3 | conservative_clear:
4 | reset_distance: 3.0
5 |
6 | aggressive_clear:
7 | reset_distance: 1.84
8 |
9 |
--------------------------------------------------------------------------------
/slam_karto/launch/build_map_w_params.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/open_karto/samples/README.txt:
--------------------------------------------------------------------------------
1 | The CMake file does not work out of the box, because you will need a few
2 | external libraries (all available on ROS) if you want to use the SPA solver for
3 | closing loops:
4 |
5 | CSparse
6 | eigen
7 | sba
8 |
9 |
10 | Alternatively, you can just not compile Tutorial2.
11 |
--------------------------------------------------------------------------------
/slam_karto/config/global_costmap_params.yaml:
--------------------------------------------------------------------------------
1 | NavfnROS:
2 | allow_unknown: false
3 | #Independent settings for the planner's costmap
4 | global_costmap:
5 | global_frame: /map
6 | robot_base_frame: base_link
7 | update_frequency: 5.0
8 | publish_frequency: 0.0
9 | static_map: true
10 | rolling_window: false
11 |
--------------------------------------------------------------------------------
/slam_karto/config/local_costmap_params.yaml:
--------------------------------------------------------------------------------
1 | local_costmap:
2 | publish_voxel_map: true
3 | global_frame: /map
4 | robot_base_frame: base_link
5 | update_frequency: 5.0
6 | publish_frequency: 2.0
7 | static_map: false
8 | rolling_window: true
9 | width: 6.0
10 | height: 6.0
11 | resolution: 0.025
12 | origin_x: 0.0
13 | origin_y: 0.0
14 |
--------------------------------------------------------------------------------
/open_karto/README.md:
--------------------------------------------------------------------------------
1 | # Open Karto
2 |
3 | Catkinized ROS Package of the OpenKarto Library (LGPL3)
4 |
5 | # Status
6 |
7 | * Devel Job Status: [](http://build.ros.org/job/Mdev__open_karto__ubuntu_bionic_amd64/)
8 | * AMD64 Debian Job Status: [](http://build.ros.org/job/Mbin_uB64__open_karto__ubuntu_bionic_amd64__binary/)
9 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/include/sparse_bundle_adjustment/visualization.h:
--------------------------------------------------------------------------------
1 | #ifndef VSLAM_SYSTEM_VISUALIZATION_H
2 | #define VSLAM_SYSTEM_VISUALIZATION_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace sba {
9 |
10 | // draw the graph on rviz
11 | void drawGraph(const SysSBA &sba, const ros::Publisher &camera_pub,
12 | const ros::Publisher &point_pub, int decimation = 1, int bicolor = 0);
13 |
14 | } // namespace sba
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/slam_karto/launch/karto_slam.launch:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/slam_karto/launch/karto_stage.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/open_karto/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | open_karto
4 | 1.2.3
5 | Catkinized ROS packaging of the OpenKarto library
6 |
7 | Michael Ferguson
8 | Russell Toris
9 | Luc Bettaieb
10 |
11 | LGPLv3
12 |
13 | catkin
14 |
15 | boost
16 |
17 | boost
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/package.xml:
--------------------------------------------------------------------------------
1 |
2 | sparse_bundle_adjustment
3 | ROS wrapper for the sparse bundle adjustment (sba) library (needed for slam_karto)
4 | 0.4.4
5 | BSD
6 | Michael Ferguson
7 | Luc Bettaieb
8 |
9 | catkin
10 |
11 | roscpp
12 | eigen
13 | liblapack-dev
14 | libblas-dev
15 | suitesparse
16 |
17 |
18 |
--------------------------------------------------------------------------------
/slam_karto/config/base_local_planner_params.yaml:
--------------------------------------------------------------------------------
1 | TrajectoryPlannerROS:
2 | #Independent settings for the local costmap
3 | transform_tolerance: 0.3
4 | sim_time: 1.7
5 | sim_granularity: 0.025
6 | dwa: true
7 | vx_samples: 3
8 | vtheta_samples: 20
9 | max_vel_x: 0.65
10 | min_vel_x: 0.1
11 | max_rotational_vel: 1.0
12 | min_in_place_rotational_vel: 0.4
13 | xy_goal_tolerance: 0.4
14 | yaw_goal_tolerance: 0.05
15 | goal_distance_bias: 0.8
16 | path_distance_bias: 0.6
17 | occdist_scale: 0.01
18 | heading_lookahead: 0.325
19 | oscillation_reset_dist: 0.05
20 | holonomic_robot: true
21 | acc_lim_th: 3.2
22 | acc_lim_x: 2.5
23 | acc_lim_y: 2.5
24 |
--------------------------------------------------------------------------------
/slam_karto/config/explore_costmap_params.yaml:
--------------------------------------------------------------------------------
1 | loop_closure_planner:
2 | allow_unknown: false
3 | explore_planner:
4 | allow_unknown: false
5 | #Independent settings for the planner's costmap
6 | global_costmap:
7 | global_frame: /map
8 | robot_base_frame: base_link
9 | update_frequency: 5.0
10 | publish_frequency: 0.0
11 | static_map: true
12 | rolling_window: false
13 | # global_frame: /map
14 | # robot_base_frame: base_link
15 | # update_frequency: 1.0
16 | # publish_frequency: 0.0
17 | # raytrace_range: 5.0
18 | # obstacle_range: 5.0
19 | # static_map: false
20 | # rolling_window: false
21 | # width: 60.0
22 | # height: 60.0
23 | # resolution: 0.2
24 | # origin_x: -30.0
25 | # origin_y: -30.0
26 | # track_unknown_space: true
27 |
--------------------------------------------------------------------------------
/slam_karto/config/costmap_common_params.yaml:
--------------------------------------------------------------------------------
1 | #START VOXEL STUFF
2 | map_type: voxel
3 | origin_z: 0.0
4 | z_resolution: 0.2
5 | z_voxels: 10
6 | unknown_threshold: 9
7 | mark_threshold: 0
8 | #END VOXEL STUFF
9 | transform_tolerance: 0.3
10 | obstacle_range: 2.5
11 | max_obstacle_height: 2.0
12 | raytrace_range: 3.0
13 | footprint: [[-0.325, -0.325], [-0.325, 0.325], [0.325, 0.325], [0.46, 0.0], [0.325, -0.325]]
14 | #robot_radius: 0.46
15 | footprint_padding: 0.01
16 | inflation_radius: 0.55
17 | cost_scaling_factor: 10.0
18 | lethal_cost_threshold: 100
19 | unknown_cost_value: 255
20 | observation_sources: base_scan
21 | base_scan: {data_type: LaserScan, expected_update_rate: 0.4,
22 | observation_persistence: 0.0, marking: true, clearing: true, max_obstacle_height: 0.4, min_obstacle_height: 0.08}
23 |
--------------------------------------------------------------------------------
/slam_karto/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.1)
2 | project(slam_karto)
3 |
4 | if(NOT CMAKE_CXX_STANDARD)
5 | set(CMAKE_CXX_STANDARD 11)
6 | endif()
7 |
8 | find_package(catkin REQUIRED
9 | COMPONENTS
10 | message_filters
11 | nav_msgs
12 | open_karto
13 | rosconsole
14 | roscpp
15 | sensor_msgs
16 | sparse_bundle_adjustment
17 | tf
18 | visualization_msgs
19 | )
20 | find_package(Eigen3 REQUIRED)
21 |
22 | include_directories(${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS})
23 | add_definitions(${EIGEN3_DEFINITIONS})
24 |
25 | catkin_package()
26 |
27 | add_executable(slam_karto src/slam_karto.cpp src/spa_solver.cpp)
28 | target_link_libraries(slam_karto ${catkin_LIBRARIES})
29 |
30 | install(TARGETS slam_karto
31 | RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
32 | )
33 |
--------------------------------------------------------------------------------
/open_karto/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0.2)
2 | project(open_karto)
3 |
4 | find_package(catkin REQUIRED)
5 |
6 | find_package(Boost REQUIRED COMPONENTS thread)
7 |
8 | catkin_package(
9 | DEPENDS Boost
10 | INCLUDE_DIRS
11 | include
12 | LIBRARIES
13 | karto
14 | )
15 |
16 | if(BUILD_SHARED_LIBS)
17 | add_definitions(-DKARTO_DYNAMIC)
18 | endif()
19 |
20 | include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
21 | add_library(karto SHARED src/Karto.cpp src/Mapper.cpp)
22 | target_link_libraries(karto ${Boost_LIBRARIES})
23 |
24 | install(DIRECTORY include/ DESTINATION include)
25 | install(TARGETS karto
26 | LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
27 | ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
28 | RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
29 | )
30 |
--------------------------------------------------------------------------------
/slam_karto/config/move_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.1)
2 | project(sparse_bundle_adjustment)
3 |
4 | if(NOT CMAKE_CXX_STANDARD)
5 | set(CMAKE_CXX_STANDARD 11)
6 | endif()
7 |
8 | find_package(catkin REQUIRED COMPONENTS roscpp)
9 | find_package(Eigen3 REQUIRED)
10 | find_package(suitesparse QUIET)
11 | if(NOT SuiteSparse_FOUND)
12 | set(SuiteSparse_LIBRARIES blas lapack cholmod cxsparse)
13 | endif()
14 |
15 | include_directories(${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS} ${SuiteSparse_INCLUDE_DIRS})
16 | add_definitions(${EIGEN3_DEFINITIONS})
17 | INCLUDE_DIRECTORIES(include)
18 |
19 | catkin_package(
20 | INCLUDE_DIRS include
21 | LIBRARIES sba
22 | )
23 |
24 | add_definitions(-DSBA_CHOLMOD)
25 |
26 | # SBA library
27 | add_library(sba src/sba.cpp src/spa.cpp src/spa2d.cpp src/csparse.cpp src/proj.cpp src/node.cpp src/sba_file_io.cpp)
28 | #rosbuild_add_compile_flags(sba ${SSE_FLAGS})
29 | target_link_libraries(sba ${SuiteSparse_LIBRARIES})
30 |
31 | install(DIRECTORY include/sparse_bundle_adjustment/
32 | DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
33 |
34 | install(TARGETS sba
35 | LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
36 |
--------------------------------------------------------------------------------
/slam_karto/package.xml:
--------------------------------------------------------------------------------
1 |
2 | slam_karto
3 |
4 | This package pulls in the Karto mapping library, and provides a ROS
5 | wrapper for using it.
6 |
7 | 0.8.1
8 | Michael Ferguson
9 | Luc Bettaieb
10 | Russell Toris
11 | Brian Gerkey
12 | LGPL
13 |
14 | catkin
15 |
16 | eigen
17 | message_filters
18 | nav_msgs
19 | open_karto
20 | rosconsole
21 | roscpp
22 | sparse_bundle_adjustment
23 | sensor_msgs
24 | tf
25 | visualization_msgs
26 |
27 | eigen
28 | message_filters
29 | nav_msgs
30 | open_karto
31 | rosconsole
32 | roscpp
33 | sparse_bundle_adjustment
34 | sensor_msgs
35 | tf
36 | visualization_msgs
37 |
38 |
39 |
--------------------------------------------------------------------------------
/slam_karto/worlds/willow-pr2-5cm.world:
--------------------------------------------------------------------------------
1 | define block model
2 | (
3 | size [0.5 0.5 0.75]
4 | gui_nose 0
5 | )
6 |
7 | define topurg ranger
8 | (
9 | sensor(
10 | range_max 30.0
11 | fov 270.25
12 | samples 1081
13 | )
14 | # generic model properties
15 | color "black"
16 | size [ 0.05 0.05 0.1 ]
17 | )
18 |
19 | define pr2 position
20 | (
21 | size [0.65 0.65 0.25]
22 | origin [-0.05 0 0 0]
23 | gui_nose 1
24 | drive "omni"
25 | topurg(pose [ 0.275 0.000 0 0.000 ])
26 | )
27 |
28 | define floorplan model
29 | (
30 | # sombre, sensible, artistic
31 | color "gray30"
32 |
33 | # most maps will need a bounding box
34 | boundary 1
35 |
36 | gui_nose 0
37 | gui_grid 0
38 |
39 | gui_outline 0
40 | gripper_return 0
41 | fiducial_return 0
42 | ranger_return 1
43 | )
44 |
45 | # set the resolution of the underlying raytrace model in meters
46 | resolution 0.02
47 |
48 | interval_sim 100 # simulation timestep in milliseconds
49 |
50 |
51 | window
52 | (
53 | size [ 745.000 448.000 ]
54 |
55 | rotate [ 0.000 -1.560 ]
56 | scale 18.806
57 | )
58 |
59 | # load an environment bitmap
60 | floorplan
61 | (
62 | name "willow"
63 | bitmap "../maps/willow-full-0.05.pgm"
64 | size [58.25 47.25 1.0]
65 | pose [ -23.625 29.125 0 90.000 ]
66 | )
67 |
68 | # throw in a robot
69 | pr2( pose [ -28.610 13.562 0 99.786 ] name "pr2" color "blue")
70 | block( pose [ -25.062 12.909 0 180.000 ] color "red")
71 | block( pose [ -25.062 12.909 0 180.000 ] color "red")
72 | block( pose [ -25.062 12.909 0 180.000 ] color "red")
73 |
--------------------------------------------------------------------------------
/slam_karto/config/mapper_params.yaml:
--------------------------------------------------------------------------------
1 | # General Parameters
2 | use_scan_matching: true
3 | use_scan_barycenter: true
4 | minimum_time_interval: 3600
5 | minimum_travel_distance: 0.2
6 | minimum_travel_heading: 0.174 #in radians
7 | scan_buffer_size: 70
8 | scan_buffer_maximum_scan_distance: 20.0
9 | link_match_minimum_response_fine: 0.8
10 | link_scan_maximum_distance: 10.0
11 | loop_search_maximum_distance: 4.0
12 | do_loop_closing: true
13 | loop_match_minimum_chain_size: 10
14 | loop_match_maximum_variance_coarse: 0.4 # gets squared later
15 | loop_match_minimum_response_coarse: 0.8
16 | loop_match_minimum_response_fine: 0.8
17 |
18 | # Correlation Parameters - Correlation Parameters
19 | correlation_search_space_dimension: 0.3
20 | correlation_search_space_resolution: 0.01
21 | correlation_search_space_smear_deviation: 0.03
22 |
23 | # Correlation Parameters - Loop Closure Parameters
24 | loop_search_space_dimension: 8.0
25 | loop_search_space_resolution: 0.05
26 | loop_search_space_smear_deviation: 0.03
27 |
28 | # Scan Matcher Parameters
29 | distance_variance_penalty: 0.3 # gets squared later
30 | angle_variance_penalty: 0.349 # in degrees (gets converted to radians then squared)
31 | fine_search_angle_offset: 0.00349 # in degrees (gets converted to radians)
32 | coarse_search_angle_offset: 0.349 # in degrees (gets converted to radians)
33 | coarse_angle_resolution: 0.0349 # in degrees (gets converted to radians)
34 | minimum_angle_penalty: 0.9
35 | minimum_distance_penalty: 0.5
36 | use_response_expansion: false
37 |
--------------------------------------------------------------------------------
/open_karto/samples/SpaSolver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef __SPASOLVER__
19 | #define __SPASOLVER__
20 |
21 | #include
22 |
23 | #ifndef EIGEN_USE_NEW_STDVECTOR
24 | #define EIGEN_USE_NEW_STDVECTOR
25 | #endif // EIGEN_USE_NEW_STDVECTOR
26 |
27 | #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(10)
28 | #include
29 |
30 | #include "sba/spa2d.h"
31 |
32 | typedef std::vector CovarianceVector;
33 |
34 | class SpaSolver : public karto::ScanSolver
35 | {
36 | public:
37 | SpaSolver();
38 | virtual ~SpaSolver();
39 |
40 | public:
41 | virtual void Clear();
42 | virtual void Compute();
43 | virtual const karto::ScanSolver::IdPoseVector& GetCorrections() const;
44 |
45 | virtual void AddNode(karto::Vertex* pVertex);
46 | virtual void AddConstraint(karto::Edge* pEdge);
47 |
48 | private:
49 | karto::ScanSolver::IdPoseVector corrections;
50 |
51 | sba::SysSPA2d m_Spa;
52 | };
53 |
54 | #endif // __SPASOLVER__
55 |
56 |
--------------------------------------------------------------------------------
/slam_karto/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | Changelog for package slam_karto
3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | 0.8.1 (2018-09-11)
6 | ------------------
7 | * set C++11 if std not specified
8 | This is mainly for building on Lunar
9 | * Contributors: Michael Ferguson
10 |
11 | 0.8.0 (2018-08-21)
12 | ------------------
13 | * update maintainer email
14 | * Merge pull request `#19 `_ from ros-perception/maintainer-add
15 | Adding myself as a maintainer for slam_karto
16 | * Adding myself as a maintainer for slam_karto
17 | * Merge pull request `#15 `_ from jasonimercer/lock-fix
18 | Fixed locks so they stay in scope until the end of the method.
19 | * Fixed locks so they stay in scope until the end of the method.
20 | * Merge pull request `#14 `_ from xpharry/indigo-devel
21 | modify for stage simulation
22 | * modify for stage simulation
23 | * Merge pull request `#9 `_ from hvpandya/patch-1
24 | Update karto_slam.launch
25 | * Update karto_slam.launch
26 | package name must be slam_karto
27 | * Contributors: Harsh Pandya, Jason Mercer, Luc Bettaieb, Michael Ferguson, xpharry
28 |
29 | 0.7.3 (2016-02-04)
30 | ------------------
31 | * fixed the upside-down detection
32 | * update maintainer email
33 | * Contributors: Michael Ferguson, mgerdzhev
34 |
35 | 0.7.2 (2015-07-18)
36 | ------------------
37 | * Added in parameter server settings for Mapper within slam_karto
38 | * Contributors: Luc Bettaieb, Michael Ferguson
39 |
40 | 0.7.1 (2014-06-17)
41 | ------------------
42 | * build updates for sba, fix install
43 | * Contributors: Michael Ferguson
44 |
45 | 0.7.0 (2014-06-15)
46 | ------------------
47 | * First release in a very, very long time.
48 | * Catkinized, updated to work with catkinized open_karto and sba
49 | * Contributors: Jon Binney, Michael Ferguson
50 |
--------------------------------------------------------------------------------
/open_karto/include/open_karto/Types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef OPEN_KARTO_TYPES_H
19 | #define OPEN_KARTO_TYPES_H
20 |
21 | #include
22 |
23 | /**
24 | * Karto type definition
25 | * Ensures platform independent types for windows, linux and mac
26 | */
27 | #if defined(_MSC_VER)
28 |
29 | typedef signed __int8 kt_int8s;
30 | typedef unsigned __int8 kt_int8u;
31 |
32 | typedef signed __int16 kt_int16s;
33 | typedef unsigned __int16 kt_int16u;
34 |
35 | typedef signed __int32 kt_int32s;
36 | typedef unsigned __int32 kt_int32u;
37 |
38 | typedef signed __int64 kt_int64s;
39 | typedef unsigned __int64 kt_int64u;
40 |
41 | #else
42 |
43 | #include
44 |
45 | typedef int8_t kt_int8s;
46 | typedef uint8_t kt_int8u;
47 |
48 | typedef int16_t kt_int16s;
49 | typedef uint16_t kt_int16u;
50 |
51 | typedef int32_t kt_int32s;
52 | typedef uint32_t kt_int32u;
53 |
54 | #if defined(__LP64__)
55 | typedef signed long kt_int64s;
56 | typedef unsigned long kt_int64u;
57 | #else
58 | typedef signed long long kt_int64s;
59 | typedef unsigned long long kt_int64u;
60 | #endif
61 |
62 | #endif
63 |
64 | typedef bool kt_bool;
65 | typedef char kt_char;
66 | typedef float kt_float;
67 | typedef double kt_double;
68 |
69 | #endif // OPEN_KARTO_TYPES_H
70 |
--------------------------------------------------------------------------------
/slam_karto/src/spa_solver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef KARTO_SPASOLVER_H
19 | #define KARTO_SPASOLVER_H
20 |
21 | #include
22 |
23 | #ifndef EIGEN_USE_NEW_STDVECTOR
24 | #define EIGEN_USE_NEW_STDVECTOR
25 | #endif // EIGEN_USE_NEW_STDVECTOR
26 |
27 | #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(10)
28 | #include
29 |
30 | #include
31 |
32 | typedef std::vector CovarianceVector;
33 |
34 | class SpaSolver : public karto::ScanSolver
35 | {
36 | public:
37 | SpaSolver();
38 | virtual ~SpaSolver();
39 |
40 | public:
41 | virtual void Clear();
42 | virtual void Compute();
43 | virtual const karto::ScanSolver::IdPoseVector& GetCorrections() const;
44 |
45 | virtual void AddNode(karto::Vertex* pVertex);
46 | virtual void AddConstraint(karto::Edge* pEdge);
47 |
48 | // Get the underlying graph from SBA
49 | // return the graph of constraints
50 | /// x,y -> x',y' 4 floats per connection
51 | void getGraph(std::vector &g) { m_Spa.getGraph(g); }
52 |
53 | private:
54 | karto::ScanSolver::IdPoseVector corrections;
55 |
56 | sba::SysSPA2d m_Spa;
57 | };
58 |
59 | #endif // KARTO_SPASOLVER_H
60 |
61 |
--------------------------------------------------------------------------------
/open_karto/samples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2010 SRI International
3 | #
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU Lesser General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU Lesser General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU Lesser General Public License
15 | # along with this program. If not, see .
16 | #
17 |
18 | ADD_DEFINITIONS(-DUSE_SPA)
19 |
20 | if(WIN32)
21 | ADD_DEFINITIONS(-DEIGEN_DONT_ALIGN)
22 | endif()
23 |
24 | if(WIN32)
25 | # turn off various warnings
26 | foreach(warning 4251)
27 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd${warning}")
28 | endforeach(warning)
29 | endif()
30 |
31 | include_directories(../source)
32 |
33 | ############################################################################
34 | # tutorial 1
35 | add_executable(
36 | Karto_Tutorial1
37 | tutorial1.cpp
38 | )
39 |
40 | target_link_libraries(Karto_Tutorial1 OpenKarto)
41 |
42 | if (UNIX)
43 | target_link_libraries(Karto_Tutorial1 "pthread")
44 | endif()
45 |
46 | ############################################################################
47 | # tutorial 2
48 |
49 | include_directories(${CSPARSE_DIR}/CSparse/Include)
50 | include_directories(${SBA_DIR}/sba/include)
51 | include_directories(${EIGEN_DIR}/eigen)
52 |
53 | add_executable(
54 | Karto_Tutorial2
55 | tutorial2.cpp
56 | SpaSolver.h
57 | SpaSolver.cpp
58 | )
59 |
60 | target_link_libraries(Karto_Tutorial2 OpenKarto)
61 | target_link_libraries(Karto_Tutorial2 spa2d)
62 | target_link_libraries(Karto_Tutorial2 csparse)
63 |
64 | if(PNG_FOUND)
65 | target_link_libraries(Karto_Tutorial2 ${ZLIB_LIBRARIES})
66 | target_link_libraries(Karto_Tutorial2 ${PNG_LIBRARIES})
67 | endif()
68 |
69 | if (UNIX)
70 | target_link_libraries(Karto_Tutorial2 "pthread")
71 | endif()
72 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | Changelog for package sparse_bundle_adjustment
3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | 0.4.4 (2020-03-28)
6 | ------------------
7 | * fix unitialized variable causing crashes (`#10 `_)
8 | * Contributors: Michael Ferguson
9 |
10 | 0.4.3 (2020-01-31)
11 | ------------------
12 | * remove bouncing email from maintainers
13 | * Merge pull request `#9 `_ from seanyen/modern_cpp
14 | [windows] use modern cpp & more portable fixes
15 | * modernize cpp code & CMake files.
16 | * Changing maintainer email
17 | * Contributors: Luc Bettaieb, Michael Ferguson, seanyen
18 |
19 | 0.4.2 (2018-08-23)
20 | ------------------
21 | * rework how we set the C++ standard
22 | * Merge pull request `#6 `_ from moriarty/set-cpp-11
23 | Set C++ 11
24 | * [Maintainers] Add myself as a maintainer
25 | Mostly so that I can see build failures.
26 | * [CMake][C++11] compile with -std=c++11
27 | * Contributors: Alexander Moriarty, Michael Ferguson
28 |
29 | 0.4.1 (2018-08-21)
30 | ------------------
31 | * Merge pull request `#4 `_ from moriarty/eigen-and-pkg-fmt-2
32 | Fixes Eigen3 warnings and bumps to package.xml format 2
33 | * Update email address so I see build failures
34 | * [REP-140] Package.xml format 2
35 | * fix deprecated eigen3 cmake warning
36 | * Contributors: Alexnader Moriarty, Michael Ferguson, Steffen Fuchs
37 |
38 | 0.4.0 (2018-08-18)
39 | ------------------
40 | * Merge pull request `#3 `_ from moriarty/melodic-devel
41 | [melodic-devel][18.04] fix compile errors
42 | * [melodic-devel][18.04] fix compile errors
43 | fix compile errors for newer gcc
44 | * Merge pull request `#2 `_ from ros-perception/maintainer-add
45 | Adding myself as a maintainer for sparse_bundle_adjustment
46 | * Adding myself as a maintainer for sparse_bundle_adjustment
47 | * Contributors: Alexander Moriarty, Luc Bettaieb, Michael Ferguson
48 |
49 | 0.3.2 (2014-06-17)
50 | ------------------
51 | * major build/install fixes for the farm
52 | * Contributors: Michael Ferguson
53 |
54 | 0.3.1 (2014-06-17)
55 | ------------------
56 | * add depend on eigen
57 | * Contributors: Michael Ferguson
58 |
59 | 0.3.0 (2014-06-16)
60 | ------------------
61 | * import cleaned up sba (this is the version from wg)
62 | * Contributors: Michael Ferguson
63 |
--------------------------------------------------------------------------------
/open_karto/samples/SpaSolver.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "SpaSolver.h"
19 | #include
20 |
21 | SpaSolver::SpaSolver()
22 | {
23 |
24 | }
25 |
26 | SpaSolver::~SpaSolver()
27 | {
28 |
29 | }
30 |
31 | void SpaSolver::Clear()
32 | {
33 | corrections.clear();
34 | }
35 |
36 | const karto::ScanSolver::IdPoseVector& SpaSolver::GetCorrections() const
37 | {
38 | return corrections;
39 | }
40 |
41 | void SpaSolver::Compute()
42 | {
43 | corrections.clear();
44 |
45 | typedef std::vector > NodeVector;
46 |
47 | printf("DO SPA BEGIN\n");
48 | m_Spa.doSPA(40);
49 | printf("DO SPA END\n");
50 | NodeVector nodes = m_Spa.getNodes();
51 | forEach(NodeVector, &nodes)
52 | {
53 | karto::Pose2 pose(iter->trans(0), iter->trans(1), iter->arot);
54 | corrections.push_back(std::make_pair(iter->nodeId, pose));
55 | }
56 | }
57 |
58 | void SpaSolver::AddNode(karto::Vertex* pVertex)
59 | {
60 | karto::Pose2 pose = pVertex->GetObject()->GetCorrectedPose();
61 | Eigen::Vector3d vector(pose.GetX(), pose.GetY(), pose.GetHeading());
62 | m_Spa.addNode2d(vector, pVertex->GetObject()->GetUniqueId());
63 | }
64 |
65 | void SpaSolver::AddConstraint(karto::Edge* pEdge)
66 | {
67 | karto::LocalizedRangeScan* pSource = pEdge->GetSource()->GetObject();
68 | karto::LocalizedRangeScan* pTarget = pEdge->GetTarget()->GetObject();
69 | karto::LinkInfo* pLinkInfo = (karto::LinkInfo*)(pEdge->GetLabel());
70 |
71 | karto::Pose2 diff = pLinkInfo->GetPoseDifference();
72 | Eigen::Vector3d mean(diff.GetX(), diff.GetY(), diff.GetHeading());
73 |
74 | karto::Matrix3 precisionMatrix = pLinkInfo->GetCovariance().Inverse();
75 | Eigen::Matrix m;
76 | m(0,0) = precisionMatrix(0,0);
77 | m(0,1) = m(1,0) = precisionMatrix(0,1);
78 | m(0,2) = m(2,0) = precisionMatrix(0,2);
79 | m(1,1) = precisionMatrix(1,1);
80 | m(1,2) = m(2,1) = precisionMatrix(1,2);
81 | m(2,2) = precisionMatrix(2,2);
82 |
83 | m_Spa.addConstraint2d(pSource->GetUniqueId(), pTarget->GetUniqueId(), mean, m);
84 | }
85 |
--------------------------------------------------------------------------------
/slam_karto/src/spa_solver.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #include "spa_solver.h"
19 | #include
20 |
21 | #include "ros/console.h"
22 |
23 | SpaSolver::SpaSolver()
24 | {
25 |
26 | }
27 |
28 | SpaSolver::~SpaSolver()
29 | {
30 |
31 | }
32 |
33 | void SpaSolver::Clear()
34 | {
35 | corrections.clear();
36 | }
37 |
38 | const karto::ScanSolver::IdPoseVector& SpaSolver::GetCorrections() const
39 | {
40 | return corrections;
41 | }
42 |
43 | void SpaSolver::Compute()
44 | {
45 | corrections.clear();
46 |
47 | typedef std::vector > NodeVector;
48 |
49 | ROS_INFO("Calling doSPA for loop closure");
50 | m_Spa.doSPA(40);
51 | ROS_INFO("Finished doSPA for loop closure");
52 | NodeVector nodes = m_Spa.getNodes();
53 | forEach(NodeVector, &nodes)
54 | {
55 | karto::Pose2 pose(iter->trans(0), iter->trans(1), iter->arot);
56 | corrections.push_back(std::make_pair(iter->nodeId, pose));
57 | }
58 | }
59 |
60 | void SpaSolver::AddNode(karto::Vertex* pVertex)
61 | {
62 | karto::Pose2 pose = pVertex->GetObject()->GetCorrectedPose();
63 | Eigen::Vector3d vector(pose.GetX(), pose.GetY(), pose.GetHeading());
64 | m_Spa.addNode(vector, pVertex->GetObject()->GetUniqueId());
65 | }
66 |
67 | void SpaSolver::AddConstraint(karto::Edge* pEdge)
68 | {
69 | karto::LocalizedRangeScan* pSource = pEdge->GetSource()->GetObject();
70 | karto::LocalizedRangeScan* pTarget = pEdge->GetTarget()->GetObject();
71 | karto::LinkInfo* pLinkInfo = (karto::LinkInfo*)(pEdge->GetLabel());
72 |
73 | karto::Pose2 diff = pLinkInfo->GetPoseDifference();
74 | Eigen::Vector3d mean(diff.GetX(), diff.GetY(), diff.GetHeading());
75 |
76 | karto::Matrix3 precisionMatrix = pLinkInfo->GetCovariance().Inverse();
77 | Eigen::Matrix m;
78 | m(0,0) = precisionMatrix(0,0);
79 | m(0,1) = m(1,0) = precisionMatrix(0,1);
80 | m(0,2) = m(2,0) = precisionMatrix(0,2);
81 | m(1,1) = precisionMatrix(1,1);
82 | m(1,2) = m(2,1) = precisionMatrix(1,2);
83 | m(2,2) = precisionMatrix(2,2);
84 |
85 | m_Spa.addConstraint(pSource->GetUniqueId(), pTarget->GetUniqueId(), mean, m);
86 | }
87 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/src/cholmod_timing.cpp:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Software License Agreement (BSD License)
3 | *
4 | * Copyright (c) 2009, Willow Garage, Inc.
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above
14 | * copyright notice, this list of conditions and the following
15 | * disclaimer in the documentation and/or other materials provided
16 | * with the distribution.
17 | * * Neither the name of the Willow Garage nor the names of its
18 | * contributors may be used to endorse or promote products derived
19 | * from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | * POSSIBILITY OF SUCH DAMAGE.
33 | *********************************************************************/
34 |
35 | #include "cholmod.h"
36 | #include "sparse_bundle_adjustment/sba.h"
37 | #include
38 | #define CPUTIME ((double) (clock ( )) / CLOCKS_PER_SEC)
39 |
40 | int main (void)
41 | {
42 | cholmod_sparse *A ;
43 | cholmod_dense *x, *b, *r ;
44 | cholmod_factor *L ;
45 | double one [2] = {1,0}, m1 [2] = {-1,0} ; /* basic scalars */
46 | cholmod_common c ;
47 | cholmod_start (&c) ; /* start CHOLMOD */
48 | A = cholmod_read_sparse (stdin, &c) ; /* read in a matrix */
49 | cholmod_print_sparse (A, "A", &c) ; /* print the matrix */
50 | if (A == NULL || A->stype == 0) /* A must be symmetric */
51 | {
52 | cholmod_free_sparse (&A, &c) ;
53 | cholmod_finish (&c) ;
54 | return (0) ;
55 | }
56 | b = cholmod_ones (A->nrow, 1, A->xtype, &c) ; /* b = ones(n,1) */
57 | double t0 = CPUTIME;
58 | L = cholmod_analyze (A, &c) ; /* analyze */
59 | cholmod_factorize (A, L, &c) ; /* factorize */
60 | x = cholmod_solve (CHOLMOD_A, L, b, &c) ; /* solve Ax=b */
61 | double t1 = CPUTIME;
62 | printf("Time: %12.4f \n", t1-t0);
63 | r = cholmod_copy_dense (b, &c) ; /* r = b */
64 | cholmod_sdmult (A, 0, m1, one, x, r, &c) ; /* r = r-Ax */
65 | printf ("norm(b-Ax) %8.1e\n",
66 | cholmod_norm_dense (r, 0, &c)) ; /* print norm(r) */
67 | cholmod_free_factor (&L, &c) ; /* free matrices */
68 | cholmod_free_sparse (&A, &c) ;
69 | cholmod_free_dense (&r, &c) ;
70 | cholmod_free_dense (&x, &c) ;
71 | cholmod_free_dense (&b, &c) ;
72 | cholmod_finish (&c) ; /* finish CHOLMOD */
73 | return (0) ;
74 | }
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Karto-Note
2 | Karto Slam源码详细注释。
3 |
4 | Karto是一种2D激光SLAM解决方案,它是基于稀疏图优化的方法,带闭环检测。
5 |
6 | 本文对Karto的主流程代码进行分析,主要对局部map的维护、基于相关方法的scan-to-map匹配、闭环检测、BA图构建、计数法更新栅格地图等几个方面进行讲解。希望可以帮到有需要的同学,错误的地方请您批评指正。
7 |
8 | :) 如果对您有帮助,帮我点个star呦~
9 |
10 | ## 目录(知乎)
11 | - [Karto源码解析(一):工程运行](https://zhuanlan.zhihu.com/p/350852337)
12 | - [Karto源码解析(二):代码解析](https://zhuanlan.zhihu.com/p/352388229)
13 |
14 | ## 一、主流程
15 |
16 | 先放一个自己画的Karto流程简图。
17 |
18 | 
19 |
20 | 每当新来一帧数据,都会执行一次完整的主流程。
21 |
22 | 1. 首先判断当前帧与前一帧是否间隔足够大,不够大则直接丢弃,可以理解为只处理关键帧;
23 |
24 | 2. 接下来要对当前帧位姿进行校正,采用scan-to-map的配准方法。map是选择当前帧时空维度上相邻的帧组成的集合,我们称之为局部map。在当前帧位姿搜索空间中,对当前帧激光点进行变换,与局部map的激光点集合进行匹配,计算响应值,选择响应值最高的匹配位姿,作为当前帧位姿;
25 |
26 | 3. 前面两步相当于SLAM的前端,得到了当前帧的优化位姿。接着,构建BA优化图,添加当前帧为新的顶点,然后添加一些边。一共要添加四种边:
27 |
28 | - 与前一帧建立边;
29 | - 与局部map中最近的一帧建立边;
30 | - 与当前帧的广搜邻近帧的chain,建立边,后边再解释是啥;
31 | - 与闭环候选帧中最接近的一帧建立边;
32 |
33 | 4. 闭环检测。在历史帧中查找当前帧时间上相隔较远,空间上相隔较近的帧,作为候选闭环帧,与当前帧进行scan-to-map匹配。如果匹配较好,认为找到闭环了;
34 |
35 | 5. 如果找到闭环,就执行BA图优化,更新所有顶点位姿。
36 |
37 | ## 二、局部map
38 |
39 | 局部map是指与当前帧在时间、空间维度上邻近的帧集合。用于与当前帧进行scan-to-map匹配,优化当前帧位姿。局部map中的激光点需要过滤一下,不能直接全部拿来匹配。因为即便局部帧与当前帧很近,但仍有可能局部帧与当前帧处在一个物体的两面,比如穿过一堵墙,那么局部帧看到墙这一面的点,当前帧已经到了墙另一面,这些点是看不到的。这样的点需要剔除,如何辨识这些点,可以看看FindValidPoints方法。
40 |
41 | 相关函数包括:AddRunningScan、AddScans、AddScan、FindValidPoints。
42 |
43 | ## 三、基于相关方法的scan-to-map匹配
44 |
45 | scan-to-map匹配是激光雷达中一个基础的概念,scan是当前帧,map是当前帧时空维度上临近的帧组成的集合。map已经经过不断地优化,有一定精度了,而当前帧只有一个初始的估计位姿。至于怎么来的,可以是用前一帧位姿+运动计算,也可以是有外部传感器IMU、轮式里程计等得到的,总之它是不准确的。那么我们可以将当前帧的激光点,随意变换一下,再与map的激光点进行匹配。如果匹配的特别好,我们认为这个随意变换的pose就是我们需要的校正位姿。当然,随意变换是有个限制的,不能变换的特别特别大吧,所以定义了一个变化范围,称之为搜索空间。包括平移(x、y)、旋转(theta)维度上的搜索。
46 |
47 | 伪代码大致是这样的:
48 |
49 | ```
50 | scan, map
51 | bestPose = (x,y,theta)
52 | bestScore = Score(scan, map)
53 | for dx in (-dx, dx):
54 | for dy in (-dy, dy):
55 | for dtheta in (-dtheta, dtheta):
56 | T = (x + dx, y + dy, theta + dtheta)
57 | scan = T * scan
58 | score = Score(scan, map)
59 | if score > bestScore:
60 | bestScore = score
61 | bestPose = T
62 | ```
63 |
64 | 如何判断scan与map匹配的好不好呢?很简单,scan的激光点变换之后的位置,有map点接盘,不管是什么点,只要有个点就算匹配上了。统计一下匹配上的比例,用它来评判匹配好不好。为啥有效呢?可以想想。
65 |
66 | 另外要提一点,搜索空间中的角度问题。如果每平移一个(dx, dy)之后,再计算旋转dtheta角度对应的激光点位置,那计算DX*DY*DTheta次。能不能精简一下呢,可以的。我们知道旋转这个东西跟在哪没有关系,所以一开始就先计算好旋转一个dtheta角之后,激光点的偏移量,注意是偏移量。后面对于任何平移(dx, dy)之后的位置,加上这个偏移量就可以了。整个计算量就是DX*DY + DTheta次,少了很多。
67 |
68 | scan-to-map匹配在很多地方都会用到。当前帧与局部map匹配,当前帧与闭环候选帧集合匹配,当前帧与广搜临近帧的chain匹配,都会调用这个方法。
69 |
70 | 相关函数包括:MatchScan、CorrelateScan、ComputeOffsets、GetResponse、ComputePositionalCovariance、ComputeAngularCovariance。
71 |
72 | ## 四、闭环检测
73 |
74 | 闭环就是机器人走了一圈(也有可能是好多圈),我们要在历史帧中找当前帧位置的帧,构建闭环。闭环帧跟当前帧的位置要很接近,时间呢又要求隔得比较远,不然就是相邻帧了。找到这些候选帧,称之为闭环map,再与当前帧进行scan-to-map匹配,优化当前帧的位姿。
75 |
76 | 相关函数包括:TryCloseLoop、FindPossibleLoopClosure。
77 |
78 | ## 五、BA图构建
79 |
80 | 这里属于SLAM后端部分了,BA图的顶点为历史帧,边则有很多情况。每当新来一帧,需要从图中挑出来以下这些顶点,与之建立一条边。
81 |
82 | - 与前一帧建立边;
83 | - 与局部map中最接近的一帧建立边;
84 | - 与闭环map中最接近的一帧建立边,可以理解为闭环边;
85 | - 这个复杂一点,首先在BA图中当前帧顶点位置处,广搜得到一些距离较近的帧,然后对于每一帧截取前后时间段范围内的帧,作为该邻近帧的chain。再在chain里面找一帧最近的帧,与当前帧建立边。目的都是尽可能多的把距离相近的帧关联起来,不然图过于稀疏。
86 |
87 | 相关函数包括:AddEdges、LinkNearChains、LinkChainToScan、FindNearChains、FindNearLinkedScans。
88 |
89 | ## 六、计数法更新栅格地图
90 |
91 | 每当新增一帧激光点数据,如何融入已有的地图中呢?我们为栅格定义了三种状态
92 |
93 | ```
94 | typedef enum
95 | {
96 | GridStates_Unknown = 0,
97 | GridStates_Occupied = 100,
98 | GridStates_Free = 255
99 | } GridStates;
100 | ```
101 |
102 | 从激光发射器位置发射一束激光,打在物体表面,得到一个激光点数据。那么激光点位置记为占用,激光束穿过的的位置都是free,物体后面的区域是未知的。每当新增一帧激光点数据,对激光束路径上的点累加一次free或者occupied计数,用occupied/free来判断是否占用。
103 |
104 | 相关函数包括:CreateFromScans、AddScan、RayTrace、UpdateCell。
105 |
106 | 如有错误请您批评指正,希望内容对您有帮助,更多细节可以查看代码注释~
107 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/include/sparse_bundle_adjustment/sba_setup.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Software License Agreement (BSD License)
3 | *
4 | * Copyright (c) 2009, Willow Garage, Inc.
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above
14 | * copyright notice, this list of conditions and the following
15 | * disclaimer in the documentation and/or other materials provided
16 | * with the distribution.
17 | * * Neither the name of the Willow Garage nor the names of its
18 | * contributors may be used to endorse or promote products derived
19 | * from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | * POSSIBILITY OF SUCH DAMAGE.
33 | *********************************************************************/
34 |
35 | //
36 | // Functions defined in various test setup files
37 | //
38 |
39 | #ifndef _SBA_SETUP_H_
40 | #define _SBA_SETUP_H_
41 |
42 | #include "sparse_bundle_adjustment/sba.h"
43 | #include "sparse_bundle_adjustment/spa2d.h"
44 | using namespace Eigen;
45 | using namespace sba;
46 | using namespace frame_common;
47 |
48 | #include
49 | #include
50 | #include
51 |
52 | using namespace std;
53 |
54 | // elapsed time in microseconds
55 | long long utime();
56 | // set up spiral system
57 | void
58 | spiral_setup(SysSBA &sba, CamParams &cpars, vector,Eigen::aligned_allocator > > &cps,
59 | double s_near, double s_far,
60 | double ptsize, double kfang, double initang, double cycles,
61 | double inoise, double pnoise, double qnoise);
62 |
63 | void
64 | sphere_setup(SysSBA &sba, CamParams &cpars, vector, Eigen::aligned_allocator > > &cps,
65 | int ncams, // number of cameras
66 | int ncpts, // number of new pts per camera
67 | int nccs, // number of camera connections per camera
68 | double inoise, double pnoise, double qnoise);
69 |
70 |
71 | void
72 | spa_spiral_setup(SysSPA &spa, bool use_cross_links,
73 | vector, Eigen::aligned_allocator > > &cps,
74 | Matrix prec, Matrix vprec,
75 | Matrix a10prec, Matrix a15prec,
76 | double kfang, double initang, double cycles,
77 | double pnoise, double qnoise, double snoise, // measurement noise (m,deg), scale noise (percent)
78 | double mpnoise, double mqnoise); // initial displacement (m,deg)
79 |
80 |
81 | void
82 | spa2d_spiral_setup(SysSPA2d &spa,
83 | vector, Eigen::aligned_allocator > > &cps,
84 | Matrix prec, Matrix vprec,
85 | Matrix a10prec, Matrix a15prec,
86 | double kfang, double initang, double cycles,
87 | double pnoise, double qnoise, double snoise, double dpnoise, double dqnoise);
88 |
89 |
90 | #endif // _VO_SETUP_H_
91 |
--------------------------------------------------------------------------------
/open_karto/CHANGELOG.rst:
--------------------------------------------------------------------------------
1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | Changelog for package open_karto
3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 |
5 | 1.2.3 (2020-11-10)
6 | ------------------
7 | * update destructor to not use c11 feature (`#26 `_)
8 | * fix parameter passing bug of first link to other robots (`#23 `_)
9 | * Fix -Wdelete-non-virtual-dtor and -Wreorder warnings (`#24 `_)
10 | * Contributors: Michael Ferguson, Survy Vaish, Zezhou.Sun
11 |
12 | 1.2.2 (2020-08-07)
13 | ------------------
14 | * Move the C++ classes and definitions of inline functions from the Mapper.cpp file to the Mapper.h file (`#22 `_)
15 | * add Hokuyo configuration in `SetAngularResolution` function (`#20 `_)
16 | Karto has five kinds of lidar parameter configurations (LMS100, LMS200, LMS291, UTM_30LX, URG_04LX), but there are only the first three configurations in the `SetAngularResolution` function, so I added the parameter configuration of UTM_30LX and URG_04LX.
17 | * Contributors: Jian Wen, Zezhou.Sun
18 |
19 | 1.2.1 (2020-04-24)
20 | ------------------
21 | * bump version to silence CMP0048
22 | * Merge pull request `#19 `_ from moriarty/patch-1
23 | Melodic: build status badges Indigo is EOL.
24 | * Melodic: build status badges Indigo is EOL.
25 | * Merge pull request `#18 `_ from ms-iot/windows_port
26 | [Windows][melodic] Fix Windows build break
27 | * Changing maintainer email
28 | * Fix windows build.
29 | * Contributors: Alex Moriarty, Luc Bettaieb, Michael Ferguson, Sean Yen
30 |
31 | 1.2.0 (2018-07-11)
32 | ------------------
33 | * Adds maintainer and branches for melodic
34 | * Merge pull request `#14 `_ from ros-perception/maintainer-add
35 | Adding myself as a maintainer for open_karto
36 | * Adding myself as a maintainer for open_karto
37 | * Merge pull request `#11 `_ from Maidbot/minimum_time_interval
38 | Process scan if enough time has elapsed since the previous one
39 | * Merge pull request `#10 `_ from mikepurvis/fix-cpp11
40 | Use std::isnan/isinf, for C++11 compatibility.
41 | * [Mapper] Take time into account in HasMoveEnough
42 | The function HasMovedEnough now also returns true if more than MinimumTimeInterval time has elapsed since the previously processed laser scan
43 | * [Mapper] Add new parameter, MinimumTimeInterval
44 | * Use std::isnan/isinf, for C++11 compatibility.
45 | * Merge pull request `#8 `_ from mig-em/feature/invalidScans1.1.4
46 | Add invalid scan detection for scanmatcher
47 | * Merge pull request `#9 `_ from Maidbot/ignore_min_readings
48 | Ignore readings less than the sensor's minimum range
49 | * [Karto] Also ignore readings less than the minimum range
50 | * Add invalid scan detection for scanmatcher
51 | * Contributors: Luc Bettaieb, Michael Ferguson, Mike Purvis, Russell Toris, Spyros Maniatopoulos, mig-em
52 |
53 | 1.1.4 (2016-03-02)
54 | ------------------
55 | * update build status badges
56 | * Adds LocalizedRangeScanWithPoints range scan
57 | * Contributors: Michael Ferguson, Russell Toris
58 |
59 | 1.1.3 (2016-02-16)
60 | ------------------
61 | * Link against, and export depend on, boost
62 | * Contributors: Hai Nguyen, Michael Ferguson
63 |
64 | 1.1.2 (2015-07-13)
65 | ------------------
66 | * Added getters and setters for parameters inside Mapper so they can be changed via the ROS param server.
67 | * Contributors: Luc Bettaieb, Michael Ferguson
68 |
69 | 1.1.1 (2015-05-07)
70 | ------------------
71 | * Makes FindValidPoints robust to the first point in the scan being a NaN
72 | * Bump minimum cmake version requirement
73 | * Fix cppcheck warnings
74 | * Fix newlines (dos2unix) & superfluous whitespace
75 | * Protect functions that throw away const-ness (check dirty flag) with mutex
76 | * Don't modify scan during loop closure check - work on a copy of it
77 | * removed useless return to avoid cppcheck error
78 | * Add Mapper::SetUseScanMatching
79 | * Remove html entities from log output
80 | * Fix NANs cause raytracing to take forever
81 | * Contributors: Daniel Pinyol, Michael Ferguson, Paul Mathieu, Siegfried-A. Gevatter Pujals, liz-murphy
82 |
83 | 1.1.0 (2014-06-15)
84 | ------------------
85 | * Release as a pure catkin ROS package
86 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/include/sparse_bundle_adjustment/read_spa.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | * Software License Agreement (BSD License)
3 | *
4 | * Copyright (c) 2009, Willow Garage, Inc.
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | *
11 | * * Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | * * Redistributions in binary form must reproduce the above
14 | * copyright notice, this list of conditions and the following
15 | * disclaimer in the documentation and/or other materials provided
16 | * with the distribution.
17 | * * Neither the name of the Willow Garage nor the names of its
18 | * contributors may be used to endorse or promote products derived
19 | * from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 | * POSSIBILITY OF SUCH DAMAGE.
33 | *********************************************************************/
34 |
35 | // convert a file in Freiburg's VERTEX / EDGE format into a set of constraints
36 |
37 | #ifndef SBA_READ_SPA_H
38 | #define SBA_READ_SPA_H
39 |
40 | #ifndef EIGEN_USE_NEW_STDVECTOR
41 | #define EIGEN_USE_NEW_STDVECTOR
42 | #endif // EIGEN_USE_NEW_STDVECTOR
43 |
44 | #define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(10)
45 | #include
46 | #include
47 |
48 | struct tinfo
49 | {
50 | int pn; // index of point
51 | int fn0, fn1; // index of frames
52 | int fpn0, fpn1; // local point index in frame
53 | double x0,y0,z0,u0,v0; // local XYZ coords and projection
54 | double x1,y1,z1,u1,v1; // local XYZ coords and projection
55 | };
56 |
57 | int
58 | ReadSPAFile(char *fin, // input file
59 | // node translation
60 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ntrans,
61 | // node rotation
62 | std::vector< Eigen::Vector4d, Eigen::aligned_allocator > &nqrot,
63 | // constraint indices
64 | std::vector< Eigen::Vector2i, Eigen::aligned_allocator > &cind,
65 | // constraint local translation
66 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ctrans,
67 | // constraint local rotation as quaternion
68 | std::vector< Eigen::Vector4d, Eigen::aligned_allocator > &cqrot,
69 | // constraint covariance
70 | std::vector< Eigen::Matrix, Eigen::aligned_allocator > > &cvar,
71 | // track info: point projections, see format description in IntelSeattle files
72 | std::vector &tracks
73 | );
74 |
75 | int
76 | ReadSPA2dFile(char *fin, // input file
77 | // node translation
78 | std::vector< Eigen::Vector2d, Eigen::aligned_allocator > &ntrans,
79 | // node rotation
80 | std::vector< double > &nqrot,
81 | // constraint indices
82 | std::vector< Eigen::Vector2i, Eigen::aligned_allocator > &cind,
83 | // constraint local translation
84 | std::vector< Eigen::Vector2d, Eigen::aligned_allocator > &ctrans,
85 | // constraint local rotation as quaternion
86 | std::vector< double > &cqrot,
87 | // constraint covariance
88 | std::vector< Eigen::Matrix, Eigen::aligned_allocator > > &cvar,
89 | // scan points
90 | std::vector< std::vector< Eigen::Vector2d, Eigen::aligned_allocator > > &scans
91 | );
92 |
93 | #endif
94 |
--------------------------------------------------------------------------------
/slam_karto/launch/karto_slam.rviz:
--------------------------------------------------------------------------------
1 | Panels:
2 | - Class: rviz/Displays
3 | Help Height: 78
4 | Name: Displays
5 | Property Tree Widget:
6 | Expanded:
7 | - /Global Options1
8 | - /Status1
9 | Splitter Ratio: 0.5
10 | Tree Height: 549
11 | - Class: rviz/Selection
12 | Name: Selection
13 | - Class: rviz/Tool Properties
14 | Expanded:
15 | - /2D Pose Estimate1
16 | - /2D Nav Goal1
17 | - /Publish Point1
18 | Name: Tool Properties
19 | Splitter Ratio: 0.5886790156364441
20 | - Class: rviz/Views
21 | Expanded:
22 | - /Current View1
23 | Name: Views
24 | Splitter Ratio: 0.5
25 | - Class: rviz/Time
26 | Experimental: false
27 | Name: Time
28 | SyncMode: 0
29 | SyncSource: ""
30 | Preferences:
31 | PromptSaveOnExit: true
32 | Toolbars:
33 | toolButtonStyle: 2
34 | Visualization Manager:
35 | Class: ""
36 | Displays:
37 | - Alpha: 0.5
38 | Cell Size: 1
39 | Class: rviz/Grid
40 | Color: 160; 160; 164
41 | Enabled: true
42 | Line Style:
43 | Line Width: 0.029999999329447746
44 | Value: Lines
45 | Name: Grid
46 | Normal Cell Count: 0
47 | Offset:
48 | X: 0
49 | Y: 0
50 | Z: 0
51 | Plane: XY
52 | Plane Cell Count: 10
53 | Reference Frame:
54 | Value: true
55 | - Alpha: 0.699999988079071
56 | Class: rviz/Map
57 | Color Scheme: map
58 | Draw Behind: false
59 | Enabled: true
60 | Name: Map
61 | Topic: /map
62 | Unreliable: false
63 | Use Timestamp: false
64 | Value: true
65 | - Class: rviz/MarkerArray
66 | Enabled: true
67 | Marker Topic: /visualization_marker_array
68 | Name: MarkerArray
69 | Namespaces:
70 | {}
71 | Queue Size: 100
72 | Value: true
73 | Enabled: true
74 | Global Options:
75 | Background Color: 48; 48; 48
76 | Default Light: true
77 | Fixed Frame: map
78 | Frame Rate: 30
79 | Name: root
80 | Tools:
81 | - Class: rviz/Interact
82 | Hide Inactive Objects: true
83 | - Class: rviz/MoveCamera
84 | - Class: rviz/Select
85 | - Class: rviz/FocusCamera
86 | - Class: rviz/Measure
87 | - Class: rviz/SetInitialPose
88 | Theta std deviation: 0.2617993950843811
89 | Topic: /initialpose
90 | X std deviation: 0.5
91 | Y std deviation: 0.5
92 | - Class: rviz/SetGoal
93 | Topic: /move_base_simple/goal
94 | - Class: rviz/PublishPoint
95 | Single click: true
96 | Topic: /clicked_point
97 | Value: true
98 | Views:
99 | Current:
100 | Class: rviz/Orbit
101 | Distance: 10
102 | Enable Stereo Rendering:
103 | Stereo Eye Separation: 0.05999999865889549
104 | Stereo Focal Distance: 1
105 | Swap Stereo Eyes: false
106 | Value: false
107 | Field of View: 0.7853981852531433
108 | Focal Point:
109 | X: 0
110 | Y: 0
111 | Z: 0
112 | Focal Shape Fixed Size: true
113 | Focal Shape Size: 0.05000000074505806
114 | Invert Z Axis: false
115 | Name: Current View
116 | Near Clip Distance: 0.009999999776482582
117 | Pitch: 0.785398006439209
118 | Target Frame:
119 | Yaw: 0.785398006439209
120 | Saved: ~
121 | Window Geometry:
122 | Displays:
123 | collapsed: false
124 | Height: 846
125 | Hide Left Dock: false
126 | Hide Right Dock: false
127 | QMainWindow State: 000000ff00000000fd000000040000000000000156000002b0fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003d000002b0000000c900fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261000000010000010f000002b0fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003d000002b0000000a400fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004b00000003efc0100000002fb0000000800540069006d00650100000000000004b0000002eb00fffffffb0000000800540069006d006501000000000000045000000000000000000000023f000002b000000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
128 | Selection:
129 | collapsed: false
130 | Time:
131 | collapsed: false
132 | Tool Properties:
133 | collapsed: false
134 | Views:
135 | collapsed: false
136 | Width: 1200
137 | X: 597
138 | Y: 466
139 |
--------------------------------------------------------------------------------
/open_karto/include/open_karto/Macros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 SRI International
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef OPEN_KARTO_MACROS_H
19 | #define OPEN_KARTO_MACROS_H
20 |
21 | ////////////////////////////////////////////////////////////////////////////////////////
22 | ////////////////////////////////////////////////////////////////////////////////////////
23 | ////////////////////////////////////////////////////////////////////////////////////////
24 |
25 | /**
26 | * Karto defines for handling deprecated code
27 | */
28 | #ifndef KARTO_DEPRECATED
29 | # if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__>=1))
30 | # define KARTO_DEPRECATED __attribute__((deprecated))
31 | # elif defined(__INTEL) || defined(_MSC_VER)
32 | # define KARTO_DEPRECATED __declspec(deprecated)
33 | # else
34 | # define KARTO_DEPRECATED
35 | # endif
36 | #endif
37 |
38 | ////////////////////////////////////////////////////////////////////////////////////////
39 | ////////////////////////////////////////////////////////////////////////////////////////
40 | ////////////////////////////////////////////////////////////////////////////////////////
41 |
42 | /**
43 | * Karto defines for windows dynamic build
44 | */
45 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
46 | # if defined( _LIB ) || defined( KARTO_STATIC ) || defined( STATIC_BUILD )
47 | # define KARTO_EXPORT
48 | # else
49 | # ifdef KARTO_DYNAMIC
50 | # define KARTO_EXPORT __declspec(dllexport)
51 | # else
52 | # define KARTO_EXPORT __declspec(dllimport)
53 | # endif // KARTO_DYNAMIC
54 | # endif
55 | #else
56 | # define KARTO_EXPORT
57 | #endif
58 |
59 | ////////////////////////////////////////////////////////////////////////////////////////
60 | ////////////////////////////////////////////////////////////////////////////////////////
61 | ////////////////////////////////////////////////////////////////////////////////////////
62 |
63 | /**
64 | * Helper defines for std iterator loops
65 | */
66 | #define forEach( listtype, list ) \
67 | for ( listtype::iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
68 |
69 | #define forEachAs( listtype, list, iter ) \
70 | for ( listtype::iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
71 |
72 | #define const_forEach( listtype, list ) \
73 | for ( listtype::const_iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
74 |
75 | #define const_forEachAs( listtype, list, iter ) \
76 | for ( listtype::const_iterator iter = (list)->begin(); iter != (list)->end(); ++iter )
77 |
78 | #define forEachR( listtype, list ) \
79 | for ( listtype::reverse_iterator iter = (list)->rbegin(); iter != (list)->rend(); ++iter )
80 |
81 | #define const_forEachR( listtype, list ) \
82 | for ( listtype::const_reverse_iterator iter = (list)->rbegin(); iter != (list)->rend(); ++iter )
83 |
84 |
85 | ////////////////////////////////////////////////////////////////////////////////////////
86 | ////////////////////////////////////////////////////////////////////////////////////////
87 | ////////////////////////////////////////////////////////////////////////////////////////
88 |
89 | /**
90 | * Disable annoying compiler warnings
91 | */
92 |
93 | #if defined(__INTEL) || defined(_MSC_VER)
94 |
95 | // Disable the warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
96 | #pragma warning(disable:4251)
97 |
98 | #endif
99 |
100 | #ifdef __INTEL_COMPILER
101 |
102 | // Disable the warning: conditional expression is constant
103 | #pragma warning(disable:4127)
104 |
105 | // Disable the warning: 'identifier' : unreferenced formal parameter
106 | #pragma warning(disable:4100)
107 |
108 | // remark #383: value copied to temporary, reference to temporary used
109 | #pragma warning(disable:383)
110 |
111 | // remark #981: operands are evaluated in unspecified order
112 | // disabled -> completely pointless if the functions do not have side effects
113 | #pragma warning(disable:981)
114 |
115 | // remark #1418: external function definition with no prior declaration
116 | #pragma warning(disable:1418)
117 |
118 | // remark #1572: floating-point equality and inequality comparisons are unreliable
119 | // disabled -> everyone knows it, the parser passes this problem deliberately to the user
120 | #pragma warning(disable:1572)
121 |
122 | // remark #10121:
123 | #pragma warning(disable:10121)
124 |
125 | #endif // __INTEL_COMPILER
126 |
127 | #endif // OPEN_KARTO_MACROS_H
128 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/src/visualization.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | namespace sba {
4 |
5 | void drawGraph(const SysSBA &sba, const ros::Publisher &camera_pub,
6 | const ros::Publisher &point_pub, int decimation, int bicolor)
7 | {
8 | int num_points = sba.tracks.size();
9 | int num_cameras = sba.nodes.size();
10 | if (num_points == 0 && num_cameras == 0) return;
11 |
12 | visualization_msgs::Marker camera_marker, point_marker;
13 | camera_marker.header.frame_id = "/pgraph";
14 | camera_marker.header.stamp = ros::Time::now();
15 | camera_marker.ns = "pgraph";
16 | camera_marker.id = 0;
17 | camera_marker.action = visualization_msgs::Marker::ADD;
18 | camera_marker.pose.position.x = 0;
19 | camera_marker.pose.position.y = 0;
20 | camera_marker.pose.position.z = 0;
21 | camera_marker.pose.orientation.x = 0.0;
22 | camera_marker.pose.orientation.y = 0.0;
23 | camera_marker.pose.orientation.z = 0.0;
24 | camera_marker.pose.orientation.w = 1.0;
25 | camera_marker.scale.x = 0.02;
26 | camera_marker.scale.y = 0.02;
27 | camera_marker.scale.z = 0.02;
28 | camera_marker.color.r = 0.0f;
29 | camera_marker.color.g = 1.0f;
30 | camera_marker.color.b = 1.0f;
31 | camera_marker.color.a = 1.0f;
32 | camera_marker.lifetime = ros::Duration();
33 | camera_marker.type = visualization_msgs::Marker::LINE_LIST;
34 |
35 | point_marker = camera_marker;
36 | point_marker.color.r = 1.0f;
37 | point_marker.color.g = 0.0f;
38 | point_marker.color.b = 0.0f;
39 | point_marker.color.a = 0.5f;
40 | point_marker.scale.x = 0.02;
41 | point_marker.scale.y = 0.02;
42 | point_marker.scale.z = 0.02;
43 | point_marker.type = visualization_msgs::Marker::POINTS;
44 |
45 | // draw points, decimated
46 | point_marker.points.resize((int)(num_points/(double)decimation + 0.5));
47 | point_marker.colors.resize((int)(num_points/(double)decimation + 0.5));
48 | for (int i=0, ii=0; i < num_points; i += decimation, ii++)
49 | {
50 | const Vector4d &pt = sba.tracks[i].point;
51 | point_marker.colors[ii].r = 1.0f;
52 | if (bicolor > 0 && i >= bicolor)
53 | point_marker.colors[ii].g = 1.0f;
54 | else
55 | point_marker.colors[ii].g = 0.0f;
56 | point_marker.colors[ii].b = 0.0f;
57 | point_marker.points[ii].x = pt(2);
58 | point_marker.points[ii].y = -pt(0);
59 | point_marker.points[ii].z = -pt(1);
60 | }
61 |
62 | // draw cameras
63 | camera_marker.points.resize(num_cameras*6);
64 | for (int i=0, ii=0; i < num_cameras; i++)
65 | {
66 | const Node &nd = sba.nodes[i];
67 | Vector3d opt;
68 | Matrix tr;
69 | transformF2W(tr,nd.trans,nd.qrot);
70 |
71 | camera_marker.points[ii].x = nd.trans.z();
72 | camera_marker.points[ii].y = -nd.trans.x();
73 | camera_marker.points[ii++].z = -nd.trans.y();
74 | opt = tr*Vector4d(0,0,0.3,1);
75 | camera_marker.points[ii].x = opt.z();
76 | camera_marker.points[ii].y = -opt.x();
77 | camera_marker.points[ii++].z = -opt.y();
78 |
79 | camera_marker.points[ii].x = nd.trans.z();
80 | camera_marker.points[ii].y = -nd.trans.x();
81 | camera_marker.points[ii++].z = -nd.trans.y();
82 | opt = tr*Vector4d(0.2,0,0,1);
83 | camera_marker.points[ii].x = opt.z();
84 | camera_marker.points[ii].y = -opt.x();
85 | camera_marker.points[ii++].z = -opt.y();
86 |
87 | camera_marker.points[ii].x = nd.trans.z();
88 | camera_marker.points[ii].y = -nd.trans.x();
89 | camera_marker.points[ii++].z = -nd.trans.y();
90 | opt = tr*Vector4d(0,0.1,0,1);
91 | camera_marker.points[ii].x = opt.z();
92 | camera_marker.points[ii].y = -opt.x();
93 | camera_marker.points[ii++].z = -opt.y();
94 | }
95 |
96 | // draw point-plane projections
97 | int num_tracks = sba.tracks.size();
98 | int ii = camera_marker.points.size();
99 |
100 | for (int i=0; i < num_tracks; i++)
101 | {
102 | const ProjMap &prjs = sba.tracks[i].projections;
103 | for (ProjMap::const_iterator itr = prjs.begin(); itr != prjs.end(); itr++)
104 | {
105 | const Proj &prj = (*itr).second;
106 | if (prj.pointPlane) // have a ptp projection
107 | {
108 | camera_marker.points.resize(ii+2);
109 | Point pt0 = sba.tracks[i].point;
110 | Vector3d plane_point = prj.plane_point;
111 | Vector3d plane_normal = prj.plane_normal;
112 | Eigen::Vector3d w = pt0.head<3>()-plane_point;
113 | // Eigen::Vector3d projpt = plane_point+(w.dot(plane_normal))*plane_normal;
114 | Eigen::Vector3d projpt = pt0.head<3>() - (w.dot(plane_normal))*plane_normal;
115 | // Vector3d pt1 = pt0.head<3>()+0.1*plane_normal;
116 | Vector3d pt1 = projpt;
117 |
118 | camera_marker.points[ii].x = pt0.z();
119 | camera_marker.points[ii].y = -pt0.x();
120 | camera_marker.points[ii++].z = -pt0.y();
121 | camera_marker.points[ii].x = pt1.z();
122 | camera_marker.points[ii].y = -pt1.x();
123 | camera_marker.points[ii++].z = -pt1.y();
124 | }
125 | }
126 | }
127 |
128 | camera_pub.publish(camera_marker);
129 | point_pub.publish(point_marker);
130 | }
131 |
132 | } // namespace sba
133 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/include/sparse_bundle_adjustment/sba_file_io.h:
--------------------------------------------------------------------------------
1 | #ifndef SBA_BUNDLER_FILE_H
2 | #define SBA_BUNDLER_FILE_H
3 |
4 | #ifndef EIGEN_USE_NEW_STDVECTOR
5 | #define EIGEN_USE_NEW_STDVECTOR
6 | #endif // EIGEN_USE_NEW_STDVECTOR
7 |
8 | //#define EIGEN_DEFAULT_IO_FORMAT Eigen::IOFormat(10)
9 |
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 | #include "sparse_bundle_adjustment/sba.h"
17 |
18 | namespace Eigen
19 | {
20 | typedef Matrix Vector11d;
21 | typedef Matrix Vector5d;
22 | }
23 |
24 | namespace sba
25 | {
26 |
27 | /** \brief Reads bundle adjustment data from a Bundler file to an instance of SysSBA.
28 | *
29 | * \param filename The name of the bundler-formatted file to read from.
30 | * \param sbaout An instance of SBA that the file will be written to.
31 | * It should be noted that the bundler format does not support stereo points;
32 | * all points read in will be monocular.
33 | * Note: documentation of the Bundler format can be found at
34 | * http://phototour.cs.washington.edu/bundler/bundler-v0.3-manual.html .
35 | */
36 | int readBundlerFile(const char *filename, sba::SysSBA& sbaout);
37 |
38 | /** \brief Writes bundle adjustment data from an instance of SysSBA to a Bundler file.
39 | *
40 | * \param filename The name of the bundler-formatted file to write to.
41 | * The file is created, or if it already exists, truncated.
42 | * \param sbain An instance of SBA that the file will be written from.
43 | * It should be noted that the bundler format does not support stereo points;
44 | * all points written will be monocular. Also, since SBA does not store point
45 | * color information, all points will be colored white.
46 | * Note: documentation of the Bundler format can be found at
47 | * http://phototour.cs.washington.edu/bundler/bundler-v0.3-manual.html .
48 | */
49 | int writeBundlerFile(const char *filename, sba::SysSBA& sbain);
50 |
51 | /** \brief A low-level parser for bundler files. */
52 | int
53 | ParseBundlerFile(const char *fin, // input file
54 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &camp, // cam params
55 | std::vector< Eigen::Matrix3d, Eigen::aligned_allocator > &camR, // cam rotation matrix
56 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &camt, // cam translation
57 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ptp, // point position
58 | std::vector< Eigen::Vector3i, Eigen::aligned_allocator > &ptc, // point color
59 | std::vector< std::vector< Eigen::Vector4d, Eigen::aligned_allocator > > &ptt // point tracks - each vector is
60 | );
61 |
62 | /** \brief Reads bundle adjustment data from a graph-type file to an instance of SysSBA.
63 | *
64 | * \param filename The name of the bundler-formatted file to read from.
65 | * \param sbaout An instance of SBA that the file will be written to.
66 | * Note: where is the documentation for this format?
67 | */
68 | int readGraphFile(const char *filename, sba::SysSBA& sbaout);
69 |
70 | /** \brief A low-level parser for graph files. */
71 | int
72 | ParseGraphFile(const char *fin, // input file
73 | std::vector< Eigen::Vector5d, Eigen::aligned_allocator > &camps, // cam params
74 | std::vector< Eigen::Vector4d, Eigen::aligned_allocator > &camqs, // cam rotation matrix
75 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &camts, // cam translation
76 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ptps, // point position
77 | std::vector< std::vector< Eigen::Vector11d, Eigen::aligned_allocator > > &ptts // point tracks - each vector is
78 | );
79 |
80 |
81 | /// write out system in SBA form
82 | void writeLourakisFile(const char *fname, SysSBA& sba);
83 | void writeA(const char *fname, SysSBA& sba); // save precision matrix
84 | void writeSparseA(const char *fname, SysSBA& sba); // save precision matrix in CSPARSE format
85 |
86 | /**
87 | * \brief Writes out the current SBA system as an ascii graph file
88 | * suitable to be read in by the Freiburg HChol system.
89 | * is true if only monocular projections are desired
90 | */
91 | int writeGraphFile(const char *filename, SysSBA& sba, bool mono=false);
92 |
93 |
94 | /** \brief Reads 3D pose graph data from a graph-type file to an instance of SysSPA.
95 | *
96 | * \param filename The name of the bundler-formatted file to read from.
97 | * \param spaout An instance of SPA that the file will be written to.
98 | * Note: where is the documentation for this format?
99 | */
100 |
101 | int readSPAGraphFile(const char *filename, SysSPA& spaout);
102 |
103 | /** \brief A low-level parser for graph files. */
104 | int
105 | ParseSPAGraphFile(const char *fin, // input file
106 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ntrans, // node translation
107 | std::vector< Eigen::Vector4d, Eigen::aligned_allocator > &nqrot, // node rotation
108 | std::vector< Eigen::Vector2i, Eigen::aligned_allocator > &cind, // constraint indices
109 | std::vector< Eigen::Vector3d, Eigen::aligned_allocator > &ctrans, // constraint local translation
110 | std::vector< Eigen::Vector4d, Eigen::aligned_allocator > &cqrot, // constraint local rotation as quaternion
111 | std::vector< Eigen::Matrix, Eigen::aligned_allocator > > &cvar); // constraint covariance
112 |
113 | }; // namespace SBA
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/src/node.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | using namespace std;
4 | using namespace Eigen;
5 |
6 | namespace sba
7 | {
8 | void Node::setTransform()
9 | { transformW2F(w2n,trans,qrot); }
10 |
11 | //
12 | // sets incremental angle derivatives
13 | //
14 | void Node::setDri()
15 | {
16 | setDr(true);
17 | }
18 |
19 | // constant derivative matrices
20 | // these are the derivatives of the *inverse* rotation
21 | Eigen::Matrix3d Node::dRidx, Node::dRidy, Node::dRidz;
22 |
23 | void Node::initDr()
24 | {
25 | dRidx << 0.0,0.0,0.0,
26 | 0.0,0.0,2.0,
27 | 0.0,-2.0,0.0;
28 | dRidy << 0.0,0.0,-2.0,
29 | 0.0,0.0,0.0,
30 | 2.0,0.0,0.0;
31 | dRidz << 0.0,2.0,0.0,
32 | -2.0,0.0,0.0,
33 | 0.0,0.0,0.0;
34 | }
35 |
36 |
37 | void Node::normRot()
38 | {
39 | // std::cout << "[NormRot] qrot start = " << qrot.transpose() << std::endl;
40 | if (qrot.w() < 0) qrot.coeffs().head<3>() = -qrot.coeffs().head<3>();
41 | double sn = qrot.coeffs().head<3>().squaredNorm();
42 | if (sn >= 0.9999) // too close to high derivatives
43 | qrot.coeffs().head<3>() *= -1.0/(sqrt(sn)*1.0001); // switch sides; 1e-4 seems to work well
44 | qrot.w() = sqrt(1.0 - qrot.coeffs().head<3>().squaredNorm());
45 | if (std::isnan(qrot.x()) || std::isnan(qrot.y()) || std::isnan(qrot.z()) || std::isnan(qrot.w()) )
46 | {
47 | printf("[NormRot] Bad quaternion: %f %f %f %f\n", qrot.x(), qrot.y(), qrot.z(), qrot.w());
48 | exit(1);
49 | }
50 | // std::cout << "[NormRot] qrot end = " << qrot.transpose() << std::endl;
51 | }
52 |
53 | //
54 | // sets angle derivatives
55 | //
56 | void Node::setDr(bool local)
57 | {
58 | // for dS'*R', with dS the incremental change
59 | if (local)
60 | {
61 | #if 0
62 | dRdx = w2n.block<3,3>(0,0) * dRidx;
63 | dRdy = w2n.block<3,3>(0,0) * dRidy;
64 | dRdz = w2n.block<3,3>(0,0) * dRidz;
65 | #endif
66 | dRdx = dRidx * w2n.block<3,3>(0,0);
67 | dRdy = dRidy * w2n.block<3,3>(0,0);
68 | dRdz = dRidz * w2n.block<3,3>(0,0);
69 |
70 | }
71 | else
72 | {
73 | double x2 = qrot.x() * 2.0;
74 | double y2 = qrot.y() * 2.0;
75 | double z2 = qrot.z() * 2.0;
76 | double w2 = qrot.w() * 2.0;
77 | double xw = qrot.x()/qrot.w(); // these are problematic for w near zero
78 | double yw = qrot.y()/qrot.w();
79 | double zw = qrot.z()/qrot.w();
80 |
81 | // dR/dx
82 | dRdx(0,0) = 0.0;
83 | dRdx(0,1) = y2-zw*x2;
84 | dRdx(0,2) = z2+yw*x2;
85 |
86 | dRdx(1,0) = y2+zw*x2;
87 | dRdx(1,1) = -2.0*x2;
88 | dRdx(1,2) = w2-xw*x2;
89 |
90 | dRdx(2,0) = z2-yw*x2;
91 | dRdx(2,1) = -dRdx(1,2);
92 | dRdx(2,2) = dRdx(1,1);
93 |
94 | // dR/dy
95 | dRdy(0,0) = -2.0*y2;
96 | dRdy(0,1) = x2-zw*y2;
97 | dRdy(0,2) = (-w2)+yw*y2;
98 |
99 | dRdy(1,0) = x2+zw*y2;
100 | dRdy(1,1) = 0.0;
101 | dRdy(1,2) = dRdx(2,0);
102 |
103 | dRdy(2,0) = -dRdy(0,2);
104 | dRdy(2,1) = dRdx(0,2);
105 | dRdy(2,2) = dRdy(0,0);
106 |
107 | // dR/dz
108 | dRdz(0,0) = -2.0*z2;
109 | dRdz(0,1) = w2-zw*z2;
110 | dRdz(0,2) = dRdy(1,0);
111 |
112 | dRdz(1,0) = -dRdz(0,1);
113 | dRdz(1,1) = dRdz(0,0);
114 | dRdz(1,2) = dRdx(0,1);
115 |
116 | dRdz(2,0) = dRdy(0,1);
117 | dRdz(2,1) = dRdx(1,0);
118 | dRdz(2,2) = 0.0;
119 | }
120 | }
121 |
122 | void Node::normRotLocal()
123 | {
124 | qrot.normalize();
125 | if (qrot.w() < 0) qrot.coeffs().head<3>() = -qrot.coeffs().head<3>();
126 | if (std::isnan(qrot.x()) || std::isnan(qrot.y()) || std::isnan(qrot.z()) || std::isnan(qrot.w()) )
127 | {
128 | printf("[NormRot] Bad quaternion in normRotLocal(): %f %f %f %f\n", qrot.x(), qrot.y(), qrot.z(), qrot.w());
129 | exit(1);
130 | }
131 | // std::cout << "[NormRot] qrot end = " << qrot.transpose() << std::endl;
132 | }
133 |
134 | void Node::projectMono(const Point& point, Eigen::Vector3d& proj)
135 | {
136 | Vector2d proj2d;
137 | project2im(proj2d, point);
138 |
139 | proj.head<2>() = proj2d;
140 | }
141 |
142 | void Node::projectStereo(const Point& point, Eigen::Vector3d& proj)
143 | {
144 | Vector2d proj2d;
145 | Vector3d pc, baseline_vect;
146 | project2im(proj2d, point);
147 |
148 | // Camera coords for right camera
149 | baseline_vect << baseline, 0, 0;
150 | pc = Kcam * (w2n*point - baseline_vect);
151 | proj.head<2>() = proj2d;
152 | proj(2) = pc(0)/pc(2);
153 | }
154 |
155 |
156 | // transforms
157 | void transformW2F(Eigen::Matrix &m,
158 | const Eigen::Matrix &trans,
159 | const Eigen::Quaternion &qrot)
160 | {
161 | m.block<3,3>(0,0) = qrot.toRotationMatrix().transpose();
162 | m.col(3).setZero(); // make sure there's no translation
163 | m.col(3) = -m*trans;
164 | };
165 |
166 | void transformF2W(Eigen::Matrix &m,
167 | const Eigen::Matrix &trans,
168 | const Eigen::Quaternion &qrot)
169 | {
170 | m.block<3,3>(0,0) = qrot.toRotationMatrix();
171 | m.col(3) = trans.head(3);
172 | };
173 |
174 |
175 | // returns the local R,t in nd0 that produces nd1
176 | // NOTE: returns a postfix rotation; should return a prefix
177 | void transformN2N(Eigen::Matrix &trans,
178 | Eigen::Quaternion &qr,
179 | Node &nd0, Node &nd1)
180 | {
181 | Matrix tfm;
182 | Quaterniond q0,q1;
183 | q0 = nd0.qrot;
184 | transformW2F(tfm,nd0.trans,q0);
185 | trans.head(3) = tfm*nd1.trans;
186 | trans(3) = 1.0;
187 | q1 = nd1.qrot;
188 | qr = q0.inverse()*q1;
189 | qr.normalize();
190 | if (qr.w() < 0)
191 | qr.coeffs() = -qr.coeffs();
192 | }
193 |
194 |
195 | } // namespace sba
196 |
197 |
198 |
--------------------------------------------------------------------------------
/sparse_bundle_adjustment/src/nodes/sba_node.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // Messages
5 | #include
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | #include