Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def ball_velocity(udp, receive_packet, receive_game_controller_signal, stop_even
try:

ball_position = track_ball_position(udp, receive_packet, receive_game_controller_signal, stop_event, debug, sock)
ball_velocity_path = os.path.join(path, "ball_velocity.csv")
if not os.path.isdir(path):
os.mkdir(path)
if ball_position:
ball_posi.append(ball_position[0]) # 最新データを追加
# print("ball_position: ", ball_position)
Expand All @@ -61,6 +64,16 @@ def ball_velocity(udp, receive_packet, receive_game_controller_signal, stop_even
print("vy:", vy)
print("ball_velocity:", speed)

direction = math.atan2(vy/vx)

new_velocity_data = [speed,direction,state1,state2,frame2]

df = pd.DataFrame(new_velocity_data, columns=["speed","direction","state1","state2","frame_number"])
if not os.path.exists(ball_velocity_path):
df.to_csv(ball_velocity_path, mode='w', header=True, index=False) # Create a new ball velocity CSV file if it does not exist
else:
df.to_csv(ball_velocity_path, mode='a', header=False, index=False) # Add if it exists

ball_posi[0] = ball_posi[1] # 最新データを更新
ball_posi.pop(-1) # 2つを超えたら古いものを削除
except KeyboardInterrupt:
Expand Down