Go to the documentation of this file.00001
00012 #include <arm_navigation_msgs/SimplePoseConstraint.h>
00013 #include <arm_navigation_msgs/utils.h>
00014 #include <iostream>
00015 #include <rail_cv_project/robot.h>
00016 #include <rail_cv_project/processor.h>
00017
00018 using namespace std;
00019
00020 robot::robot() :
00021 move_l_arm("/move_left_arm", true), move_r_arm("/move_right_arm", true)
00022 {
00023 last_x = -100;
00024 last_y = -100;
00025 last_z = -100;
00026
00027 move_l_arm.waitForServer();
00028 move_r_arm.waitForServer();
00029 ROS_INFO("Arm control started");
00030
00031
00032 reset_left();
00033 reset_right();
00034 }
00035
00036 void robot::reset_right()
00037 {
00038
00039 move_arm_to_pose(0.095, -0.884, 1.144, BASE_FRAME, "right_arm");
00040 }
00041
00042 void robot::reset_left()
00043 {
00044
00045 move_arm_to_pose(0.095, 0.884, 1.144, BASE_FRAME, "left_arm");
00046 }
00047
00048 void robot::move_arm_to_pose(float x, float y, float z, string frame, string group)
00049 {
00050
00051 arm_navigation_msgs::MoveArmGoal arm_goal;
00052 arm_goal.motion_plan_request.group_name = group;
00053 arm_goal.motion_plan_request.num_planning_attempts = 1;
00054 arm_goal.motion_plan_request.planner_id = "";
00055 arm_goal.planner_service_name = "ompl_planning/plan_kinematic_path";
00056 arm_goal.motion_plan_request.allowed_planning_time = ros::Duration(5.0);
00057
00058 arm_navigation_msgs::SimplePoseConstraint pose;
00059 pose.header.frame_id = frame;
00060
00061 if (group.compare("right_arm") == 0)
00062 pose.link_name = "r_wrist_roll_link";
00063 else
00064 pose.link_name = "l_wrist_roll_link";
00065 pose.pose.position.x = x;
00066 pose.pose.position.y = y;
00067 pose.pose.position.z = z;
00068
00069 pose.pose.orientation.x = 0.0;
00070 pose.pose.orientation.y = 0.0;
00071 pose.pose.orientation.z = 0.0;
00072
00073 if (group.compare("right_arm") == 0)
00074 pose.pose.orientation.w = -1.0;
00075 else
00076 pose.pose.orientation.w = 1.0;
00077
00078
00079 pose.absolute_position_tolerance.x = 0.02;
00080 pose.absolute_position_tolerance.y = 0.02;
00081 pose.absolute_position_tolerance.z = 0.02;
00082 pose.absolute_roll_tolerance = 0.04;
00083 pose.absolute_pitch_tolerance = 0.04;
00084 pose.absolute_yaw_tolerance = 0.04;
00085 arm_navigation_msgs::addGoalConstraintToMoveArmGoal(pose, arm_goal);
00086
00087
00088 ROS_INFO("Moving arm...");
00089
00090 if (group.compare("right_arm") == 0)
00091 {
00092 move_r_arm.sendGoal(arm_goal);
00093 if (move_r_arm.waitForResult(ros::Duration(60.0)))
00094 move_r_arm.cancelGoal();
00095 }
00096 else
00097 {
00098 move_l_arm.sendGoal(arm_goal);
00099 if (move_l_arm.waitForResult(ros::Duration(60.0)))
00100 move_l_arm.cancelGoal();
00101 }
00102
00103 ROS_INFO("Arm move finished.");
00104 }
00105
00106 void robot::checkTF()
00107 {
00108 tf::StampedTransform stf;
00109
00110 if (tfl.waitForTransform(CLOUD_FRAME, GOAL_FRAME, ros::Time(), ros::Duration(1.0)))
00111 {
00112 tfl.lookupTransform(CLOUD_FRAME, GOAL_FRAME, ros::Time(0), stf);
00113
00114 if (stf.stamp_ > t)
00115 {
00116
00117 tf::Vector3 v = stf.getOrigin();
00118 double dist = sqrt(
00119 pow((double)(v.getX() - last_x), 2.0) + pow((double)(v.getY() - last_y), 2.0)
00120 + pow((double)(v.getZ() - last_z), 2.0));
00121 if (dist > HEAD_MOVE_THRESH)
00122 {
00123 move_arm_to_pose(v.getX(), v.getY(), v.getZ(), CLOUD_FRAME, "left_arm");
00124 reset_left();
00125
00126 t = stf.stamp_;
00127 last_x = v.getX();
00128 last_y = v.getY();
00129 last_z = v.getZ();
00130 }
00131 }
00132 }
00133 }
00134
00135 int main(int argc, char **argv)
00136 {
00137
00138 ros::init(argc, argv, "robot");
00139 robot r;
00140
00141
00142 while (ros::ok())
00143 {
00144
00145 r.checkTF();
00146 ros::spinOnce();
00147 }
00148
00149 return EXIT_SUCCESS;
00150 }