actuator_extra_interface.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2021, Qiayuan Liao
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *******************************************************************************/
33 
34 //
35 // Created by qiayuan on 5/14/21.
36 //
37 
38 #pragma once
39 
40 #include <utility>
41 #include <hardware_interface/internal/hardware_resource_manager.h>
42 
43 namespace rm_control
44 {
46 {
47 public:
48  ActuatorExtraHandle() = default;
49  ActuatorExtraHandle(std::string name, bool* halted, bool* need_calibration, bool* calibrated,
50  bool* calibration_reading, double* pos, double* offset)
51  : name_(std::move(name))
52  , halted_(halted)
53  , need_calibration_(need_calibration)
54  , calibrated_(calibrated)
55  , calibration_reading_(calibration_reading)
56  , pos_(pos)
57  , offset_(offset)
58  {
59  if (!halted)
60  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
61  "'. halted pointer is null.");
62  if (!need_calibration)
63  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
64  "'. need_calibration pointer is null.");
65  if (!calibrated)
66  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
67  "'. calibrated pointer is null.");
68  if (!calibration_reading)
69  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
70  "'. calibration reading pointer is null.");
71  if (!pos)
72  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name + "'. pos pointer is null.");
73  if (!offset)
74  throw hardware_interface::HardwareInterfaceException("Cannot create handle '" + name +
75  "'. offset pointer is null.");
76  }
77  std::string getName() const
78  {
79  return name_;
80  }
81  bool getHalted() const
82  {
83  assert(halted_);
84  return *halted_;
85  }
86  bool getNeedCalibration() const
87  {
88  assert(need_calibration_);
89  return *need_calibration_;
90  }
91  bool getCalibrated() const
92  {
93  assert(calibrated_);
94  return *calibrated_;
95  }
96  bool getCalibrationReading() const
97  {
98  assert(calibration_reading_);
99  return *calibration_reading_;
100  }
101  double getPosition() const
102  {
103  assert(pos_);
104  return *pos_;
105  }
106  double getOffset() const
107  {
108  assert(offset_);
109  return *offset_;
110  }
111  void setOffset(double offset)
112  {
113  *offset_ = offset;
114  }
115  void setCalibrated(bool calibrated)
116  {
117  *calibrated_ = calibrated;
118  }
119 
120 private:
121  std::string name_;
122  bool* halted_ = { nullptr };
123  bool* need_calibration_ = { nullptr };
124  bool* calibrated_ = { nullptr };
125  bool* calibration_reading_ = { nullptr };
126  double* pos_{};
127  double* offset_{};
128 };
129 
130 class ActuatorExtraInterface
131  : public hardware_interface::HardwareResourceManager<ActuatorExtraHandle, hardware_interface::ClaimResources>
132 {
133 };
134 
135 } // namespace rm_control
rm_control::ActuatorExtraHandle::calibration_reading_
bool * calibration_reading_
Definition: actuator_extra_interface.h:187
rm_control::ActuatorExtraHandle::need_calibration_
bool * need_calibration_
Definition: actuator_extra_interface.h:185
rm_control::ActuatorExtraHandle::pos_
double * pos_
Definition: actuator_extra_interface.h:188
rm_control::ActuatorExtraHandle::getHalted
bool getHalted() const
Definition: actuator_extra_interface.h:143
rm_control::ActuatorExtraHandle::setOffset
void setOffset(double offset)
Definition: actuator_extra_interface.h:173
rm_control::ActuatorExtraHandle::name_
std::string name_
Definition: actuator_extra_interface.h:183
rm_control::ActuatorExtraHandle::calibrated_
bool * calibrated_
Definition: actuator_extra_interface.h:186
rm_control::ActuatorExtraHandle::offset_
double * offset_
Definition: actuator_extra_interface.h:189
rm_control::ActuatorExtraHandle::getName
std::string getName() const
Definition: actuator_extra_interface.h:139
rm_control
Definition: actuator_extra_interface.h:43
rm_control::ActuatorExtraHandle::getOffset
double getOffset() const
Definition: actuator_extra_interface.h:168
rm_control::ActuatorExtraHandle::getCalibrationReading
bool getCalibrationReading() const
Definition: actuator_extra_interface.h:158
rm_control::ActuatorExtraHandle::getCalibrated
bool getCalibrated() const
Definition: actuator_extra_interface.h:153
rm_control::ActuatorExtraHandle::ActuatorExtraHandle
ActuatorExtraHandle()=default
rm_control::ActuatorExtraHandle::setCalibrated
void setCalibrated(bool calibrated)
Definition: actuator_extra_interface.h:177
rm_control::ActuatorExtraHandle::getNeedCalibration
bool getNeedCalibration() const
Definition: actuator_extra_interface.h:148
rm_control::ActuatorExtraHandle::getPosition
double getPosition() const
Definition: actuator_extra_interface.h:163
rm_control::ActuatorExtraHandle
Definition: actuator_extra_interface.h:76
rm_control::ActuatorExtraHandle::halted_
bool * halted_
Definition: actuator_extra_interface.h:184


rm_common
Author(s):
autogenerated on Sun Apr 6 2025 02:22:01