ros2_control - rolling
Loading...
Searching...
No Matches
semantic_component_command_interface.hpp
1// Copyright (c) 2024, Sherpa Mobile Robotics
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_
16#define SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_
17
18#include <string>
19#include <vector>
20
21#include "controller_interface/helpers.hpp"
22#include "hardware_interface/loaned_command_interface.hpp"
23
24namespace semantic_components
25{
26template <typename MessageInputType>
28{
29public:
31 const std::string & name, const std::vector<std::string> & interface_names)
32 : name_(name), interface_names_(interface_names)
33 {
34 assert(interface_names.size() > 0);
35 command_interfaces_.reserve(interface_names.size());
36 }
37
38 virtual ~SemanticComponentCommandInterface() = default;
39
48 std::vector<hardware_interface::LoanedCommandInterface> & command_interfaces)
49 {
50 return controller_interface::get_ordered_interfaces(
51 command_interfaces, interface_names_, "", command_interfaces_);
52 }
53
57 void release_interfaces() { command_interfaces_.clear(); }
58
69 const std::vector<std::string> & get_command_interface_names() const { return interface_names_; }
70
77 bool set_values(const std::vector<double> & values)
78 {
79 // check we have sufficient memory
80 if (values.size() != command_interfaces_.size())
81 {
82 return false;
83 }
84 // set values
85 bool all_set = true;
86 for (auto i = 0u; i < values.size(); ++i)
87 {
88 all_set &= command_interfaces_[i].get().set_value(values[i]);
89 }
90 return all_set;
91 }
92
98 virtual bool set_values_from_message(const MessageInputType & /* message */) = 0;
99
100protected:
101 std::string name_;
102 std::vector<std::string> interface_names_;
103 std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
104 command_interfaces_;
105};
106
107} // namespace semantic_components
108
109#endif // SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_
Definition semantic_component_command_interface.hpp:28
const std::vector< std::string > & get_command_interface_names() const
Definition of command interface names for the component.
Definition semantic_component_command_interface.hpp:69
bool set_values(const std::vector< double > &values)
Return all values.
Definition semantic_component_command_interface.hpp:77
virtual bool set_values_from_message(const MessageInputType &)=0
Set values from MessageInputType.
void release_interfaces()
Release loaned command interfaces from the hardware.
Definition semantic_component_command_interface.hpp:57
bool assign_loaned_command_interfaces(std::vector< hardware_interface::LoanedCommandInterface > &command_interfaces)
Assign loaned command interfaces from the hardware.
Definition semantic_component_command_interface.hpp:47