robot_interface
Native robot interface for making the visual manipulation
All Classes Files Functions Variables Pages
control_base.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Intel Corporation. All Rights Reserved
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
27 #pragma once
28 
29 #include <mutex>
30 #include <thread>
31 #include <Eigen/Geometry>
32 #include <rclcpp/rclcpp.hpp>
33 #include <tf2_eigen/tf2_eigen.h>
34 #include <sensor_msgs/msg/joint_state.hpp>
35 #include <geometry_msgs/msg/pose_stamped.hpp>
36 #include <tf2_ros/static_transform_broadcaster.h>
37 
44 struct TcpPose
45 {
46  double x;
47  double y;
48  double z;
49  double alpha;
50  double beta;
51  double gamma;
52 };
53 
57 class ArmControlBase: public rclcpp::Node
58 {
59 public:
60 
66  ArmControlBase(const std::string node_name, const rclcpp::NodeOptions & options)
67  : Node(node_name, options), broadcaster_(this)
68  {
69  joint_pub_ = this->create_publisher<sensor_msgs::msg::JointState>("/joint_states", 1);
70  time_out_ = 15.0;
71 
72  tf_msg_.header.frame_id = "base"; // Used to void TF_NO_FRAME_ID error, updated by user later
73  tf_msg_.child_frame_id = "pose_goal";
74  // Initialize rotation to avoid TF_DENORMALIZED_QUATERNION error
75  tf_msg_.transform.rotation.x = 0.0;
76  tf_msg_.transform.rotation.y = 0.0;
77  tf_msg_.transform.rotation.z = 0.0;
78  tf_msg_.transform.rotation.w = 1.0;
79  tf_thread_ = std::thread(&ArmControlBase::publishTFGoal, this);
80  }
81 
85  virtual ~ArmControlBase()
86  {
87  rclcpp::shutdown();
88  tf_thread_.join();
89  }
90 
103  virtual bool moveToTcpPose(double x, double y, double z,
104  double alpha, double beta, double gamma,
105  double vel, double acc) = 0;
106 
114  virtual bool moveToTcpPose(const Eigen::Isometry3d& pose, double vel, double acc);
115 
123  virtual bool moveToTcpPose(const geometry_msgs::msg::PoseStamped& pose_stamped, double vel, double acc);
124 
132  virtual bool moveToJointValues(const std::vector<double>& joint_values, double vel, double acc) = 0;
133 
139  virtual bool open(const double distance = 0) = 0;
140 
146  virtual bool close(const double distance = 0) = 0;
147 
171  virtual bool pick(double x, double y, double z,
172  double alpha, double beta, double gamma,
173  double vel, double acc, double vel_scale, double approach);
174 
193  virtual bool pick(const geometry_msgs::msg::PoseStamped& pose_stamped,
194  double vel, double acc, double vel_scale, double approach);
195 
218  virtual bool place(double x, double y, double z,
219  double alpha, double beta, double gamma,
220  double vel, double acc, double vel_scale, double retract);
221 
239  virtual bool place(const geometry_msgs::msg::PoseStamped& pose_stamped,
240  double vel, double acc, double vel_scale, double retract);
241 
248  void toTcpPose(const geometry_msgs::msg::PoseStamped& pose_stamped, TcpPose& tcp_pose);
249 
256  void toTcpPose(const Eigen::Isometry3d& pose, TcpPose& tcp_pose);
257 
264  virtual bool checkTcpGoalArrived(Eigen::Isometry3d& tcp_goal);
265 
272  virtual bool checkJointValueGoalArrived(const std::vector<double>& joint_goal);
273 
281  virtual void parseArgs() = 0;
282 
288  virtual bool startLoop() = 0;
289 
294  virtual void publishTFGoal();
295 
300  void updateTFGoal(const geometry_msgs::msg::PoseStamped& pose_stamped);
301 
308  Eigen::Vector3d getUnitApproachVector(const double& alpha, const double& beta, const double& gamma);
309 
310 protected:
312  rclcpp::Publisher<sensor_msgs::msg::JointState>::SharedPtr joint_pub_;
314  std::vector<std::string> joint_names_;
318  std::vector<double> joint_values_;
320  std::mutex m_;
322  double time_out_;
324  std::thread tf_thread_;
326  geometry_msgs::msg::TransformStamped tf_msg_;
328  tf2_ros::StaticTransformBroadcaster broadcaster_;
329 };
ArmControlBase(const std::string node_name, const rclcpp::NodeOptions &options)
Constructor of class ArmControlBase.
Definition: control_base.hpp:66
TcpPose tcp_pose_
Current end-effctor pose.
Definition: control_base.hpp:316
Data type to represent robot arm&#39;s end-effector pose in 3D cartesian space.
Definition: control_base.hpp:44
Robot arm control interface.
Definition: control_base.hpp:57
double y
Definition: control_base.hpp:47
double x
Definition: control_base.hpp:46
double beta
Definition: control_base.hpp:50
rclcpp::Publisher< sensor_msgs::msg::JointState >::SharedPtr joint_pub_
Joint state publisher.
Definition: control_base.hpp:312
virtual ~ArmControlBase()
Default destructor of class ArmControlBase.
Definition: control_base.hpp:85
double gamma
Definition: control_base.hpp:51
tf2_ros::StaticTransformBroadcaster broadcaster_
TF broadcaster.
Definition: control_base.hpp:328
std::vector< double > joint_values_
Current joint value.
Definition: control_base.hpp:318
double alpha
Definition: control_base.hpp:49
double z
Definition: control_base.hpp:48
std::mutex m_
Mutex to guard the tcp_pose_ usage.
Definition: control_base.hpp:320
double time_out_
Time duration to finish a pick or place task.
Definition: control_base.hpp:322
std::thread tf_thread_
Thread to publish tf pose.
Definition: control_base.hpp:324
geometry_msgs::msg::TransformStamped tf_msg_
TF message converted from the pose stamped input to the move or pick/place commands.
Definition: control_base.hpp:326
virtual void publishTFGoal()
Publish tf_msg_.
Definition: control_base.cpp:23
std::vector< std::string > joint_names_
Joint names.
Definition: control_base.hpp:314