Closed kamiradi closed 2 days ago
Hi @kamiradi, thanks for your interest in our work! I'm not able to tell what the issue is from this code, and I'm also not sure what "the discrete system assertion" is referring to. A smaller and self contained example would be helpful, preferably with a simpler system as well.
Hi @vincekurtz, thanks for your response.
In your ilqr.py
file, this line makes sure that the diagram you have passed into this system is a discrete-time system. The method that I wrote in the main description of the issue replaces your create_system_model
function with my own model. I now see that it is a bit too large so I have created smaller function that loads my system, without changing how I am instantiating the MultibodyPlant
. This is as follows
def CreateSystemModel(plant, scene_graph, config):
# create system model for iLQR implementation
iiwa_dmd = './assembly.dmd.yaml'
parser = Parser(plant)
# add iiwa robot, tables, and hole
model_indices = parser.AddModels(iiwa_dmd)
# add some transforms to denote the hole
hole_index = plant.GetModelInstanceByName("hole")
hole_frame = plant.AddFrame(
FixedOffsetFrame(
"hole_frame",
plant.GetFrameByName(
"base_link",
hole_index),
RigidTransform(RotationMatrix.MakeXRotation(-np.pi/2))
)
)
# adding peg to the scene
G_PPcm_P = UnitInertia.SolidCylinder(
config["peg_width"]*0.5,
config["peg_length"],
[0, 0, 1]
)
M_PPcm_P = SpatialInertia(
config["peg_mass"],
[0, 0, 0],
G_PPcm_P
)
peg_geom = Cylinder(
config["peg_width"]*0.5,
config["peg_length"]
)
peg = plant.AddRigidBody(
'peg',
plant.GetModelInstanceByName(
'iiwa'),
M_PPcm_P
)
plant.RegisterVisualGeometry(
peg,
RigidTransform(),
peg_geom,
'peg',
[0.5, 0.5, 0.5, 1.0]
)
plant.RegisterCollisionGeometry(
peg,
RigidTransform(),
peg_geom,
'peg',
config['peg_props']
)
plant.WeldFrames(
plant.GetFrameByName("iiwa_link_7"),
peg.body_frame(),
RigidTransform([0, 0, 0.06])
)
stiffness_frame = plant.AddFrame(
FixedOffsetFrame(
"stiffness_frame",
peg.body_frame(),
RigidTransform(
RotationMatrix.MakeXRotation(-np.pi),
[0, 0, config["peg_length"]/2]))
)
plant.RegisterVisualGeometry(
peg,
RigidTransform(
[0, 0, config['peg_length']/2]),
Sphere(0.002),
"peg_tip",
[1.0, 0.0, 0.0, 1.0]
)
plant.Finalize()
logger.info(f" time step: {plant.time_step()}")
assert plant.IsDifferenceEquationSystem() "Has to be discrete time"
return plant, scene_graph
plant_config = MultibodyPlantConfig()
plant_config.time_step = 1e-2
plant_config.contact_model = "hydroelastic_with_fallback"
plant_config.contact_surface_representation = "polygon"
plant_config.penetration_allowance = 1e-5
plant, scene_graph = AddMultibodyPlant(
config=plant_config,
builder=builder
)
plant, scene_graph = CreateSystemModel(plant, scene_graph, config)
I also put the same assert just before returning plant and scene_graph, and it still fires false. I posted this issue in-case it was a drake bug. Let me know if you need further clarification.
Hi I am trying to use your iLQR implementation for my own system. The discrete system assertion is being called whenever I try and run the code on my system. To the best of my knowledge, this is if you have given a time_step of 0.0 to your multibody plant when intialising it. However, I give it a discrete time step of 1e-2. Any ideas of where I could be going wrong?
The following is the function I use instead of your
create_system_model
functionI have left comments on the code for it to be more readable. Let me know if I can create a smaller example for this to be grokable. I then pass the returned
diagram
to the iLQR class. Do let me know if you want further clarification!