Skip to content

Commit

Permalink
Add heightmap visualization in rviz using markers
Browse files Browse the repository at this point in the history
  • Loading branch information
RajPShinde committed Nov 19, 2020
1 parent 180a751 commit d5c617a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 203 deletions.
200 changes: 13 additions & 187 deletions CMakeLists.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,202 +1,28 @@
cmake_minimum_required(VERSION 3.0.2)
project(footstep_affordance)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
tf
tf_conversions
octomap_msgs
geometry_msgs
octomap_ros)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES footstep_affordance
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
# ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/footstep_affordance.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/footstep_affordance_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# )

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )

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

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############
include_directories(include ${catkin_INCLUDE_DIRS} ${OCTOMAP_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS} ${OCTOMAP_LIBRARY_DIRS})

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_footstep_affordance.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
add_executable(footstepAffordance src/footstepAffordance.cpp src/features.cpp src/interface.cpp)
target_link_libraries(footstepAffordance ${catkin_LIBRARIES})
add_dependencies(footstepAffordance ${catkin_EXPORTED_TARGETS})

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
13 changes: 11 additions & 2 deletions include/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#include <tf/transform_listener.h>
#include <tf/message_filter.h>
#include <message_filters/subscriber.h>
#include <visualization_msgs/MarkerArray.h>
#include <visualization_msgs/Marker.h>
#include <footstepAffordance.hpp>


namespace footstepAffordance
{

Expand All @@ -26,18 +27,26 @@ class Interface{

void getRobotState(Eigen::Vector3d &robotStateXYZ, Eigen::Vector3d &robotStateRPY, const octomap_msgs::Octomap::ConstPtr& msg);

void displayHeightmap(std::map<std::pair<double, double>, double> &hMap);

void visualizeHeightMap(std::map<std::pair<double, double>, double> &hMap);

void visualizeCostMap(std::map<std::pair<double, double>, double> &hMap, std::map<std::pair<double, double>, double> &cMap);

private:

std::string robotFrame_, worldFrame_;
ros::NodeHandle node_;
ros::NodeHandle vis_;
ros::NodeHandle interface_;
message_filters::Subscriber<octomap_msgs::Octomap>* octomapSub_;
tf::MessageFilter<octomap_msgs::Octomap>* tfOctomapSub_;
tf::TransformListener tf_listener_;
costmap::FootstepAffordance cost;
std::map<std::pair<double, double>, double> heightMap;
std::map<std::pair<double, double>, double> costMap;

ros::Publisher visualizeHeightMapPub;
ros::Publisher visualizeCostMapPub;
};
}

