-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropping Jupyter notebooks for rigid body demos
- Loading branch information
Showing
2 changed files
with
173 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import numpy as np | ||
import rainbow.math.vector3 as V3 | ||
import rainbow.math.quaternion as Q | ||
import rainbow.geometry.surface_mesh as MESH | ||
import rainbow.simulators.prox_rigid_bodies.api as API | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def setup_scene(engine): | ||
V, T = MESH.create_box(4.0, 4.0, 4.0) | ||
mesh = API.create_mesh(V, T) | ||
API.create_shape(engine, 'box', mesh) | ||
|
||
V, T = MESH.create_sphere(2.0, 16, 16) | ||
mesh = API.create_mesh(V, T) | ||
API.create_shape(engine, 'sphere', mesh) | ||
|
||
API.create_rigid_body(engine, 'A') | ||
API.connect_shape(engine, 'A', 'box') | ||
API.set_mass_properties(engine, 'A', 1.0) | ||
API.set_orientation(engine, 'A', Q.identity(), use_model_frame=True) | ||
API.set_position(engine, 'A', V3.make(3.0, 0.0, 0.0), use_model_frame=True) | ||
API.set_velocity(engine, 'A', V3.make(0.0, 0.0, 0.0)) | ||
API.set_spin(engine, 'A', V3.make(0.0, 0.0, 0.0)) | ||
API.set_body_type(engine, 'A', 'fixed') | ||
|
||
API.create_rigid_body(engine, 'B') | ||
API.connect_shape(engine, 'B', 'sphere') | ||
API.set_mass_properties(engine, 'B', 1.0) | ||
API.set_orientation(engine, 'B', Q.identity(), use_model_frame=True) | ||
API.set_position(engine, 'B', V3.make(-1.25, 0.0, 0.0), use_model_frame=True) | ||
API.set_velocity(engine, 'B', V3.make(10.0, 0.0, 0.0)) | ||
API.set_spin(engine, 'B', V3.make(0.0, 0.0, 20.0)) | ||
|
||
|
||
def simulate(engine): | ||
dt = engine.params.time_step | ||
T = 1.0 # total time | ||
fps = 1.0 / dt | ||
steps = int(np.round(T * fps)) | ||
for i in range(steps): | ||
API.simulate(engine, dt, debug_on=True) | ||
print("simulated ", i, " steps, with ", len(engine.contact_points), " contact points") | ||
|
||
|
||
def plot(engine): | ||
stats = API.get_log(engine) | ||
fig = plt.figure() | ||
ax = plt.subplot(111) | ||
ax.set_title('Converegence rates') | ||
ax.set_xlabel('Iterations') | ||
ax.set_ylabel('Merit') | ||
plt.grid(True) | ||
for i in range(len(stats)): | ||
data = stats[i] | ||
if 'residuals' in data.keys(): | ||
residuals = data['residuals'] | ||
reject = data['reject'] | ||
ax.plot(residuals[np.where(reject == False)]) | ||
plt.show() | ||
|
||
|
||
def main(): | ||
engine = API.create_engine() | ||
|
||
setup_scene(engine) | ||
|
||
simulate(engine) | ||
|
||
plot(engine) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters