Skip to content

Commit

Permalink
Changed add joints to use_joint_state_publisher | added joint state p… (
Browse files Browse the repository at this point in the history
#470)

* Added fake viz

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

* Added docs

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>

---------

Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
  • Loading branch information
delihus authored Dec 20, 2024
1 parent a229d32 commit 4a7e624
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ Launch arguments are largely common to both simulation and physical robot. Howev

| 🤖 | 🖥️ | Argument | Description <br/> ***Type:*** `Default` |
| --- | --- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
||| `add_wheel_joints` | Flag enabling joint_state_publisher to publish information about the wheel position. Should be false when there is a controller that sends this information. <br/> ***bool:*** `False` |
||| `add_world_transform` | Adds a world frame that connects the tf trees of individual robots (useful when running multiple robots). <br/> ***bool:*** `False` |
||| `animations_config_path` | Path to a YAML file with a description of led configuration. This file includes definition of robot panels, virtual segments and default animations. <br/> ***string:*** [`{robot_model}_animations.yaml`](./husarion_ugv_lights/config) |
||| `battery_config_path` | Path to the Ignition LinearBatteryPlugin configuration file. This configuration is intended for use in simulations only. <br/> ***string:*** `None` |
Expand All @@ -108,6 +107,8 @@ Launch arguments are largely common to both simulation and physical robot. Howev
||| `safety_bt_project_path` | Path to BehaviorTree project file, responsible for safety and shutdown management. <br/> ***string:*** [`SafetyBT.btproj`](./husarion_ugv_manager/behavior_trees/SafetyBT.btproj) |
||| `shutdown_hosts_config_path` | Path to file with list of hosts to request shutdown. <br/> ***string:*** [`shutdown_hosts.yaml`](./husarion_ugv_manager/config/shutdown_hosts.yaml) |
||| `use_ekf` | Enable or disable EKF. <br/> ***bool:*** `True` |
||| `use_joint_state_publisher` | Flag enabling joint_state_publisher to publish information about the wheel position. Should be false when there is a controller that sends this information. <br/> ***bool:*** `False` |
||| `use_joint_state_publisher_gui` | Flag enabling joint_state_publisher_gui to publish information about the wheel position. Should be false when there is a controller that sends this information. <br/> ***bool:*** `False` |
||| `use_rviz` | Run RViz simultaneously. <br/> ***bool:*** `True` |
||| `use_sim` | Whether simulation is used. <br/> ***bool:*** `False` |
||| `user_led_animations_path` | Path to a YAML file with a description of the user-defined animations. <br/> ***string:*** `''` |
Expand Down
69 changes: 69 additions & 0 deletions husarion_ugv_description/CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# husarion_ugv_description

## URDF - Robot Model Configuration

### Configure Components

Create `components.yaml` file with the desired components. Here's a sample configuration:

```yaml
components:
- type: MAN02
parent_link: cover_link
xyz: 0.2 -0.2 0.0
rpy: 0.0 0.0 0.0
device_namespace: ur5
```
In this example:
- `type`: MAN02: Specifies the component type.
- `parent_link`: cover_link: Defines the parent link to attach the component.
- `xyz`: 0.2 -0.2 0.0: Sets the position of the component.
- `rpy`: 0.0 0.0 0.0: Sets the rotation of the component.
- `device_namespace`: ur5: Sets the device namespace.

### Visualize Robot Model Configuration

To use the `ros2 launch` command to launch the `visualize_fake_robot.launch.py` file with a specified robot model and components configuration path, follow these steps:

1. Open a terminal.
2. Source build workspace.
3. Execute the following command:

```bash
ros2 launch husarion_ugv_description visualize_fake_robot.launch.py robot_model:=lynx use_joint_state_publisher:=true components_config_path:=$(pwd)/components.yaml
```

If you want to move the wheels or move the manipulator you can run the launch file with `joint_state_publisher_gui`:

```bash
ros2 launch husarion_ugv_description visualize_fake_robot.launch.py robot_model:=lynx use_joint_state_publisher_gui:=true components_config_path:=$(pwd)/components.yaml
```

### Overwrite Robot Model Configuration

To change the configuration let's add another manipulator to `components.yaml`:

```yaml
components:
- type: MAN02
parent_link: cover_link
xyz: 0.2 -0.2 0.0
rpy: 0.0 0.0 0.0
device_namespace: left_ur5
- type: MAN02
parent_link: cover_link
xyz: 0.2 0.2 0.0
rpy: 0.0 0.0 0.0
device_namespace: right_ur5
```

To use the `ros2 launch` command to launch the `overwrite_robot_description.launch.py` file with the appropriate arguments to overwrite the robot model, follow these steps:

1. Open a terminal.
2. Source workspace.
3. Execute the following command:

```bash
ros2 launch husarion_ugv_description overwrite_robot_description.launch.py robot_model:=lynx components_config_path:=$(pwd)/components.yaml
```
20 changes: 0 additions & 20 deletions husarion_ugv_description/launch/load_urdf.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch.substitutions import (
Command,
EnvironmentVariable,
Expand All @@ -33,15 +32,6 @@


def generate_launch_description():
add_wheel_joints = LaunchConfiguration("add_wheel_joints")
declared_add_wheel_joints_arg = DeclareLaunchArgument(
"add_wheel_joints",
default_value="True",
description="Flag enabling joint_state_publisher to publish information about the wheel "
"position. Should be false when there is a controller that sends this information.",
choices=["True", "true", "False", "false"],
)

battery_config_path = LaunchConfiguration("battery_config_path")
declare_battery_config_path_arg = DeclareLaunchArgument(
"battery_config_path",
Expand Down Expand Up @@ -183,16 +173,7 @@ def generate_launch_description():
emulate_tty=True,
)

joint_state_publisher_node = Node(
package="joint_state_publisher",
executable="joint_state_publisher",
namespace=namespace,
emulate_tty=True,
condition=IfCondition(add_wheel_joints),
)

actions = [
declared_add_wheel_joints_arg,
declare_battery_config_path_arg,
declare_components_config_path_arg,
declare_robot_model_arg, # robot_model is used by wheel_type
Expand All @@ -203,7 +184,6 @@ def generate_launch_description():
declare_wheel_config_path_arg,
SetParameter(name="use_sim_time", value=use_sim),
robot_state_pub_node,
joint_state_publisher_node, # do not publish, when use_sim is true
]

return LaunchDescription(actions)
153 changes: 153 additions & 0 deletions husarion_ugv_description/launch/visualize_fake_robot.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env python3

# Copyright 2020 ros2_control Development Team
# Copyright 2024 Husarion sp. z o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import (
EnvironmentVariable,
LaunchConfiguration,
PathJoinSubstitution,
PythonExpression,
)
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
components_config_path = LaunchConfiguration("components_config_path")
declare_components_config_path_arg = DeclareLaunchArgument(
"components_config_path",
default_value=PathJoinSubstitution(
[FindPackageShare("husarion_ugv_description"), "config", "components.yaml"]
),
description=(
"Additional components configuration file. Components described in this file "
"are dynamically included in Panther's urdf."
"Panther options are described here "
"https://husarion.com/manuals/panther/panther-options/"
),
)

namespace = LaunchConfiguration("namespace")
declare_namespace_arg = DeclareLaunchArgument(
"namespace",
default_value=EnvironmentVariable("ROBOT_NAMESPACE", default_value=""),
description="Add namespace to all launched nodes.",
)

robot_model = LaunchConfiguration("robot_model")
robot_model_dict = {"LNX": "lynx", "PTH": "panther"}
robot_model_env = os.environ.get("ROBOT_MODEL", default="PTH")
declare_robot_model_arg = DeclareLaunchArgument(
"robot_model",
default_value=robot_model_dict[robot_model_env],
description="Specify robot model.",
choices=["lynx", "panther"],
)

rviz_config = LaunchConfiguration("rviz_config")
declare_rviz_config_arg = DeclareLaunchArgument(
"rviz_config",
default_value=PathJoinSubstitution(
[FindPackageShare("husarion_ugv_description"), "rviz", "robot_model.rviz"]
),
description="RViz configuration file.",
)

use_joint_state_publisher = LaunchConfiguration("use_joint_state_publisher")
declare_use_joint_state_publisher_arg = DeclareLaunchArgument(
"use_joint_state_publisher",
default_value="False",
description="Flag enabling joint_state_publisher to publish information about joints positions. Should be false when there is a controller that sends this information.",
choices=["True", "true", "False", "false"],
)

use_joint_state_publisher_gui = LaunchConfiguration("use_joint_state_publisher_gui")
declare_use_joint_state_publisher_gui_arg = DeclareLaunchArgument(
"use_joint_state_publisher_gui",
default_value="False",
description="Flag enabling joint_state_publisher_gui to publish information about joints positions. Should be false when there is a controller that sends this information.",
choices=["True", "true", "False", "false"],
)

wheel_type = LaunchConfiguration("wheel_type")
default_wheel_type = {"lynx": "WH05", "panther": "WH01"}
declare_wheel_type_arg = DeclareLaunchArgument(
"wheel_type",
default_value=PythonExpression([f"{default_wheel_type}['", robot_model, "']"]),
description=(
"Specify the wheel type. If the selected wheel type is not 'custom', "
"the 'wheel_config_path' and 'controller_config_path' arguments will be "
"automatically adjusted and can be omitted."
),
choices=["WH01", "WH02", "WH04", "WH05", "custom"],
)

load_urdf = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[FindPackageShare("husarion_ugv_description"), "/launch/load_urdf.launch.py"]
),
launch_arguments={
"components_config_path": components_config_path,
"namespace": namespace,
"robot_model": robot_model,
"wheel_type": wheel_type,
}.items(),
)

