Skip to content

Commit

Permalink
added joystick as a service
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Jul 10, 2024
1 parent f83631f commit be6b6f4
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
38 changes: 38 additions & 0 deletions demo/compose.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions demo/config/joy2twist.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions demo/net.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion snap/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
50 changes: 50 additions & 0 deletions snap/local/local-ros/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit be6b6f4

Please sign in to comment.