jointconfiguration.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 
20 
22 {
24 {
25 }
26 
27 JointConfiguration::JointConfiguration(const std::string& group_name,
28  const std::vector<double>& config,
29  CreateJointNameFunc&& create_joint_name_func)
30  : RobotConfiguration(group_name), joints_(config), create_joint_name_func_(create_joint_name_func)
31 {
32 }
33 
34 JointConfiguration::JointConfiguration(const std::string& group_name,
35  const std::vector<double>& config,
36  const moveit::core::RobotModelConstPtr& robot_model)
37  : RobotConfiguration(group_name, robot_model), joints_(config)
38 {
39 }
40 
41 moveit_msgs::Constraints JointConfiguration::toGoalConstraintsWithoutModel() const
42 {
44  {
45  throw JointConfigurationException("Create-Joint-Name function not set");
46  }
47 
48  moveit_msgs::Constraints gc;
49 
50  for (size_t i = 0; i < joints_.size(); ++i)
51  {
52  moveit_msgs::JointConstraint jc;
53  jc.joint_name = create_joint_name_func_(i);
54  jc.position = joints_.at(i);
55  gc.joint_constraints.push_back(jc);
56  }
57 
58  return gc;
59 }
60 
61 moveit_msgs::Constraints JointConfiguration::toGoalConstraintsWithModel() const
62 {
63  if (!robot_model_)
64  {
65  throw JointConfigurationException("No robot model set");
66  }
67 
68  robot_state::RobotState state(robot_model_);
69  state.setToDefaultValues();
70  state.setJointGroupPositions(group_name_, joints_);
71 
72  return kinematic_constraints::constructGoalConstraints(state, state.getRobotModel()->getJointModelGroup(group_name_));
73 }
74 
76 {
78  {
79  throw JointConfigurationException("Create-Joint-Name function not set");
80  }
81 
82  moveit_msgs::RobotState robot_state;
83  for (size_t i = 0; i < joints_.size(); ++i)
84  {
85  robot_state.joint_state.name.emplace_back(create_joint_name_func_(i));
86  robot_state.joint_state.position.push_back(joints_.at(i));
87  }
88  return robot_state;
89 }
90 
91 robot_state::RobotState JointConfiguration::toRobotState() const
92 {
93  if (!robot_model_)
94  {
95  throw JointConfigurationException("No robot model set");
96  }
97 
98  robot_state::RobotState robot_state(robot_model_);
99  robot_state.setToDefaultValues();
100  robot_state.setJointGroupPositions(group_name_, joints_);
101  return robot_state;
102 }
103 
105 {
106  robot_state::RobotState start_state(toRobotState());
107  moveit_msgs::RobotState rob_state_msg;
108  moveit::core::robotStateToRobotStateMsg(start_state, rob_state_msg, false);
109  return rob_state_msg;
110 }
111 
112 sensor_msgs::JointState JointConfiguration::toSensorMsg() const
113 {
115  {
116  throw JointConfigurationException("Create-Joint-Name function not set");
117  }
118 
119  sensor_msgs::JointState state;
120  for (size_t i = 0; i < joints_.size(); ++i)
121  {
122  state.name.emplace_back(create_joint_name_func_(i));
123  state.position.push_back(joints_.at(i));
124  }
125  return state;
126 }
127 
128 std::ostream& operator<<(std::ostream& os, const JointConfiguration& obj)
129 {
130  const size_t n{ obj.size() };
131  os << "JointConfiguration: [";
132  for (size_t i = 0; i < n; ++i)
133  {
134  os << obj.getJoint(i);
135  if (i != n - 1)
136  {
137  os << ", ";
138  }
139  }
140  os << "]";
141 
142  return os;
143 }
144 
145 } // namespace pilz_industrial_motion_testutils
std::vector< double > joints_
Joint positions.
moveit_msgs::RobotState toMoveitMsgsRobotStateWithoutModel() const
moveit_msgs::RobotState toMoveitMsgsRobotStateWithModel() const
std::function< std::string(const size_t &)> CreateJointNameFunc
Class to define a robot configuration in space with the help of joint values.
moveit_msgs::Constraints toGoalConstraintsWithoutModel() const
std::ostream & operator<<(std::ostream &, const CartesianConfiguration &)
moveit_msgs::Constraints constructGoalConstraints(const robot_state::RobotState &state, const robot_model::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Class to define robot configuration in space.
moveit_msgs::Constraints toGoalConstraintsWithModel() const
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)


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