question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Joint between Rod and RigidBody

See original GitHub issue

Describe the bug According to the documentation, a numerous number of joints (and particularly the FixedJoint) should have compatibility for connecting a CosseratRod and a RigidBody (for example a Cylinder). However in practice, there are some bugs when trying to use this feature:

Error message for call simulator.connect(rigid_body, rod, first_connect_idx=0, second_connect_idx=-1):

File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/wrappers/connections.py", line 99, in _call_connections
    connection.apply_torques(
  File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/joint.py", line 250, in apply_torques
    + rod_two.rest_lengths[index_two] * rod_one.tangents[..., index_one]
AttributeError: 'Cylinder' object has no attribute 'tangents'

Error message for call simulator.connect(rod, rigid_body, first_connect_idx=0, second_connect_idx=0):

 File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/wrappers/connections.py", line 99, in _call_connections
    connection.apply_torques(
  File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/joint.py", line 250, in apply_torques
    + rod_two.rest_lengths[index_two] * rod_one.tangents[..., index_one]
AttributeError: 'Cylinder' object has no attribute 'rest_lengths'

Error message for call simulator.connect(rod, rigid_body, first_connect_idx=-1, second_connect_idx=0):

 File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/wrappers/connections.py", line 99, in _call_connections
    connection.apply_torques(
  File "/Users/maximilianstoelzle/opt/miniconda3/envs/hsa-control/lib/python3.10/site-packages/elastica/joint.py", line 239, in apply_torques
    rod_two.position_collection[..., index_two + 1]
IndexError: index 1 is out of bounds for axis 1 with size 1

To Reproduce

from elastica.joint import FixedJoint
from elastica.rod.cosserat_rod import CosseratRod
from elastica.rigidbody import Cylinder
rod = CosseratRod.straight_rod(
                n_elements=50,  # number of elements
                start=rod_base_position,  # Starting position of first node in rod
                direction=np.array([0.0, 1.0, 0.0]),  # Direction the rod extends
                normal=np.array([0.0, 0.0, 1.0]),  # normal vector of rod
                base_length=1.,  # original length of rod (m)
                base_radius=0.05,  # original radius of rod (m)
                density=1e3,  # density of rod (kg/m^3)
                nu=1e-3,  # Energy dissipation of rod
                youngs_modulus=youngs_modulus,
                shear_modulus=shear_modulus,
            )
rigid_body =  Cylinder(start=np.array[0., 0., 1.),
                            normal=np.array([0., 0., 1.]),
                            direction=np.array([1., 0., 0.]),
                            base_length=platform_thickness,
                            base_radius=platform_radius,
                            density=1.,  # TODO: replace with actual density of platform
                        )
simulator.connect(rigid_body, rod, first_connect_idx=0, second_connect_idx=-1).using(
                                    FixedJoint,
                                    k=1e8, kt=1e6, nu=1,
                                )

Environment

  • Python=3.10.5, pip=22.1.2
  • Numpy/numba version: 22.1.2
  • PyElastica version: 0.2.3
  • OS, Device: macOS / macBook Pro 15’’ 2019

Expected behavior I expect the be able to connect a RigidBody and a CosseratRod via a (Fixed)Joint, no matter which is referenced as rod_1 or rod_2 in the connect method.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
armantekinalpcommented, Jul 4, 2022

Hi @mstoelzle

Thanks for reporting the bug. Fixed joint can only connect two rods, not rigid body and a rod. So documentation was misleading and I will correct that.

However, you can still write your joint class to connect rigid body and rod. The Joint class you need to write is similar to the fixed joint. First you need to compute the tip position of rigid body to find the connection point of rigid-body and rod. Second you need to write a torque spring to fix relative orientation of rigid body and rod.

Here are some hints for you to get starting:

  • Tip position of cylinder is can be calculated as follows,
cylinder_tip_position = cylinder_two.position_collection[..., 0]
                - 0.5 * cylinder_two.length * cylinder_two.director_collection[2, :, 0]
  • Assuming rod_one is cylinder, you also need to correct this line instead of rod_one.tangents[..., index_one] you need to write rod_one.director_collection[2, :, 0]

Also after implementing joint class, you are welcome to do a PR and contribute to the PyElastica . Let me know if you have any other questions.

0reactions
mstoelzlecommented, Aug 6, 2022

I will close this issue for now as #149 is merged now into the v0.3.0 branch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploring Rigidbody Joints and Rope Physics in Unity
Unity has a number of different joints and other ways to connect Rigidbodies (Spring's come to mind). We're going to be exploring how...
Read more >
Statics: Problem 5-66: Example of a 3D Rigid Body ... - YouTube
Example of a 3D Rigid Body Equilibrium with a ball and socket joint. The ball and socket joint only applies three reaction forces...
Read more >
Kinematic Joint - an overview | ScienceDirect Topics
A third category of kinematic joint comprises the joints formed by combining ... and the 6-DoF rigid-body (RB) joint connecting the base link...
Read more >
Howto combine two rigidbodies movable together - Unity Forum
I have a rod and a tube. I want to move the rod through the tube. I think to do this with two...
Read more >
Chapter 21 Rigid Body Dynamics: Rotation and Translation ...
oriented along the y-axis and connected by a rod of negligible mass of length D, forming a rigid body. A force of magnitude...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found