-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.py
33 lines (26 loc) · 857 Bytes
/
Ball.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
GRAVITY = 9.81
DT = 0.025
class Ball:
def __init__(self):
self.radius = 0.1 # radius of robot
self.v0x = 1 #(2*np.random.random()-1)
self.v0y = -3.5 #+ (2*np.random.random()-1)
self.v0z = 10 #+ (2*np.random.random()-1)
self.launch_angle = 0
self.dt = DT # time step
self.g = -GRAVITY
self.state = [0.0, 0.0, 0.0]
def update_state(self):
dt = self.dt # time step
# Dynamics:
# x_dot = v0x
# y_dot = v0y
# z_dot = v0z
new_state = [0.0, 0.0, 0.0]
self.v0z = self.v0z + dt * self.g
new_state[0] = self.state[0] + dt * (self.v0x)
new_state[1] = self.state[1] + dt * (self.v0y)
new_state[2] = self.state[2] + dt * (self.v0z)
self.state = new_state
return self.state