Skip to content

Commit

Permalink
Added microros and combined launch
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Delicat <jakub.delicat@husarion.com>
  • Loading branch information
delihus committed Jan 23, 2024
1 parent e58f1c8 commit 0f08994
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ ros_components_description/
rosbot_controllers/
husarion/husarion_office_gz
gazebosim/gz_ros2_control
micro-ROS-Agent/
micro_ros_msgs/
industrial_ci/

# pyspelling
*.dic
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,19 @@ colcon build
> Before starting the software on the robot please make sure that you're using the latest firmware and run the `micro-ROS` agent as described in the [Usage on hardware](#usage-on-hardware) step.
2. **Running**

Flash firmware.
```bash
# Get admin permissions to flash firmware
sudo su
source install/setup.bash
ros2 run rosbot_xl_utils flash_firmware
exit
```

```
source install/setup.bash
ros2 launch rosbot_xl_bringup bringup.launch.py
ros2 launch rosbot_xl_bringup combined.launch.py
```

### Build and run Gazebo simulation
Expand Down
26 changes: 26 additions & 0 deletions rosbot_xl_bringup/config/microros_localhost_only.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--The only purpose of this file is to disable
Fast-DDS SHM transport used by default to use UDPv4-->
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<transport_descriptor>
<transport_id>CustomUdpTransport</transport_id>
<type>UDPv4</type>
<interfaceWhiteList>
<address>127.0.0.1</address>
</interfaceWhiteList>
</transport_descriptor>
</transport_descriptors>

<participant profile_name="participant_profile" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>CustomUdpTransport</transport_id>
</userTransports>

<useBuiltinTransports>false</useBuiltinTransports>
</rtps>
</participant>
</profiles>
</dds>
166 changes: 166 additions & 0 deletions rosbot_xl_bringup/launch/combined.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Copyright 2024 Husarion
#
# 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.

from launch import LaunchDescription
from launch_ros.substitutions import FindPackageShare
from launch.actions import (
IncludeLaunchDescription,
DeclareLaunchArgument,
LogInfo,
SetEnvironmentVariable,
OpaqueFunction,
)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import ThisLaunchFileDir, LaunchConfiguration
from launch_ros.actions import Node
import os


def generate_microros_agent_node(context, *args, **kwargs):
env_setup_actions = []

ros_domain_id = os.environ.get("ROS_DOMAIN_ID")
if ros_domain_id:
env_setup_actions.append(
SetEnvironmentVariable(name="XRCE_DOMAIN_ID_OVERRIDE", value=ros_domain_id)
)

port = LaunchConfiguration("port").perform(context)

localhost_only_fastrtps_profiles_file = LaunchConfiguration(
"localhost_only_fastrtps_profiles_file"
).perform(context)

if os.environ.get("ROS_LOCALHOST_ONLY") == "1":
env_setup_actions.extend(
[
LogInfo(
msg=[
"ROS_LOCALHOST_ONLY set to 1. Using FASTRTPS_DEFAULT_PROFILES_FILE=",
localhost_only_fastrtps_profiles_file,
"."
]
),
SetEnvironmentVariable(name="RMW_IMPLEMENTATION", value="rmw_fastrtps_cpp"),
SetEnvironmentVariable(
name="FASTRTPS_DEFAULT_PROFILES_FILE",
value=localhost_only_fastrtps_profiles_file,
),
]
)

microros_agent_node = Node(
package="micro_ros_agent",
executable="micro_ros_agent",
arguments=["udp4", "--port", port],
output="screen",
)

return env_setup_actions + [microros_agent_node]


def generate_launch_description():
declare_port_arg = DeclareLaunchArgument(
"port",
default_value="8888",
description="UDP4 port for micro-ROS agent",
)

mecanum = LaunchConfiguration("mecanum")
declare_mecanum_arg = DeclareLaunchArgument(
"mecanum",
default_value="False",
description=(
"Whether to use mecanum drive controller (otherwise diff drive controller is used)"
),
)

camera_model = LaunchConfiguration("camera_model")
declare_camera_model_arg = DeclareLaunchArgument(
"camera_model",
default_value="None",
description="Add camera model to the robot URDF",
choices=[
"None",
"intel_realsense_d435",
"orbbec_astra",
"stereolabs_zed",
"stereolabs_zedm",
"stereolabs_zed2",
"stereolabs_zed2i",
"stereolabs_zedx",
"stereolabs_zedxm",
],
)

