grampc / pygrampc

Python interface for the GRAMPC solver
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Double Integrator example not working with fixed time #6

Open karthyyy opened 18 hours ago

karthyyy commented 18 hours ago

Hi,

I was modifying Double Integrator example in PYGRAMPC and observed the following.

1) With OptimTIme = "On", the code is simulating correctly with states reached at around 3.5 sec. 2) With OptimTIme = "Off" in 'json' file, following error is shown,

Traceback (most recent call last):
  File "...\examples\DoubleIntegrator\DoubleIntegrator.py", line 69, in <module>
    if i + 1 > len(vec.t) or vec.t[i + 1] > Tsim:
IndexError: index 8001 is out of bounds for axis 0 with size 8001

So I changed " if i + 1 > len(vec.t) or vec.t[i + 1] > Tsim:" to " if i + 1 > len(vec.t) or vec.t[i] > Tsim:" there is no simulation error but states are not reached to the desired values even after 8 sec. In the software manual example, for fixed time problem, the states are converged within 4sec.

image

image

The JSON file content is as follows

{
  "Parameters":
  {
    "x0": [-1.0, -1.0],
    "xdes": [0.0, 0.0],
    "u0": [0.0],
    "udes": [0.0],
    "umax": [1.0],
    "umin": [-1.0],
    "Thor": 5.25,
    "Tmax": 10.0,
    "Tmin": 1.0,
    "dt": 0.01,
    "t0": 0.0
  },
  "Options":
  {
    "OptimTime": "off",
    "Nhor": 50,
    "OptimTimeLineSearchFactor": 0.35,
    "ConstraintsAbsTol": [1e-3, 1e-3]
  }
}

Can someone please help to see whether I am missing any settings ?

Thanks n Regards, Karthik

ThoreWietzke commented 17 hours ago

The index error you mentioned is indeed an error in the example.

When ´OptimTime´ is off, the example behaves like expected. GRAMPC does try to find a trade-off between the control and the setpoint specified by ´udes´.

Did I miss something @avoelz ?

karthyyy commented 16 hours ago

@ThoreWietzke,

Thanks for the reply. In that case, can I put the state error (x-xdes) in the cost function rather than putting it as Terminal constraint (or along with Terminal Constraint) ?

Regards Karthik

ThoreWietzke commented 16 hours ago

That would help the MPC to steer x to the desired state