ros2_control - jazzy
Loading...
Searching...
No Matches
led_rgb_device.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__LED_RGB_DEVICE_HPP_
16#define SEMANTIC_COMPONENTS__LED_RGB_DEVICE_HPP_
17
18#include <string>
19#include <vector>
20
21#include "semantic_components/semantic_component_command_interface.hpp"
22#include "std_msgs/msg/color_rgba.hpp"
23
24namespace semantic_components
25{
26class LedRgbDevice : public SemanticComponentCommandInterface<std_msgs::msg::ColorRGBA>
27{
28public:
39 explicit LedRgbDevice(
40 const std::string & name, const std::string & interface_r, const std::string & interface_g,
41 const std::string & interface_b)
43 name, {{name + "/" + interface_r}, {name + "/" + interface_g}, {name + "/" + interface_b}})
44 {
45 }
46
48
59 bool set_values_from_message(const std_msgs::msg::ColorRGBA & message) override
60 {
61 if (
62 message.r < 0 || message.r > 1 || message.g < 0 || message.g > 1 || message.b < 0 ||
63 message.b > 1)
64 {
65 return false;
66 }
67 bool all_set = true;
68 all_set &= command_interfaces_[0].get().set_value(static_cast<double>(message.r));
69 all_set &= command_interfaces_[1].get().set_value(static_cast<double>(message.g));
70 all_set &= command_interfaces_[2].get().set_value(static_cast<double>(message.b));
71 return all_set;
72 }
73};
74
75} // namespace semantic_components
76
77#endif // SEMANTIC_COMPONENTS__LED_RGB_DEVICE_HPP_
Definition led_rgb_device.hpp:27
bool set_values_from_message(const std_msgs::msg::ColorRGBA &message) override
Set LED states from ColorRGBA message.
Definition led_rgb_device.hpp:59
LedRgbDevice(const std::string &name, const std::string &interface_r, const std::string &interface_g, const std::string &interface_b)
Definition led_rgb_device.hpp:39
Definition semantic_component_command_interface.hpp:28