Aikido
RosJointCommandExecutor-impl.hpp
Go to the documentation of this file.
1 namespace aikido {
2 namespace control {
3 namespace ros {
4 
5 //==============================================================================
6 extern template class RosJointCommandExecutor<ExecutorType::POSITION>;
7 
8 extern template class RosJointCommandExecutor<ExecutorType::VELOCITY>;
9 
10 extern template class RosJointCommandExecutor<ExecutorType::EFFORT>;
11 
12 // Convert Dof List to Joint name List
13 static std::vector<std::string> jointNamesFromDofs(
14  const std::vector<dart::dynamics::DegreeOfFreedom*>& dofs)
15 {
16  std::vector<std::string> jointNames;
17  for (const auto& dof : dofs)
18  {
19  jointNames.push_back(dof->getName());
20  }
21  return jointNames;
22 }
23 
24 //==============================================================================
25 template <ExecutorType T>
27  const ::ros::NodeHandle& node,
28  const std::string& controllerName,
29  const std::vector<dart::dynamics::DegreeOfFreedom*>& dofs,
30  const std::chrono::milliseconds connectionTimeout,
31  const std::chrono::milliseconds connectionPollingPeriod)
32  // Does not update DoF values directly
33  : aikido::control::JointCommandExecutor<T>(
34  dofs, std::set<ExecutorType>{ExecutorType::READONLY})
35  , mClient{
36  node,
37  controllerName + "/joint_group_command",
38  jointNamesFromDofs(dofs),
39  connectionTimeout,
40  connectionPollingPeriod}
41 {
42  // Do nothing
43 }
44 
45 //==============================================================================
46 template <ExecutorType T>
48 {
49  this->stop();
50 }
51 
52 //==============================================================================
53 template <ExecutorType T>
55  const std::vector<double>& command,
56  const std::chrono::duration<double>& timeout,
57  const std::chrono::system_clock::time_point& /* timepoint */)
58 {
59  ::ros::Duration duration;
60  // Rounds to floor(seconds)
61  auto timeoutSecs = std::chrono::duration_cast<std::chrono::seconds>(timeout);
62  duration.sec = timeoutSecs.count();
63  duration.nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(
64  timeout - timeoutSecs)
65  .count();
66  return mClient.execute(T, command, duration);
67 }
68 
69 //==============================================================================
70 template <ExecutorType T>
72  const std::chrono::system_clock::time_point& /* timepoint */)
73 {
74  mClient.step();
75 }
76 
77 //==============================================================================
78 template <ExecutorType T>
80 {
81  mClient.cancel();
82 }
83 
84 } // namespace ros
85 } // namespace control
86 } // namespace aikido
aikido::control::JointCommandExecutor
Abstract class for executing a command of a single type on a group of joints.
Definition: JointCommandExecutor.hpp:21
aikido::control::ros::RosJointCommandExecutor::cancel
void cancel() override
Cancels the current command.
Definition: RosJointCommandExecutor-impl.hpp:79
aikido::control::ros::RosJointCommandExecutor::step
void step(const std::chrono::system_clock::time_point &timepoint) override
Step to a point in time.
Definition: RosJointCommandExecutor-impl.hpp:71
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::control::ExecutorType::READONLY
@ READONLY
aikido::control::ros::RosJointCommandExecutor::RosJointCommandExecutor
RosJointCommandExecutor(const ::ros::NodeHandle &node, const std::string &controllerName, const std::vector< dart::dynamics::DegreeOfFreedom * > &dofs, std::chrono::milliseconds connectionTimeout=std::chrono::milliseconds{DEFAULT_CON_TIMEOUT_MS}, std::chrono::milliseconds connectionPollingPeriod=std::chrono::milliseconds{DEFAULT_POLL_PERIOD_MS})
Constructor.
Definition: RosJointCommandExecutor-impl.hpp:26
aikido::control::ros::RosJointCommandExecutor::execute
std::future< int > execute(const std::vector< double > &command, const std::chrono::duration< double > &timeout, const std::chrono::system_clock::time_point &timepoint) override
Execute a Joint Command, setting future upon completion.
Definition: RosJointCommandExecutor-impl.hpp:54
aikido::control::ExecutorType
ExecutorType
Type of executor Can be used to determine if 2 executors make conflicting demands of individual degre...
Definition: Executor.hpp:35
aikido::control::ros::jointNamesFromDofs
static std::vector< std::string > jointNamesFromDofs(const std::vector< dart::dynamics::DegreeOfFreedom * > &dofs)
Definition: RosJointCommandExecutor-impl.hpp:13
aikido::control::ros::RosJointCommandExecutor::~RosJointCommandExecutor
virtual ~RosJointCommandExecutor()
Definition: RosJointCommandExecutor-impl.hpp:47