Skip to content
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

Proposal: system for setting initial position / velocity #2318

Open
scpeters opened this issue Feb 15, 2024 · 2 comments
Open

Proposal: system for setting initial position / velocity #2318

scpeters opened this issue Feb 15, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@scpeters
Copy link
Member

Desired behavior

I'd like to be able to specify initial model/link velocity and initial joint position/velocity. For joints, I believe this can be done by setting JointPositionReset and JointVelocityReset components programmatically. It would be consistent with this pattern to add LinearVelocityReset / AngularVelocityReset and/or WorldLinearVelocityReset / WorldAngularVelocityReset components that could be used to set initial model / link velocities.

Alternatives considered

I had started an alternative approach in #2265 based on using the existing AngularVelocityCmd and LinearVelocityCmd components with the VelocityControl system, but I think the *Reset components make more sense.

Implementation suggestion

<model name="example_model">
  <link name="parent_link" />
  <link name="child_link" />
  <joint name="multiaxis_joint" type="universal">
    <axis>
      <xyz>0 0 1</xyz>
    </axis>
    <axis2>
      <xyz>1 0 0</xyz>
    </axis2>
  </joint>
  <plugin name="SetInitialComponents" ...>
    <!-- different syntax ideas to set initial velocity for this model -->
      <!-- specify //entity/@type="model" and //entity/@name="__model__" -->
      <entity type="model" name="__model__">
        <set_component_value type="WorldLinearVelocityReset">1.0 4.0 9.0</set_component_value>
      </entity>
      <!-- specify //model/@name="__model__" -->
      <model name="__model__">
        <set_component_value type="WorldLinearVelocityReset">1.0 4.0 9.0</set_component_value>
      </model>
      <!-- or just treat set_component_value tags at the root scope as referring to the model -->
      <set_component_value type="WorldLinearVelocityReset">1.0 4.0 9.0</set_component_value>
  
    <!-- different syntax ideas to set initial velocity for a link -->
      <!-- specify //entity/@type="link" and //entity/@name="parent_link" -->
      <entity type="link" name="parent_link">
        <set_component_value type="WorldLinearVelocityReset">1.0 4.0 9.0</set_component_value>
      </entity>
      <!-- specify //link/@name="parent_link" -->
      <link name="parent_link">
        <set_component_value type="WorldLinearVelocityReset">1.0 4.0 9.0</set_component_value>
      </link>

    <!-- different syntax ideas to set initial position / velocity for a joint -->
      <!-- specify //entity/@type="joint" and //entity/@name="multiaxis_joint" -->
      <entity type="joint" name="multiaxis_joint">
        <set_component_value type="JointPositionReset">0.1 0.4</set_component_value>
        <set_component_value type="JointVelocityReset">1.0 -0.5</set_component_value>
      </entity>
      <!-- specify //joint/@name="multiaxis_joint" -->
      <joint name="multiaxis_joint">
        <set_component_value type="JointPositionReset">0.1 0.4</set_component_value>
        <set_component_value type="JointVelocityReset">1.0 -0.5</set_component_value>
      </joint>
  
  </plugin>

Thoughts are welcome for the right syntax here. I think we would have to hard-code a relationship between the //set_component_value/@type string and a gz::sim::components:: class since the component Factory doesn't allow constructing just from a string. It does have namesById and runtimeNamesById data structures but not the inverse (IdsByName). Even if we did, I'm not sure how it could be implemented.

I suggested the system name of SetInitialComponents in this example to go along with the <set_component_value> elements, but we could also use names with more specific semantics (similar to the InitialVelocityPlugin from gazebo-classic).

Additional context

@scpeters scpeters added the enhancement New feature or request label Feb 15, 2024
@scpeters
Copy link
Member Author

consider expressing the model state using the syntax of the model_state

@arjo129
Copy link
Contributor

arjo129 commented Feb 17, 2024

This would be really useful for reducing our test times. In particular we could use it to test plugins like the hydrodynamics/LiftDrag etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In progress
Development

No branches or pull requests

2 participants