Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

What does jointVelocity[] return?

Discussion in 'Robotics' started by Domi47, Sep 27, 2021.

  1. Domi47

    Domi47

    Joined:
    Feb 4, 2021
    Posts:
    10
    Hello everyone,

    I have some doubts about using joinVelocity[] (https://docs.unity3d.com/2020.2/Documentation/ScriptReference/ArticulationBody-jointVelocity.html) as I'm getting some strange values.

    I'm using the position Control as in the documentation (https://github.com/Unity-Technologi...ppendix.md#guide-to-write-your-own-controller). I calculate a DeltaStep to reach a target in a given time:

    Code (CSharp):
    1. distance = targetPos - currentPos;
    2. vel = distance/time_sec;
    3. deltaStep = vel * Time.fixedDeltaTime;
    Then, in a FixedUpdate(), I use this deltaStep to update the joint target and so reach the final one. I also get the joint position and velocity:
    Code (CSharp):
    1. ArticulationDrive joint_xDrive = joint.xDrive;
    2. joint_xDrive.target += deltaStep;
    3. joint.xDrive = joint_xDrive;
    4.  
    5. posMsg.data = joint.jointPosition[0];
    6. velMsg.data = joint.jointVelocity[0];
    When I use it in a revolute joint I set the deltaStep as degrees, and joint.jointPosition[0] returns the current position in radians. But what is joint.jointVelocity[0] returning? For example when trying to get 1.0 radians from the origin at 2.5 seconds, it means a distance of approximately 57.30 deg, and a velocity of 22.92 deg/sec (0.4 rad/sec). With a fixedDeltaTime of 0.02 sec the value of deltaStep will be 0.4584 deg (0.00799 rad). In this case joint.jointVelocity[0] returns a value similar to 0.0091 (what is also similar to my deltaStep in radians). Is it maybe the applied deltaStep in radians?

    But in case of using a Prismatic joint the returned value by joint.jointVelocity[0] is more confusing. I set a deltaStep in meters and joint.jointPosition[0] returns the current position in meters too. But if for example I try to get to 0.015 meters from the origin in 2.5 sec, this means a distance of 0.015m and a velocity of 0.006 m/s. With a fixedDeltaTime of 0.02 I will have a deltaStep of 0.00012 m. In this case when using joint.jointVelocity[0] I get a value of 0.0012, so the order of magnitude is different from my deltaStep. In this case, Is it returning an applied deltaStep in decimeters?

    I hope I explained it well. The version of ROS TCP Connector and URDF Importer that I'm using is 0.4.0 as I started the project with these ones.

    Thank you.
     
  2. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    I might need to repro your scene locally, but all of our reduced coordinate space getters/setters work on the data provided by PhysX directly -- that is angles are in rad, distances are in meters, and the velocities are direct time derivatives of those.
     
  3. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    596
    Additionally, I wanted to point out that currently we have an asymmetry in the API:
    * ArticulationBody's angular drive parameters are always in degrees (e.g. target & targetVelocity)
    * When in reduced space, we use the raw values from the physics engine -- so angles come out as radians.

    Could this be the source of the problem you're observing?
     
  4. Domi47

    Domi47

    Joined:
    Feb 4, 2021
    Posts:
    10
    Thank you for your answers @yant . Yes I realized about that asymmetry you mentioned, that's why I wanted to confirm what it is returning. So for a revolute joint it should return rad/s and for a prismatic joint it uses m/s right?
    Then I'm still having an error somewhere cause as I said in my example when I try to reach 0.4 rad/s (using a deltaStep of 0.4584 deg and a FixedDeltaTime of 0.02), it returns something like 0.0091 .