rviz = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[FindPackageShare("husarion_ugv_description"), "/launch/rviz.launch.py"]
),
launch_arguments={"namespace": namespace, "rviz_config": rviz_config}.items(),
)

joint_state_publisher_node = Node(
package="joint_state_publisher",
executable="joint_state_publisher",
namespace=namespace,
emulate_tty=True,
condition=IfCondition(use_joint_state_publisher),
)

joint_state_publisher_gui_node = Node(
package="joint_state_publisher_gui",
executable="joint_state_publisher_gui",
namespace=namespace,
emulate_tty=True,
condition=IfCondition(use_joint_state_publisher_gui),
)

actions = [
declare_components_config_path_arg,
declare_namespace_arg,
declare_robot_model_arg,
declare_rviz_config_arg,
declare_use_joint_state_publisher_arg,
declare_use_joint_state_publisher_gui_arg,
declare_wheel_type_arg,
load_urdf,
rviz,
joint_state_publisher_node,
joint_state_publisher_gui_node,
]

return LaunchDescription(actions)
1 change: 1 addition & 0 deletions husarion_ugv_description/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>joint_state_publisher</exec_depend>
<exec_depend>joint_state_publisher_gui</exec_depend>
<exec_depend>launch</exec_depend>
<exec_depend>launch_ros</exec_depend>
<exec_depend>nav2_common</exec_depend>
Expand Down
Loading

0 comments on commit 4a7e624

Please sign in to comment.