group_command.cpp
Go to the documentation of this file.
1 #include "group_command.hpp"
2 
3 namespace hebi {
4 
5 GroupCommand::GroupCommand(size_t number_of_modules)
6  : internal_(hebiGroupCommandCreate(number_of_modules)),
7  number_of_modules_(number_of_modules)
8 {
9  for (size_t i = 0; i < number_of_modules_; i++)
11 }
12 
14 {
15  if (internal_ != nullptr)
17 }
18 
19 size_t GroupCommand::size() const
20 {
21  return number_of_modules_;
22 }
23 
25 {
26  return commands_[index];
27 }
28 
29 const Command& GroupCommand::operator[](size_t index) const
30 {
31  return commands_[index];
32 }
33 
34 bool GroupCommand::readGains(const std::string& file)
35 {
36  return hebiGroupCommandReadGains(internal_, file.c_str()) == HebiStatusSuccess;
37 }
38 
39 bool GroupCommand::writeGains(const std::string& file) const
40 {
42 }
43 
44 void GroupCommand::setPosition(const Eigen::VectorXd& position)
45 {
46  if (position.size() != number_of_modules_)
47  return;
48  for (size_t i = 0; i < number_of_modules_; ++i)
49  commands_[i].actuator().position().set(position[i]);
50 }
51 void GroupCommand::setVelocity(const Eigen::VectorXd& velocity)
52 {
53  if (velocity.size() != number_of_modules_)
54  return;
55  for (size_t i = 0; i < number_of_modules_; ++i)
56  commands_[i].actuator().velocity().set(static_cast<float>(velocity[i]));
57 }
58 void GroupCommand::setEffort(const Eigen::VectorXd& effort)
59 {
60  if (effort.size() != number_of_modules_)
61  return;
62  for (size_t i = 0; i < number_of_modules_; ++i)
63  commands_[i].actuator().effort().set(static_cast<float>(effort[i]));
64 }
65 
66 void GroupCommand::setSpringConstant(const Eigen::VectorXd& springConstant)
67 {
68  if (springConstant.size() != number_of_modules_)
69  return;
70  for (size_t i = 0; i < number_of_modules_; ++i)
71  commands_[i].settings().actuator().springConstant().set(static_cast<float>(springConstant[i]));
72 }
73 
74 Eigen::VectorXd GroupCommand::getPosition() const
75 {
76  Eigen::VectorXd res(number_of_modules_);
77  for (size_t i = 0; i < number_of_modules_; ++i)
78  {
79  const auto& cmd = commands_[i].actuator().position();
80  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
81  }
82  return res;
83 }
84 Eigen::VectorXd GroupCommand::getVelocity() const
85 {
86  Eigen::VectorXd res(number_of_modules_);
87  for (size_t i = 0; i < number_of_modules_; ++i)
88  {
89  const auto& cmd = commands_[i].actuator().velocity();
90  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
91  }
92  return res;
93 }
94 Eigen::VectorXd GroupCommand::getEffort() const
95 {
96  Eigen::VectorXd res(number_of_modules_);
97  for (size_t i = 0; i < number_of_modules_; ++i)
98  {
99  const auto& cmd = commands_[i].actuator().effort();
100  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
101  }
102  return res;
103 }
104 Eigen::VectorXd GroupCommand::getSpringConstant() const
105 {
106  Eigen::VectorXd res(number_of_modules_);
107  for (size_t i = 0; i < number_of_modules_; ++i)
108  {
109  const auto& cmd = commands_[i].settings().actuator().springConstant();
110  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
111  }
112  return res;
113 }
114 
115 void GroupCommand::getPosition(Eigen::VectorXd& out) const
116 {
117  if (out.size() != number_of_modules_)
118  {
119  out.resize(number_of_modules_);
120  }
121 
122  for (size_t i = 0; i < number_of_modules_; ++i)
123  {
124  const auto& cmd = commands_[i].actuator().position();
125  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
126  }
127 }
128 void GroupCommand::getVelocity(Eigen::VectorXd& out) const
129 {
130  if (out.size() != number_of_modules_)
131  {
132  out.resize(number_of_modules_);
133  }
134 
135  for (size_t i = 0; i < number_of_modules_; ++i)
136  {
137  const auto& cmd = commands_[i].actuator().velocity();
138  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
139  }
140 }
141 void GroupCommand::getEffort(Eigen::VectorXd& out) const
142 {
143  if (out.size() != number_of_modules_)
144  {
145  out.resize(number_of_modules_);
146  }
147 
148  for (size_t i = 0; i < number_of_modules_; ++i)
149  {
150  const auto& cmd = commands_[i].actuator().effort();
151  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
152  }
153 }
154 void GroupCommand::getSpringConstant(Eigen::VectorXd& out) const
155 {
156  if (out.size() != number_of_modules_)
157  {
158  out.resize(number_of_modules_);
159  }
160 
161  for (size_t i = 0; i < number_of_modules_; ++i)
162  {
163  const auto& cmd = commands_[i].settings().actuator().springConstant();
164  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
165  }
166 }
167 
168 } // namespace hebi
HebiStatusCode hebiGroupCommandWriteGains(HebiGroupCommandPtr cmd, const char *file)
Export gains from a GroupCommand object into a file.
GroupCommand(size_t number_of_modules)
Create a group command with the specified number of modules.
string cmd
Command objects have various fields that can be set; when sent to the module, these fields control in...
Definition: command.hpp:30
Definition: color.hpp:5
Eigen::VectorXd getVelocity() const
Convenience function for returning commanded velocity values.
~GroupCommand() noexcept
Destructor cleans up group command object as necessary.
HebiGroupCommandPtr hebiGroupCommandCreate(size_t size)
Creates a GroupCommand for a group with the specified number of modules.
size_t size() const
Returns the number of module commands in this group command.
const size_t number_of_modules_
HebiCommandPtr hebiGroupCommandGetModuleCommand(HebiGroupCommandPtr cmd, size_t module_index)
Get an individual command for a particular module at index module_index.
Eigen::VectorXd getSpringConstant() const
Convenience function for returning commanded spring constant values.
Eigen::VectorXd getPosition() const
Convenience function for returning commanded position values.
Eigen::VectorXd getEffort() const
Convenience function for returning commanded effort values.
HebiStatusCode hebiGroupCommandReadGains(HebiGroupCommandPtr cmd, const char *file)
Import gains from a file into a GroupCommand object.
bool readGains(const std::string &file)
Import the gains from a file into this GroupCommand object.
Command & operator[](size_t index)
Access the command for an individual module.
void hebiGroupCommandRelease(HebiGroupCommandPtr cmd)
Frees resources created by the GroupCommand object.
HebiGroupCommandPtr internal_
std::vector< Command > commands_
bool writeGains(const std::string &file) const
Export the gains from this GroupCommand object into a file, creating it as necessary.
void setVelocity(const Eigen::VectorXd &velocity)
Convenience function for setting velocity commands from Eigen vectors.
void setSpringConstant(const Eigen::VectorXd &springConstant)
Convenience function for setting spring constant commands from Eigen vectors.
void setPosition(const Eigen::VectorXd &position)
Convenience function for setting position commands from Eigen vectors.
void setEffort(const Eigen::VectorXd &effort)
Convenience function for setting effort commands from Eigen vectors.


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:14