RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.35k stars 1.27k forks source link

Distance Link and Revolute-Spherical Joint/Constraint #19235

Open MarvinSt opened 1 year ago

MarvinSt commented 1 year ago

Feature Request: To make it convenient to model automotive suspension linkages, it would be nice to have simple joints which impose certain constraints, such as a distance constraint (to model a massless rod with two spherical joints) or a combined revolute/spherical joint. Project Chrono offers such types of linkages and they can be used interchangeably with the other more conventional type of joints. (see: https://api.projectchrono.org/8.0.0/links.html)

Solution: Support similar types of joints as in Project Chrono for cases where the mass/inertia of intermediate bodies can be neglected and the system can be simplified using combination joints.

Alternatives: N/A

Screenshots:

Consider the system (taken from Project Chrono documentation)

Which can be modelled using distance constraints (if the linkage bodies can be neglected)

Or if the bodies should be modelled, using individual or combined (control arm) bodies:

EricCousineau-TRI commented 1 year ago

Assigning @amcastro-tri for disposition

MarvinSt commented 1 year ago

This is also available in Simbody and can be implemented as follows:

auto dist = (chassis_link_pos - upright_link_pos).norm();
// Option 1:
auto link = Constraint::SphereOnSphereContact(chassis, chassis_link_pos - chassis_pos, dist / 2.0, upright, upright_link_pos - upright_pos, dist / 2.0, false);
// Option 2:
auto link = Constraint::Rod(chassis, chassis_link_pos - chassis_pos, upright, upright_link_pos - upright_pos, dist);
sherm1 commented 1 year ago

I think the distance constraint is already available when using Drake's SAP solver. Is there an example somewhere?

amcastro-tri commented 1 year ago

Yes, with the SAP solver we can already add distance and spherical joints (we call them ball) constraints. Documentaiton to the API is here in MultibodyPlant::AddDistanceConstraint(). Python bindings are available as well.

For spherical joints constraints, which we call ball constrains, these are also supported in SAP. The API with docs is here in MultibodyPlant::AddBallConstraint().

Are these what you need @MarvinSt? should we close the issue or maybe update it to reflect the missing feature?

MarvinSt commented 1 year ago

I think we can close it, it was not obvious to me how to add constraints via the Python bindings. Perhaps a minimum example would be valuable, but it seems like the feature exists already, my apologies.

amcastro-tri commented 1 year ago

no problem at all!. The unit tests (though in C++) show how to call these APIs. What did you think about the API docs? are those enough for you to get started? or how do you think we could improve them?

MarvinSt commented 1 year ago

no problem at all!. The unit tests (though in C++) show how to call these APIs. What did you think about the API docs? are those enough for you to get started? or how do you think we could improve them?

From my perspective, the docs were quite extensive in terms of background info, but difficult to actually get up and running (esp. compared to Chrono and Simbody for example). Most examples are steering towards creating models from .udf files and for the Python bindings, I indeed mostly tried to transcribe the C++ examples. It was not hard per-see, it just required a bit more work to get up and running. Where I got stuck was with kinematic loops and constraints.

I am currently doing the following:

meshcat = StartMeshcat() visualizer = MeshcatVisualizer.AddToBuilder(builder, scene_graph, meshcat, MeshcatVisualizerParams(role=Role.kPerception, prefix="visual")) diagram = builder.Build()



but I don't have the ability to do
plant.AddDistanceConstraint() or any constraint for that matter

EDIT: I suppose this has to do with using the correct solver? Perhaps, it is easier if I start working with the C++ API.