Skip to content

How to set only some constraints #8

@fengDd11

Description

@fengDd11

When I use Python to generate code, I want to limit my state variables position, velocity, and acceleration, but I don’t want to limit the position. How should I set x_min and x_max when using the setup function? If I use -inf and inf directly, I will get an error: error: ‘inf’ was not declared in this scope; did you mean ‘ynf’?

my code:
import tinympc
import numpy as np
import math
from math import inf

T_ctrl = 0.05
Ts = 0.001

num_step = int(T_ctrl / Ts)

a_d_x_ts = math.exp(-8.9916 * Ts)
b_d_x_ts = (8.9426 / 8.9916) * (1 - math.exp(-8.9916 * Ts))

a_d_y_ts = math.exp(-8.8536 * Ts)
b_d_y_ts = (8.6355 / 8.8536) * (1 - math.exp(-8.8536 * Ts))

a_d_x = math.pow(a_d_x_ts, num_step)
a_d_y = math.pow(a_d_y_ts, num_step)

b_d_x = (math.pow(a_d_x_ts, num_step) - 1) / (a_d_x_ts - 1) * b_d_x_ts
b_d_y = (math.pow(a_d_y_ts, num_step) - 1) / (a_d_y_ts - 1) * b_d_y_ts

A = np.array([[1.0 , 0.0 , T_ctrl , 0.0 , 0.0 , 0.0 ],
[0.0 , 1.0 , 0.0 , T_ctrl , 0.0 , 0.0 ],
[0.0 , 0.0 , 1.0 , 0.0 , T_ctrl , 0.0 ],
[0.0 , 0.0 , 0.0 , 1.0 , 0.0 , T_ctrl],
[0.0 , 0.0 , 0.0 , 0.0 , a_d_x , 0.0 ],
[0.0 , 0.0 , 0.0 , 0.0 , 0.0 , a_d_y ]])

B = np.array([[0.0 , 0.0 ],
[0.0 , 0.0 ],
[0.0 , 0.0 ],
[0.0 , 0.0 ],
[b_d_x , 0.0 ],
[0.0 , b_d_y]])

Q = np.diag([100, 100, 50, 50, 20, 20])
R = np.diag([2, 2])

N = 10

prob = tinympc.TinyMPC()

x_min = np.array([-inf, -inf, -10, -10, -10, -10])

x_max = np.array([inf, inf, 10, 10, 10, 10])

u_min = np.array([-10, -10])
u_max = np.array([10, 10])

A = np.asfortranarray(A).astype(np.float64)
B = np.asfortranarray(B).astype(np.float64)
Q = np.asfortranarray(Q).astype(np.float64)
R = np.asfortranarray(R).astype(np.float64)
x_min = np.asfortranarray(x_min).astype(np.float64)
x_max = np.asfortranarray(x_max).astype(np.float64)
u_min = np.asfortranarray(u_min).astype(np.float64)
u_max = np.asfortranarray(u_max).astype(np.float64)

prob.setup(A, B, Q, R, N, rho=0.1, max_iter=1000, x_min = x_min,x_max = x_max,u_min=u_min, u_max=u_max,verbose=False)

prob.codegen("mpc_test", verbose=1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions