Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TerrainSimplification and TerrainSimplificationRos packages #5

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6660160
Add TerrainSimplification and TerrainSimplificationRos packages
Jan 17, 2021
c93e508
Create README.md
oliwiermelon Jan 17, 2021
b4c9391
Check that the queried position is inside the map
Jan 21, 2021
c7a61f4
Add ros server to get a value from a map at a position, create a srv
Jan 21, 2021
e676deb
Merge branch 'add-terrain-simplification' of github.com:ori-drs/plane…
Jan 21, 2021
55810e6
[TerrainSimplification] change from boost::shared_mutex to std::mutex
Jan 26, 2021
f21eebc
[TerrainSimplificationRos::getTraversability] add missing return keyword
Jan 26, 2021
a8eff16
[TerrainSimplificationRos] load parameters from a yaml config file
Jan 26, 2021
38bffbc
[TerrainSimplificationRos] add doxygen comments
Jan 26, 2021
4b6bd58
[TerrainSimplification, TerrainSimplificationRos] use setGridMap() an…
Jan 26, 2021
a6c8887
[TerrainSimplification, TerrainSimplificationRos] use shared_ptr to T…
Jan 27, 2021
91f2839
[TerrainSimplificationRos] add getTerrainSimplification()
Jan 27, 2021
772755f
[TerrainSimplificationRos] fix ROS param name
Jan 28, 2021
5a24948
[TerrainSimplificationRos] make getTerrainSimplification() public
Jan 28, 2021
0fae537
[TerrainSimplification] add catkin dependencies and link libraries
Jan 28, 2021
a4a5f56
[TerrainSimplification::getSimplifiedGridMap] Rearrange and group pro…
Jan 29, 2021
7ab7b59
remove lcm based executable
benoit-robotics Feb 3, 2021
61cf5fc
Merge branch 'master' into add-terrain-simplification
benoit-robotics Feb 3, 2021
2fd6ade
[TerrainSimplificationRos::pubSimplifiedMap] fix small x offset in th…
Feb 5, 2021
422ca45
[terrain_simplification] add OpenCV to CMakeLists
Feb 5, 2021
a5bca91
[TerrainSimplification] create containers (struct) for related images…
Feb 5, 2021
0bd4b6f
[TerrainSimplification] compute first- and second-order partial deriv…
Feb 5, 2021
ed9d96f
Merge branch 'add-terrain-simplification' of github.com:ori-drs/plane…
Feb 5, 2021
7e16a61
[TerrainSimplification] add a base-motion-constraint gif
Feb 5, 2021
6e28902
Create README.md
oliwiermelon Feb 5, 2021
95bda33
[TerrainSimplification] add an image of the computed derivatives of t…
Feb 5, 2021
2824628
Update README.md
oliwiermelon Feb 5, 2021
4bbd36e
[TerrainSimplification] add another gif and image
Feb 5, 2021
000f946
Merge branch 'add-terrain-simplification' of github.com:ori-drs/plane…
Feb 5, 2021
0d727e3
Update README.md
oliwiermelon Feb 5, 2021
aaef071
[terrain_simplification_ros] add the main config file
Feb 7, 2021
8937546
[TerrainSimplification::getValueAtPosition] add cerr
Feb 7, 2021
dc67894
[terrain_simplification_ros] uncomment a slope-blurring filter
Feb 7, 2021
30b4bee
[TerrainSimplification] check that robot position is inside the map
Feb 7, 2021
9aaa83e
[terrain_simplification_ros] change config to use an unscaled 2.5x2.5…
Feb 7, 2021
32c088f
[TerrainSimplification::convertCvImagesOfSecondOrderDerivativesToGrid…
Feb 7, 2021
317ea82
[TerrainSimplification::simplifyGridMap] remove slope conversion
Feb 7, 2021
a12b94c
[TerrainSimplification, TerrainSimplificationRos] account for the poi…
Feb 9, 2021
35b4c1b
[terrain_simplification_ros] change trottled topic name
Feb 9, 2021
ab200cc
[TerrainSimplification] fix minor bug
Feb 10, 2021
0f879e5
[terrain_simplification] clean CMakeLists.txt and package.xml
Feb 10, 2021
ab459ba
[terrain_simplification_ros] update README.md
Feb 10, 2021
448eb58
[terrain_simplification] Fix virtual destructor
wxmerkt Feb 24, 2021
9471693
[terrain_simplification_ros] Replace loadConfigFile with loading from…
wxmerkt Feb 24, 2021
2541404
[terrain_simplification_ros] Replace "success" in constructor with ex…
wxmerkt Feb 24, 2021
b3bd970
[terrain_simplification] Make grid resolution configurable
wxmerkt Feb 24, 2021
c8c9b25
[terrain_simplification] Typos & add TODO comments
wxmerkt Feb 24, 2021
e18c39d
[terrain_simplification] Minor
wxmerkt Feb 24, 2021
318ee8f
[terrain_simplification_ros] comment out filters in filter_chain for …
Mar 1, 2021
608777b
[TerrainSimplification] make filter chain an option
Mar 13, 2021
9b6e9b4
[TerrainSimplification::simplifyGridMap] remove default "simplified" …
Mar 13, 2021
11a102f
[TerrainSimplification::simplifyGridMap] fix spelling
Mar 13, 2021
9156a01
[TerrainSimplification::simplifyGridMap] change arguments of addDataF…
Mar 13, 2021
7284ba0
[TerrainSimplification::convertCvImageToGridMap] check and print out …
Mar 13, 2021
147218f
[terrain_simplification_ros] load filter_chain within the ros node
Jul 5, 2021
b746de5
[TerrainSimplificationRos] improve warnings
Jul 5, 2021
2b1deb8
[TerrainSimplification, TerrainSimplificationRos] update deprecated f…
Jul 5, 2021
4d642ac
[terrain_simplification, terrain_simplification_ros] use grid_map_fil…
Jul 5, 2021
a372902
[TerrainSimplification] comment out derivatives
Jul 5, 2021
a599266
[terrain_simplification_ros] add fake tf publisher
Jul 5, 2021
df88525
[ts, ts_ros] make filtered layer name settable
Jul 26, 2021
25c688c
[terrain_simplification] Ignore warnings from filter_chain
wxmerkt Jul 27, 2021
d1f2c28
[terrain_simplification_ros] Remove explicit dependency on grid_map_f…
wxmerkt Aug 4, 2021
a3efd44
[terrain_simplification_ros] Update CMake version
wxmerkt Aug 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions terrain_simplification/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
cmake_minimum_required(VERSION 2.8.3)
project(terrain_simplification)

add_compile_options(-std=c++11)
set(DEFAULT_BUILD "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD}' as none was specified.")
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD} CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo")
endif()

