cartesianconfiguration.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <stdexcept>
20 
22 {
24 {
25 }
26 
27 CartesianConfiguration::CartesianConfiguration(const std::string& group_name,
28  const std::string& link_name,
29  const std::vector<double>& config)
30  : RobotConfiguration(group_name), link_name_(link_name), pose_(toPose(config))
31 {
32 }
33 
34 CartesianConfiguration::CartesianConfiguration(const std::string& group_name,
35  const std::string& link_name,
36  const std::vector<double>& config,
37  const moveit::core::RobotModelConstPtr& robot_model)
38  : RobotConfiguration(group_name, robot_model), link_name_(link_name), pose_(toPose(config))
39 {
40  if (robot_model && (!robot_model_->hasLinkModel(link_name_)))
41  {
42  std::string msg{ "Link \"" };
43  msg.append(link_name).append("\" not known to robot model");
44  throw std::invalid_argument(msg);
45  }
46 
47  if (robot_model && (!robot_state::RobotState(robot_model_).knowsFrameTransform(link_name_)))
48  {
49  std::string msg{ "Tranform of \"" };
50  msg.append(link_name).append("\" is unknown");
51  throw std::invalid_argument(msg);
52  }
53 }
54 
55 geometry_msgs::Pose CartesianConfiguration::toPose(const std::vector<double>& pose)
56 {
57  geometry_msgs::Pose pose_msg;
58  pose_msg.position.x = pose.at(0);
59  pose_msg.position.y = pose.at(1);
60  pose_msg.position.z = pose.at(2);
61  pose_msg.orientation.x = pose.at(3);
62  pose_msg.orientation.y = pose.at(4);
63  pose_msg.orientation.z = pose.at(5);
64  pose_msg.orientation.w = pose.at(6);
65 
66  return pose_msg;
67 }
68 
69 geometry_msgs::PoseStamped CartesianConfiguration::toStampedPose(const geometry_msgs::Pose& pose)
70 {
71  geometry_msgs::PoseStamped pose_stamped_msg;
72  pose_stamped_msg.pose = pose;
73  return pose_stamped_msg;
74 }
75 
76 moveit_msgs::RobotState CartesianConfiguration::toMoveitMsgsRobotState() const
77 {
78  if (!robot_model_)
79  {
80  throw std::runtime_error("No robot model set");
81  }
82 
83  robot_state::RobotState rstate(robot_model_);
84  rstate.setToDefaultValues();
85  if (hasSeed())
86  {
87  rstate.setJointGroupPositions(group_name_, getSeed().getJoints());
88  }
89 
90  rstate.update();
91 
92  // set to Cartesian pose
93  Eigen::Isometry3d start_pose;
94  tf::poseMsgToEigen(pose_, start_pose);
95  if (!rstate.setFromIK(rstate.getRobotModel()->getJointModelGroup(group_name_), start_pose, link_name_))
96  {
97  std::ostringstream os;
98  os << "No solution for ik \n" << start_pose.translation() << "\n" << start_pose.linear();
99  throw std::runtime_error(os.str());
100  }
101 
102  // Conversion to RobotState msg type
103  moveit_msgs::RobotState robot_state_msg;
104  moveit::core::robotStateToRobotStateMsg(rstate, robot_state_msg, true);
105  return robot_state_msg;
106 }
107 
108 std::ostream& operator<<(std::ostream& os, const CartesianConfiguration& obj)
109 {
110  os << "Group name: \"" << obj.getGroupName() << "\"";
111  os << " | link name: \"" << obj.getLinkName() << "\"";
112  os << "\n" << obj.getPose();
113  return os;
114 }
115 
116 } // namespace pilz_industrial_motion_testutils
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
static geometry_msgs::PoseStamped toStampedPose(const geometry_msgs::Pose &pose)
static geometry_msgs::Pose toPose(const std::vector< double > &pose)
std::ostream & operator<<(std::ostream &, const CartesianConfiguration &)
Class to define robot configuration in space.
bool hasSeed() const
States if a seed for the cartesian configuration is set.
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)
Class to define a robot configuration in space with the help of cartesian coordinates.
virtual moveit_msgs::RobotState toMoveitMsgsRobotState() const override


pilz_industrial_motion_testutils
Author(s):
autogenerated on Mon Feb 28 2022 23:13:36