NASA-AMMOS / aerie

A software framework for modeling spacecraft.
https://nasa-ammos.github.io/aerie-docs/
MIT License
68 stars 19 forks source link

Coexistence goal real resource `valueAt` cannot be assigned to real parameters #1484

Open adrienmaillard opened 2 months ago

adrienmaillard commented 2 months ago

While working on #1378, I found the following issue. Executing the following goal:

  export default () => Goal.CoexistenceGoal({
    forEach: ActivityExpression.ofType(ActivityTypes.GrowBanana),
    activityTemplate: (growBananaActivity) => ActivityTemplates.BiteBanana({biteSize: Real.Resource("/fruit").valueAt(growBananaActivity.span().starts())}),
    startsAt: TimingConstraint.singleton(WindowProperty.START).minus(Temporal.Duration.from({ minutes : 5}))
  })

leads to the following error during the ts parsing step TypeError: TS2322 Type 'Discrete<number>' is not assignable to type 'number | Real'.\n Type 'Discrete<number>' is missing the following properties from type 'Real': rate, times, plus, minus, and 6 more.

We want to assign the value of /fruit at some time to the real parameter biteSize. To do that, we use the valueAt operator. But the return of this operator is a Discrete<number> when the parameter expects either a number of a Real.

Possible fix

We could provide a

static toReal(discreteProfile: Discrete<number>): Real

method in the Real class. We'd convert the number profile into its equivalent real profile via a newRealProfileFromDiscrete constraint tree element (values would be the same, rates would be 0).

adrienmaillard commented 2 months ago

@JoelCourtney, what do you think ?