StanfordASL / neural-network-lyapunov

Synthesizing neural-network Lyapunov functions (and controllers) as stability certificate.
MIT License
138 stars 29 forks source link

Pole balancing simulation in Drake #406

Closed lujieyang closed 2 years ago

lujieyang commented 2 years ago

This change is Reviewable

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/utils.py, line 51 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
I thought we won't add schunk to the iiwa, but physically weld the end effector to the wrist link?

Sure, I will delete this function.

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 81 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Why using the discrete LQR instead of the continuous LQR? I would think we can use the continuous LQR directly. When you compute the discrete-time A, B matrix, you assume explicit Euler integration, which isn't really how Drake does time integration, so I think this discrete-time A, B aren't correct.

I see. Changing to continuous LQR

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 84 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
I don't see `pole_state_input_port` being used.

Deleted

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 87 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Why we need this iiwa_state port?

Port deleted

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/utils.py, line 20 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
This is different from the `l7_ee_offset` defined in `iiwa_and_plate.yaml`. Could you explain why? If they do mean the same thing, then I would prefer to defining it only in `iiwa_and_plate.yaml`, and read the rigid transform from yaml file.

We are not using the schunk so I'm deleting the definition. I just cleaned up the code a bit to remove dependencies on the utils.py (this file has a lot of extra functionalities that we don't need)

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 63 at r1 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
You can compute this Ac and Bc matrix pretty easily by instantiating a `Pole` system and call its `gradient` function.

I calculated Ac, Bc offline. Would you recommend do it here instead?

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 204 at r4 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Could you explain a bit why the simulation is continuous time here? The IIWA controller is a discrete time system.

When I try to use discrete time step for MultibodyPlant, Drake gives the error "MultibodyPlant's discrete update solver failed to converge at simulation time = 0.00035 with discrete update period = 1e-05. This usually means that the plant's discrete update period is too large to resolve the system's dynamics for the given simulation conditions. This is often the case during abrupt collisions or during complex and fast changing contact configurations. Another common cause is the use of high gains in the simulation of closed loop systems. These might cause numerical instabilities given our discrete solver uses an explicit treatment of actuation inputs. Possible solutions include: switch to a continuous model (discrete update period is zero)."

The collision might be due to the initial impact of the pole with the plate.

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 141 at r4 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Could you document that `Q` stands for plate frame? And just curious, why this frame is abbreviated as `Q`?

Done.

I was borrowing code from the IK tutorial for the manipulation class.

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 292 at r4 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Unused?

Currently used in building the MBP for iiwa controller (not implemented)

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 197 at r4 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
BTW, I don't think we have explained what `C` means here? Maybe document it that `C` is the point on the end effector where the pole makes contact on the end-effector, and `f_C_W` is the force applied from the pole to the end-effector at point C, and the force is measured in the world frame `W`. The reason to add this documentation is to make it clear where the force is applied, and who applies that force (since there is an equal and opposite force from the end-effector to the pole at the same point).

I'm removing f_C_W as a whole because we will later add the iiwa controller.

lujieyang commented 2 years ago

neural_network_lyapunov/examples/pole/simulation/pole_balancing_sim.py, line 197 at r4 (raw file):

Previously, hongkai-dai (Hongkai Dai) wrote…
Could you document what f_C_W is?

Done.