Skip to content

Commit

Permalink
fix: import error (#21)
Browse files Browse the repository at this point in the history
This commit fixes issue (#21) and changes the way we use the launch
file. Now we only need use wifi:=true instead of passing the robot ip.
  • Loading branch information
PedroS235 committed Apr 23, 2024
1 parent a227c6f commit d511c8f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions launch/unitree_driver_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.conditions import IfCondition
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, NotEqualsSubstitution
from launch.actions import OpaqueFunction
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration


def generate_launch_description():
pkg_dir = get_package_share_directory("unitree_ros")
default_param_file = os.path.join(pkg_dir, "config", "params.yaml")
params_file_arg = DeclareLaunchArgument(
"params_file", default_value=str(default_param_file)
"params_file",
default_value=str(default_param_file),
description="Parameters file to be used.",
)
use_wifi_arg = DeclareLaunchArgument(
"wifi",
default_value="false",
description="Uses the wifi IP for communicating with the robot",
)
robot_ip_arg = DeclareLaunchArgument("robot_ip", default_value=str(""))

return LaunchDescription(
[params_file_arg, robot_ip_arg, launch_unitree_driver()]
[params_file_arg, use_wifi_arg, OpaqueFunction(function=launch_unitree_driver)]
)


def launch_unitree_driver():
def launch_unitree_driver(context):
params_file = LaunchConfiguration("params_file")
robot_ip = LaunchConfiguration("robot_ip")
wifi = context.launch_configurations.get("wifi", "false")
if wifi == "true":
robot_ip = "192.168.12.1"
else:
robot_ip = "192.168.123.161"

unitree_driver_node = Node(
package="unitree_ros",
executable="unitree_driver",
parameters=[params_file, {"robot_ip": robot_ip}],
output="screen",
condition=IfCondition(NotEqualsSubstitution(robot_ip, "")),
)

return unitree_driver_node
return [unitree_driver_node]

0 comments on commit d511c8f

Please sign in to comment.