Skip to content

Commit

Permalink
Merge branch 'tier4/universe' into fix/to_use_nebula_v0-2-1
Browse files Browse the repository at this point in the history
  • Loading branch information
SakodaShintaro authored Jan 16, 2025
2 parents 35acf7d + a03c37d commit cec16f0
Show file tree
Hide file tree
Showing 90 changed files with 7,132 additions and 702 deletions.
19 changes: 19 additions & 0 deletions aip_urdf_compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.5)
project(aip_urdf_compiler)

find_package(ament_cmake_auto REQUIRED)

ament_auto_find_build_dependencies()

# Install cmake directory
install(
DIRECTORY cmake templates scripts
DESTINATION share/${PROJECT_NAME}
)

# Export the package's share directory path

# Add the config extras
ament_package(
CONFIG_EXTRAS "cmake/aip_cmake_urdf_compile.cmake"
)
33 changes: 33 additions & 0 deletions aip_urdf_compiler/cmake/aip_cmake_urdf_compile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@



macro(aip_cmake_urdf_compile)
# Set the correct paths
find_package(PythonInterp REQUIRED) # cspell: ignore Interp
set(aip_urdf_compiler_BASE_DIR "${aip_urdf_compiler_DIR}/../")
set(PYTHON_SCRIPT "${aip_urdf_compiler_BASE_DIR}/scripts/compile_urdf.py")
set(PYTHON_TEMPLATE_DIRECTORY "${aip_urdf_compiler_BASE_DIR}/templates")
set(PYTHON_CALIBRATION_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/config")
set(PYTHON_XACRO_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/urdf")

message(STATUS "PYTHON_SCRIPT path: ${PYTHON_SCRIPT}")
message(STATUS "PYTHON_TEMPLATE_DIRECTORY path: ${PYTHON_TEMPLATE_DIRECTORY}")

# Verify that the required files exist
if(NOT EXISTS "${PYTHON_SCRIPT}")
message(FATAL_ERROR "Could not find compile_urdf.py at ${PYTHON_SCRIPT}")
endif()

# Create a custom command to run the Python script
add_custom_target(xacro_compilation ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python_script_run_flag
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python_script_run_flag
COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_SCRIPT} ${PYTHON_TEMPLATE_DIRECTORY} ${PYTHON_CALIBRATION_DIRECTORY} ${PYTHON_XACRO_DIRECTORY} ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PYTHON_SCRIPT}
COMMENT "Running Python script for URDF creation"
)
endmacro()
17 changes: 17 additions & 0 deletions aip_urdf_compiler/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<package format="2">
<name>aip_urdf_compiler</name>
<version>0.1.0</version>
<description>The aip_urdf_compiler package</description>

<maintainer email="yukihiro.saito@tier4.jp">Yukihiro Saito</maintainer>
<maintainer email="uken.ryu.2@tier4.jp">Yuxuan Liu</maintainer>
<license>Apache 2</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<depend>python3-jinja2</depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
142 changes: 142 additions & 0 deletions aip_urdf_compiler/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# aip_urdf_compiler

## Overview

The aip_urdf_compiler package provides tools for dynamically generating URDF (Unified Robot Description Format) files from configuration files during the build process. It simplifies sensor model management by automatically URDF models from sensor configurations.

## Key Features

- Dynamic URDF generation during colcon build
- Automated sensor transform processing
- Support for multiple sensor types and configurations

## Usage

### Package Integration

To use aip_urdf_compiler in your description package:

- Add the dependency in `package.xml`:

```xml
<depend>aip_urdf_compiler</depend>
```

- Add the following to `CMakeLists.txt`:

```cmake
find_package(aip_urdf_compiler REQUIRED)
aip_cmake_urdf_compile()
```

- Configure your sensors in `config/sensors.yaml` with metadata values (Note: do not need to add meta values in `individual_params`):

- `type`: Required string, corresponding to the string value from [existing sensors](#existing-sensors)
- `frame_id`: Optional string, overwrites the TF frame ID.

- Clean up existing `.xacro` files and add to `.gitignore`:

```gitignore
# In your URDF folder
*.xacro
```

### Existing Sensors

```python
class LinkType(enum.Enum):
"""Enum class for the type of the link."""

CAMERA = "monocular_camera"
IMU = "imu"
LIVOX = "livox_horizon"
PANDAR_40P = "pandar_40p"
PANDAR_OT128 = "pandar_ot128"
PANDAR_XT32 = "pandar_xt32"
PANDAR_QT = "pandar_qt"
PANDAR_QT128 = "pandar_qt128"
VELODYNE16 = "velodyne_16"
VLS128 = "velodyne_128"
RADAR = "radar"
GNSS = "gnss"
JOINT_UNITS = "units"
```

## Architecture

### Components

1. **aip_urdf_compiler**

- Main package handling URDF generation
- Processes configuration files
- Manages build-time compilation

2. **aip_cmake_urdf_compile**

- CMake macro implementation
- Creates build targets
- Ensures URDF regeneration on each build

3. **compile_urdf.py**
- Configuration parser
- Transform processor
- URDF generator

### Compilation Process

1. **Configuration Reading**

- Parses `config/sensors.yaml`
- Extracts transformation data
- Validates configurations

2. **Transform Processing**

- Processes each sensor transform
- Determines sensor types and frame IDs
- Generates appropriate macro strings
- Creates `sensors.xacro`

3. **Joint Unit Processing**
- Handles joint unit transforms
- Processes related YAML files
- Generates separate URDF xacro files

## Adding New Sensors

1. Add sensor descriptions (xacro module files) in either:

- Your target package
- `common_sensor_description` package

2. Update the following in `compile_urdf.py`:
- `LinkType` enumeration
- `link_dict` mapping

## Troubleshooting

### Debug Logs

Check build logs for debugging information:

```bash
cat $workspace/log/build_<timestamp>/aip_{project}_description/streams.log
```

### Common Issues

1. Missing sensor definitions

- Ensure sensor type is defined in `LinkType`
- Verify xacro file exists in description package

2. TF Trees errors
- Check frame_id values in sensors.yaml
- Verify transform chain completeness

## Contributing

1. Follow ROS coding standards
2. Test URDF generation with various configurations
3. Update documentation for new features
Loading

0 comments on commit cec16f0

Please sign in to comment.