Expand Down
Empty file modified package.xml
100644 → 100755
Empty file.
103 changes: 89 additions & 14 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ Interface::~Interface(){

void Interface::octomapCallback(const octomap_msgs::Octomap::ConstPtr& msg){
ROS_ERROR_STREAM("Octomap Callback");
// Creating an octree
octomap::OcTree* octomap = NULL;
// Creating an octree
octomap::OcTree* octomap = NULL;

// convert ros msg to octomaptree for use with octomap library
octomap::AbstractOcTree* tree = octomap_msgs::msgToMap(*msg);
octomap::AbstractOcTree* tree = octomap_msgs::msgToMap(*msg);

if (tree) {
octomap = dynamic_cast<octomap::OcTree*>(tree);
}
if (tree) {
octomap = dynamic_cast<octomap::OcTree*>(tree);
}

if (!octomap) {
ROS_WARN("Failed to create octree structure");
return;
}
if (!octomap) {
ROS_WARN("Failed to create octree structure");
return;
}

Eigen::Vector3d robotStateXYZ = Eigen::Vector3d::Zero();
Eigen::Vector3d robotStateRPY = Eigen::Vector3d::Zero();
getRobotState(robotStateXYZ, robotStateRPY, msg);
getRobotState(robotStateXYZ, robotStateRPY, msg);

cost.run(octomap ,robotStateXYZ, robotStateRPY, heightMap, costMap);
// displayHeightmap(heightMap);
Expand Down Expand Up @@ -73,10 +73,85 @@ void Interface::getRobotState(Eigen::Vector3d &robotStateXYZ, Eigen::Vector3d &r
ROS_WARN_STREAM("YPR:"<<yaw<<" | "<<pitch<<" | "<<roll);
}

void Interface::displayHeightmap(std::map<std::pair<double, double>, double> &hMap) {
ROS_ERROR_STREAM("Printing Heightmap");
for (const auto& x : hMap) {
std::cout << x.first.first<<" "<<x.first.second <<" " <<x.second<<"***\n";
}
}

void Interface::visualizeHeightMap(std::map<std::pair<double, double>, double> &hMap){
ROS_ERROR_STREAM("Visualize");
visualization_msgs::MarkerArray marker;

int i=0;
marker.markers.resize(hMap.size());

for (const auto& x : hMap) {
marker.markers[i].header.frame_id = worldFrame_;
marker.markers[i].header.stamp = ros::Time();
marker.markers[i].ns = "heightMap";
marker.markers[i].id = i;
marker.markers[i].type = visualization_msgs::Marker::CUBE;
marker.markers[i].action = visualization_msgs::Marker::ADD;
marker.markers[i].pose.position.x = x.first.first;
marker.markers[i].pose.position.y = x.first.second;
marker.markers[i].pose.position.z = x.second;
marker.markers[i].pose.orientation.x = 0;
marker.markers[i].pose.orientation.y = 0;
marker.markers[i].pose.orientation.z = 0;
marker.markers[i].pose.orientation.w = 1.0;
marker.markers[i].scale.x = 0.02;
marker.markers[i].scale.y = 0.02;
marker.markers[i].scale.z = 0.02;
marker.markers[i].color.a = 1.0;
marker.markers[i].color.r = 1.0;
marker.markers[i].color.g = 0.0;
marker.markers[i].color.b = 0.0;
i++;
}
visualizeHeightMapPub.publish(marker);
}

void Interface::visualizeCostMap(std::map<std::pair<double, double>, double> &hMap, std::map<std::pair<double, double>, double> &cMap){
ROS_ERROR_STREAM("Visualize");
visualization_msgs::MarkerArray marker;

int i=0;
marker.markers.resize(hMap.size());

for (const auto& x : hMap) {
auto it = cMap.find(std::make_pair(x.first.first, x.first.second));
marker.markers[i].header.frame_id = worldFrame_;
marker.markers[i].header.stamp = ros::Time();
marker.markers[i].ns = "costMap";
marker.markers[i].id = i;
marker.markers[i].type = visualization_msgs::Marker::CUBE;
marker.markers[i].action = visualization_msgs::Marker::ADD;
marker.markers[i].pose.position.x = x.first.first;
marker.markers[i].pose.position.y = x.first.second;
marker.markers[i].pose.position.z = x.second;
marker.markers[i].pose.orientation.x = 0;
marker.markers[i].pose.orientation.y = 0;
marker.markers[i].pose.orientation.z = 0;
marker.markers[i].pose.orientation.w = 1.0;
marker.markers[i].scale.x = 0.02;
marker.markers[i].scale.y = 0.02;
marker.markers[i].scale.z = 0.02;
marker.markers[i].color.a = 1.0;
marker.markers[i].color.r = 0.0;
marker.markers[i].color.g = 0.0;
marker.markers[i].color.b = 1.0/it->second;
i++;
}
visualizeCostMapPub.publish(marker);
}
}

int main(int argc, char **argv){
ros::init(argc, argv, "footstepAffordance");
ros::init(argc, argv, "footstepAffordance");
ros::NodeHandle nh;
footstepAffordance::Interface start(nh);
ros::spin();
return 0;
ros::spin();
return 0;
}

0 comments on commit d5c617a

Please sign in to comment.