HEBI C++ API  3.8.0
group_command.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 
5 #include <memory>
6 #include <vector>
7 
8 #include "Eigen/Eigen"
9 #include "command.hpp"
11 #include "util.hpp"
12 
13 namespace hebi {
14 
19 class GroupCommand final {
20 public:
21 #ifndef DOXYGEN_OMIT_INTERNAL
22 
26  std::shared_ptr<GroupCommandWrapper> internal_;
27 #endif // DOXYGEN_OMIT_INTERNAL
28 
29 private:
33  const size_t number_of_modules_;
37  std::vector<Command> commands_;
41  const bool is_subview_{};
42 
46  GroupCommand(std::shared_ptr<GroupCommandWrapper>, std::vector<int> indices);
47 
48 public:
52  GroupCommand(size_t number_of_modules);
53 
57  ~GroupCommand() noexcept = default;
58 
62  GroupCommand(GroupCommand&&) = default;
63 
74  GroupCommand subview(std::vector<int> indices) const;
75 
79  bool isSubview() const { return is_subview_; }
80 
84  size_t size() const;
85 
89  Command& operator[](size_t index);
90 
94  const Command& operator[](size_t index) const;
95 
100  void clear();
101 
106  bool readGains(const std::string& file);
107 
112  bool writeGains(const std::string& file) const;
113 
118  FunctionCallResult readSafetyParameters(const std::string& file) {
119  if (is_subview_)
120  return FunctionCallResult{false, "Cannot call this method on a subview!"};
121  auto res = hebiGroupCommandReadSafetyParameters(internal_->internal_, file.c_str()) == HebiStatusSuccess;
122  if (res) {
123  return FunctionCallResult{true};
124  }
125  return FunctionCallResult{false, std::string{hebiSafetyParametersGetLastError()}};
126  }
127 
132  FunctionCallResult writeSafetyParameters(const std::string& file) const {
133  if (is_subview_)
134  return FunctionCallResult{false, "Cannot call this method on a subview!"};
135  auto res = hebiGroupCommandWriteSafetyParameters(internal_->internal_, file.c_str()) == HebiStatusSuccess;
136  if (res) {
137  return FunctionCallResult{true};
138  }
139  return FunctionCallResult{false, std::string{hebiSafetyParametersGetLastError()}};
140  }
141 
148  void setPosition(const Eigen::VectorXd& position);
155  void setVelocity(const Eigen::VectorXd& velocity);
162  void setEffort(const Eigen::VectorXd& effort);
169  void setSpringConstant(const Eigen::VectorXd& springConstant);
170 
174  Eigen::VectorXd getPosition() const;
178  Eigen::VectorXd getVelocity() const;
182  Eigen::VectorXd getEffort() const;
186  Eigen::VectorXd getSpringConstant() const;
187 
191  void getPosition(Eigen::VectorXd& out) const;
195  void getVelocity(Eigen::VectorXd& out) const;
199  void getEffort(Eigen::VectorXd& out) const;
203  void getSpringConstant(Eigen::VectorXd& out) const;
204 };
205 
206 } // namespace hebi
GroupCommand subview(std::vector< int > indices) const
Creates a "subview" of this group command object, with shared access to a subset of the Command eleme...
Definition: group_command.cpp:17
Eigen::VectorXd getPosition() const
Convenience function for returning commanded position values.
Definition: group_command.cpp:75
Command objects have various fields that can be set; when sent to the module, these fields control in...
Definition: command.hpp:34
Definition: arm.cpp:8
bool writeGains(const std::string &file) const
Export the gains from this GroupCommand object into a file, creating it as necessary.
Definition: group_command.cpp:43
FunctionCallResult readSafetyParameters(const std::string &file)
Import the safety parameters from a file into this GroupCommand object.
Definition: group_command.hpp:118
Eigen::VectorXd getSpringConstant() const
Convenience function for returning commanded spring constant values.
Definition: group_command.cpp:99
Eigen::VectorXd getEffort() const
Convenience function for returning commanded effort values.
Definition: group_command.cpp:91
size_t size() const
Returns the number of module commands in this group command.
Definition: group_command.cpp:25
bool readGains(const std::string &file)
Import the gains from a file into this GroupCommand object.
Definition: group_command.cpp:37
Command & operator[](size_t index)
Access the command for an individual module.
Definition: group_command.cpp:27
Used as a return.
Definition: util.hpp:28
A list of Command objects appropriate for sending to a Group of modules; the size() must match the nu...
Definition: group_command.hpp:19
FunctionCallResult writeSafetyParameters(const std::string &file) const
Export the safety parameters from this GroupCommand object into a file, creating it as necessary.
Definition: group_command.hpp:132
bool isSubview() const
Was this created as a subview of another GroupCommand?
Definition: group_command.hpp:79
void setVelocity(const Eigen::VectorXd &velocity)
Convenience function for setting velocity commands from Eigen vectors.
Definition: group_command.cpp:55
void setSpringConstant(const Eigen::VectorXd &springConstant)
Convenience function for setting spring constant commands from Eigen vectors.
Definition: group_command.cpp:68
void setPosition(const Eigen::VectorXd &position)
Convenience function for setting position commands from Eigen vectors.
Definition: group_command.cpp:49
~GroupCommand() noexcept=default
Destructor cleans up group command object as necessary.
void setEffort(const Eigen::VectorXd &effort)
Convenience function for setting effort commands from Eigen vectors.
Definition: group_command.cpp:61
void clear()
Clears all data in this GroupCommand object; this returns to the state the GroupCommand was at time o...
Definition: group_command.cpp:31
Eigen::VectorXd getVelocity() const
Convenience function for returning commanded velocity values.
Definition: group_command.cpp:83