-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/async/controller/deactivation
- Loading branch information
Showing
63 changed files
with
899 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
controller_interface/include/semantic_components/led_rgb_device.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) 2024, Sherpa Mobile Robotics | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef SEMANTIC_COMPONENTS__LED_RGB_DEVICE_HPP_ | ||
#define SEMANTIC_COMPONENTS__LED_RGB_DEVICE_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "semantic_components/semantic_component_command_interface.hpp" | ||
#include "std_msgs/msg/color_rgba.hpp" | ||
|
||
namespace semantic_components | ||
{ | ||
class LedRgbDevice : public SemanticComponentCommandInterface<std_msgs::msg::ColorRGBA> | ||
{ | ||
public: | ||
/** | ||
* Constructor for a LED RGB device with interface names set based on device name. | ||
* The constructor sets the command interface names to "<name>/interface_r", | ||
* "<name>/interface_g", "<name>/interface_b". | ||
* | ||
* \param[in] name name of the LED device, used as a prefix for the command interface names | ||
* \param[in] interface_r name of the command interface for the red channel | ||
* \param[in] interface_g name of the command interface for the green channel | ||
* \param[in] interface_b name of the command interface for the blue channel | ||
*/ | ||
explicit LedRgbDevice( | ||
const std::string & name, const std::string & interface_r, const std::string & interface_g, | ||
const std::string & interface_b) | ||
: SemanticComponentCommandInterface( | ||
name, {{name + "/" + interface_r}, {name + "/" + interface_g}, {name + "/" + interface_b}}) | ||
{ | ||
} | ||
|
||
/// Set LED states from ColorRGBA message | ||
|
||
/** | ||
* Set the values of the LED RGB device from a ColorRGBA message. | ||
* | ||
* \details Sets the values of the red, green, and blue channels from the message. | ||
* If any of the values are out of the range [0, 1], the function fails and returns false. | ||
* | ||
* \param[in] message ColorRGBA message | ||
* | ||
* \return true if all values were set, false otherwise | ||
*/ | ||
bool set_values_from_message(const std_msgs::msg::ColorRGBA & message) override | ||
{ | ||
if ( | ||
message.r < 0 || message.r > 1 || message.g < 0 || message.g > 1 || message.b < 0 || | ||
message.b > 1) | ||
{ | ||
return false; | ||
} | ||
bool all_set = true; | ||
all_set &= command_interfaces_[0].get().set_value(message.r); | ||
all_set &= command_interfaces_[1].get().set_value(message.g); | ||
all_set &= command_interfaces_[2].get().set_value(message.b); | ||
return all_set; | ||
} | ||
}; | ||
|
||
} // namespace semantic_components | ||
|
||
#endif // SEMANTIC_COMPONENTS__LED_RGB_DEVICE_HPP_ |
103 changes: 103 additions & 0 deletions
103
controller_interface/include/semantic_components/semantic_component_command_interface.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2024, Sherpa Mobile Robotics | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_ | ||
#define SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "controller_interface/helpers.hpp" | ||
#include "hardware_interface/loaned_command_interface.hpp" | ||
|
||
namespace semantic_components | ||
{ | ||
template <typename MessageInputType> | ||
class SemanticComponentCommandInterface | ||
{ | ||
public: | ||
SemanticComponentCommandInterface( | ||
const std::string & name, const std::vector<std::string> & interface_names) | ||
: name_(name), interface_names_(interface_names) | ||
{ | ||
assert(interface_names.size() > 0); | ||
command_interfaces_.reserve(interface_names.size()); | ||
} | ||
|
||
virtual ~SemanticComponentCommandInterface() = default; | ||
|
||
/// Assign loaned command interfaces from the hardware. | ||
/** | ||
* Assign loaned command interfaces on the controller start. | ||
* | ||
* \param[in] command_interfaces vector of command interfaces provided by the controller. | ||
*/ | ||
bool assign_loaned_command_interfaces( | ||
std::vector<hardware_interface::LoanedCommandInterface> & command_interfaces) | ||
{ | ||
return controller_interface::get_ordered_interfaces( | ||
command_interfaces, interface_names_, "", command_interfaces_); | ||
} | ||
|
||
/// Release loaned command interfaces from the hardware. | ||
void release_interfaces() { command_interfaces_.clear(); } | ||
|
||
/// Definition of command interface names for the component. | ||
/** | ||
* The function should be used in "command_interface_configuration()" of a controller to provide | ||
* standardized command interface names semantic component. | ||
* | ||
* \default Default implementation defined command interfaces as "name/NR" where NR is number | ||
* from 0 to size of values; | ||
* \return list of strings with command interface names for the semantic component. | ||
*/ | ||
const std::vector<std::string> & get_command_interface_names() const { return interface_names_; } | ||
|
||
/// Return all values. | ||
/** | ||
* \return true if it gets all the values, else false (i.e., invalid size or if the method | ||
* ``hardware_interface::LoanedCommandInterface::set_value`` fails). | ||
*/ | ||
bool set_values(const std::vector<double> & values) | ||
{ | ||
// check we have sufficient memory | ||
if (values.size() != command_interfaces_.size()) | ||
{ | ||
return false; | ||
} | ||
// set values | ||
bool all_set = true; | ||
for (auto i = 0u; i < values.size(); ++i) | ||
{ | ||
all_set &= command_interfaces_[i].get().set_value(values[i]); | ||
} | ||
return all_set; | ||
} | ||
|
||
/// Set values from MessageInputType | ||
/** | ||
* \return True if all values were set successfully, false otherwise. | ||
*/ | ||
virtual bool set_values_from_message(const MessageInputType & /* message */) = 0; | ||
|
||
protected: | ||
std::string name_; | ||
std::vector<std::string> interface_names_; | ||
std::vector<std::reference_wrapper<hardware_interface::LoanedCommandInterface>> | ||
command_interfaces_; | ||
}; | ||
|
||
} // namespace semantic_components | ||
|
||
#endif // SEMANTIC_COMPONENTS__SEMANTIC_COMPONENT_COMMAND_INTERFACE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="2"> | ||
<name>controller_interface</name> | ||
<version>4.24.0</version> | ||
<version>4.26.0</version> | ||
<description>Description of controller_interface</description> | ||
<maintainer email="[email protected]">Bence Magyar</maintainer> | ||
<maintainer email="[email protected]">Denis Štogl</maintainer> | ||
|
Oops, something went wrong.