-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.py
101 lines (79 loc) · 2.76 KB
/
move.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'''
EN.640.635 Software Carpentry
Final project
This Python file defines functions for moving and
updating objects within a simulation environment,
particularly focusing on a robot fish.
It includes methods for updating positions, velocities,
and orientations of objects over time,
as well as handling specific behaviors of the robot fish.
'''
from util import *
def move(a, timestep):
"""
Update the position, orientation, and velocities of the object.
Parameters:
a (object): The object to be moved
timestep (float): The time step for the movement update
"""
# Update position and orientation
a.x = a.x + a.x_dot * timestep
a.y = a.y + a.y_dot * timestep
a.theta = normalize_theta(a.theta + a.w * timestep)
# Update velocities
a.v = a.v + a.v * a.f * timestep
a.w = a.w + a.w * a.f * timestep
# Set x_dot and y_dot based on current velocity and orientation
a.set_x_dot_and_y_dot()
# Special handling for robotfish
if a.name == "robotfish":
# Update angular and linear velocities based on mode
a.w_dot = a.w_dot_list[a.w_mode]
a.v_dot = a.v_dot_list[a.v_mode]
# Update orientation with angular velocity
a.w = a.w + a.w_dot * a.w_dot_direction * timestep
# Update x_dot and y_dot with linear velocity and orientation
a.x_dot = a.x_dot + a.v_dot * math.cos(a.realtime_theta) * timestep
a.y_dot = a.y_dot + a.v_dot * math.sin(a.realtime_theta) * timestep
# Set v and theta_v based on updated velocities
a.set_v_and_theta_v()
# Perform tail waving for robotfish
a.wave_tail()
# Update the object
update(a)
def move_next(a, move, timestep):
"""
Move the current object and its children recursively.
Parameters:
a (object): The current object
move (function): The move function to be applied
timestep (float): The time step for the movement update
"""
move(a, timestep)
# Move each child recursively
if a.next != []:
for i in a.next:
move_next(i, move, timestep)
def set_move_last(a):
"""
Set the object's position and orientation to its last state.
Parameters:
a (object): The object to be updated to its last state
"""
a.theta = a.theta_last
a.x = a.x_last
a.y = a.y_last
def update(a):
"""
Update the object's real-time properties.
Parameters:
a (object): The object to be updated
"""
# Update real-time orientation for all objects
a.realtime_theta = a.get_realtime_theta()
# Special handling for robotfish
if a.name == 'robotfish':
a.update()
# Update real-time points and core for all objects
a.realtime_points = a.get_realtime_points()
a.core = a.get_core()