Skip to content

Commit

Permalink
python: use pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Aug 26, 2024
1 parent c076f38 commit b0ef108
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 60 deletions.
8 changes: 4 additions & 4 deletions demo/demo_quadruped.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import subprocess
import sys
import time
from pathlib import Path

import gepetto.corbaserver
import matplotlib.pyplot as plt
import numpy as np
import pinocchio as pin
import plot_utils as plut
import tsid
from numpy import nan
from numpy.linalg import norm as norm

import tsid

sys.path += [os.getcwd() + "/../exercizes"]
sys.path += [Path.cwd().parent / "exercizes"]

np.set_printoptions(precision=3, linewidth=200, suppress=True)

Expand Down Expand Up @@ -43,7 +43,7 @@
DISPLAY_N = 25 # update robot configuration in viwewer every DISPLAY_N time steps
N_SIMULATION = 6000 # number of time steps simulated

filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../models"
urdf = path + "/quadruped/urdf/quadruped.urdf"
vector = pin.StdVec_StdString()
Expand Down
7 changes: 3 additions & 4 deletions demo/demo_tsid_talos_gripper_closed_kinematic_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
(c) MIPT
"""

import os
import time
from pathlib import Path

import numpy as np
import pinocchio as pin
from numpy.linalg import norm as norm

import tsid
from numpy.linalg import norm as norm

np.set_printoptions(precision=3, linewidth=200, suppress=True)

Expand Down Expand Up @@ -38,7 +37,7 @@
# Talos gripepr model (c) 2016, PAL Robotics, S.L.
# Please use https://github.com/egordv/tsid_demo_closed_kinematic_chain repo for the model files

filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "../../tsid_demo_closed_kinematic_chain/models/talos_gripper"
urdf = path + "../../tsid_demo_closed_kinematic_chain/urdf/talos_gripper_half.urdf"
vector = pin.StdVec_StdString()
Expand Down
4 changes: 2 additions & 2 deletions exercizes/ex_4_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

import os
from pathlib import Path

import numpy as np
import pinocchio as pin
Expand All @@ -16,7 +16,7 @@

# robot parameters
# ----------------------------------------------
filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../models/romeo"
urdf = path + "/urdf/romeo.urdf"
srdf = path + "/srdf/romeo_collision.srdf"
Expand Down
4 changes: 2 additions & 2 deletions exercizes/ex_4_long_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

import os
from pathlib import Path

import numpy as np

Expand All @@ -15,7 +15,7 @@

# robot parameters
# ----------------------------------------------
filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../models/romeo"
urdf = path + "/urdf/romeo.urdf"
srdf = path + "/srdf/romeo_collision.srdf"
Expand Down
14 changes: 7 additions & 7 deletions exercizes/ex_4_talos_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

import os
from pathlib import Path

import numpy as np
import pinocchio as pin
Expand All @@ -17,12 +17,12 @@

# robot parameters
# ----------------------------------------------
filename = str(os.path.dirname(os.path.abspath(__file__)))
urdf = "/talos_data/robots/talos_reduced.urdf"
modelPath = getModelPath(urdf)
urdf = modelPath + urdf
srdf = modelPath + "/talos_data/srdf/talos.srdf"
path = os.path.join(modelPath, "../..")
filename = str(Path(__file__).resolve().parent)
urdf = "talos_data/robots/talos_reduced.urdf"
modelPath = Path(getModelPath(urdf))
urdf = modelPath / urdf
srdf = modelPath / "talos_data/srdf/talos.srdf"
path = modelPath / "../.."

nv = 38
foot_scaling = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"\n",
"sys.path.append(\"..\")\n",
"\n",
Expand All @@ -28,7 +29,6 @@
"import tsid\n",
"\n",
"# import gepetto.corbaserver\n",
"import os\n",
"\n",
"import talos_arm_conf as conf"
]
Expand Down Expand Up @@ -161,7 +161,7 @@
"outputs": [],
"source": [
"robot_display = pin.RobotWrapper.BuildFromURDF(\n",
" conf.urdf, [os.path.join(conf.path, \"../..\")]\n",
" conf.urdf, [str(Path(conf.path) / \"../..\")]\n",
")\n",
"# Viewer = pin.visualize.GepettoVisualizer\n",
"Viewer = pin.visualize.MeshcatVisualizer\n",
Expand Down
4 changes: 2 additions & 2 deletions exercizes/notebooks/ex_1_com_sin_track_talos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from numpy.linalg import norm\n",
"import os\n",
"from pathlib import Path\n",
"import time as tmp\n",
"\n",
"# import the library TSID for the Whole-Body Controller\n",
Expand Down Expand Up @@ -353,7 +353,7 @@
"source": [
"# Creation of the robot wrapper for gepetto viewer (graphical interface)\n",
"robot_display = pin.RobotWrapper.BuildFromURDF(\n",
" urdf, [os.path.join(path, \"../..\")], pin.JointModelFreeFlyer()\n",
" urdf, [str(Path(path) / \"../..\")], pin.JointModelFreeFlyer()\n",
")\n",
"# Viewer = pin.visualize.GepettoVisualizer\n",
"Viewer = pin.visualize.MeshcatVisualizer\n",
Expand Down
10 changes: 5 additions & 5 deletions exercizes/romeo_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

import os
from pathlib import Path

import numpy as np
import pinocchio as pin
Expand Down Expand Up @@ -72,7 +72,7 @@
LF_SPHERE_COLOR = (0, 0, 1, 0.5)
LF_REF_SPHERE_COLOR = (0.5, 0, 1, 0.5)

filename = str(os.path.dirname(os.path.abspath(__file__)))
path = filename + "/../models/romeo"
urdf = path + "/urdf/romeo.urdf"
srdf = path + "/srdf/romeo_collision.srdf"
filename = Path(__file__).resolve().parent
path = filename / "../models/romeo"
urdf = path / "urdf/romeo.urdf"
srdf = path / "srdf/romeo_collision.srdf"
6 changes: 4 additions & 2 deletions exercizes/talos_arm_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import numpy as np
from example_robot_data.robots_loader import getModelPath

Expand Down Expand Up @@ -45,5 +47,5 @@
EE_REF_SPHERE_COLOR = (1, 0, 0, 0.5)

urdf = "/talos_data/robots/talos_left_arm.urdf"
path = getModelPath(urdf)
urdf = path + urdf
path = Path(getModelPath(urdf))
urdf = path / urdf
10 changes: 5 additions & 5 deletions exercizes/talos_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as pin
Expand Down Expand Up @@ -104,7 +104,7 @@
LF_REF_SPHERE_COLOR = (0.5, 0, 1, 0.5)

urdf = "/talos_data/robots/talos_reduced.urdf"
path = getModelPath(urdf)
urdf = path + urdf
srdf = path + "/talos_data/srdf/talos.srdf"
path = os.path.join(path, "../..")
path = Path(getModelPath(urdf))
urdf = path / urdf
srdf = path / "talos_data/srdf/talos.srdf"
path = path / "../.."
8 changes: 4 additions & 4 deletions exercizes/ur5_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

from os.path import join
from pathlib import Path

import numpy as np
from example_robot_data.robots_loader import getModelPath
Expand Down Expand Up @@ -54,6 +54,6 @@


urdf = "ur_description/urdf/ur5_robot.urdf"
path = getModelPath(urdf)
urdf = join(path, urdf)
path = join(path, "../..")
path = Path(getModelPath(urdf))
urdf = path / urdf
path = path / "../.."
8 changes: 4 additions & 4 deletions exercizes/ur5_reaching_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@author: student
"""

