0

here is the problem:

constants: enter image description here

dependent value functions:

def v_ego(self,ego_vel_x,ego_a_ini_x,t):
    v_ego = ego_vel_x + ego_a_ini_x * t
    return v_ego

def x_obj(self,x_obj_ini,obj_vel_x,obj_a_ini_x,t):
    x_obj = x_obj_ini + obj_vel_x * t + 0.5 * obj_a_ini_x * t ** 2

    return x_obj

def x_ego(self,x_ego_ini,ego_vel_x,ego_a_ini_x,t):
    x_ego = x_ego_ini + ego_vel_x * t + 0.5 * ego_a_ini_x * t ** 2
    return x_ego

def y_obj(self,y_obj_ini,obj_vel_y,obj_a_ini_y,t):
    y_obj = y_obj_ini + obj_vel_y * t + 0.5 * obj_a_ini_y * t ** 2
    return y_obj

def y_t(self):
    y_t = math.sqrt(self._r_t ** 2 - self._l_f ** 2) - (self._w_ego / 2)

    return y_t

def y_r(self,ego_vel_x,ego_a_ini_x,t):
    y_r = math.sqrt(max(0, ((self.v_ego(ego_vel_x,ego_a_ini_x,t) ** 2 / (self
                                                                         ._Mu_rt * self._g)) ** 2 - self._l_c ** 2)))
    return y_r

def y_min(self,ego_vel_x,ego_a_ini_x,t):
    y_min = max(self.y_t(), self.y_r(ego_vel_x,ego_a_ini_x,t))
    return y_min

def r_min(self,ego_vel_x,ego_a_ini_x,t):
    r_min = max(self._r_t, math.sqrt(self._l_f ** 2 + (self.y_min(ego_vel_x,ego_a_ini_x,t) + self._w_ego / 2) ** 2))
    return r_min
tts, delta_t = sym.symbols('tts,delta_t')

e_10 = sym.Eq(math.atan((self.x_obj(x_obj_ini, obj_vel_x, obj_a_ini_x, tts + delta_t) - self.x_ego(x_ego_ini,ego_vel_x,ego_a_ini_x,tts)+ self._l_f) / (self.y_min(ego_vel_x, ego_a_ini_x, tts) - self.y_obj(y_obj_ini, obj_vel_y, obj_a_ini_y,tts + delta_t))) - ((self.v_ego(ego_vel_x, ego_a_ini_x, tts) * delta_t) / self.r_min(ego_vel_x, ego_a_ini_x, tts) - (math.asin(min(1.0, self._l_f / self.r_min(ego_vel_x, ego_a_ini_x, tts))))), 0)

e_11 = sym.Eq((self.x_obj(x_obj_ini, obj_vel_x, obj_a_ini_x, tts + delta_t) - self.x_ego(x_ego_ini, ego_vel_x,ego_a_ini_x,tts)+ self._l_f) ** 2 + (self.y_min(ego_vel_x, ego_a_ini_x, tts) - self.y_obj(y_obj_ini, obj_vel_y, obj_a_ini_y,tts + delta_t)) ** 2 - (self.r_min(ego_vel_x, ego_a_ini_x, tts)) ** 2, 0)
print(sym.solve([e_10, e_11], (tts, delta_t)))

I am getting TypeError: cannot determine truth value of Relational

These are the equations: non linear equations that I am trying to solve

and these are the dependent values that need to be calculated:

dependent functions

any help is appreciated

  • 1
    Please, take the time to write a fully working example. As of now, we are unable to run your code. What are `lf, w_ego, x_obj, ...`? All variables must be defined for us to tackle the problem. – Davide_sd Nov 22 '22 at 21:32
  • You can't use functions from the `math` library with sympy symbols as arguments (neither numpy and scipy functions will work with sympy symbols). You need `sym.atan`, `sym.sqrt` etc.. You should also try to avoid using floats: `sympy.S(1)/2` is an exact value, while `0.5` is an inexact float. – JohanC Nov 22 '22 at 21:41
  • @JohanC I changed and tried it again still no luck could it be that min and max usage is the problem ? – sherry12555 Nov 22 '22 at 21:42
  • @Davide_sd Sorry I have updated the code – sherry12555 Nov 22 '22 at 21:43
  • Indeed, you probably need `sym.Max` – JohanC Nov 22 '22 at 21:43
  • @sherry12555 what are `self._r_t, self._l_f, self._w_ego, self._g, self._Mu_rt, self._l_c`? – Davide_sd Nov 22 '22 at 22:05
  • @they are constants – sherry12555 Nov 22 '22 at 23:59
  • @JohanC i made the changes in min and max with the sympy version but I have been running the function for the past hour and the programs seems to be stuck in some kind of loop my PC is working fine and so is the IDE but no output – sherry12555 Nov 23 '22 at 00:04
  • my goal is to find root for variables of delta_t and TTS which are lies in between a range of values eg for TTS [0, 16.8] and for delta_t [0. 3.9] is it possible to do this with f solve as will ? I tried it before and did get a solution but couldn't find a suitable one as I got the negative root – sherry12555 Nov 23 '22 at 00:07

1 Answers1

0

When you use min with a SymPy expressions, it will complain if it can't figure out what the min is, e.g. min(x,y) -> TypeError: cannot determine truth value of Relational.

Since you are only selecting a minimum of two values, the function is easy to write as a Piecewise as in the following example where the equation x - min(y,z) is being solved.

enter image description here

Replace max with a similar rewrite, too.

smichr
  • 16,948
  • 2
  • 27
  • 34