From be6b6f4c95992b42c55d5333be8d035a98b04ed1 Mon Sep 17 00:00:00 2001 From: dominikn Date: Wed, 10 Jul 2024 14:15:09 +0000 Subject: [PATCH] added joystick as a service --- demo/compose.yaml | 38 ++++++++++++++++++++++++++ demo/config/joy2twist.yaml | 22 +++++++++++++++ demo/net.env | 18 +++++++++++++ snap/hooks/configure | 2 +- snap/local/local-ros/utils.sh | 50 +++++++++++++++++++++++++++++++++++ snap/snapcraft.yaml | 2 ++ 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 demo/compose.yaml create mode 100644 demo/config/joy2twist.yaml create mode 100644 demo/net.env diff --git a/demo/compose.yaml b/demo/compose.yaml new file mode 100644 index 0000000..6cd9d00 --- /dev/null +++ b/demo/compose.yaml @@ -0,0 +1,38 @@ +# Usage: +# xhost +local:docker && docker compose up + +x-net-config: + &net-config + network_mode: host + ipc: host + env_file: net.env + +x-gpu-config: + &gpu-config + runtime: nvidia + environment: + - DISPLAY=${DISPLAY:?err} + - NVIDIA_VISIBLE_DEVICES=all + - NVIDIA_DRIVER_CAPABILITIES=all + +services: + rviz: + # Launching rviz with moveit2 requires all the configs, using manipulation simulation image is easiest option + image: husarion/rosbot-xl-manipulation-gazebo:humble + <<: [ *net-config, *gpu-config ] + container_name: rviz + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix:rw + - ./config/rosbot_xl.rviz:/ros2_ws/install/rosbot_xl_manipulation_moveit/share/rosbot_xl_manipulation_moveit/config/moveit.rviz + command: ros2 launch rosbot_xl_manipulation_moveit rviz.launch.py + + joy2twist: + image: husarion/joy2twist:humble-1.0.0-20230204-stable + <<: *net-config + devices: + - /dev/input + volumes: + - ./config/joy2twist.yaml:/joy2twist.yaml + command: > + ros2 launch joy2twist gamepad_controller.launch.py + joy2twist_params_file:=/joy2twist.yaml \ No newline at end of file diff --git a/demo/config/joy2twist.yaml b/demo/config/joy2twist.yaml new file mode 100644 index 0000000..4806940 --- /dev/null +++ b/demo/config/joy2twist.yaml @@ -0,0 +1,22 @@ +/**: + ros__parameters: + linear_velocity_factor: + fast: 1.0 + regular: 0.5 + slow: 0.2 + + angular_velocity_factor: + fast: 1.5 + regular: 0.8 + slow: 0.4 + + # This button mapping should be adjusted to the specific controller + # The following map is suited for Logitech F710 + button_index_map: + axis: + angular_z: 2 # Right joystick + linear_x: 1 # Left joystick + linear_y: 0 # Left joystick + dead_man_switch: 4 # LB + fast_mode: 7 # RT + slow_mode: 5 # RB diff --git a/demo/net.env b/demo/net.env new file mode 100644 index 0000000..a498c9c --- /dev/null +++ b/demo/net.env @@ -0,0 +1,18 @@ +# ======================================= +# Network config options (uncomment one) +# ======================================= + +# 1. Fast DDS + LAN +# RMW_IMPLEMENTATION=rmw_fastrtps_cpp + +# 2. Cyclone DDS + LAN +RMW_IMPLEMENTATION=rmw_cyclonedds_cpp + +# 3. Fast DDS + VPN +# RMW_IMPLEMENTATION=rmw_fastrtps_cpp +# FASTRTPS_DEFAULT_PROFILES_FILE=/husarnet-fastdds.xml + +# 4. Cyclone DDS + VPN +# RMW_IMPLEMENTATION=rmw_cyclonedds_cpp +# FASTRTPS_DEFAULT_PROFILES_FILE=/husarnet-fastdds.xml +# CYCLONEDDS_URI=file:///husarnet-cyclonedds.xml \ No newline at end of file diff --git a/snap/hooks/configure b/snap/hooks/configure index 0917d99..5425f40 100644 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -65,7 +65,7 @@ fi $SNAP/usr/bin/configure_hook_ros.sh # restart services with new ROS 2 config -for service in daemon web-ui web-ws; do +for service in daemon web-ui web-ws joy; do if snapctl services ${SNAP_NAME}.${service} | grep -qw enabled; then snapctl restart ${SNAP_NAME}.${service} log "Restarted ${SNAP_NAME}.${service}" diff --git a/snap/local/local-ros/utils.sh b/snap/local/local-ros/utils.sh index 672876f..7f05342 100755 --- a/snap/local/local-ros/utils.sh +++ b/snap/local/local-ros/utils.sh @@ -117,7 +117,57 @@ validate_number() { fi } +validate_regex() { + local value_key=$1 + local regex=$2 + local error_message=$3 + + # Get the value using snapctl + local value=$(snapctl get "$value_key") + + # Check if the value matches the regex + if ! [[ "$value" =~ $regex ]]; then + log_and_echo "'${value}' is not a supported value for '${value_key}'. ${error_message}" + exit 1 + fi +} + +validate_path() { + local value_key=$1 + + # Get the value using snapctl + local config_path=$(snapctl get "$value_key") + + # Check if the path is a valid file + if [ ! -f "$config_path" ]; then + log_and_echo "The path specified in '$value_key' does not exist: '$config_path'." + exit 1 + fi +} + +validate_ipv4_addr() { + local value_key=$1 + + # Get the value using snapctl + local ip_address=$(snapctl get "$value_key") + local ip_address_regex='^(([0-9]{1,3}\.){3}[0-9]{1,3})$' + + if [[ "$ip_address" =~ $ip_address_regex ]]; then + # Split the IP address into its parts + IFS='.' read -r -a octets <<< "$ip_address" + # Check each octet + for octet in "${octets[@]}"; do + if ((octet < 0 || octet > 255)); then + log_and_echo "Invalid format for '$value_key'. Each part of the IPv4 address must be between 0 and 255. Received: '$ip_address'." + exit 1 + fi + done + else + log_and_echo "Invalid format for '$value_key'. Expected format: a valid IPv4 address. Received: '$ip_address'." + exit 1 + fi +} # Universal function to validate serial ports validate_serial_port() { diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index b33ba9f..9d39ba8 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -172,6 +172,8 @@ apps: joy: command: usr/bin/joy_launcher.sh command-chain: [usr/bin/ros_setup.sh] + daemon: simple + install-mode: disable environment: LD_LIBRARY_PATH: "$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio:$LD_LIBRARY_PATH" plugs: [hardware-observe, joystick, network, network-bind, shm-plug]