rm_control
Loading...
Searching...
No Matches
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
43namespace rm_control
44{
46{
47public:
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 }
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
120private:
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
131 : public hardware_interface::HardwareResourceManager<ActuatorExtraHandle, hardware_interface::ClaimResources>
132{
133};
134
135} // namespace rm_control
Definition actuator_extra_interface.h:46
ActuatorExtraHandle(std::string name, bool *halted, bool *need_calibration, bool *calibrated, bool *calibration_reading, double *pos, double *offset)
Definition actuator_extra_interface.h:49
std::string getName() const
Definition actuator_extra_interface.h:77
void setCalibrated(bool calibrated)
Definition actuator_extra_interface.h:115
bool getHalted() const
Definition actuator_extra_interface.h:81
bool getCalibrationReading() const
Definition actuator_extra_interface.h:96
bool getNeedCalibration() const
Definition actuator_extra_interface.h:86
bool getCalibrated() const
Definition actuator_extra_interface.h:91
double getPosition() const
Definition actuator_extra_interface.h:101
void setOffset(double offset)
Definition actuator_extra_interface.h:111
double getOffset() const
Definition actuator_extra_interface.h:106
Definition actuator_extra_interface.h:132
Definition actuator_extra_interface.h:44