Skip to content

Commit

Permalink
Joystick teleop works now.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisl8 committed Oct 17, 2024
1 parent 6f97749 commit 01fea19
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 80 deletions.
17 changes: 0 additions & 17 deletions arlobot_ros/launch/keyboard_teleop.launch.py

This file was deleted.

4 changes: 0 additions & 4 deletions arlobot_ros/launch/robot.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def generate_launch_description():
name='scanTopicSource',
default_value=os.environ.get('SCAN_TOPIC_SOURCE', 'rplidar')
),
launch.actions.DeclareLaunchArgument(
name='loadJoystick',
default_value=os.environ.get('HAS_XBOX_JOYSTICK', 'false')
),
launch.actions.DeclareLaunchArgument(
name='loadRPLIDAR',
default_value=os.environ.get('HAS_RPLIDAR', 'true')
Expand Down
82 changes: 32 additions & 50 deletions arlobot_ros/launch/xbox360_teleop.launch.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,62 +1,44 @@
import os
# https://docs.ros.org/en/ros2_packages/iron/api/teleop_twist_joy/standard_docs/README.html
# Based on: jazzy/share/teleop_twist_joy/launch/teleop-launch.py

from ament_index_python.packages import get_package_share_directory
import launch
import launch_ros.actions
from launch.substitutions import EnvironmentVariable, LaunchConfiguration
from launch import LaunchDescription


# Push the left frontal button labeled as 'LB' to activate cmd_vel publishing.
# Move the left stick around to control the velocity.

# TODO: Does teleop_tiwst_joy_node need paramemter 'scale_angular': 1.5?

def generate_launch_description():
return LaunchDescription([
launch.actions.DeclareLaunchArgument(
name='joy_config',
default_value='xbox'
),
launch.actions.DeclareLaunchArgument(
name='config_filepath',
default_value=LaunchConfiguration(
'joy_config')
),
launch.actions.DeclareLaunchArgument(
name='joy_topic',
default_value='joy'
),
joy_config = launch.substitutions.LaunchConfiguration('joy_config')
joy_dev = launch.substitutions.LaunchConfiguration('joy_dev')
publish_stamped_twist = launch.substitutions.LaunchConfiguration('publish_stamped_twist')
config_filepath = launch.substitutions.LaunchConfiguration('config_filepath')

return launch.LaunchDescription([
launch.actions.DeclareLaunchArgument('joy_vel', default_value='joy_vel'),
launch.actions.DeclareLaunchArgument('joy_config', default_value='xbox'),
launch.actions.DeclareLaunchArgument('joy_dev', default_value='0'),
launch.actions.DeclareLaunchArgument('publish_stamped_twist', default_value='false'),
launch.actions.DeclareLaunchArgument('config_filepath', default_value=[
launch.substitutions.TextSubstitution(text=os.path.join(
get_package_share_directory('teleop_twist_joy'), 'config', '')),
joy_config, launch.substitutions.TextSubstitution(text='.config.yaml')]),

launch_ros.actions.Node(
package='joy',
executable='joy_node',
name='joy_node',
parameters=[
{
'dev': EnvironmentVariable('JOY_DEVICE')
},
{
'deadzone': 0.3
},
{
# ROS requires a repeat on the output to keep moving the robot,
# although this means you need a cooldown on button inputs if you use them for anything else.
'autorepeat_rate': 20.0
}
]
),
package='joy', executable='joy_node', name='joy_node',
parameters=[{
'device_id': joy_dev,
'deadzone': 0.3,
'autorepeat_rate': 20.0,
}]),
launch_ros.actions.Node(
package='teleop_twist_joy',
executable='teleop_node',
name='teleop_twist_joy',
parameters=[
{
'scale_angular': 1.5
},
{
'enable_button': 4
},
LaunchConfiguration('config_filepath')
]
)
package='teleop_twist_joy', executable='teleop_node',
name='teleop_twist_joy_node',
parameters=[config_filepath, {'publish_stamped_twist': publish_stamped_twist, 'enable_button': 4}],
remappings={('/cmd_vel', launch.substitutions.LaunchConfiguration('joy_vel'))},
),
])


if __name__ == '__main__':
generate_launch_description()
9 changes: 0 additions & 9 deletions scripts/ros_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,3 @@ else
NC='\033[0m' # NoColor
printf "\n${YELLOW}Without an activity board your robot will not function!${NC}\n"
fi

JOY_DEVICE="/dev/input/js0" # default
if [[ $(jq '.hasXboxController' "${HOME}/.arlobot/personalDataForBehavior.json") == true ]]; then
export HAS_XBOX_JOYSTICK=true
if [[ $("${SCRIPTDIR}/find_xbox_controller.sh") ]]; then
JOY_DEVICE="$("${SCRIPTDIR}/find_xbox_controller.sh")"
fi
fi
export JOY_DEVICE

0 comments on commit 01fea19

Please sign in to comment.