cmower / optas

OpTaS: An optimization-based task specification library for trajectory optimization and model predictive control.
https://cmower.github.io/optas/
Other
99 stars 14 forks source link

Enable user to specify functions that always output numpy arrays #118

Closed cmower closed 1 year ago

cmower commented 1 year ago

Motivation

The benefit of this is when the user creates functions that they want to evaluate later (this is assuming you don't pass symbolic variables). For example, when I want the wrench at the end-effector from the joint, I want a function to evaluate the Jacobian. Since I am not defining an optimization problem, I will be doing the computation in Numpy (faster than casadi DM).

Difference

Before

robot = optas.RobotModel(...)
pos = robot.get_global_link_position_function(ee_link)

p = pos(q).toarray().flatten()  # pos(q) outputs a casadi.DM array

After

robot = optas.RobotModel(...)
pos = robot.get_global_link_position_function(ee_link, numpy_output=True)

p = pos(q)  # since numpy_output=True is specified, the output is automatically converted to a numpy array

When numpy_output=True is specified, if you pass a symbolic variable in then the method will fail since you are telling optas that you are expecting not to be passing symbolic variables.

Todo before merge

joaomoura24 commented 1 year ago

For me it all seems good. Go ahead with merging it when you can.

cmower commented 1 year ago

Thanks @joaomoura24, merging when tests all go green