Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
pinocchio
Commits
df1d9c78
Unverified
Commit
df1d9c78
authored
Jun 11, 2020
by
Justin Carpentier
Committed by
GitHub
Jun 11, 2020
Browse files
examples: make the example idenpendant
parent
1bc52ffc
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/build-reduced-model.py
View file @
df1d9c78
import
pinocchio
as
pin
from
pinocchio.robot_wrapper
import
RobotWrapper
import
example_robot_data
import
numpy
as
np
import
os
# Goal: Build a reduced model from an existing URDF model by fixing the desired joints at a specified position.
# Load UR robot arm
modelPath
=
os
.
path
.
join
(
os
.
environ
.
get
(
'HOME'
),
"Dev"
)
URDF_FILENAME
=
"ur5_robot.urdf"
URDF_SUBPATH
=
"/ur_description/urdf/"
+
URDF_FILENAME
robot
=
RobotWrapper
.
BuildFromURDF
(
modelPath
+
URDF_SUBPATH
,
[
modelPath
])
# This path refers to Pinocchio source code but you can define your own directory here.
pinocchio_model_dir
=
join
(
dirname
(
dirname
(
str
(
abspath
(
__file__
)))),
"models"
)
model_path
=
pinocchio_model_dir
+
'/others/robots'
mesh_dir
=
model_path
# You should change here to set up your own URDF file
urdf_filename
=
model_path
+
'/ur_description/urdf/ur5_robot.urdf'
model
,
collision_model
,
visual_model
=
pinocchio
.
buildModelsFromUrdf
(
urdf_model_path
,
mesh_dir
)
# Check dimensions of the original model
print
(
'standard model: dim='
+
str
(
len
(
robot
.
model
.
joints
)))
for
jn
in
robot
.
model
.
joints
:
print
(
'standard model: dim='
+
str
(
len
(
model
.
joints
)))
for
jn
in
model
.
joints
:
print
(
jn
)
# Create a list of joints to lock
...
...
@@ -23,22 +24,23 @@ jointsToLock = ['wrist_1_joint', 'wrist_2_joint', 'wrist_3_joint']
# Get the ID of all existing joints
jointsToLockIDs
=
[]
for
jn
in
jointsToLock
:
if
robot
.
model
.
existJointName
(
jn
):
jointsToLockIDs
.
append
(
robot
.
model
.
getJointId
(
jn
))
if
model
.
existJointName
(
jn
):
jointsToLockIDs
.
append
(
model
.
getJointId
(
jn
))
else
:
print
(
'Warning: joint '
+
str
(
jn
)
+
' does not belong to the model!'
)
# Set initial position of both fixed and revoulte joints
initialJointConfig
=
np
.
array
([
0
,
0
,
0
,
# shoulder and elbow
# Set initial position of both fixed and revoulte joints
initialJointConfig
=
np
.
array
([
0
,
0
,
0
,
# shoulder and elbow
1
,
1
,
1
])
# gripper)
# Option 1: Build the reduced model including the geometric model for proper displaying of the robot
robot
.
model
,
robot
.
visual_model
=
pin
.
buildReducedModel
(
robot
.
model
,
robot
.
visual_model
,
jointsToLockIDs
,
initialJointConfig
)
model_reduced
,
visual_model
_reduced
=
pin
.
buildReducedModel
(
model
,
visual_model
,
jointsToLockIDs
,
initialJointConfig
)
# Option 2: Only build the reduced model in case no display needed:
#
robot.model
= pin.buildReducedModel(
robot.
model, jointsToLockIDs, initialJointConfig)
#
model_reduced
= pin.buildReducedModel(model, jointsToLockIDs, initialJointConfig)
# Check dimensions of the reduced model
print
(
'reduced model: dim='
+
str
(
len
(
robot
.
model
.
joints
)))
for
jn
in
robot
.
model
.
joints
:
print
(
jn
)
\ No newline at end of file
print
(
'reduced model: dim='
+
str
(
len
(
model_reduced
.
joints
)))
for
jn
in
model_reduced
.
joints
:
print
(
jn
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment