group.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 #include "util.hpp"
5 
6 #include <functional>
7 #include <memory>
8 #include <mutex>
9 #include <vector>
10 
11 namespace hebi {
12 
34 class LogFile;
35 class GroupCommand;
36 class GroupFeedback;
37 class GroupInfo;
38 
43 using GroupFeedbackHandler = std::function<void (const GroupFeedback&)>;
44 
49 class Group final
50 {
51  private:
56 
60  const int number_of_modules_;
61 
65  std::mutex handler_lock_;
66 
71  std::vector<GroupFeedbackHandler> handlers_;
72 
73  #ifndef DOXYGEN_OMIT_INTERNAL
74 
78  friend void callbackWrapper(HebiGroupFeedbackPtr group_feedback, void* user_data);
79  #endif // DOXYGEN_OMIT_INTERNAL
80 
85  void callAttachedHandlers(HebiGroupFeedbackPtr group_feedback);
86 
87  public:
92  static const int32_t DEFAULT_TIMEOUT_MS = 500;
93 
94  #ifndef DOXYGEN_OMIT_INTERNAL
95 
100  Group(HebiGroupPtr group,
101  float initial_feedback_frequency = 0.0f,
102  int32_t initial_command_lifetime = 0);
103  #endif // DOXYGEN_OMIT_INTERNAL
104 
108  ~Group() noexcept; /* annotating specified destructor as noexcept is best-practice */
109 
113  int size();
114 
125  bool setCommandLifetimeMs(int32_t ms);
126 
138  bool sendCommand(const GroupCommand& group_command);
139 
159  bool sendCommandWithAcknowledgement(const GroupCommand& group_command, int32_t timeout_ms=DEFAULT_TIMEOUT_MS);
160 
172  bool sendFeedbackRequest();
173 
194  bool getNextFeedback(GroupFeedback& feedback, int32_t timeout_ms=DEFAULT_TIMEOUT_MS);
195 
204  bool requestInfo(GroupInfo& info, int32_t timeout_ms=DEFAULT_TIMEOUT_MS);
205 
214  std::string startLog(const std::string& dir);
215 
226  std::string startLog(const std::string& dir, const std::string& file);
227 
234  std::shared_ptr<LogFile> stopLog();
235 
243  bool setFeedbackFrequencyHz(float frequency);
249  float getFeedbackFrequencyHz();
258  void clearFeedbackHandlers();
259 
267  static std::shared_ptr<Group> createImitation(size_t size);
268 
269  private:
274 };
275 
276 } // namespace hebi
void addFeedbackHandler(GroupFeedbackHandler handler)
Adds a handler function to be called by the internal feedback request thread.
Definition: group.cpp:158
std::string startLog(const std::string &dir)
Starts log (stopping any active log).
Definition: group.cpp:94
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
void clearFeedbackHandlers()
Removes all feedback handlers presently added.
Definition: group.cpp:166
Represents a group of physical HEBI modules, and allows Command, Feedback, and Info objects to be sen...
Definition: group.hpp:49
A list of Info objects that can be received from a Group of modules; the size() must match the number...
Definition: group_info.hpp:14
Group(HebiGroupPtr group, float initial_feedback_frequency=0.0f, int32_t initial_command_lifetime=0)
Definition: group.cpp:36
float getFeedbackFrequencyHz()
Gets the frequency of the internal feedback request + callback thread.
Definition: group.cpp:153
~Group() noexcept
Destructor cleans up group.
Definition: group.cpp:52
bool sendCommandWithAcknowledgement(const GroupCommand &group_command, int32_t timeout_ms=DEFAULT_TIMEOUT_MS)
Send a command to the given group, requesting an acknowledgement of transmission to be sent back...
Definition: group.cpp:74
struct _HebiGroup * HebiGroupPtr
The C-style&#39;s API representation of a group.
Definition: hebi.h:330
struct _HebiGroupFeedback * HebiGroupFeedbackPtr
The C-style&#39;s API representation of group feedback.
Definition: hebi.h:346
void callAttachedHandlers(HebiGroupFeedbackPtr group_feedback)
Definition: group.cpp:16
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: color.hpp:5
int size()
Returns the number of modules in the group.
Definition: group.cpp:59
static const int32_t DEFAULT_TIMEOUT_MS
The default timeout for any send-with-acknowledgement or request operation is 500 ms...
Definition: group.hpp:92
bool sendCommand(const GroupCommand &group_command)
Send a command to the given group without requesting an acknowledgement.
Definition: group.cpp:69
bool setCommandLifetimeMs(int32_t ms)
Sets the command lifetime for the modules in this group.
Definition: group.cpp:64
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
std::shared_ptr< LogFile > stopLog()
Stops any active log.
Definition: group.cpp:136
static std::shared_ptr< Group > createImitation(size_t size)
Creates an imitation group of provided size.
Definition: group.cpp:47
bool getNextFeedback(GroupFeedback &feedback, int32_t timeout_ms=DEFAULT_TIMEOUT_MS)
Returns the most recently stored feedback from a sent feedback request, or returns the next one recei...
Definition: group.cpp:84
HebiGroupPtr internal_
Definition: group.hpp:55
A list of Command objects appropriate for sending to a Group of modules; the size() must match the nu...
std::mutex handler_lock_
Definition: group.hpp:65
bool requestInfo(GroupInfo &info, int32_t timeout_ms=DEFAULT_TIMEOUT_MS)
Request info from the group, and store it in the passed-in info object.
Definition: group.cpp:89
std::vector< GroupFeedbackHandler > handlers_
Definition: group.hpp:71
const int number_of_modules_
Definition: group.hpp:60
bool setFeedbackFrequencyHz(float frequency)
Sets the frequency of the internal feedback request + callback thread.
Definition: group.cpp:148
friend void callbackWrapper(HebiGroupFeedbackPtr group_feedback, void *user_data)
Definition: group.cpp:10
bool sendFeedbackRequest()
Requests feedback from the group.
Definition: group.cpp:79
std::function< void(const GroupFeedback &)> GroupFeedbackHandler
Definition of a callback function for GroupFeedback returned from a Group of modules.
Definition: group.hpp:43


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