def render(self): data_viewer(self.x1, self.y1, u1=self.u1, phit=self.phi1, rudder_angle=self.Rudder_angle, t=self._t, xlim_left=self.xlim_left, xlim_right=self.xlim_right, ylim_left=self.ylim_left, ylim_right=self.ylim_right, goal_x=self.target_position[0], goal_y=self.target_position[1])
def render(self): data_viewer(self.x1, self.y1, u1=self.u1, phit=self.phi1, rudder_angle=self.Rudder_angle, t=self._t, xlim_left=-10, xlim_right=120, ylim_left=-10, ylim_right=120, goal_x=100, goal_y=100)
def render(self): data_viewer(self.x2, self.y2, u1=self.u2, phit=self.phit, rudder_angle=self.Rudder_angle, t=self._t, xlim_left=-100, xlim_right=200, ylim_left=-100, ylim_right=200, goal_x=100, goal_y=100)
def simulation(): # initial state state_0 = np.array( [ [0], [0], [0], [0], # eta1 [0], [0], [0], [0], # V1 [0], [0], [6.2], [0], # eta2 [0], [0], [0], [0] ], float) # V2 # sea state H = 1 omega = 0.15 c_dir = 0 c_speed = 0 WG = WG_dynamics(H, omega, c_dir, c_speed) data_elimation() # Turn on when previous data needs to be cleared for t in simulation_time(terminal_time=500): rudder_angle = 0.5 # data storage if t % 1 == 0: _t.append(t) x1.append(state_0.item(0)) y1.append(state_0.item(1)) z1.append(state_0.item(2)) phi1.append(state_0.item(3)) u1.append(state_0.item(4)) v1.append(state_0.item(5)) w1.append(state_0.item(6)) r1.append(state_0.item(7)) x2.append(state_0.item(8)) y2.append(state_0.item(9)) z2.append(state_0.item(10)) phit.append(state_0.item(11)) u2.append(state_0.item(12)) v2.append(state_0.item(13)) w2.append(state_0.item(14)) r2.append(state_0.item(15)) Rudder_angle.append(rudder_angle) T0, Ffoil_0, Ffoil_2, Frudder_0, Frudder_1, Frudder_3 = WG.forces( state_0, rudder_angle, t) T.append(T0) Ffoil_x.append(Ffoil_0) Ffoil_z.append(Ffoil_2) Frudder_x.append(Frudder_0) Frudder_y.append(Frudder_1) Frudder_n.append(Frudder_3) # print(t) data_storage(x1, y1, phit, t, rudder_angle=Rudder_angle, u1=u1, T=T) # store data in local files # Runge-Kutta time_step = 0.001 k1 = WG.f(state_0, rudder_angle, t) k2 = WG.f(state_0 + 0.5 * k1 * time_step, rudder_angle, t + 0.5 * time_step) k3 = WG.f(state_0 + 0.5 * k2 * time_step, rudder_angle, t + 0.5 * time_step) k4 = WG.f(state_0 + k3 * time_step, rudder_angle, t + time_step) state_0 += (1 / 6) * (k1 + 2 * k2 + 2 * k3 + k4) * time_step ''' if state_0.item(11) > pi: state_0[11] = state_0.item(11) - 2*pi elif state_0.item(11) < -pi: state_0[11] = state_0.item(11) + 2*pi ''' # print(u1[-1], np.mean(u1)) # interval of refreshing the monitor, default: 2s if t % 2 == 0: data_viewer(x1, y1, u1, phit, Rudder_angle, _t, xlim_left=0, xlim_right=200, ylim_left=-100, ylim_right=100, goal_x=50, goal_y=50) # T=T, Ffoil_x=Ffoil_x return x1, y1, z1, phi1, \ x2, y2, z2, phit, \ u1, v1, w1, r1, \ u2, v2, w2, r2, \ _t, T, Ffoil_x, Ffoil_z, \ Frudder_x, Frudder_y, Frudder_n, Rudder_angle