group.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 
5 #include <functional>
6 #include <memory>
7 #include <mutex>
8 #include <vector>
9 
10 #include "util.hpp"
11 
12 namespace hebi {
13 
14 class LogFile;
15 class GroupCommand;
16 class GroupFeedback;
17 class GroupInfo;
18 
23 using GroupFeedbackHandler = std::function<void(const GroupFeedback&)>;
24 
29 class Group final {
30 private:
35 
39  const int number_of_modules_;
40 
44  std::mutex handler_lock_;
45 
50  std::vector<GroupFeedbackHandler> handlers_;
51 
52 #ifndef DOXYGEN_OMIT_INTERNAL
53 
57  friend void callbackWrapper(HebiGroupFeedbackPtr group_feedback, void* user_data);
58 #endif // DOXYGEN_OMIT_INTERNAL
59 
64  void callAttachedHandlers(HebiGroupFeedbackPtr group_feedback);
65 
66 public:
71  static const int32_t DEFAULT_TIMEOUT_MS = 500;
72 
73 #ifndef DOXYGEN_OMIT_INTERNAL
74 
79  Group(HebiGroupPtr group, float initial_feedback_frequency = 0.0f, int32_t initial_command_lifetime = 0);
80 #endif // DOXYGEN_OMIT_INTERNAL
81 
85  ~Group() noexcept; /* annotating specified destructor as noexcept is best-practice */
86 
90  int size();
91 
102  bool setCommandLifetimeMs(int32_t ms);
103 
115  bool sendCommand(const GroupCommand& group_command);
116 
136  bool sendCommandWithAcknowledgement(const GroupCommand& group_command, int32_t timeout_ms = DEFAULT_TIMEOUT_MS);
137 
149  bool sendFeedbackRequest();
150 
171  bool getNextFeedback(GroupFeedback& feedback, int32_t timeout_ms = DEFAULT_TIMEOUT_MS);
172 
181  bool requestInfo(GroupInfo& info, int32_t timeout_ms = DEFAULT_TIMEOUT_MS);
182 
191  std::string startLog(const std::string& dir);
192 
203  std::string startLog(const std::string& dir, const std::string& file);
204 
211  std::shared_ptr<LogFile> stopLog();
212 
220  bool setFeedbackFrequencyHz(float frequency);
226  float getFeedbackFrequencyHz();
235  void clearFeedbackHandlers();
236 
244  static std::shared_ptr<Group> createImitation(size_t size);
245 
246 private:
251 };
252 
253 } // namespace hebi
hebi::LogFile
Definition: log_file.hpp:11
hebi::Group::sendCommandWithAcknowledgement
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:58
HebiGroupFeedbackPtr
struct HebiGroupFeedback_ * HebiGroupFeedbackPtr
The C-style's API representation of a feedback object for a group of modules.
Definition: hebi.h:476
HebiGroupPtr
struct HebiGroup_ * HebiGroupPtr
The C-style's API representation of a group.
Definition: hebi.h:493
hebi::GroupFeedback
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
Definition: group_feedback.hpp:16
hebi::GroupCommand
A list of Command objects appropriate for sending to a Group of modules; the size() must match the nu...
Definition: group_command.hpp:17
hebi::Group::setFeedbackFrequencyHz
bool setFeedbackFrequencyHz(float frequency)
Sets the frequency of the internal feedback request + callback thread.
Definition: group.cpp:119
hebi::Group::sendCommand
bool sendCommand(const GroupCommand &group_command)
Send a command to the given group without requesting an acknowledgement.
Definition: group.cpp:54
hebi::Group::createImitation
static std::shared_ptr< Group > createImitation(size_t size)
Creates an imitation group of provided size.
Definition: group.cpp:38
HEBI_DISABLE_COPY_MOVE
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:6
hebi::Group::internal_
HebiGroupPtr internal_
Definition: group.hpp:34
hebi::Group::clearFeedbackHandlers
void clearFeedbackHandlers()
Removes all feedback handlers presently added.
Definition: group.cpp:132
hebi::Group::getFeedbackFrequencyHz
float getFeedbackFrequencyHz()
Gets the frequency of the internal feedback request + callback thread.
Definition: group.cpp:123
hebi::GroupFeedbackHandler
std::function< void(const GroupFeedback &)> GroupFeedbackHandler
Definition of a callback function for GroupFeedback returned from a Group of modules.
Definition: group.hpp:23
hebi::Group::DEFAULT_TIMEOUT_MS
static const int32_t DEFAULT_TIMEOUT_MS
The default timeout for any send-with-acknowledgement or request operation is 500 ms.
Definition: group.hpp:71
hebi::Group::requestInfo
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:68
hebi::Group::stopLog
std::shared_ptr< LogFile > stopLog()
Stops any active log.
Definition: group.cpp:110
hebi
Definition: arm.cpp:5
hebi::Group::~Group
~Group() noexcept
Destructor cleans up group.
Definition: group.cpp:42
hebi::GroupInfo
A list of Info objects that can be received from a Group of modules; the size() must match the number...
Definition: group_info.hpp:16
hebi::Group::handlers_
std::vector< GroupFeedbackHandler > handlers_
Definition: group.hpp:50
hebi::Group::getNextFeedback
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:64
hebi::Group::callAttachedHandlers
void callAttachedHandlers(HebiGroupFeedbackPtr group_feedback)
Definition: group.cpp:16
hebi::Group::callbackWrapper
friend void callbackWrapper(HebiGroupFeedbackPtr group_feedback, void *user_data)
Definition: group.cpp:11
hebi::Group::addFeedbackHandler
void addFeedbackHandler(GroupFeedbackHandler handler)
Adds a handler function to be called by the internal feedback request thread.
Definition: group.cpp:125
hebi.h
hebi::Group::handler_lock_
std::mutex handler_lock_
Definition: group.hpp:44
hebi::Group::number_of_modules_
const int number_of_modules_
Definition: group.hpp:39
hebi::Group::setCommandLifetimeMs
bool setCommandLifetimeMs(int32_t ms)
Sets the command lifetime for the modules in this group.
Definition: group.cpp:50
hebi::Group::Group
Group(HebiGroupPtr group, float initial_feedback_frequency=0.0f, int32_t initial_command_lifetime=0)
Definition: group.cpp:30
hebi::Group::size
int size()
Returns the number of modules in the group.
Definition: group.cpp:48
hebi::Group::startLog
std::string startLog(const std::string &dir)
Starts log (stopping any active log).
Definition: group.cpp:72
util.hpp
hebi::Group::sendFeedbackRequest
bool sendFeedbackRequest()
Requests feedback from the group.
Definition: group.cpp:62
hebi::Group
Represents a group of physical HEBI modules, and allows Command, Feedback, and Info objects to be sen...
Definition: group.hpp:29


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Fri Aug 2 2024 08:35:18