Search code examples
drake

RuntimeError when using pydrake.symbolic.Evaluate


When trying to use evaluate to retrieve the numerical value of my continuous decision variable q, I get the following error:

RuntimeError: The following environment does not have an entry for the variable q(0,0)

Trying to get the value of a single entry in q (akin to the answer given here), results in this error:

TypeError: Evaluate(): incompatible function arguments. The following argument types are supported:
1. (m: numpy.ndarray[object[m, n]], env: Dict[pydrake.symbolic.Variable, float] = {}, generator: pydrake.common._module_py.RandomGenerator = None) -> numpy.ndarray[numpy.float64[m, n]]
2. (m: numpy.ndarray[object[m, n]], env: Dict[pydrake.symbolic.Variable, float]) -> numpy.ndarray[numpy.float64[m, n]]

Invoked with: Variable('q(0,0)', Continuous)

What am I missing?


Solution

  • Evaluate(expression) will only provide output if the Expression is a constant. To get the values of your decision variables, use MathmaticalProgramResult.GetSolution.

    There are many great tutorials on using MathematicalProgram here: https://github.com/RobotLocomotion/drake/blob/master/tutorials/README.md