Reputation: 5566
I am trying to use direct transcription to solve my trajectory optimization problem which involves some trigonometric functions.
I have the following variable types
a[i] = array([<Expression "(state_0(0) + 0.001 * state_0(4))">,
<Expression "(state_0(1) + 0.001 * state_0(5))">,
<Expression "(state_0(2) + 0.001 * state_0(6))">,
<Expression "(state_0(3) + 0.001 * state_0(7))">,
<Expression "...omitted...">,
<Expression "...omitted...">,
<Expression "...omitted...">,
<Expression "...omitted...">], dtype=object)
b[i] = array([Variable('state_1(0)', Continuous),
Variable('state_1(1)', Continuous),
Variable('state_1(2)', Continuous),
Variable('state_1(3)', Continuous),
Variable('state_1(4)', Continuous),
Variable('state_1(5)', Continuous),
Variable('state_1(6)', Continuous),
Variable('state_1(7)', Continuous)], dtype=object)
I'm trying to create a constraint as follows
mp.AddConstraint(b[i] <= a[i])
But I get the following error
RuntimeError: You should not call `__bool__` / `__nonzero__` on `Formula`. If you are trying to make a map with `Variable`, `Expression`, or `Polynomial` as keys (and then access the map in Python), please use pydrake.common.containers.EqualToDict`.
Upvotes: 2
Views: 168
Reputation: 5533
That's correct. Although you can also use the function names like eq(a,b)
https://github.com/RobotLocomotion/drake/issues/8315
Upvotes: 1
Reputation: 5566
It appears that the constraint must be specified per element, i.e.
for j in range(8):
mp.AddConstraint(b[i][j] <= a[i][j])
Upvotes: 0