8 linear_move_server(pnh,
"linear_move",
boost::bind(&
LinearController::executeLinearMove, this, _1), false),
9 arm_control_client(
"arm_controller/follow_joint_trajectory")
19 hold_goal.trajectory.joint_names.push_back(
"shoulder_pan_joint");
20 hold_goal.trajectory.joint_names.push_back(
"shoulder_lift_joint");
21 hold_goal.trajectory.joint_names.push_back(
"upperarm_roll_joint");
22 hold_goal.trajectory.joint_names.push_back(
"elbow_flex_joint");
23 hold_goal.trajectory.joint_names.push_back(
"forearm_roll_joint");
24 hold_goal.trajectory.joint_names.push_back(
"wrist_flex_joint");
25 hold_goal.trajectory.joint_names.push_back(
"wrist_roll_joint");
35 fetch_simple_linear_controller::LinearMoveResult result;
37 geometry_msgs::Point goal_point;
38 if (goal->point.header.frame_id !=
"base_link")
41 goal->point.header.frame_id,
48 goal_point = goal->point.point;
54 double x_err = goal_point.x - gripper_tf.transform.translation.x;
55 double y_err = goal_point.y - gripper_tf.transform.translation.y;
56 double z_err = goal_point.z - gripper_tf.transform.translation.z;
58 geometry_msgs::TwistStamped
cmd;
59 cmd.header.frame_id =
"base_link";
62 double move_duration =
max(
max(fabs(x_err), fabs(y_err)), fabs(z_err)) /
max_vel;
66 double x_err_accum = 0;
67 double y_err_accum = 0;
68 double z_err_accum = 0;
75 x_err = goal_point.x - gripper_tf.transform.translation.x;
76 y_err = goal_point.y - gripper_tf.transform.translation.y;
77 z_err = goal_point.z - gripper_tf.transform.translation.z;
83 double dx =
kp*x_err +
ki*x_err_accum;
84 double dy =
kp*y_err +
ki*y_err_accum;
85 double dz =
kp*z_err +
ki*z_err_accum;
87 double max_cmd =
max(
max(fabs(dx), fabs(dy)), fabs(dz));
96 cmd.twist.linear.x = dx;
97 cmd.twist.linear.y = dy;
98 cmd.twist.linear.z = dz;
102 controller_rate.
sleep();
105 cmd.twist.linear.x = 0;
106 cmd.twist.linear.y = 0;
107 cmd.twist.linear.z = 0;
110 if (goal->hold_final_pose)
112 sensor_msgs::JointStateConstPtr js_msg;
113 sensor_msgs::JointState joint_state;
114 while (joint_state.position.size() <= 3)
116 js_msg = ros::topic::waitForMessage<sensor_msgs::JointState>(
"joint_states",
n);
119 joint_state = *js_msg;
124 hold_goal.trajectory.points[0].positions.clear();
125 for (
size_t i = 6; i < 6 +
hold_goal.trajectory.joint_names.size(); i ++)
127 hold_goal.trajectory.points[0].positions.push_back(joint_state.position[i]);
137 x_err = goal_point.x - gripper_tf.transform.translation.x;
138 y_err = goal_point.y - gripper_tf.transform.translation.y;
139 z_err = goal_point.z - gripper_tf.transform.translation.z;
141 result.error.x = x_err;
142 result.error.y = y_err;
143 result.error.z = z_err;
145 ROS_INFO(
"Final linear translation error: (%f, %f, %f)", x_err, y_err, z_err);
148 ROS_INFO(
"Did not pass execution threshold, aborting linear move action server.");
157 int main(
int argc,
char **argv)
159 ros::init(argc, argv,
"linear_controller");
tf2_ros::Buffer tf_buffer
actionlib::SimpleActionServer< fetch_simple_linear_controller::LinearMoveAction > linear_move_server
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
void publish(const boost::shared_ptr< M > &message) const
void executeLinearMove(const fetch_simple_linear_controller::LinearMoveGoalConstPtr &goal)
ros::Publisher arm_cartesian_cmd_publisher
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
control_msgs::FollowJointTrajectoryGoal hold_goal
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
tf2_ros::Buffer * tf_buffer
double max(double a, double b)
actionlib::SimpleActionClient< control_msgs::FollowJointTrajectoryAction > arm_control_client