sequence.h
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 
17 #ifndef SEQUENCE_H
18 #define SEQUENCE_H
19 
20 #include <stdexcept>
21 #include <vector>
22 #include <utility>
23 #include <typeinfo>
24 
25 #include <pilz_msgs/MotionSequenceRequest.h>
26 
27 #include "command_types_typedef.h"
28 #include "motioncmd.h"
29 
31 {
35 class Sequence
36 {
37 public:
42  void add(const CmdVariant& cmd, const double blend_radius = 0.);
43 
47  size_t size() const;
48 
49  template <class T>
50  T& getCmd(const size_t index_cmd);
51 
52  template <class T>
53  const T& getCmd(const size_t index_cmd) const;
54 
59  template <class T>
60  bool cmdIsOfType(const size_t index_cmd) const;
61 
67  MotionCmd& getCmd(const size_t index_cmd);
68 
70  void setBlendRadius(const size_t index_cmd, const double blend_radius);
71  double getBlendRadius(const size_t index_cmd) const;
72 
76  void erase(const size_t start, const size_t end);
77 
78  pilz_msgs::MotionSequenceRequest toRequest() const;
79 
80 private:
81  using TCmdRadiiPair = std::pair<CmdVariant, double>;
82  std::vector<TCmdRadiiPair> cmds_;
83 };
84 
85 inline void Sequence::add(const CmdVariant& cmd, const double blend_radius)
86 {
87  cmds_.emplace_back(cmd, blend_radius);
88 }
89 
90 inline size_t Sequence::size() const
91 {
92  return cmds_.size();
93 }
94 
95 template <class T>
96 inline T& Sequence::getCmd(const size_t index_cmd)
97 {
98  return boost::get<T>(cmds_.at(index_cmd).first);
99 }
100 
101 template <class T>
102 inline const T& Sequence::getCmd(const size_t index_cmd) const
103 {
104  return boost::get<T>(cmds_.at(index_cmd).first);
105 }
106 
107 inline double Sequence::getBlendRadius(const size_t index_cmd) const
108 {
109  return cmds_.at(index_cmd).second;
110 }
111 
112 inline void Sequence::setBlendRadius(const size_t index_cmd, const double blend_radius)
113 {
114  cmds_.at(index_cmd).second = blend_radius;
115 }
116 
118 {
119  std::for_each(cmds_.begin(), cmds_.end(), [](TCmdRadiiPair& cmd) { cmd.second = 0.; });
120 }
121 
122 template <class T>
123 inline bool Sequence::cmdIsOfType(const size_t index_cmd) const
124 {
125  return cmds_.at(index_cmd).first.type() == typeid(T);
126 }
127 
128 } // namespace pilz_industrial_motion_testutils
129 
130 #endif // SEQUENCE_H
ROSCPP_DECL void start()
double getBlendRadius(const size_t index_cmd) const
Definition: sequence.h:107
string cmd
Base class for commands storing all general information of a command.
Definition: motioncmd.h:30
void setBlendRadius(const size_t index_cmd, const double blend_radius)
Definition: sequence.h:112
size_t size() const
Returns the number of commands.
Definition: sequence.h:90
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:77
T & getCmd(const size_t index_cmd)
Definition: sequence.h:96
std::pair< CmdVariant, double > TCmdRadiiPair
Definition: sequence.h:81
Data class storing all information regarding a Sequence command.
Definition: sequence.h:35
bool cmdIsOfType(const size_t index_cmd) const
Definition: sequence.h:123
void add(const CmdVariant &cmd, const double blend_radius=0.)
Adds a command to the end of the sequence.
Definition: sequence.h:85
boost::variant< PtpJoint, PtpJointCart, PtpCart, LinJoint, LinCart, CircCenterCart, CircInterimCart, CircJointCenterCart, CircJointInterimCart, Gripper > CmdVariant
pilz_msgs::MotionSequenceRequest toRequest() const
Definition: sequence.cpp:50
std::vector< TCmdRadiiPair > cmds_
Definition: sequence.h:82


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