Skip to content

Commit

Permalink
feat: xacro compilation (#361)
Browse files Browse the repository at this point in the history
* aip launch fix for XX1

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* aip_xx1_gen2 example

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* clean up

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* feat(aip_urdf_compiler): significantly improve documentation; add additional script for comparing different xacro files for testing; add optional keywords for frame_id

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix(xx1_des): add frame_id for certain sensors to restore the original look

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix(xx1_gen2_des): add frame_id for certain sensors to restore the original look

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* create a cmake macro to simplify adaptation of other packages

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* xx1_des utilize the new macro

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* xx1_gen2 utilize the new macro

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fixbug

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix debug

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* ci(pre-commit): autofix

* add requirement on jinja2

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* add GNSS type; improve error handling; fix velodyne sensor names

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* added read me documentation, improve the warning and debugging outputs

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* improve documentation

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix grammar

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix cspell

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* unify the name in aip_urdf_compiler to be URDF compile

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

* fix bug

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>

---------

Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Owen-Liuyuxuan and pre-commit-ci[bot] authored Dec 27, 2024
1 parent 6eb32ab commit ef46885
Show file tree
Hide file tree
Showing 22 changed files with 1,114 additions and 656 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="[email protected]">Yukihiro Saito</maintainer>
<maintainer email="[email protected]">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 ef46885

Please sign in to comment.