Go to the documentation of this file.00001 #include "darwin_simple_nav_client_alg_node.h"
00002
00003 DarwinSimpleNavClientAlgNode::DarwinSimpleNavClientAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<DarwinSimpleNavClientAlgorithm>(),
00005 move_base_client_("move_base", true)
00006 {
00007
00008
00009
00010
00011
00012
00013 this->target_pose_subscriber_ = this->public_node_handle_.subscribe("target_pose", 100, &DarwinSimpleNavClientAlgNode::target_pose_callback, this);
00014
00015
00016
00017
00018
00019
00020
00021
00022 this->motion_done=true;
00023 }
00024
00025 DarwinSimpleNavClientAlgNode::~DarwinSimpleNavClientAlgNode(void)
00026 {
00027
00028 }
00029
00030 void DarwinSimpleNavClientAlgNode::mainNodeThread(void)
00031 {
00032
00033
00034
00035
00036
00037
00038
00039 }
00040
00041
00042 void DarwinSimpleNavClientAlgNode::target_pose_callback(const geometry_msgs::PoseStamped::ConstPtr& msg)
00043 {
00044 ROS_INFO("DarwinSimpleNavClientAlgNode::target_pose_callback: New Message Received");
00045
00046
00047
00048
00049
00050
00051 if(motion_done)
00052 {
00053 move_base_goal_.target_pose.header=msg->header;
00054 move_base_goal_.target_pose.pose.position.x=msg->pose.position.x;
00055 move_base_goal_.target_pose.pose.position.y=msg->pose.position.y;
00056 move_base_goal_.target_pose.pose.position.z=0.0;
00057 move_base_goal_.target_pose.pose.orientation=msg->pose.orientation;
00058 move_baseMakeActionRequest();
00059 }
00060
00061
00062
00063
00064 }
00065
00066
00067
00068
00069 void DarwinSimpleNavClientAlgNode::move_baseDone(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result)
00070 {
00071 if( state.toString().compare("SUCCEEDED") == 0 )
00072 ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseDone: Goal Achieved!");
00073 else
00074 ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseDone: %s", state.toString().c_str());
00075
00076
00077 this->motion_done=true;
00078 }
00079
00080 void DarwinSimpleNavClientAlgNode::move_baseActive()
00081 {
00082
00083 }
00084
00085 void DarwinSimpleNavClientAlgNode::move_baseFeedback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback)
00086 {
00087
00088
00089 bool feedback_is_ok = true;
00090
00091
00092
00093 std::cout << "Current position : (" << feedback->base_position.pose.position.x << "," << feedback->base_position.pose.position.y << ")" << std::endl;
00094
00095
00096 if( !feedback_is_ok )
00097 {
00098 move_base_client_.cancelGoal();
00099
00100 }
00101 }
00102
00103
00104 void DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest()
00105 {
00106 ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Starting New Request!");
00107
00108
00109
00110 move_base_client_.waitForServer();
00111 ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Server is Available!");
00112
00113 this->motion_done=false;
00114
00115
00116 move_base_client_.sendGoal(move_base_goal_,
00117 boost::bind(&DarwinSimpleNavClientAlgNode::move_baseDone, this, _1, _2),
00118 boost::bind(&DarwinSimpleNavClientAlgNode::move_baseActive, this),
00119 boost::bind(&DarwinSimpleNavClientAlgNode::move_baseFeedback, this, _1));
00120 ROS_INFO("DarwinSimpleNavClientAlgNode::move_baseMakeActionRequest: Goal Sent. Wait for Result!");
00121 }
00122
00123 void DarwinSimpleNavClientAlgNode::node_config_update(Config &config, uint32_t level)
00124 {
00125 this->alg_.lock();
00126
00127 this->alg_.unlock();
00128 }
00129
00130 void DarwinSimpleNavClientAlgNode::addNodeDiagnostics(void)
00131 {
00132 }
00133
00134
00135 int main(int argc,char *argv[])
00136 {
00137 return algorithm_base::main<DarwinSimpleNavClientAlgNode>(argc, argv, "darwin_simple_nav_client_alg_node");
00138 }