add_definitions(-DMELO_FUNCTION_PRINTS)

find_package(catkin REQUIRED COMPONENTS
std_msgs
geometry_msgs
visualization_msgs
grid_map_core
grid_map_filters
grid_map_cv
message_generation
)

# Generate messages in the 'msg' folder
#add_message_files(
# FILES
# XXX.msg
#)
#
#generate_messages(
# DEPENDENCIES
# std_msgs
# geometry_msgs
#)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS
grid_map_core
grid_map_filters
grid_map_cv
message_runtime
std_msgs
geometry_msgs
)

###########
## Build ##
###########
add_library(${PROJECT_NAME}
src/terrain_simplification.cpp
)

include_directories(
include
${catkin_INCLUDE_DIRS}
)


#############
## Install ##
#############
# Mark library for installation
install(
TARGETS
${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

# Mark header files for installation
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.hpp"
)

# Mark other files for installation
install(
DIRECTORY launch config
wxmerkt marked this conversation as resolved.
Show resolved Hide resolved
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/**
* @file terrain_simplification.hpp
* @brief A module that simplifies the observed terrain, represented as a gridmap,
* by applying an OpenCV-based low-pass filter to extract the high-level geometry
* and qualify its irregularity by computing traversability using a filter chain.
* @author Oliwier Melon ([email protected])
* @bug No known bugs.
* @date 07/01/2021
* @version 1.1
* @note The computation can be accelerated if the functionality of the Filter Chain
* were manually implemented.
* @copyright 2020, Oliwier Melon. BSD-3-Clause
*/

#ifndef TERRAIN_SIMPLIFICATION_HPP
#define TERRAIN_SIMPLIFICATION_HPP

#include <grid_map_core/grid_map_core.hpp>
#include <grid_map_ros/grid_map_ros.hpp>
#include <filters/filter_chain.h>

#include <thread>
#include <atomic>
#include <boost/thread/pthread/shared_mutex.hpp>

namespace terrain_simplification {

class TerrainSimplification {

public:
/**
* @brief Constructs a multi-threaded (2) object
*/
TerrainSimplification();

/**
* @brief Destructs the multi-threaded (2) object
*/
~TerrainSimplification();

protected:
/**
* @brief Assigns a shared pointer to the filter_chain_ object
* @param[in] filter_chain shared pointer to a filter chain object in the derived class (ros).
*/
void setFilterChain(
std::shared_ptr<filters::FilterChain<grid_map::GridMap> > filter_chain) {
filter_chain_ = filter_chain;
}

/**
* @brief Set the position and orientation of the robot
* @param[in] position the position of the robot
* @param[in] orientation the orientation of the robot
*/
void setRobotPose (
const Eigen::Vector3d& position,
const Eigen::Quaterniond& orientation) {
robot_position_ = position;
robot_orientation_ = orientation;
}

/**
* @brief Computes the yaw angle from the local copy of the robot's orientation.
* Stores the result in a member variable;
* @return Yaw angle
*/
double getRobotYaw ();

/**
* @brief Sets a member variable of the full map and sets received_ flag to true.
* @param[in] map the full elevation map
*/
void setGridMap(
const grid_map::GridMap& map);

/**
* @brief Simplifies the acquired elevation map and stores the result in a member variable.
*/
void simplifyGridMap();

/**
* @brief Converts a layer of a gridmap to an image
* @param[in] layer_name the name of the layer from which to extract the gridmap
* @param[in] map the input gridmap
* @param[out] image the output image
*/
void convertGridMapToCvImage(
const std::string& layer_name,
const grid_map::GridMap& map,
cv::Mat& image);

/**
* @brief Converts an image to a layer of a gridmap
* @param[in] layer_name the name of the layer
* @param[in] image the input image
* @param[out] map the output gridmap
*/
void convertCvImageToGridMap(
const std::string& layer_name,
const cv::Mat& image,
grid_map::GridMap& map);

/**
* @brief Filters an image using OpenCV filters by applying directional blur
* @param[in] image the input image
* @param[in/out] image_filtered the output image
*/
void filterCvImage(
const cv::Mat& image,
cv::Mat& image_filtered);

/**
* @brief Scales an image
* @param[in] scale the scaling factor
* @param[in] image the input image
* @param[in/out] image_scaled the output image
*/
void scaleCvImage(
const double& scale,
const cv::Mat& image,
cv::Mat& image_scaled);

/**
* @brief Gets the Kernel dependent on robot's orientation (yaw)
* for the 2D filter (directional Gaussian blur)
*/
cv::Mat getDirectionalBlurKernel();

/**
* @brief Gets the simplified gridmap of the terrain
* @param[in/out] simplified_map the simplified map
* @param[in] scale an optional scaling factor
*/
void getSimplifiedGridMap(
grid_map::GridMap& simplified_map,
const double& scale = 1.0);

/**
* @brief Applies a sequence of filters defined via the Filter Chain to a gridmap
* @param[in] map_in the input map without the filters applied
* @param[in/out] map_out the output map with the filters applied
*/
void applyFilterChain(
const grid_map::GridMap& map_in,
grid_map::GridMap& map_out);

/**
* @brief Gets a value from a layer of the simplified map at a specific position
* @param layer name of the accessed layer
* @param position xy-coordinates
* @param is_inside flag that states whether the provided position is inside the map
* @return value at a position
*/
double getValueAtPosition(
const std::string& layer,
const Eigen::Vector2d& position,
bool& is_inside);

/**
* @brief The run function for the TerrainSimplification
* which calls advance() in a while loop.
* It is started in a separate thread by a rosservice callback function.
*/
void run();

/**
* @brief The run function for the TerrainSimplification
* which calls advance() in a while loop.
* It is started in a separate thread by a rosservice callback function.
*/
void setRun(const bool& run) { run_ = run; }

/**
* @brief Set the size of the simplified map
*/
void setMapSize(const Eigen::Vector2d& map_size) { map_size_ = map_size; }

/**
* @brief The advance function for the TerrainSimplification.
* It can be stopped by a rosservice call which sets the stop_ flag.
* @return true if successful
*/
bool advance();

/**
* @brief Returns the received_ flag indicating that the raw elevation map has been received
* @return true if received_
*/
bool isReceived() { return received_; }

/**
* @brief Returns the ready_ flag indicating that the simplified map has been created
* @return true if ready_
*/
bool isReady() { return ready_; }

private:
// Flags
bool run_ = true; ///< flag allowing run() to execute
bool received_ = false; ///< flag indicating that the raw elevation map has been received
bool ready_ = false; ///< flag indicating that the simplified map has been created
std::thread thread_run_; ///< thread for run()
std::atomic_bool thread_loop_; ///< flag for the thread

// Gridmaps
grid_map::GridMap map_full_; ///< full elevation map
grid_map::GridMap map_sub_; ///< submap of the full elevation map
grid_map::GridMap map_simplified_wo_traversability_; ///< filtered submap, without the Filter Chain applied (because the class is multi-threaded and applying the filter takes significant time)
grid_map::GridMap map_simplified_; ///< filtered submap, with the Filter Chain applied
grid_map::GridMap map_simplified_scaled_; ///< scaled filtered submap, with the Filter Chain applied

// Gridmaps' parameters
Eigen::Vector2d map_size_; ///< size of the submap
int k_size_ = 51; ///< size of the kernel (for the directional Gaussian blur filter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly should be exposed as a rosparam since it may depend on the grid map resolution


// Filter Chain
std::shared_ptr<filters::FilterChain<grid_map::GridMap> > filter_chain_; ///< filter chain for traversability layer

// Images
cv::Mat img_raw_; ///< image of the raw elevation map
cv::Mat img_simplified_; ///< image of the simplified map
cv::Mat img_simplified_scaled_; ///< scaled image of the simplified map
cv::Mat img_traversability_; ///< image of the traversability map
cv::Mat img_traversability_scaled_; ///< scaled image of the traversability map

// Robot's state
Eigen::Vector3d robot_position_; ///< robot's xyz position in the world (odom) frame
Eigen::Quaterniond robot_orientation_; ///< robot's base orientation (quaternion) in the base frame, aligned with the world frame
double yaw_prev_ = 0.0; ///< robot's base orientation (yaw) in the base frame, aligned with the world frame

// Mutex
boost::shared_mutex mutex_; ///< mutex for map_ and img_ variables
boost::shared_mutex mutex_state_; ///< mutex for robot's position and orientation variables

};

} //end namespace

#endif //TERRAIN_SIMPLIFICATION_HPP
24 changes: 24 additions & 0 deletions terrain_simplification/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package format="2">
<name>terrain_simplification</name>
<version>1.0.0</version>
<description>
A module that simplifies the observed terrain, represented as a gridmap, by applying a low-pass filter to extract the high-level geometry and qualify its irregularity.
</description>

<author>Oliwier Melon</author>
<maintainer email="[email protected]">Oliwier Melon</maintainer>
<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>

<depend>message_runtime</depend>
<depend>message_generation</depend>
<depend>std_msgs</depend>
<depend>geometry_msgs</depend>
<depend>grid_map_core</depend>
<depend>grid_map_cv</depend>
<depend>grid_map_filters</depend>
<exec_depend>rviz</exec_depend>
<exec_depend>rqt_bag</exec_depend>
</package>
Loading