Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Oscillations when setting cable lengths, probably due to dynamics
#3
(29-03-2023, 09:45 AM)josemendez Wrote: 1.- Just in case: make sure all ropes are part of the same solver and the same updater, since they're involved in the same simulation. Otherwise they will behave independently, calculating and applying forces as if no other ropes were attached to the rigidbody.

2.- You're assuming the rope is kinematic and has no momentum, so it cannot stretch or compress due to inertia. I'd recommend to leave some room for the rope to expand/contract a bit, like so:

Code:
if (c2_len > c2_control_ip + room)
        {
            cursor_2.ChangeLength(rope_2.restLength - c2_control_ip * time_dt/10);
        }

        else if(c2_len < c2_control_ip - room)
        {
            cursor_2.ChangeLength(rope_2.restLength + c2_control_ip * time_dt/10);
        }

Otherwise if the rope stretches or compresses even a little bit, it will trigger a change in rest length.  This is similar to what the included sample ObiRopeReel script does:

Code:
// Update is called once per frame
void Update()
{
    // get current and rest lengths:
    float length = rope.CalculateLength();
    float restLength = rope.restLength;

    // calculate difference between current length and rest length:
    float diff = Mathf.Max(0, length - restLength);

    // if the rope has been stretched beyond the reel out threshold, increase its rest length:
    if (diff > outThreshold)
        restLength += diff * outSpeed;

    // if the rope is not stretched past the reel in threshold, decrease its rest length:
    if (diff < inThreshold)
        restLength -= diff * inSpeed;

    // set the new rest length:
    cursor.ChangeLength(restLength);
}

so I tried giving some threshold for the control inputs.

Code:
    public float cable_threshold = 0.01f;

Code:
    public void set_c1()
    {
        if (c1_len > c1_control_ip + cable_threshold)
        {
            cursor_1.ChangeLength(rope_1.restLength - c1_control_ip * time_dt);
        }

        else if(c1_len < c1_control_ip - cable_threshold)
        {
            cursor_1.ChangeLength(rope_1.restLength + c1_control_ip * time_dt);
        }

        else
        {
            Debug.Log("Current Length and Control input are the same for Cable 1");
        }
       
    }

for all the cables.
Now its not oscillating, however when I read the cable length using,
Code:
rope1.CalculateLength();

Its not the same as the control input, well it should not be since we provided the threshold, but atleast it should be within the threshold.

I am getting the error between the control inputs and current lengths (after changing the cable lengths) as,

Code:
Error in Control:
Cable1:  -0.2439530000000012
Cable2:  -0.48052399999999906
Cable3:  -0.3184590000000007
Cable4:  -0.26758999999999844

I am using the same fixed updater for all the cables with same Obi solver with 5 substeps.
The resolution of the rope is 0.6 with 100 pooled particles.

In Distance contraints I put stretching scale as 0.1, since with stretching scale = 1, the rope is sagging enormously.
Reply


Messages In This Thread
RE: Oscillations when setting cable lengths, probably due to dynamics - by rohit_dhak - 29-03-2023, 12:44 PM