Skip to content

Commit fb3c074

Browse files
committed
export_interfaces_2() virtual for custom interface export
1 parent 3232114 commit fb3c074

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
@@ -181,6 +181,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
181181
return {};
182182
}
183183

184+
/**
185+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
186+
*
187+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
188+
* version is removed.
189+
*
190+
* \return vector of shared pointers to the created and stored StateInterfaces
191+
*/
192+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
193+
{
194+
// return empty vector by default.
195+
return {};
196+
}
197+
184198
/**
185199
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
186200
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -190,7 +204,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
190204
*/
191205
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
192206
{
193-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
207+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
194208
state_interfaces.reserve(joint_state_interfaces_.size());
195209

196210
for (const auto & [name, descr] : joint_state_interfaces_)
@@ -226,6 +240,20 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
226240
return {};
227241
}
228242

243+
/**
244+
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
245+
*
246+
* Note method name is going to be changed to export_command_interfaces() as soon as the
247+
* deprecated version is removed.
248+
*
249+
* \return vector of shared pointers to the created and stored StateInterfaces
250+
*/
251+
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
252+
{
253+
// return empty vector by default.
254+
return {};
255+
}
256+
229257
/**
230258
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
231259
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -235,7 +263,8 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
235263
*/
236264
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
237265
{
238-
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
266+
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
267+
export_command_interfaces_2();
239268
command_interfaces.reserve(joint_command_interfaces_.size());
240269

241270
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
@@ -40,9 +40,9 @@ struct InterfaceInfo
4040
std::string max;
4141
/// (Optional) Initial value of the interface.
4242
std::string initial_value;
43-
/// (Optional) The datatype of the interface, e.g. "bool", "int". Used by GPIOs.
43+
/// (Optional) The datatype of the interface, e.g. "bool", "int".
4444
std::string data_type;
45-
/// (Optional) If the handle is an array, the size of the array. Used by GPIOs.
45+
/// (Optional) If the handle is an array, the size of the array.
4646
int size;
4747
/// (Optional) enable or disable the limits for the command interfaces
4848
bool enable_limits;
@@ -142,11 +142,6 @@ struct InterfaceDescription
142142
*/
143143
std::string prefix_name;
144144

145-
/**
146-
* What type of component is exported: joint, sensor or gpio
147-
*/
148-
std::string component_type;
149-
150145
/**
151146
* Information about the Interface type (position, velocity,...) as well as limits and so on.
152147
*/

hardware_interface/include/hardware_interface/sensor_interface.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
165165
return {};
166166
}
167167

168+
/**
169+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
170+
*
171+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
172+
* version is removed.
173+
*
174+
* \return vector of shared pointers to the created and stored StateInterfaces
175+
*/
176+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
177+
{
178+
// return empty vector by default.
179+
return {};
180+
}
181+
168182
/**
169183
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
170184
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
@@ -174,7 +188,7 @@ class SensorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
174188
*/
175189
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
176190
{
177-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
191+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
178192
state_interfaces.reserve(sensor_state_interfaces_.size());
179193

180194
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
@@ -200,16 +200,30 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
200200
return {};
201201
}
202202

203+
/**
204+
* Override this method to export custom StateInterfaces which are not defined in the URDF file.
205+
*
206+
* Note method name is going to be changed to export_state_interfaces() as soon as the deprecated
207+
* version is removed.
208+
*
209+
* \return vector of shared pointers to the created and stored StateInterfaces
210+
*/
211+
virtual std::vector<std::shared_ptr<StateInterface>> export_state_interfaces_2()
212+
{
213+
// return empty vector by default.
214+
return {};
215+
}
216+
203217
/**
204218
* Default implementation for exporting the StateInterfaces. The StateInterfaces are created
205219
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
206220
* assigned here and resides in the system_interface.
207221
*
208222
* \return vector of shared pointers to the created and stored StateInterfaces
209223
*/
210-
virtual std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
224+
std::vector<std::shared_ptr<StateInterface>> on_export_state_interfaces()
211225
{
212-
std::vector<std::shared_ptr<StateInterface>> state_interfaces;
226+
std::vector<std::shared_ptr<StateInterface>> state_interfaces = export_state_interfaces_2();
213227
state_interfaces.reserve(
214228
joint_state_interfaces_.size() + sensor_state_interfaces_.size() +
215229
gpio_state_interfaces_.size());
@@ -259,16 +273,31 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
259273
return {};
260274
}
261275

276+
/**
277+
* Override this method to export custom CommandInterfaces which are not defined in the URDF file.
278+
*
279+
* Note method name is going to be changed to export_command_interfaces() as soon as the
280+
* deprecated version is removed.
281+
*
282+
* \return vector of shared pointers to the created and stored StateInterfaces
283+
*/
284+
virtual std::vector<std::shared_ptr<CommandInterface>> export_command_interfaces_2()
285+
{
286+
// return empty vector by default.
287+
return {};
288+
}
289+
262290
/**
263291
* Default implementation for exporting the CommandInterfaces. The CommandInterfaces are created
264292
* according to the InterfaceDescription. The memory accessed by the controllers and hardware is
265293
* assigned here and resides in the system_interface.
266294
*
267295
* \return vector of shared pointers to the created and stored CommandInterfaces
268296
*/
269-
virtual std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
297+
std::vector<std::shared_ptr<CommandInterface>> on_export_command_interfaces()
270298
{
271-
std::vector<std::shared_ptr<CommandInterface>> command_interfaces;
299+
std::vector<std::shared_ptr<CommandInterface>> command_interfaces =
300+
export_command_interfaces_2();
272301
command_interfaces.reserve(joint_command_interfaces_.size() + gpio_command_interfaces_.size());
273302

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

0 commit comments

Comments
 (0)