lidar_model = LaunchConfiguration("lidar_model")
declare_lidar_model_arg = DeclareLaunchArgument(
"lidar_model",
default_value="slamtec_rplidar_s1",
description="Add LiDAR model to the robot URDF",
choices=[
"None",
"slamtec_rplidar_a2",
"slamtec_rplidar_a3",
"slamtec_rplidar_s1",
"slamtec_rplidar_s2",
"slamtec_rplidar_s3",
"velodyne_puck",
],
)

include_camera_mount = LaunchConfiguration("include_camera_mount")
declare_include_camera_mount_arg = DeclareLaunchArgument(
"include_camera_mount",
default_value="False",
description="Whether to include camera mount to the robot URDF",
)

# Locate the rosbot_bringup package
package_dir = FindPackageShare("rosbot_xl_bringup").find("rosbot_xl_bringup")

# Construct the path to the XML file within the package
fastrtps_profiles_file = os.path.join(package_dir, "config", "microros_localhost_only.xml")

declare_localhost_only_fastrtps_profiles_file_arg = DeclareLaunchArgument(
"localhost_only_fastrtps_profiles_file",
default_value=fastrtps_profiles_file,
description=(
"Path to the Fast RTPS default profiles file for Micro-ROS agent for localhost only"
" setup"
),
)

bringup_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), "/bringup.launch.py"]),
launch_arguments={
"mecanum": mecanum,
"lidar_model": lidar_model,
"camera_model": camera_model,
"include_camera_mount": include_camera_mount,
}.items(),
)

return LaunchDescription(
[
declare_port_arg,
declare_localhost_only_fastrtps_profiles_file_arg,
declare_mecanum_arg,
declare_camera_model_arg,
declare_lidar_model_arg,
declare_include_camera_mount_arg,
OpaqueFunction(function=generate_microros_agent_node),
bringup_launch,
]
)
1 change: 1 addition & 0 deletions rosbot_xl_bringup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
("share/" + package_name, ["package.xml"]),
(os.path.join("share", package_name, "launch"), glob("launch/*.launch.py")),
(os.path.join("share", package_name, "config"), glob("config/*.yaml")),
(os.path.join("share", package_name, "config"), glob("config/*.xml")),
],
install_requires=["setuptools"],
zip_safe=True,
Expand Down
10 changes: 2 additions & 8 deletions rosbot_xl_utils/rosbot_xl_utils/flash_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def main(args=None):
signal.signal(signal.SIGINT, signal_handler)

parser = argparse.ArgumentParser(description="Flash Firmware ROS 2 Node")
parser.add_argument("--usb", action="store_true", help="Use the USB flashing script")
parser.add_argument(
"-p", "--port", default="/dev/ttyUSB0", help="Specify the USB port (default: /dev/ttyUSB0)"
)
Expand All @@ -88,15 +87,10 @@ def main(args=None):
firmware_file = args.file if args.file else find_firmware_file()

try:
if args.usb:
script_name = "flash-firmware-usb.py"
else:
script_name = "flash-firmware.py"
script_name = "flash-firmware.py"

script_path = os.path.join(os.path.dirname(__file__), script_name)
additional_args = (
["-p", args.port, "--file", firmware_file] if args.usb else ["--file", firmware_file]
)
additional_args = ["-p", args.port, "--file", firmware_file]

# Print the flashing details
print(f"Flashing {firmware_file} over {args.port}")
Expand Down
3 changes: 3 additions & 0 deletions rosbot_xl_utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from glob import glob
from setuptools import find_packages, setup

package_name = "rosbot_xl_utils"
Expand All @@ -23,6 +25,7 @@
data_files=[
("share/ament_index/resource_index/packages", ["resource/" + package_name]),
("share/" + package_name, ["package.xml"]),
(os.path.join("share", package_name, "firmware"), glob("firmware/*.bin")),
],
install_requires=["setuptools"],
zip_safe=True,
Expand Down

0 comments on commit 0f08994

Please sign in to comment.