Skip to content

Commit

Permalink
General URDF created
Browse files Browse the repository at this point in the history
  • Loading branch information
LudovicaDanovaro committed Dec 11, 2024
1 parent 0e57109 commit 95b1e72
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import idyntree.bindings as iDynTree
from urdfModifiers.utils import *
import re

sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
from src import *
Expand Down Expand Up @@ -42,6 +43,8 @@
URDF_MESHES_FILE_FOLDER,
)

# URDF_MESHES_FILE_PATH = "package:/"

URDF_FILE_FOLDER = "humanModels"
URDF_FILE_NAME = input("\n[INPUT] Insert the model name: ") + ".urdf"

Expand Down Expand Up @@ -110,6 +113,25 @@
# Write URDF to a new file, also adding back the previously removed <gazebo> tags
utils.write_urdf_to_file(robot, URDF_FILE_PATH, gazebo_plugin_text)

with open(URDF_FILE_PATH, "r") as file:
urdf_content = file.read()

def modify_mesh_line(match):

filename = match.group(1)
scale_values = match.group(2)

new_filename = "package://meshes/" + filename.split("\\")[-1]

return f'<mesh filename="{new_filename}" scale="{scale_values}"/>'

modified_urdf_content = re.sub(r'<mesh filename=".*?\\meshes\\(.*?)" scale="(.*?)"/>', modify_mesh_line, urdf_content)

with open(URDF_FILE_PATH, "w") as file:
file.write(modified_urdf_content)

print("[OUTPUT] Model with \"package\" successfully created. \u2713")

print("[OUTPUT] Model successfully created. \u2713")
print("[OUTPUT] Model successfully saved. \u2713")
print(
Expand Down Expand Up @@ -158,6 +180,33 @@
# LOAD THE MODEL
#################################################################

package_value = os.getenv('package')

if not package_value:
raise EnvironmentError("The environment variable 'package' is not set")

with open(URDF_FILE_PATH, "r") as file:
urdf_content = file.read()

def modify_mesh_line2(match):

filename = match.group(1)
scale_values = match.group(2)

new_filename = f"{package_value}/" + filename.split("\\")[-1]

return f'<mesh filename="{new_filename}" scale="{scale_values}"/>'

modified_urdf_content = re.sub(r'<mesh filename=".*?//meshes/(.*?)" scale="(.*?)"/>', modify_mesh_line2, urdf_content)


with open(URDF_FILE_PATH, "w") as file:
file.write(modified_urdf_content)

print("[OUTPUT] Model with path successfully created. \u2713")



dynComp = iDynTree.KinDynComputations()
mdlLoader = iDynTree.ModelLoader()
# Possibility of inserting a reduced list of joints
Expand Down Expand Up @@ -263,3 +312,6 @@

if OPT_VISUALIZZATION_MEASUREOFCONTROL:
measurementControl(linkMass, linkDimensions)



2 changes: 1 addition & 1 deletion code/src/modifyMeshModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def updateRobotWithMeshAndMuscles(
)
link.visuals.append(muscle_visual)

return robot
return robot

0 comments on commit 95b1e72

Please sign in to comment.