from os.path import join
from pathlib import Path

import numpy as np
from example_robot_data.robots_loader import getModelPath
Expand Down Expand Up @@ -54,6 +54,6 @@


urdf = "ur_description/urdf/ur5_robot.urdf"
path = getModelPath(urdf)
urdf = join(path, urdf)
path = join(path, "../..")
path = Path(getModelPath(urdf))
urdf = path / urdf
path = path / "../.."
4 changes: 2 additions & 2 deletions tests/python/test_Contact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as se3
Expand All @@ -11,7 +11,7 @@

tol = 1e-5

filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = se3.StdVec_StdString()
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_ContactPoint.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as se3

import tsid

print("")
print("Test Contact")
print("")

tol = 1e-5
filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)

path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = se3.StdVec_StdString()
Expand Down
7 changes: 3 additions & 4 deletions tests/python/test_Formulation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as se3
from numpy.linalg import norm

import tsid
from numpy.linalg import norm

print("")
print("Test InvDyn")
print("")

filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = se3.StdVec_StdString()
Expand Down
5 changes: 2 additions & 3 deletions tests/python/test_Gravity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from pathlib import Path

import pinocchio as se3

import tsid

print("")
print("Test setGravity")
print("")


filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = se3.StdVec_StdString()
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_RobotWrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as se3
Expand All @@ -10,7 +10,7 @@
print("")


filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = se3.StdVec_StdString()
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_Tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
from pathlib import Path

import numpy as np
import pinocchio as pin
Expand All @@ -14,7 +14,7 @@


tol = 1e-5
filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = pin.StdVec_StdString()
Expand Down Expand Up @@ -204,7 +204,7 @@
print("")

tol = 1e-5
filename = str(os.path.dirname(os.path.abspath(__file__)))
filename = str(Path(__file__).resolve().parent)
path = filename + "/../../models/romeo"
urdf = path + "/urdf/romeo.urdf"
vector = pin.StdVec_StdString()
Expand Down

0 comments on commit b0ef108

Please sign in to comment.