drake icon indicating copy to clipboard operation
drake copied to clipboard

Represent the Image of a Trajectory Under Arbitrary Mappings

Open cohnt opened this issue 1 year ago • 5 comments

If I'm given a trajectory $q:[t_0,t_1]\to\mathbb R^n$, and a smooth function $f:\mathbb R^n\to\mathbb R^m$, then the composition $f\circ q:[t_0,t_1]\to\mathbb R^m$ is also a valid trajectory. However, there's no general way to represent such an object in Drake, so I can't use features such as Toppra (which requires a trajectory object as input).

My current workaround is to densely sample points from the trajectory and then interpolate them to construct a new trajectory, but this has been very finicky in practice (and is how I encountered the issue described in #20619). Such a feature would be extremely helpful for my constrained bimanual manipulation work, where robot trajectories live parametrization of configuration space that is more amenable to planning. Ideally, the feature would be compatible with functions defined with Drake's symbolic engine and "autodiff"-able functions.

cc @sageshoyu @shrutigarg914 @RussTedrake

cohnt avatar Dec 20 '23 15:12 cohnt

Assigned to Russ for disposition.

sherm1 avatar Dec 21 '23 01:12 sherm1

Back in the matlab days of Drake, we had a FunctionHandleTrajectory class. We could bring that back easily enough. It would basically create a subclass of Trajectory that takes a std::function mapping time to the vector/matrix output. We can bind a python method to it via pybind. Would that be a sufficient solution?

RussTedrake avatar Feb 04 '24 19:02 RussTedrake

Just to confirm my understanding of the workflow, I could write a (autodiff-compatible) function in Python, and use it to construct a FunctionHandleTrajectory? If I'm trying to remap a trajectory, I could just write a function that takes in a time t, computes the trajectory value at that time, and applies my desired transformation to that value? (Does autodiff play nicely throughout all that if I'm calling trajectory.value(t)?)

cohnt avatar Feb 05 '24 15:02 cohnt

The Trajectory class is templated. The autodiff variant, Trajectory<AutoDiffXd>, when it calls value(t) would pass an autodiff and expect an autodiff output. And yes, we should be able to make that work for the python function, too. (We do this for mathematicalprogram costs and constraints).

RussTedrake avatar Feb 06 '24 02:02 RussTedrake

Perfect, then! This feature would be extremely helpful.

cohnt avatar Feb 06 '24 16:02 cohnt