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
41
47 std::vector<hardware_interface::LoanedCommandInterface> & command_interfaces)
48 {
49 return controller_interface::get_ordered_interfaces(
50 command_interfaces, interface_names_, "", command_interfaces_);
51 }
52
54 void release_interfaces() { command_interfaces_.clear(); }
55
57
65 const std::vector<std::string> & get_command_interface_names() const { return interface_names_; }
66
68
72 bool set_values(const std::vector<double> & values)
73 {
74 // check we have sufficient memory
75 if (values.size() != command_interfaces_.size())
76 {
77 return false;
78 }
79 // set values
80 bool all_set = true;
81 for (auto i = 0u; i < values.size(); ++i)
82 {
83 all_set &= command_interfaces_[i].get().set_value(values[i]);
84 }
85 return all_set;
86 }
87
89
92 virtual bool set_values_from_message(const MessageInputType & /* message */) = 0;
93
94protected:
95 std::string name_;
96 std::vector<std::string> interface_names_;
97 std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>>
98 command_interfaces_;
99};
100
101} // namespace semantic_components
102
103#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:65
bool set_values(const std::vector< double > &values)
Return all values.
Definition semantic_component_command_interface.hpp:72
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:54
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:46