mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-04 08:47:45 +08:00
Added move_base actionlib to set goal with feedback
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<launch>
|
<launch>
|
||||||
|
|
||||||
<!-- args: "delete_db_on_start" and "udebug" -->
|
<!-- args: "delete_db_on_start" and "udebug" -->
|
||||||
<arg name="rtabmap_args" default="--delete_db_on_start" />
|
<arg name="rtabmap_args" default="" />
|
||||||
|
|
||||||
<!-- AZIMUT 3 bringup: launch motors/odometry, laser scan and openni -->
|
<!-- AZIMUT 3 bringup: launch motors/odometry, laser scan and openni -->
|
||||||
<include file="$(find az3_bringup)/az3_standalone.launch"/>
|
<include file="$(find az3_bringup)/az3_standalone.launch"/>
|
||||||
@@ -26,8 +26,10 @@
|
|||||||
<remap from="depth/image" to="/camera/data_throttled_image_depth"/>
|
<remap from="depth/image" to="/camera/data_throttled_image_depth"/>
|
||||||
<remap from="rgb/camera_info" to="/camera/data_throttled_camera_info"/>
|
<remap from="rgb/camera_info" to="/camera/data_throttled_camera_info"/>
|
||||||
|
|
||||||
<remap from="goal_pose" to="/planner_goal"/>
|
<remap from="goal_out" to="/planner_goal"/>
|
||||||
|
<remap from="move_base" to="/planner/move_base"/>
|
||||||
|
|
||||||
|
<param name="use_action_for_goal" type="bool" value="true"/>
|
||||||
<param name="queue_size" type="int" value="10"/>
|
<param name="queue_size" type="int" value="10"/>
|
||||||
|
|
||||||
<param name="RGBD/PoseScanMatching" type="string" value="true"/>
|
<param name="RGBD/PoseScanMatching" type="string" value="true"/>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
<build_depend>message_filters</build_depend>
|
<build_depend>message_filters</build_depend>
|
||||||
<build_depend>class_loader</build_depend>
|
<build_depend>class_loader</build_depend>
|
||||||
<build_depend>rtabmap</build_depend>
|
<build_depend>rtabmap</build_depend>
|
||||||
|
<build_depend>move_base_msgs</build_depend>
|
||||||
|
|
||||||
<run_depend>cv_bridge</run_depend>
|
<run_depend>cv_bridge</run_depend>
|
||||||
<run_depend>roscpp</run_depend>
|
<run_depend>roscpp</run_depend>
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
<run_depend>message_filters</run_depend>
|
<run_depend>message_filters</run_depend>
|
||||||
<run_depend>class_loader</run_depend>
|
<run_depend>class_loader</run_depend>
|
||||||
<run_depend>rtabmap</run_depend>
|
<run_depend>rtabmap</run_depend>
|
||||||
|
<run_depend>move_base_msgs</run_depend>
|
||||||
|
|
||||||
<build_depend>libpcl-all-dev</build_depend>
|
<build_depend>libpcl-all-dev</build_depend>
|
||||||
|
|
||||||
|
|||||||
+69
-11
@@ -71,6 +71,7 @@ CoreWrapper::CoreWrapper(bool deleteDbOnStart) :
|
|||||||
configPath_(""),
|
configPath_(""),
|
||||||
databasePath_(UDirectory::homeDir()+"/.ros/"+rtabmap::Parameters::getDefaultDatabaseName()),
|
databasePath_(UDirectory::homeDir()+"/.ros/"+rtabmap::Parameters::getDefaultDatabaseName()),
|
||||||
waitForTransform_(false),
|
waitForTransform_(false),
|
||||||
|
useActionForGoal_(false),
|
||||||
mapToOdom_(tf::Transform::getIdentity()),
|
mapToOdom_(tf::Transform::getIdentity()),
|
||||||
depthSync_(0),
|
depthSync_(0),
|
||||||
depthScanSync_(0),
|
depthScanSync_(0),
|
||||||
@@ -79,7 +80,8 @@ CoreWrapper::CoreWrapper(bool deleteDbOnStart) :
|
|||||||
stereoExactSync_(0),
|
stereoExactSync_(0),
|
||||||
transformThread_(0),
|
transformThread_(0),
|
||||||
rate_(Parameters::defaultRtabmapDetectionRate()),
|
rate_(Parameters::defaultRtabmapDetectionRate()),
|
||||||
time_(ros::Time::now())
|
time_(ros::Time::now()),
|
||||||
|
mbClient_("move_base", true)
|
||||||
{
|
{
|
||||||
ros::NodeHandle nh;
|
ros::NodeHandle nh;
|
||||||
ros::NodeHandle pnh("~");
|
ros::NodeHandle pnh("~");
|
||||||
@@ -121,6 +123,7 @@ CoreWrapper::CoreWrapper(bool deleteDbOnStart) :
|
|||||||
pnh.param("publish_tf", publishTf, publishTf);
|
pnh.param("publish_tf", publishTf, publishTf);
|
||||||
pnh.param("tf_delay", tfDelay, tfDelay);
|
pnh.param("tf_delay", tfDelay, tfDelay);
|
||||||
pnh.param("wait_for_transform", waitForTransform_, waitForTransform_);
|
pnh.param("wait_for_transform", waitForTransform_, waitForTransform_);
|
||||||
|
pnh.param("use_action_for_goal", useActionForGoal_, useActionForGoal_);
|
||||||
|
|
||||||
ROS_INFO("rtabmap: frame_id = %s", frameId_.c_str());
|
ROS_INFO("rtabmap: frame_id = %s", frameId_.c_str());
|
||||||
ROS_INFO("rtabmap: map_frame_id = %s", mapFrameId_.c_str());
|
ROS_INFO("rtabmap: map_frame_id = %s", mapFrameId_.c_str());
|
||||||
@@ -132,9 +135,9 @@ CoreWrapper::CoreWrapper(bool deleteDbOnStart) :
|
|||||||
mapGraph_ = nh.advertise<rtabmap_ros::Graph>("graph", 1);
|
mapGraph_ = nh.advertise<rtabmap_ros::Graph>("graph", 1);
|
||||||
|
|
||||||
// planning topics
|
// planning topics
|
||||||
goalSub_ = nh.subscribe("in_goal", 1, &CoreWrapper::goalCallback, this);
|
goalSub_ = nh.subscribe("goal", 1, &CoreWrapper::goalCallback, this);
|
||||||
goalGlobalSub_ = nh.subscribe("in_goal_global", 1, &CoreWrapper::goalGlobalCallback, this);
|
goalGlobalSub_ = nh.subscribe("goal_global", 1, &CoreWrapper::goalGlobalCallback, this);
|
||||||
nextMetricGoalPub_ = nh.advertise<geometry_msgs::PoseStamped>("out_goal", 1);
|
nextMetricGoalPub_ = nh.advertise<geometry_msgs::PoseStamped>("goal_out", 1);
|
||||||
goalReachedPub_ = nh.advertise<std_msgs::Empty>("goal_reached", 1);
|
goalReachedPub_ = nh.advertise<std_msgs::Empty>("goal_reached", 1);
|
||||||
globalPathPub_ = nh.advertise<nav_msgs::Path>("global_path", 1);
|
globalPathPub_ = nh.advertise<nav_msgs::Path>("global_path", 1);
|
||||||
localPathPub_ = nh.advertise<nav_msgs::Path>("local_path", 1);
|
localPathPub_ = nh.advertise<nav_msgs::Path>("local_path", 1);
|
||||||
@@ -1379,18 +1382,73 @@ void CoreWrapper::publishCurrentGoal(const ros::Time & stamp)
|
|||||||
{
|
{
|
||||||
ROS_INFO("Planning: Publishing next goal: Location %d pose=%s",
|
ROS_INFO("Planning: Publishing next goal: Location %d pose=%s",
|
||||||
rtabmap_.getPathCurrentGoalId(), currentMetricGoal_.prettyPrint().c_str());
|
rtabmap_.getPathCurrentGoalId(), currentMetricGoal_.prettyPrint().c_str());
|
||||||
if(nextMetricGoalPub_.getNumSubscribers())
|
|
||||||
|
geometry_msgs::PoseStamped poseMsg;
|
||||||
|
poseMsg.header.frame_id = mapFrameId_;
|
||||||
|
poseMsg.header.stamp = stamp;
|
||||||
|
rtabmap_ros::transformToPoseMsg(currentMetricGoal_, poseMsg.pose);
|
||||||
|
|
||||||
|
if(useActionForGoal_)
|
||||||
{
|
{
|
||||||
geometry_msgs::PoseStamped goalMsg;
|
if(!mbClient_.isServerConnected())
|
||||||
goalMsg.header.frame_id = mapFrameId_;
|
{
|
||||||
goalMsg.header.stamp = ros::Time::now();
|
ROS_INFO("Connecting to move_base action server...");
|
||||||
rtabmap_ros::transformToPoseMsg(currentMetricGoal_, goalMsg.pose);
|
mbClient_.waitForServer(ros::Duration(5.0));
|
||||||
ROS_INFO("Publishing next goal: %d", rtabmap_.getPathCurrentGoalId());
|
}
|
||||||
nextMetricGoalPub_.publish(goalMsg);
|
if(mbClient_.isServerConnected())
|
||||||
|
{
|
||||||
|
move_base_msgs::MoveBaseGoal goal;
|
||||||
|
goal.target_pose = poseMsg;
|
||||||
|
|
||||||
|
ROS_INFO("Publishing next goal: %d", rtabmap_.getPathCurrentGoalId());
|
||||||
|
mbClient_.sendGoal(goal,
|
||||||
|
boost::bind(&CoreWrapper::goalDoneCb, this, _1, _2),
|
||||||
|
boost::bind(&CoreWrapper::goalActiveCb, this),
|
||||||
|
boost::bind(&CoreWrapper::goalFeedbackCb, this, _1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ROS_ERROR("Cannot connect to move_base action server!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(nextMetricGoalPub_.getNumSubscribers())
|
||||||
|
{
|
||||||
|
ROS_INFO("Publishing next goal: %d", rtabmap_.getPathCurrentGoalId());
|
||||||
|
nextMetricGoalPub_.publish(poseMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called once when the goal completes
|
||||||
|
void CoreWrapper::goalDoneCb(const actionlib::SimpleClientGoalState& state,
|
||||||
|
const move_base_msgs::MoveBaseResultConstPtr& result)
|
||||||
|
{
|
||||||
|
if(state == actionlib::SimpleClientGoalState::SUCCEEDED)
|
||||||
|
{
|
||||||
|
ROS_INFO("Planning: move_base success");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ROS_INFO("Planning: move_base failed for some reason.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called once when the goal becomes active
|
||||||
|
void CoreWrapper::goalActiveCb()
|
||||||
|
{
|
||||||
|
ROS_INFO("Planning: Goal just went active");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called every time feedback is received for the goal
|
||||||
|
void CoreWrapper::goalFeedbackCb(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback)
|
||||||
|
{
|
||||||
|
Transform basePosition = rtabmap_ros::transformFromPoseMsg(feedback->base_position.pose);
|
||||||
|
ROS_INFO("Planning: feedback base_position = %s", basePosition.prettyPrint().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void CoreWrapper::publishLocalPath(const ros::Time & stamp)
|
void CoreWrapper::publishLocalPath(const ros::Time & stamp)
|
||||||
{
|
{
|
||||||
if(rtabmap_.getPath().size())
|
if(rtabmap_.getPath().size())
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <image_transport/image_transport.h>
|
#include <image_transport/image_transport.h>
|
||||||
#include <image_transport/subscriber_filter.h>
|
#include <image_transport/subscriber_filter.h>
|
||||||
|
|
||||||
|
#include <actionlib/client/simple_action_client.h>
|
||||||
|
#include <move_base_msgs/MoveBaseAction.h>
|
||||||
|
#include <move_base_msgs/MoveBaseActionGoal.h>
|
||||||
|
#include <move_base_msgs/MoveBaseActionResult.h>
|
||||||
|
#include <move_base_msgs/MoveBaseActionFeedback.h>
|
||||||
|
#include <actionlib_msgs/GoalStatusArray.h>
|
||||||
|
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
|
||||||
|
|
||||||
class CoreWrapper
|
class CoreWrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -132,6 +140,9 @@ private:
|
|||||||
|
|
||||||
void publishStats(const rtabmap::Statistics & stats, const ros::Time & stamp);
|
void publishStats(const rtabmap::Statistics & stats, const ros::Time & stamp);
|
||||||
void publishCurrentGoal(const ros::Time & stamp);
|
void publishCurrentGoal(const ros::Time & stamp);
|
||||||
|
void goalDoneCb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result);
|
||||||
|
void goalActiveCb();
|
||||||
|
void goalFeedbackCb(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback);
|
||||||
void publishLocalPath(const ros::Time & stamp);
|
void publishLocalPath(const ros::Time & stamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -147,6 +158,7 @@ private:
|
|||||||
std::string configPath_;
|
std::string configPath_;
|
||||||
std::string databasePath_;
|
std::string databasePath_;
|
||||||
bool waitForTransform_;
|
bool waitForTransform_;
|
||||||
|
bool useActionForGoal_;
|
||||||
|
|
||||||
tf::Transform mapToOdom_;
|
tf::Transform mapToOdom_;
|
||||||
boost::mutex mapToOdomMutex_;
|
boost::mutex mapToOdomMutex_;
|
||||||
@@ -234,6 +246,8 @@ private:
|
|||||||
ros::ServiceServer publishMapDataSrv_;
|
ros::ServiceServer publishMapDataSrv_;
|
||||||
ros::ServiceServer setGoalSrv_;
|
ros::ServiceServer setGoalSrv_;
|
||||||
|
|
||||||
|
MoveBaseClient mbClient_;
|
||||||
|
|
||||||
boost::thread* transformThread_;
|
boost::thread* transformThread_;
|
||||||
|
|
||||||
float rate_;
|
float rate_;
|
||||||
|
|||||||
Reference in New Issue
Block a user