Commit 97894501 authored by Daniel Müller's avatar Daniel Müller
Browse files

Merge branch 'cpp_lib' into 'master'

Cpp Library

See merge request !7
parents 96d618ef d514208a
......@@ -35,7 +35,10 @@ endif()
set(CMAKE_BUILD_TYPE Release)
catkin_package(
INCLUDE_DIRS include
INCLUDE_DIRS
include
LIBRARIES
HomerNavigationLib
CATKIN_DEPENDS
roscpp
roslib
......@@ -84,11 +87,24 @@ add_dependencies(narrow_passage_detection_node ${catkin_EXPORTED_TARGETS})
target_link_libraries(narrow_passage_detection_node ${catkin_LIBRARIES} ${OpenCV_LIBS})
#--------------------------------------------------------------------------------------
add_library(HomerNavigationLib
src/HomerNavigationLib.cpp
)
add_dependencies(HomerNavigationLib
${catkin_EXPORTED_TARGETS}
${${PROJECT_NAME}_EXPORTED_TARGETS}
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
install(TARGETS homer_navigation drive_to depth_occupancy_map
install(
TARGETS
homer_navigation drive_to depth_occupancy_map HomerNavigationLib
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
......@@ -100,9 +116,9 @@ install(PROGRAMS
)
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
)
install(DIRECTORY config/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
)
#pragma once
#include <string>
#include <actionlib/client/simple_action_client.h>
#include <homer_mapnav_msgs/DriveToAction.h>
namespace homer_navigation
{
void drive_to_POI(const std::string& poi_name, float distance_to_target = 0.03,
bool suppress_speaking = false, bool skip_final_turn = false,
bool stop_before_obstacle = false, bool check_obstacle_type = false,
const boost::function<void(const actionlib::SimpleClientGoalState& state,
const homer_mapnav_msgs::DriveToResultConstPtr&)>& callback = 0,
bool keep_torso_position = false);
homer_mapnav_msgs::DriveToResultConstPtr drive_to_POI_blocked(const std::string& poi_name,
float distance_to_target = 0.03, bool suppress_speaking = false, bool skip_final_turn = false,
bool stop_before_obstacle = false, bool check_obstacle_type = false,
ros::Duration timeout = ros::Duration(0), bool keep_torso_position = false);
}
#include <homer_navigation/HomerNavigationLib.h>
#include <homer_mapnav_msgs/DriveToGoal.h>
#include <utility>
namespace homer_navigation
{
typedef actionlib::SimpleActionClient<homer_mapnav_msgs::DriveToAction> ActionClient;
namespace
{
std::pair<std::unique_ptr<ActionClient>, homer_mapnav_msgs::DriveToGoal> create_client_and_goal(
const std::string& poi_name, float distance_to_target = 0.03,
bool suppress_speaking = false, bool skip_final_turn = false,
bool stop_before_obstacle = false, bool check_obstacle_type = false,
bool keep_torso_position = false)
{
auto ac = std::make_unique<ActionClient>("drive_to", true);
bool is_alive = ac->waitForServer(ros::Duration(5));
if (!is_alive)
{
ROS_ERROR_STREAM("drive_to action server not reachable");
return {};
}
ROS_INFO_STREAM("[DriveTo]:\n goal_location: \t" << poi_name
<< "\n distance_to_target: \t" << distance_to_target
<< "\n speaking: \t\t" << (!suppress_speaking ? "true" : "false"));
homer_mapnav_msgs::DriveToGoal goal;
goal.goal_location = poi_name;
goal.distance_to_target = distance_to_target;
goal.suppress_speaking = suppress_speaking;
goal.skip_final_turn = skip_final_turn;
goal.stop_before_obstacle = stop_before_obstacle;
goal.check_obstacle = check_obstacle_type;
goal.keep_torso_position = keep_torso_position;
auto result = std::make_pair(std::move(ac), goal);
return result;
}
}
void drive_to_POI(const std::string& poi_name, float distance_to_target,
bool suppress_speaking, bool skip_final_turn,
bool stop_before_obstacle, bool check_obstacle_type,
const boost::function<void(const actionlib::SimpleClientGoalState& state,
const homer_mapnav_msgs::DriveToResultConstPtr&)>& callback,
bool keep_torso_position)
{
auto pair = create_client_and_goal(poi_name, distance_to_target, suppress_speaking,
skip_final_turn, stop_before_obstacle, check_obstacle_type, keep_torso_position);
if (!pair.first)
{
ROS_ERROR_STREAM("Aborting drive_to_POI request.");
return;
}
pair.first->sendGoal(pair.second, callback);
ros::Duration(0.1).sleep(); //required for the callback; otherwise its not called
}
homer_mapnav_msgs::DriveToResultConstPtr drive_to_POI_blocked(const std::string& poi_name,
float distance_to_target, bool suppress_speaking, bool skip_final_turn,
bool stop_before_obstacle, bool check_obstacle_type, ros::Duration timeout,
bool keep_torso_position)
{
auto pair = create_client_and_goal(poi_name, distance_to_target, suppress_speaking,
skip_final_turn, stop_before_obstacle, check_obstacle_type, keep_torso_position);
if (!pair.first)
{
ROS_ERROR_STREAM("Aborting drive_to_POI_blocked request.");
return nullptr;
}
auto client = std::move(pair.first);
auto goal = pair.second;
client->sendGoal(goal);
bool delivered = client->waitForResult(timeout);
if (!delivered)
{
ROS_ERROR_STREAM("Timeout of drive_to_POI_blocked result.");
return nullptr;
}
return client->getResult();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment