SMACC2
Loading...
Searching...
No Matches
cb_relay_on.hpp
Go to the documentation of this file.
1// Copyright 2024 RobosoftAI Inc.
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/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
25
26namespace cl_modbus_tcp_relay
27{
28
35{
36public:
41 explicit CbRelayOn(int channel) : channel_(channel) {}
42
43 virtual ~CbRelayOn() {}
44
45 template <typename TOrthogonal, typename TSourceObject>
53
54 virtual void onEntry() override
55 {
56 RCLCPP_INFO(getLogger(), "[CbRelayOn] Turning ON channel %d", channel_);
57
58 if (!relayComponent_)
59 {
60 RCLCPP_ERROR(getLogger(), "[CbRelayOn] Relay component not available");
61 this->postFailureEvent();
62 return;
63 }
64
65 bool success = relayComponent_->writeCoil(channel_, true);
66
67 if (success)
68 {
69 RCLCPP_INFO(getLogger(), "[CbRelayOn] Channel %d turned ON successfully", channel_);
70 this->postSuccessEvent();
71 }
72 else
73 {
74 RCLCPP_ERROR(getLogger(), "[CbRelayOn] Failed to turn ON channel %d", channel_);
75 this->postFailureEvent();
76 }
77 }
78
79private:
83};
84
85} // namespace cl_modbus_tcp_relay
Client behavior to turn ON a specific relay channel.
virtual void onEntry() override
CbRelayOn(int channel)
Construct behavior to turn on specified channel.
SMACC2 Client for controlling Modbus TCP relays.
Component that handles Modbus coil read/write operations for 8-channel relay.
bool writeCoil(int channel, bool state)
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)