Hi, I am Sunil from IIT Kanpur, and I am working on contact dynamics to simulate cube toss experiments. The total energy, i.e., the sum of kinetic and potential energy of the cube toss data stored in data/tosses_processed after impact, comes out to be greater than the initial total energy of the cube for some of the experiment data e.g., 0.pt, 7.pt, 12.pt etc. as shown below.
Please check the Python code below to reproduce these plots:
import torch,os
import numpy as np
import matplotlib.pyplot as plt
dt = 1/148 #148 Hz
#Cube parameters (Acosta et al 2022)
m = 0.37 # mass of the cube in kg
I = 0.0081 #mass moment of inertia
width = 0.1 #10x10x10cm cube
mu=0.18 #friction
e=0.125 #restitution
blockWidthScale =0.0524 # scale factor used in dataset
#Get current directory
base_dir = os.path.dirname(os.path.abspath(__file__))
#Load trajectory data .pt from GitHub/contact-nets/data/tosses_processed/file.pt
data_dir=os.path.join(base_dir, "GitHub/contact-nets/data/tosses_processed")
for i in range(0, 20): # files are named 0.pt, 1.pt, ..., 570.pt
data_path = os.path.join(data_dir, f"{i}.pt")
#load .pt file data using torch
data = torch.load(data_path)
print(f"Loaded data with shape {data.shape}")
#Remove batch dimension if present
data = data.squeeze(0) # Now shape [111, 19]
#Assume features: 0=x, 1=y, 2=z, 3=q0, 4=q1, 5=q2, 6=q3, 7=dx, 8=dy, 9=dz, 10=wx, 11=wy, 12=wz, 13-18=zeros
#Time is not stored,
#frequency is 148 Hz, so time step is 1/148 seconds
t = dt*np.arange(data.shape[0])
#plot total energy
KE= 0.5 * m * blockWidthScale**2*(data[:, 7]**2 + data[:, 8]**2 + data[:, 9]**2) + 0.5 * I * (data[:, 10]**2 + data[:, 11]**2 + data[:, 12]**2)
PE= m * 9.81 * blockWidthScale*data[:, 2] # m*g*h
TE= KE + PE
plt.figure()
plt.plot(t, TE, marker='o', label='KE+PE')
plt.xlabel('Time (s)')
plt.ylabel('Energy (J)')
#plt.title('Total Energy during Toss')
plt.legend()
plt.grid()
plt.show()
The total energy after impact can not be greater than the initial energy of the cube. Could you check and let me know if there are any issues with the above Python code or the experimental data?
Hi, I am Sunil from IIT Kanpur, and I am working on contact dynamics to simulate cube toss experiments. The total energy, i.e., the sum of kinetic and potential energy of the cube toss data stored in
data/tosses_processedafter impact, comes out to be greater than the initial total energy of the cube for some of the experiment data e.g.,0.pt,7.pt,12.ptetc. as shown below.Please check the Python code below to reproduce these plots:
The total energy after impact can not be greater than the initial energy of the cube. Could you check and let me know if there are any issues with the above Python code or the experimental data?