sequence.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 <algorithm>
20 #include <boost/variant.hpp>
21 
23 {
24 
28 class ToReqVisitor : public boost::static_visitor<planning_interface::MotionPlanRequest>
29 {
30 public:
31  template<typename T>
33  {
34  return cmd.toRequest();
35  }
36 };
37 
41 class ToBaseVisitor : public boost::static_visitor<MotionCmd& >
42 {
43 public:
44  template<typename T>
45  MotionCmd& operator()( T & cmd) const
46  {
47  return cmd;
48  }
49 };
50 
51 pilz_msgs::MotionSequenceRequest Sequence::toRequest() const
52 {
53  pilz_msgs::MotionSequenceRequest req;
54 
55  std::vector<std::string> group_names;
56  for (const auto& cmd : cmds_)
57  {
58  pilz_msgs::MotionSequenceItem item;
59  item.req = boost::apply_visitor( ToReqVisitor(), cmd.first);
60 
61  if ( std::find(group_names.begin(), group_names.end(), item.req.group_name) != group_names.end() )
62  {
63  // Remove start state because only the first request of a group
64  // is allowed to have a start state in a sequence.
65  item.req.start_state = moveit_msgs::RobotState();
66  }
67  else
68  {
69  group_names.emplace_back(item.req.group_name);
70  }
71 
72  item.blend_radius = cmd.second;
73  req.items.push_back(item);
74  }
75  return req;
76 }
77 
78 void Sequence::erase(const size_t start, const size_t end)
79 {
80  const size_t orig_n {size()};
81  if (start > orig_n || end > orig_n)
82  {
83  std::string msg;
84  msg.append("Parameter start=").append(std::to_string(start));
85  msg.append(" and end=").append(std::to_string(end));
86  msg.append(" must not be greater then the number of #commands=");
87  msg.append(std::to_string(size()));
88  throw std::invalid_argument(msg);
89  }
90  cmds_.erase(cmds_.begin()+start, cmds_.begin()+end);
91  if (end == orig_n)
92  {
93  // Make sure last radius is set zero
94  cmds_.at(size()-1).second = 0.;
95  }
96 }
97 
98 MotionCmd& Sequence::getCmd(const size_t index_cmd)
99 {
100  return boost::apply_visitor( ToBaseVisitor(), cmds_.at(index_cmd).first);
101 }
102 
103 } // namespace pilz_industrial_motion_testutils
Visitor transforming the stored command into a MotionPlanRequest.
Definition: sequence.cpp:28
string cmd
Base class for commands storing all general information of a command.
Definition: motioncmd.h:31
std::size_t size(custom_string const &s)
void erase(const size_t start, const size_t end)
Deletes all commands from index &#39;start&#39; to index &#39;end&#39;.
Definition: sequence.cpp:78
T & getCmd(const size_t index_cmd)
Definition: sequence.h:97
planning_interface::MotionPlanRequest operator()(T &cmd) const
Definition: sequence.cpp:32
moveit_msgs::MotionPlanRequest MotionPlanRequest
pilz_msgs::MotionSequenceRequest toRequest() const
Definition: sequence.cpp:51
Visitor returning not the specific command type but the base type.
Definition: sequence.cpp:41


pilz_industrial_motion_testutils
Author(s):
autogenerated on Mon Apr 6 2020 03:17:28