|
@@ -18,10 +18,13 @@ Robot::Robot() :
|
|
|
threshold_(0.1) {
|
|
|
}
|
|
|
|
|
|
-void Robot::odometryCallback (const nav_msgs::Odometry::ConstPtr& msg) {
|
|
|
+void Robot::odometryCallback (const nav_msgs::Odometry::ConstPtr& msg)
|
|
|
+{
|
|
|
ROS_DEBUG("got odometry");
|
|
|
- robot_pose_ = msg->pose.pose;
|
|
|
- if (execute_) {
|
|
|
+ robot_pose_ = msg->pose.pose;
|
|
|
+
|
|
|
+ if (execute_)
|
|
|
+ {
|
|
|
followTheCarrot();
|
|
|
}
|
|
|
}
|
|
@@ -86,79 +89,95 @@ bool Robot::followTheCarrot()
|
|
|
command_publisher_->publish(command);
|
|
|
return true;
|
|
|
}
|
|
|
- else {
|
|
|
- while (!plan_.empty() && plan_.front().distanceTo(robot_pose_) < threshold_) {
|
|
|
- plan_.pop_front();
|
|
|
- }
|
|
|
-
|
|
|
- MoveBaseClient ac("/robot1/stdr_robot1_move_base", true);
|
|
|
- while(!ac.waitForServer(ros::Duration(5.0)))
|
|
|
+ else
|
|
|
{
|
|
|
- ROS_WARN("Waiting for the stdr_robot1_move_base action server to come up");
|
|
|
- }
|
|
|
-
|
|
|
- Waypoint actual_goal = plan_.front();
|
|
|
- move_base_msgs::MoveBaseGoal goal;
|
|
|
-
|
|
|
- goal.target_pose.header.frame_id = ros::this_node::getName();
|
|
|
- goal.target_pose.header.stamp = ros::Time::now();
|
|
|
-
|
|
|
- goal.target_pose.pose.position.x = actual_goal.pose.orientation.x;
|
|
|
- goal.target_pose.pose.position.y = actual_goal.pose.orientation.y;
|
|
|
- goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(M_PI);
|
|
|
-
|
|
|
- ROS_INFO("Sending goal");
|
|
|
- ac.sendGoal(goal);
|
|
|
-
|
|
|
- ac.waitForResult();
|
|
|
-
|
|
|
- if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
|
|
|
- ROS_INFO("Move goal ok !");
|
|
|
- else
|
|
|
- ROS_WARN("Move goal failed !");
|
|
|
-
|
|
|
- #if 0
|
|
|
- const double dist = actual_goal.distanceTo(robot_pose_);
|
|
|
- const double angle = actual_goal.angleTo(robot_pose_);
|
|
|
- tf::Quaternion q(
|
|
|
- robot_pose_.orientation.x,
|
|
|
- robot_pose_.orientation.y,
|
|
|
- robot_pose_.orientation.z,
|
|
|
- robot_pose_.orientation.w);
|
|
|
- tf::Matrix3x3 m(q);
|
|
|
- double roll;
|
|
|
- double pitch;
|
|
|
- double yaw;
|
|
|
- m.getRPY(roll, pitch, yaw);
|
|
|
- ROS_INFO("distance %f and angle %f to goal", dist,angle);
|
|
|
- ROS_INFO("robot roll %f , pitch %f yaw %f", roll, pitch, yaw);
|
|
|
- geometry_msgs::Twist command;
|
|
|
- double delta = angle - yaw;
|
|
|
- if (delta > M_PI ) {
|
|
|
- delta -= 2 * M_PI;
|
|
|
- }
|
|
|
- if (delta < -M_PI ) {
|
|
|
- delta += 2 * M_PI;
|
|
|
- }
|
|
|
- ROS_INFO_STREAM(ros::Time::now() << " " << actual_goal.timepoint);
|
|
|
- const double time_to_goal = ((execute_start_time_ + actual_goal.timepoint) - ros::Time::now()).toSec();
|
|
|
-
|
|
|
- ROS_INFO("time to goal %f ", time_to_goal);
|
|
|
- double speed;
|
|
|
- if (time_to_goal > 0) {
|
|
|
- speed = dist/time_to_goal ;
|
|
|
- } else {
|
|
|
- speed = 1;
|
|
|
- }
|
|
|
- command.angular.z = 2 * (sin(delta) - 0.333 * sin(3 * delta));
|
|
|
- command.angular.z = delta;
|
|
|
- command.linear.x = speed * (cos(delta) + 0.333 * cos(3 * delta));
|
|
|
- if (command.linear.x < 0) {
|
|
|
- command.linear.x = 0;
|
|
|
- }
|
|
|
- command_publisher_->publish(command);
|
|
|
- #endif
|
|
|
+ while (!plan_.empty() && plan_.front().distanceTo(robot_pose_) < threshold_)
|
|
|
+ {
|
|
|
+ plan_.pop_front();
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string nodeName = ros::this_node::getName();
|
|
|
+
|
|
|
+ std::string actionClientName = "";
|
|
|
+ std::string::size_type idx;
|
|
|
+ idx = nodeName.find("robot0");
|
|
|
+ if(idx != std::string::npos)
|
|
|
+ {
|
|
|
+ actionClientName = "/robot0/move_base";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ actionClientName = "/robot1/move_base";
|
|
|
+ }
|
|
|
+ ROS_WARN_STREAM("actionName: " << actionClientName);
|
|
|
+ MoveBaseClient ac(actionClientName, false);
|
|
|
+ while(!ac.waitForServer(ros::Duration(5.0)))
|
|
|
+ {
|
|
|
+ ROS_WARN("Waiting for the move_base action server to come up");
|
|
|
+ }
|
|
|
+
|
|
|
+ Waypoint actual_goal = plan_.front();
|
|
|
+ move_base_msgs::MoveBaseGoal goal;
|
|
|
+
|
|
|
+ goal.target_pose.header.frame_id = ros::this_node::getName();
|
|
|
+ goal.target_pose.header.stamp = ros::Time::now();
|
|
|
+
|
|
|
+ goal.target_pose.pose.position.x = actual_goal.pose.orientation.x;
|
|
|
+ goal.target_pose.pose.position.y = actual_goal.pose.orientation.y;
|
|
|
+ goal.target_pose.pose.orientation = tf::createQuaternionMsgFromYaw(M_PI);
|
|
|
+ ROS_WARN_STREAM("pose_x:"<<goal.target_pose.pose.position.x<<" , pose_y:"<<goal.target_pose.pose.position.y);
|
|
|
+ ROS_INFO("Sending goal");
|
|
|
+ ac.sendGoal(goal);
|
|
|
+
|
|
|
+ ac.waitForResult();
|
|
|
+
|
|
|
+ if(ac.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
|
|
|
+ ROS_INFO("Move goal ok !");
|
|
|
+ else
|
|
|
+ ROS_WARN("Move goal failed !");
|
|
|
+
|
|
|
+ #if 0
|
|
|
+ const double dist = actual_goal.distanceTo(robot_pose_);
|
|
|
+ const double angle = actual_goal.angleTo(robot_pose_);
|
|
|
+ tf::Quaternion q(
|
|
|
+ robot_pose_.orientation.x,
|
|
|
+ robot_pose_.orientation.y,
|
|
|
+ robot_pose_.orientation.z,
|
|
|
+ robot_pose_.orientation.w);
|
|
|
+ tf::Matrix3x3 m(q);
|
|
|
+ double roll;
|
|
|
+ double pitch;
|
|
|
+ double yaw;
|
|
|
+ m.getRPY(roll, pitch, yaw);
|
|
|
+ ROS_INFO("distance %f and angle %f to goal", dist,angle);
|
|
|
+ ROS_INFO("robot roll %f , pitch %f yaw %f", roll, pitch, yaw);
|
|
|
+ geometry_msgs::Twist command;
|
|
|
+ double delta = angle - yaw;
|
|
|
+ if (delta > M_PI ) {
|
|
|
+ delta -= 2 * M_PI;
|
|
|
+ }
|
|
|
+ if (delta < -M_PI ) {
|
|
|
+ delta += 2 * M_PI;
|
|
|
+ }
|
|
|
+ ROS_INFO_STREAM(ros::Time::now() << " " << actual_goal.timepoint);
|
|
|
+ const double time_to_goal = ((execute_start_time_ + actual_goal.timepoint) - ros::Time::now()).toSec();
|
|
|
+
|
|
|
+ ROS_INFO("time to goal %f ", time_to_goal);
|
|
|
+ double speed;
|
|
|
+ if (time_to_goal > 0) {
|
|
|
+ speed = dist/time_to_goal ;
|
|
|
+ } else {
|
|
|
+ speed = 1;
|
|
|
+ }
|
|
|
+ command.angular.z = 2 * (sin(delta) - 0.333 * sin(3 * delta));
|
|
|
+ command.angular.z = delta;
|
|
|
+ command.linear.x = speed * (cos(delta) + 0.333 * cos(3 * delta));
|
|
|
+ if (command.linear.x < 0) {
|
|
|
+ command.linear.x = 0;
|
|
|
+ }
|
|
|
+ command_publisher_->publish(command);
|
|
|
+ #endif
|
|
|
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|