Skip to content

Commit 798c9ca

Browse files
committed
Build spacenav_device along with main project
1 parent c184329 commit 798c9ca

File tree

5 files changed

+398
-384
lines changed

5 files changed

+398
-384
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
path: .deps/swig
8484

8585
- name: Install dependencies via apt
86-
run: apt-get update && apt-get install -qq ccache make ${{matrix.system.compiler.apt}} libeigen3-dev bison googletest
86+
run: apt-get update && apt-get install -qq ccache make ${{matrix.system.compiler.apt}} libeigen3-dev bison ros-${{matrix.system.ros}}-tf2 ros-${{matrix.system.ros}}-tf2-geometry-msgs googletest
8787

8888
- name: Set up CMake
8989
uses: jwlawson/actions-setup-cmake@v2

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ add_subdirectory(bindings)
6868
add_subdirectory(doc)
6969
add_subdirectory(examples/cpp)
7070

71+
# ROS workspace.
72+
cmake_dependent_option(ENABLE_ros2_ws_spacenav_device "Enable/disable spacenav_device ROS 2 package" ON
73+
rclcpp_FOUND OFF)
74+
75+
if(ENABLE_ros2_ws_spacenav_device)
76+
add_subdirectory(ros2_ws/src/spacenav_device)
77+
endif()
78+
7179
# Collect public exported dependencies.
7280
get_property(_exported_dependencies GLOBAL PROPERTY _exported_dependencies)
7381

ros2_ws/src/spacenav_device/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ find_package(geometry_msgs REQUIRED)
2222
find_package(tf2 REQUIRED)
2323
find_package(tf2_geometry_msgs REQUIRED)
2424

25+
if(NOT TARGET ROBOTICSLAB::KinematicsDynamicsInterfaces)
26+
find_package(ROBOTICSLAB_KINEMATICS_DYNAMICS REQUIRED)
27+
endif()
28+
2529
add_executable(spacenav_device src/spacenav_device.cpp)
2630

31+
target_link_libraries(spacenav_device ROBOTICSLAB::KinematicsDynamicsInterfaces)
32+
2733
ament_target_dependencies(spacenav_device rclcpp std_msgs sensor_msgs geometry_msgs tf2 tf2_geometry_msgs)
2834

2935
install(TARGETS
3036
spacenav_device
3137
DESTINATION lib/${PROJECT_NAME})
3238

3339
ament_package()
34-
35-

ros2_ws/src/spacenav_device/include/spacenav_device.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <string>
55
#include <mutex>
66

7-
#include <ICartesianControl.h>
8-
97
#include <rclcpp/rclcpp.hpp>
108

119
#include <geometry_msgs/msg/twist.hpp>
@@ -20,27 +18,33 @@
2018
#include <tf2/LinearMath/Quaternion.h>
2119
#include <tf2/LinearMath/Vector3.h>
2220

21+
#include <ICartesianControl.h>
22+
2323
using SetParameters = rcl_interfaces::srv::SetParameters;
2424
using Parameter = rcl_interfaces::msg::Parameter;
2525
using ParameterValue = rcl_interfaces::msg::ParameterValue;
2626
using SetParametersResult = rcl_interfaces::msg::SetParametersResult;
2727

28+
/**
29+
* @ingroup kinematics-dynamics-programs
30+
* @defgroup SpacenavSubscriber SpacenavSubscriber
31+
* @brief Creates an instance of SpacenavSubscriber.
32+
*/
2833
class SpacenavSubscriber : public rclcpp::Node
2934
{
3035
public:
3136
SpacenavSubscriber();
32-
~SpacenavSubscriber();
3337

3438
private:
3539
void spnav_callback(const sensor_msgs::msg::Joy::SharedPtr msg);
3640
void state_callback(const geometry_msgs::msg::PoseStamped::SharedPtr msg);
37-
bool set_preset_streaming_cmd(const std::string &value);
41+
bool set_preset_streaming_cmd(const std::string &value);
3842
SetParametersResult parameter_callback(const std::vector<rclcpp::Parameter> &parameters);
3943
void timer_callback();
4044

4145
rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr subscription_spnav_{nullptr};
4246
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr subscription_state_pose_{nullptr};
43-
47+
4448
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher_spnav_twist_{nullptr};
4549
rclcpp::Publisher<geometry_msgs::msg::Pose>::SharedPtr publisher_spnav_pose_{nullptr};
4650
rclcpp::Publisher<geometry_msgs::msg::Wrench>::SharedPtr publisher_spnav_wrench_{nullptr};
@@ -75,6 +79,4 @@ class SpacenavSubscriber : public rclcpp::Node
7579
/*Notice that order of gripper_state enum values matches the same order from CartesianControlServerROS2. If modify, please, update*/
7680
enum gripper_state { GRIPPER_NONE, GRIPPER_OPEN, GRIPPER_CLOSE, GRIPPER_STOP };
7781
gripper_state gripper_state_{GRIPPER_NONE};
78-
7982
};
80-

0 commit comments

Comments
 (0)