Advertisement
SamirBaghirzada

roboticsas1.3A

Apr 17th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.integrate import ode
  4.  
  5. Ts = 0.1
  6.  
  7. t = np.arange(0, 10, Ts)
  8.  
  9. x0 = 0
  10. y0 = 0
  11. phi0 = 0
  12.  
  13.  
  14. x = []
  15. y = []
  16. phi = []
  17.  
  18. x.append(x0)
  19. y.append(y0)
  20. phi.append(phi0)
  21.  
  22. def fun(t, y):
  23. return [np.sqrt(1+4*t**2)* np.cos(y[2]), np.sqrt(1+4*t**2)*np.sin(y[2]), 2/(4*t**2+1)]
  24.  
  25. r = ode(fun).set_integrator('dopri5')
  26. r.set_initial_value([x0, y0, phi0])
  27.  
  28. for i in t:
  29.  
  30. if r.successful():
  31. r.integrate(r.t + Ts)
  32. x.append(r.y[0])
  33. y.append(r.y[1])
  34. phi.append((r.y[2]) % (2 * np.pi)) #Just to keep phi in range 0 to 2pi
  35.  
  36.  
  37. x = np.array(x)
  38. y = np.array(y)
  39. plt.grid()
  40. plt.plot(x, y)
  41. plt.annotate("Starting point",(x0,y0))
  42. plt.scatter(x0,y0)
  43. plt.xlabel("x")
  44. plt.ylabel("y")
  45. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement