Skip to main content

2.1 Kinematika — Amaliyot

Laboratoriya ishi: Python da harakat simulyatsiyasi


1. Tekis Tezlanuvchan Harakat​

import numpy as np
import matplotlib.pyplot as plt

def uniform_acceleration(v0, a, t_max, dt=0.01):
"""Tekis tezlanuvchan harakat simulyatsiyasi"""
t = np.arange(0, t_max, dt)
v = v0 + a * t
x = v0 * t + 0.5 * a * t**2
return t, x, v

# Misol: Avtomobil tezlanishi
v0 = 0 # m/s
a = 3 # m/s²
t_max = 10 # s

t, x, v = uniform_acceleration(v0, a, t_max)

fig, axes = plt.subplots(1, 3, figsize=(15, 4))

axes[0].plot(t, x, 'b-', linewidth=2)
axes[0].set_xlabel('Vaqt (s)')
axes[0].set_ylabel('Pozitsiya (m)')
axes[0].set_title('x(t)')
axes[0].grid(True)

axes[1].plot(t, v, 'r-', linewidth=2)
axes[1].set_xlabel('Vaqt (s)')
axes[1].set_ylabel('Tezlik (m/s)')
axes[1].set_title('v(t)')
axes[1].grid(True)

axes[2].axhline(y=a, color='g', linewidth=2)
axes[2].set_xlabel('Vaqt (s)')
axes[2].set_ylabel('Tezlanish (m/s²)')
axes[2].set_title('a(t) = const')
axes[2].set_ylim(0, a*1.5)
axes[2].grid(True)

plt.tight_layout()
plt.savefig('uniform_acceleration.png', dpi=150)
plt.show()

print(f"10 s da: pozitsiya = {x[-1]:.1f} m, tezlik = {v[-1]:.1f} m/s")

2. Proektil Harakati Simulyatsiyasi​

import numpy as np
import matplotlib.pyplot as plt

def projectile_simulation(v0, angle_deg, h0=0, g=9.81, dt=0.001):
"""To'liq proektil simulyatsiyasi"""
angle = np.radians(angle_deg)
vx0 = v0 * np.cos(angle)
vy0 = v0 * np.sin(angle)

# Vaqt qadamlari
t_flight = (vy0 + np.sqrt(vy0**2 + 2*g*h0)) / g
t = np.arange(0, t_flight, dt)

# Traektoriya
x = vx0 * t
y = h0 + vy0 * t - 0.5 * g * t**2

# Tezliklar
vx = np.full_like(t, vx0)
vy = vy0 - g * t
v = np.sqrt(vx**2 + vy**2)

return t, x, y, vx, vy, v

# Turli burchaklarda solishtirish
angles = [30, 45, 60, 75]
v0 = 50 # m/s

plt.figure(figsize=(12, 8))
for angle in angles:
t, x, y, vx, vy, v = projectile_simulation(v0, angle)
plt.plot(x, y, linewidth=2, label=f'{angle}°')

plt.xlabel('Masofa (m)')
plt.ylabel('Balandlik (m)')
plt.title(f'Proektil Traektoriyalari (vā‚€ = {v0} m/s)')
plt.legend()
plt.grid(True)
plt.axis('equal')
plt.savefig('projectile_angles.png', dpi=150)
plt.show()

3. Aylanma Harakat​

import numpy as np
import matplotlib.pyplot as plt

def circular_motion(radius, omega, t_max, dt=0.01):
"""Tekis aylanma harakat"""
t = np.arange(0, t_max, dt)
theta = omega * t

x = radius * np.cos(theta)
y = radius * np.sin(theta)

# Tezlik (tangensial)
vx = -radius * omega * np.sin(theta)
vy = radius * omega * np.cos(theta)

# Tezlanish (markazga intilma)
ax = -radius * omega**2 * np.cos(theta)
ay = -radius * omega**2 * np.sin(theta)

return t, x, y, vx, vy, ax, ay

# Simulyatsiya
r = 5 # m
omega = 2 # rad/s
t_max = 2 * np.pi / omega # bir to'liq aylanish

t, x, y, vx, vy, ax, ay = circular_motion(r, omega, t_max)

fig, axes = plt.subplots(1, 2, figsize=(14, 6))

# Traektoriya
axes[0].plot(x, y, 'b-', linewidth=2)
axes[0].set_xlabel('X (m)')
axes[0].set_ylabel('Y (m)')
axes[0].set_title('Aylana Traektoriya')
axes[0].axis('equal')
axes[0].grid(True)

# Bir nechta nuqtada tezlik va tezlanish vektorlari
step = len(t) // 8
for i in range(0, len(t), step):
# Tezlik (yashil)
axes[0].arrow(x[i], y[i], vx[i]*0.2, vy[i]*0.2,
head_width=0.3, color='green', alpha=0.7)
# Tezlanish (qizil)
axes[0].arrow(x[i], y[i], ax[i]*0.05, ay[i]*0.05,
head_width=0.3, color='red', alpha=0.7)

# Vaqt bo'yicha grafiklar
axes[1].plot(t, np.sqrt(vx**2 + vy**2), 'g-', linewidth=2, label='|v|')
axes[1].plot(t, np.sqrt(ax**2 + ay**2), 'r-', linewidth=2, label='|a|')
axes[1].set_xlabel('Vaqt (s)')
axes[1].set_ylabel('Kattalik')
axes[1].set_title('Tezlik va Tezlanish')
axes[1].legend()
axes[1].grid(True)

plt.tight_layout()
plt.savefig('circular_motion.png', dpi=150)
plt.show()

print(f"Tezlik: {r*omega:.2f} m/s (doimiy)")
print(f"Markazga intilma tezlanish: {r*omega**2:.2f} m/s²")

4. Dron Traektoriya Simulyatsiyasi​

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

class DroneSimulator:
def __init__(self, initial_pos, max_velocity=10, max_accel=5):
self.pos = np.array(initial_pos, dtype=float)
self.vel = np.zeros(3)
self.max_vel = max_velocity
self.max_acc = max_accel
self.history = [self.pos.copy()]

def move_to(self, target, dt=0.1, duration=None):
"""Maqsadga tekis harakat"""
target = np.array(target)

if duration is None:
distance = np.linalg.norm(target - self.pos)
duration = distance / self.max_vel * 2

t = 0
while t < duration:
# Yo'nalish
direction = target - self.pos
dist = np.linalg.norm(direction)

if dist < 0.1:
break

direction = direction / dist

# Tezlikni hisoblash (sekinlashtirish bilan)
brake_dist = self.max_vel**2 / (2 * self.max_acc)
if dist < brake_dist:
speed = self.max_vel * (dist / brake_dist)
else:
speed = self.max_vel

self.vel = direction * speed
self.pos = self.pos + self.vel * dt
self.history.append(self.pos.copy())
t += dt

def get_trajectory(self):
return np.array(self.history)

# Dron missiyasi
drone = DroneSimulator([0, 0, 0], max_velocity=5)

waypoints = [
[20, 0, 10],
[20, 20, 15],
[0, 20, 10],
[0, 0, 5],
]

for wp in waypoints:
drone.move_to(wp)

trajectory = drone.get_trajectory()

# 3D vizualizatsiya
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')

ax.plot(trajectory[:, 0], trajectory[:, 1], trajectory[:, 2],
'b-', linewidth=2, label='Traektoriya')

# Waypoint'larni belgilash
for i, wp in enumerate([[0,0,0]] + waypoints):
ax.scatter(*wp, s=100, marker='o')
ax.text(wp[0], wp[1], wp[2], f' WP{i}', fontsize=10)

ax.set_xlabel('X (m)')
ax.set_ylabel('Y (m)')
ax.set_zlabel('Z (m)')
ax.set_title('Dron Missiya Traektoriyasi')
ax.legend()

plt.savefig('drone_trajectory_3d.png', dpi=150)
plt.show()

5. Differensial Drive Robot​

import numpy as np
import matplotlib.pyplot as plt

class DifferentialDriveRobot:
def __init__(self, wheel_base=0.5, wheel_radius=0.1):
self.L = wheel_base # G'ildiraklar orasidagi masofa
self.r = wheel_radius # G'ildirak radiusi
self.x = 0
self.y = 0
self.theta = 0 # Yo'nalish burchagi
self.history = [(0, 0, 0)]

def set_wheel_speeds(self, omega_left, omega_right, dt=0.01, duration=1.0):
"""G'ildirak burchak tezliklarini berish"""
v_left = self.r * omega_left
v_right = self.r * omega_right

t = 0
while t < duration:
# Robot tezligi va burchak tezligi
v = (v_right + v_left) / 2
omega = (v_right - v_left) / self.L

# Yangilash
self.x += v * np.cos(self.theta) * dt
self.y += v * np.sin(self.theta) * dt
self.theta += omega * dt

self.history.append((self.x, self.y, self.theta))
t += dt

def get_trajectory(self):
return np.array(self.history)

# Robot harakati simulyatsiyasi
robot = DifferentialDriveRobot(wheel_base=0.3, wheel_radius=0.05)

# Harakat ketma-ketligi
movements = [
(10, 10, 2), # To'g'ri
(10, 5, 1), # O'ngga burilish
(10, 10, 2), # To'g'ri
(5, 10, 1), # Chapga burilish
(10, 10, 2), # To'g'ri
]

for omega_l, omega_r, duration in movements:
robot.set_wheel_speeds(omega_l, omega_r, duration=duration)

trajectory = robot.get_trajectory()

plt.figure(figsize=(10, 8))
plt.plot(trajectory[:, 0], trajectory[:, 1], 'b-', linewidth=2)
plt.plot(trajectory[0, 0], trajectory[0, 1], 'go', markersize=15, label='Start')
plt.plot(trajectory[-1, 0], trajectory[-1, 1], 'r*', markersize=15, label='End')

# Yo'nalish o'qlarini ko'rsatish
step = len(trajectory) // 10
for i in range(0, len(trajectory), step):
dx = 0.1 * np.cos(trajectory[i, 2])
dy = 0.1 * np.sin(trajectory[i, 2])
plt.arrow(trajectory[i, 0], trajectory[i, 1], dx, dy,
head_width=0.05, color='red', alpha=0.5)

plt.xlabel('X (m)')
plt.ylabel('Y (m)')
plt.title('Differensial Drive Robot Traektoriyasi')
plt.legend()
plt.axis('equal')
plt.grid(True)
plt.savefig('diff_drive_robot.png', dpi=150)
plt.show()

6. Topshiriq: Raketa Uchishi​

import numpy as np
import matplotlib.pyplot as plt

def rocket_launch(thrust, mass_initial, fuel_rate, burn_time, g=9.81, dt=0.01):
"""
Raketa uchishi simulyatsiyasi

thrust: itarish kuchi (N)
mass_initial: boshlang'ich massa (kg)
fuel_rate: yonilg'i sarfi (kg/s)
burn_time: yonilg'i yonish vaqti (s)
"""
# TODO: Simulyatsiyani yarating
# 1. Yonilg'i yonayotganda: massa kamayadi, tezlanish ortadi
# 2. Yonilg'i tugagandan keyin: erkin tushish (tezlanish = -g)
# 3. h = 0 bo'lganda to'xtash

# Sizning kodingiz...

pass

# Test parametrlari
# thrust = 15000 N
# mass_initial = 1000 kg
# fuel_rate = 10 kg/s
# burn_time = 50 s
Yechim
def rocket_launch(thrust, mass_initial, fuel_rate, burn_time, g=9.81, dt=0.01):
t_list, h_list, v_list, a_list, m_list = [], [], [], [], []

t = 0
h = 0
v = 0
m = mass_initial

# Simulyatsiya
while h >= 0 or v > 0:
# Yonilg'i yonayotganmi?
if t < burn_time:
F_thrust = thrust
m = mass_initial - fuel_rate * t
else:
F_thrust = 0
m = mass_initial - fuel_rate * burn_time

# Tezlanish
a = (F_thrust - m * g) / m

# Yangilash
v = v + a * dt
h = h + v * dt
t = t + dt

# Saqlash
t_list.append(t)
h_list.append(max(0, h))
v_list.append(v)
a_list.append(a)
m_list.append(m)

# Yerga tushganmi?
if h < 0 and t > burn_time:
break

return np.array(t_list), np.array(h_list), np.array(v_list), np.array(a_list), np.array(m_list)

# Simulyatsiya
t, h, v, a, m = rocket_launch(15000, 1000, 10, 50)

fig, axes = plt.subplots(2, 2, figsize=(14, 10))

axes[0, 0].plot(t, h/1000, 'b-', linewidth=2)
axes[0, 0].axvline(x=50, color='r', linestyle='--', label='Dvigatel o\'chdi')
axes[0, 0].set_xlabel('Vaqt (s)')
axes[0, 0].set_ylabel('Balandlik (km)')
axes[0, 0].set_title('Balandlik')
axes[0, 0].legend()
axes[0, 0].grid(True)

axes[0, 1].plot(t, v, 'r-', linewidth=2)
axes[0, 1].axvline(x=50, color='r', linestyle='--')
axes[0, 1].set_xlabel('Vaqt (s)')
axes[0, 1].set_ylabel('Tezlik (m/s)')
axes[0, 1].set_title('Tezlik')
axes[0, 1].grid(True)

axes[1, 0].plot(t, a, 'g-', linewidth=2)
axes[1, 0].axvline(x=50, color='r', linestyle='--')
axes[1, 0].axhline(y=-9.81, color='k', linestyle=':', label='g')
axes[1, 0].set_xlabel('Vaqt (s)')
axes[1, 0].set_ylabel('Tezlanish (m/s²)')
axes[1, 0].set_title('Tezlanish')
axes[1, 0].legend()
axes[1, 0].grid(True)

axes[1, 1].plot(t, m, 'm-', linewidth=2)
axes[1, 1].axvline(x=50, color='r', linestyle='--')
axes[1, 1].set_xlabel('Vaqt (s)')
axes[1, 1].set_ylabel('Massa (kg)')
axes[1, 1].set_title('Massa')
axes[1, 1].grid(True)

plt.tight_layout()
plt.savefig('rocket_launch.png', dpi=150)
plt.show()

print(f"Maksimal balandlik: {max(h)/1000:.2f} km")
print(f"Maksimal tezlik: {max(v):.2f} m/s")
print(f"Uchish vaqti: {t[-1]:.2f} s")

āœ… Laboratoriya Tekshirish Ro'yxati​

  • Tekis tezlanuvchan harakat
  • Proektil traektoriyalari
  • Aylanma harakat
  • Dron simulyatsiyasi
  • Differensial drive robot
  • Raketa topshiriq

Keyingi Mavzu​

šŸ“– 2.2 Dinamika