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


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