New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a pre-curved rod #12
Comments
Hi @emersonkt There are couple of things you need to do before creating a curved rod:
tangents = position[…,1:] - position[…,:-1] Tangents are unit vectors so we should normalize them by dividing its length. In PyElastica we have a build in function to compute lengths of vectors. Import the following; from elastica._linalg import _batch_norm
tangents /= _batch_norm(tangents)
At this point you know position and directors of the rod. Next step is to create the rod and send shearable_rod = CosseratRod.straight_rod (n_elem,
start,
direction,
normal,
base_length,
base_radius,
density,
nu,
youngs_modulus,
poisson_ratio=0.5,
position=position,
directors=directors) Since rod is not straight and curved initially we should compute the rest curvature and strain. However PyElastica has already computed curvature and strain for you when shearable_rod.rest_kappa[:] = shearable_rod.kappa[:]
shearable_rod.rest_sigma[:] = shearable_rod.sigma[:] Now you have a curved rod. |
Thank you very much ! It worked well and I got the desired pre-curved rod. In the other hand, when a force is defined in the end tip of the robot, I got a movement just in the last element of the rod as the attached image. Why are the elements not connected ? Here below I send you the code as I typed it. Code in Python
|
Hi @emersonkt, Can you also provide how you provide your forcing class? Also did you see any numerical instabilities in your simulation i.e. |
Here below the forcing class:
Looking at the position and velocity arrays, I got the following results. So maybe the velocities are good! However, just on the last element of the x axis I am getting an ununderstandable result.
|
Hi @emersonkt, I realized there was a bug in the public version of PyElastica. Latest PR #14 should fix the issue. Can you pull from master and try again? Let me know if you have any problems. |
Hi @armantekinalp, Thank you very much for the support, however I am still having the same problem. My project is being done via Google Colab, so I guess the library is pulled on each build, right ? |
Hi @emersonkt , I am not familiar with how Google Colab pulls the library. If it is doing Can you check if you can clone |
I get it. Your comment led me to this website https://medium.com/@ashwindesilva/how-to-use-google-colaboratory-to-clone-a-github-repository-e07cf8d3d22b which explains how to use git with google colab (if anyone else is interested). Now it is perfect ! Thank you very much for your excellent work! |
Hi @armantekinalp , |
Hi @MehtaMeet54 , Can you please provide the version of PyElastica you are using and also how you are initializing the rod? |
VERSION = "0.1.0.post2" n_elem = 100
start = np.array([0.0, 0.0, 0.0])
direction = np.array([0.0, 0.0, 1.0])
normal = np.array([0.0, 1.0, 0.0])
base_length = 1.0
base_radius = 0.05
base_area = np.pi * base_radius ** 2
density = 8000
nu = 0.2
E = 1e11
poisson_ratio=0.3
position = np.zeros((n_elem+1,3))
for i in range(0, n_elem+1):
position[i][0] = (i/n_elem)**2/base_length #y
position[i][1] = 0 #z
position[i][2] = (base_length/n_elem)*i #x
position = np.transpose(position)
tangents = np.zeros((3,n_elem))
for i in range(0, 3):
tangents[i] = position[i,1:] - position[i,:-1]
tangents /= _batch_norm(tangents)
d3 = tangents
d2 = np.zeros((n_elem,3))
d1 = np.zeros((n_elem,3))
for i in range(0,n_elem):
d2[i][0] = 0
d2[i][1] = 1
d2[i][2] = 0
d1[i] = np.cross(d2[i],np.transpose(tangents)[i])
d2 = np.transpose(d2)
d1 = np.transpose(d1)
directors = np.zeros((3,3,n_elem))
directors[0] = d1
directors[1] = d2
directors[2] = d3
shearable_rod = CosseratRod.straight_rod(n_elem,start,direction,normal,base_length,base_radius,density,nu,E,poisson_ratio,position=position,directors=directors)
shearable_rod.rest_kappa[:] = shearable_rod.kappa[:]
shearable_rod.rest_sigma[:] = shearable_rod.sigma[:]
dynamic_update_sim.append(shearable_rod)
dynamic_update_sim.constrain(shearable_rod).using(OneEndFixedRod, constrained_position_idx=(0,), constrained_director_idx=(0,))
force = 100
dynamic_update_sim.add_forcing_to(shearable_rod).using(UniformForces, force, np.array([-1.0,0.0,0.0]))
dynamic_update_sim.finalize() |
@MehtaMeet54 Hi Thank you for providing the code. I checked the director is not initialized properly in the version There was a bug in initializing rod with custom directors. The bug is fixed in Code I testedClick to expandimport numpy as np
from elastica import *
from elastica._linalg import _batch_norm
n_elem = 100
start = np.array([0.0, 0.0, 0.0])
direction = np.array([0.0, 0.0, 1.0])
normal = np.array([0.0, 1.0, 0.0])
base_length = 1.0
base_radius = 0.05
base_area = np.pi * base_radius ** 2
density = 8000
nu = 0.2
E = 1e11
poisson_ratio=0.3
position = np.zeros((n_elem+1,3))
for i in range(0, n_elem+1):
position[i][0] = (i/n_elem)**2/base_length #y
position[i][1] = 0 #z
position[i][2] = (base_length/n_elem)*i #x
position = np.transpose(position)
tangents = np.zeros((3,n_elem))
for i in range(0, 3):
tangents[i] = position[i,1:] - position[i,:-1]
tangents /= _batch_norm(tangents)
d3 = tangents
d2 = np.zeros((n_elem,3))
d1 = np.zeros((n_elem,3))
for i in range(0,n_elem):
d2[i][0] = 0
d2[i][1] = 1
d2[i][2] = 0
d1[i] = np.cross(d2[i],np.transpose(tangents)[i])
d2 = np.transpose(d2)
d1 = np.transpose(d1)
directors = np.zeros((3,3,n_elem))
directors[0] = d1
directors[1] = d2
directors[2] = d3
shearable_rod = CosseratRod.straight_rod(n_elem,start,direction,normal,base_length,base_radius,density,nu,E,poisson_ratio,position=position,directors=directors)
shearable_rod.rest_kappa[:] = shearable_rod.kappa[:]
shearable_rod.rest_sigma[:] = shearable_rod.sigma[:]
print(f"{np.allclose(shearable_rod.position_collection, position)=}")
print(f"{np.allclose(shearable_rod.director_collection, directors)=}") Result (python 3.8.0, pyelastica 0.2.1)Click to expandnp.allclose(shearable_rod.position_collection, position)=True
np.allclose(shearable_rod.director_collection, directors)=True |
Hello PyElastica,
I am a student and I am trying to apply the library 'PyElastica' in my project for a rod with a pre-curvature. But I could only create a straight rod. Could you please advise me if there is a way to make a pre-curved rod?
Thank you in advance for your help and congratulations for this beautiful work !
Émerson
The text was updated successfully, but these errors were encountered: