Skip to content

Commit

Permalink
update explicit type support and force rebuild at every colcon build
Browse files Browse the repository at this point in the history
Signed-off-by: YuxuanLiuTier4Desktop <[email protected]>
  • Loading branch information
Owen-Liuyuxuan committed Dec 13, 2024
1 parent bdd2539 commit 0712865
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
25 changes: 11 additions & 14 deletions aip_xx1_description/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.5)
project(aip_xx1_description)


find_package(ament_cmake_auto REQUIRED)

ament_auto_find_build_dependencies()
Expand All @@ -13,22 +12,20 @@ set(PYTHON_TEMPLATE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/templates")
set(PYTHON_CALIBRATION_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/config")
set(PYTHON_XACRO_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/urdf")

# Run the Python script
execute_process(
# Create a custom command to run the Python script

add_custom_target(xacro_compilation ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python_script_run_flag # this target will ask for `python_script_run_flag`
)

add_custom_command(
# this command will claim to create `python_script_run_flag`, but will not actually do so; only running the script
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}
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error
DEPENDS ${PYTHON_SCRIPT} # Add dependencies here
COMMENT "Running Python script for URDF creation"
)
# message(WARNING "Python script output: ${output}")

if(NOT result EQUAL 0)
message(FATAL_ERROR "Python script failed with error: ${error}")
else()
message(WARNING "Xacro Compiling Success")
endif()


ament_auto_package(INSTALL_TO_SHARE
urdf
Expand Down
13 changes: 13 additions & 0 deletions aip_xx1_description/config/sensor_kit_calibration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,100 @@ sensor_kit_base_link:
roll: -0.025
pitch: 0.315
yaw: 1.035
type: monocular_camera
camera1/camera_link:
x: -0.10731
y: -0.56343
z: -0.27697
roll: -0.025
pitch: 0.32
yaw: -2.12
type: monocular_camera
camera2/camera_link:
x: 0.10731
y: -0.56343
z: -0.27697
roll: -0.00
pitch: 0.335
yaw: -1.04
type: monocular_camera
camera3/camera_link:
x: -0.10731
y: 0.56343
z: -0.27697
roll: 0.0
pitch: 0.325
yaw: 2.0943951
type: monocular_camera
camera4/camera_link:
x: 0.07356
y: 0.0
z: -0.0525
roll: 0.0
pitch: -0.03
yaw: -0.005
type: monocular_camera
camera5/camera_link:
x: -0.07356
y: 0.0
z: -0.0525
roll: 0.0
pitch: -0.01
yaw: 3.125
type: monocular_camera
camera6/camera_link:
x: 0.05
y: 0.0175
z: -0.1
roll: 0.0
pitch: 0.0
yaw: 0.0
type: monocular_camera
camera7/camera_link:
x: 0.05
y: -0.0175
z: -0.1
roll: 0.0
pitch: 0.0
yaw: 0.0
type: monocular_camera
velodyne_top_base_link:
x: 0.0
y: 0.0
z: 0.0
roll: 0.0
pitch: 0.0
yaw: 1.575
type: VLS-128.urdf
velodyne_left_base_link:
x: 0.0
y: 0.56362
z: -0.30555
roll: -0.02
pitch: 0.71
yaw: 1.575
type: VLP-16.urdf
velodyne_right_base_link:
x: 0.0
y: -0.56362
z: -0.30555
roll: -0.01
pitch: 0.71
yaw: -1.580
type: VLP-16.urdf
gnss_link:
x: -0.1
y: 0.0
z: -0.2
roll: 0.0
pitch: 0.0
yaw: 0.0
type: imu
tamagawa/imu_link:
x: 0.0
y: 0.0
z: 0.0
roll: 3.14159265359
pitch: 0.0
yaw: 3.14159265359
type: imu
5 changes: 5 additions & 0 deletions aip_xx1_description/config/sensors_calibration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@ base_link:
roll: 0.0
pitch: 0.0
yaw: 0.0
type: radar
sensor_kit_base_link:
x: 0.9
y: 0.0
z: 2.0
roll: -0.001
pitch: 0.015
yaw: -0.0364
type: units
livox_front_right_base_link:
x: 3.290
y: -0.65485
z: 0.3216
roll: 0.0
pitch: 0.0
yaw: -0.872664444
type: livox_horizon
livox_front_left_base_link:
x: 3.290
y: 0.65485
z: 0.3016
roll: -0.021
pitch: 0.05
yaw: 0.872664444
type: livox_horizon
velodyne_rear_base_link:
x: -0.358
y: 0.0
z: 1.631
roll: -0.02
pitch: 0.7281317
yaw: 3.141592
type: VLP-16.urdf
25 changes: 19 additions & 6 deletions aip_xx1_description/scripts/compile_xacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, transformation: Dict, base_frame: str, child_frame: str):
self.yaw = transformation["yaw"]
self.base_frame = base_frame
self.child_frame = child_frame
self.type: str = transformation.get("type", "")

self.name = self.child_frame.replace("_base_link", "").replace("_link", "")

Expand Down Expand Up @@ -93,6 +94,19 @@ class LinkType(enum.Enum):
JOINT_UNITS = "units"


def obtain_link_type(link: Transformation) -> LinkType:
if len(link.type) > 0:
# use explicit type string to obtain link
link_type_lower = link.type.lower()

# Check each enum value for a match
for type_enum in LinkType:
if link_type_lower == type_enum.value.lower():
return type_enum
# if there is no match, or the type is not defined:
return determine_link_type(link.child_frame)


def determine_link_type(link_name: str) -> LinkType:
if "cam" in link_name:
return LinkType.CAMERA
Expand Down Expand Up @@ -276,9 +290,7 @@ def main(

render_meta_data = {}
render_meta_data["default_config_path"] = f"$(find {project_name})/config"
render_meta_data[
"sensor_calibration_yaml_path"
] = f"$(find {project_name})/config/sensors_calibration.yaml"
render_meta_data["sensor_calibration_yaml_path"] = "$(arg config_dir)/sensors_calibration.yaml"
render_meta_data["sensor_units_includes"] = []
render_meta_data["sensor_units"] = []
render_meta_data["isolated_sensors_includes"] = []
Expand All @@ -287,7 +299,7 @@ def main(
include_text = set()
sensor_items = []
for _, transform in calib.transforms.items():
link_type: LinkType = determine_link_type(transform.child_frame)
link_type: LinkType = obtain_link_type(transform)
if link_type == LinkType.JOINT_UNITS:
render_meta_data["sensor_units_includes"].append(
link_dicts[link_type]["including_file"].format(filename=transform.name)
Expand Down Expand Up @@ -330,12 +342,13 @@ def main(
sensor_unit_render_meta_data["default_config_path"] = render_meta_data[
"default_config_path"
]

sensor_unit_render_meta_data["joint_unit_name"] = sensor_unit["name"]
sensor_unit_render_meta_data["current_base_link"] = sensor_unit_calib.base_frame
sensor_unit_isolated_sensors = []
for _, transform in sensor_unit_calib.transforms.items():
link_type: LinkType = determine_link_type(transform.child_frame)
link_type: LinkType = obtain_link_type(transform)
include_text.add(link_dicts[link_type]["including_file"])
print(transform.child_frame)
sensor_unit_isolated_sensors.append(link_dicts[link_type]["string_api"](transform))
sensor_unit_render_meta_data["isolated_sensors_includes"] = list(include_text)
sensor_unit_render_meta_data["isolated_sensors"] = sensor_unit_isolated_sensors
Expand Down
2 changes: 1 addition & 1 deletion aip_xx1_description/templates/sensor_unit.xacro.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</link>

<!-- sensor -->
<xacro:property name="calibration" value="${xacro.load_yaml('$(arg config_dir)/sensor_kit_calibration.yaml')}"/>
<xacro:property name="calibration" value="${xacro.load_yaml('$(arg config_dir)/{{ joint_unit_name }}_calibration.yaml')}"/>

{% for item in isolated_sensors %}
{{ item }}
Expand Down

0 comments on commit 0712865

Please sign in to comment.