Skip to content

Commit 5e4118b

Browse files
committed
export_interfaces_2() virtual for custom interface export
1 parent a7db21d commit 5e4118b

File tree

6 files changed

+281
-79
lines changed

6 files changed

+281
-79
lines changed

hardware_interface/include/hardware_interface/actuator_interface.hpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
159159
return {};
160160
}
161161

162+
/**
163+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
164+
*
165+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
166+
* version is removed.
167+
*
168+
* \return vector of shared pointers to the created and stored StateInterfaces
169+
*/
170+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
171+
{
172+
// return empty vector by default.
173+
return {};
174+
}
175+
162176
/**
163177
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
164178
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -168,7 +182,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
168182
*/
169183
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
170184
{
171-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
185+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
172186
state_interfaces.reserve(joint_state_interfaces_.size());
173187

174188
for (const auto & [name, descr] : joint_state_interfaces_)
@@ -204,6 +218,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
204218
return {};
205219
}
206220

221+
/**
222+
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
223+
*
224+
* Note method name is going to be changed to export_command_interfaces() as soon as the
225+
* deprecated version is removed.
226+
*
227+
* \return vector of shared pointers to the created and stored StateInterfaces
228+
*/
229+
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
230+
{
231+
// return empty vector by default.
232+
return {};
233+
}
234+
207235
/**
208236
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
209237
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -213,7 +241,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
213241
*/
214242
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
215243
{
216-
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
244+
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
245+
export_command_interfaces_2();
217246
command_interfaces.reserve(joint_command_interfaces_.size());
218247

219248
for (const auto & [name, descr] : joint_command_interfaces_)

hardware_interface/include/hardware_interface/hardware_info.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ struct InterfaceInfo
3838
std::string max;
3939
/// (Optional) Initial value of the interface.
4040
std::string initial_value;
41-
/// (Optional) The datatype of the interface, e.g. "bool", "int". Used by GPIOs.
41+
/// (Optional) The datatype of the interface, e.g. "bool", "int".
4242
std::string data_type;
43-
/// (Optional) If the handle is an array, the size of the array. Used by GPIOs.
43+
/// (Optional) If the handle is an array, the size of the array.
4444
int size;
4545
};
4646

@@ -118,11 +118,6 @@ struct InterfaceDescription
118118
*/
119119
std::string prefix_name;
120120

121-
/**
122-
* What type of component is exported: joint, sensor or gpio
123-
*/
124-
std::string component_type;
125-
126121
/**
127122
* Information about the Interface type (position, velocity,...) as well as limits and so on.
128123
*/

hardware_interface/include/hardware_interface/sensor_interface.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
143143
return {};
144144
}
145145

146+
/**
147+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
148+
*
149+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
150+
* version is removed.
151+
*
152+
* \return vector of shared pointers to the created and stored StateInterfaces
153+
*/
154+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
155+
{
156+
// return empty vector by default.
157+
return {};
158+
}
159+
146160
/**
147161
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
148162
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -152,7 +166,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
152166
*/
153167
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
154168
{
155-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
169+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
156170
state_interfaces.reserve(sensor_state_interfaces_.size());
157171

158172
for (const auto & [name, descr] : sensor_state_interfaces_)

hardware_interface/include/hardware_interface/system_interface.hpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,30 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
178178
return {};
179179
}
180180

181+
/**
182+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
183+
*
184+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
185+
* version is removed.
186+
*
187+
* \return vector of shared pointers to the created and stored StateInterfaces
188+
*/
189+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
190+
{
191+
// return empty vector by default.
192+
return {};
193+
}
194+
181195
/**
182196
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
183197
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
184198
* assigned here and resides in the system_interface.
185199
*
186200
* \return vector of shared pointers to the created and stored StateInterfaces
187201
*/
188-
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
202+
std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
189203
{
190-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
204+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
191205
state_interfaces.reserve(
192206
joint_state_interfaces_.size() + sensor_state_interfaces_.size() +
193207
gpio_state_interfaces_.size());
@@ -237,16 +251,31 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
237251
return {};
238252
}
239253

254+
/**
255+
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
256+
*
257+
* Note method name is going to be changed to export_command_interfaces() as soon as the
258+
* deprecated version is removed.
259+
*
260+
* \return vector of shared pointers to the created and stored StateInterfaces
261+
*/
262+
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
263+
{
264+
// return empty vector by default.
265+
return {};
266+
}
267+
240268
/**
241269
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
242270
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
243271
* assigned here and resides in the system_interface.
244272
*
245273
* \return vector of shared pointers to the created and stored CommandInterfaces
246274
*/
247-
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
275+
std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
248276
{
249-
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
277+
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
278+
export_command_interfaces_2();
250279
command_interfaces.reserve(joint_command_interfaces_.size() + gpio_command_interfaces_.size());
251280

252281
for (const auto & [name, descr] : joint_command_interfaces_)

0 commit comments

Comments
 (0)