Skip to content

Commit c9397e3

Browse files
Added comments to 8 functions across 2 files
1 parent 6bbb479 commit c9397e3

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

IROS_experiments/person_controller_webots/src/person.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
class Person(Supervisor):
1313
def __init__(self, person_number):
14+
"""
15+
initializes an instance of `Robot`, which is responsible for controlling
16+
a humanoid robot's movement based on user input and BVH animation data.
17+
It sets up various fields and methods for controlling the robot's position,
18+
rotation, and velocity.
19+
20+
Args:
21+
person_number (int): 3D human character that the function is supposed
22+
to animate, and is used to load the appropriate motion data for
23+
that character from the library `/usr/local/webots/projects/humans/skin_animated_humans/libraries/bvh_util/libbvh_util.so`.
24+
25+
"""
1426
parent = os.path.dirname(os.path.realpath(__file__))
1527
main_directory = os.path.abspath(os.path.join(parent, os.pardir))
1628
print(main_directory)
@@ -43,6 +55,19 @@ def set_speed(self, data):
4355
########## In case the receibed speed is in the person frame ##########
4456
# if time.time() - self.last_time_sent_velocity > self.time_between_velocity_commands:
4557
# self.last_time_sent_velocity = time.time()
58+
"""
59+
takes in the velocity data of a person and calculates the orientation of
60+
that person based on the axles of their body. Then it uses the calculated
61+
orientation to convert the input velocity to world coordinates, and finally
62+
sets the new velocity of the person's node in the scene using PySAM.
63+
64+
Args:
65+
data (float): 6DOF (degree of freedom) velocity input for the person,
66+
which is used to calculate the converted linear velocity in the
67+
body-centered coordinate system and then passed to the `setVelocity()`
68+
method of the `PersonNode`.
69+
70+
"""
4671
person_orientation = self.person_node.getOrientation()
4772
orientation = math.atan2(person_orientation[0], person_orientation[1]) - math.pi / 2
4873
rotation_matrix = np.array(
@@ -57,11 +82,30 @@ def set_speed(self, data):
5782
[converted_speed[0] / 2.5, converted_speed[1] / 2.5, 0, 0, 0, -data.axes[0].value * math.pi / 2])
5883

5984
def set_initial_pose(self, data):
85+
"""
86+
sets the initial position and orientation of an object based on button
87+
input data.
88+
89+
Args:
90+
data (`sf::Data` type in the given code snippet.): 3D transform of the
91+
object at the start position, which is used to set the initial
92+
pose of the robot when `if data.buttons[3]:` condition is met.
93+
94+
- `buttons`: A 32-bit integer vector representing button states
95+
(0 for none, non-zero for pressed buttons).
96+
97+
98+
"""
6099
if data.buttons[3]:
61100
self.traslation_field.setSFVec3f(self.start_pose)
62101
self.rotation_field.setSFRotation(self.start_rotation)
63102

64103
def get_camera_image(self):
104+
"""
105+
captures an image from a person's camera, converts it to RGB format, and
106+
displays it using `cv2.imshow()`.
107+
108+
"""
65109
color = self.person_camera.getImage()
66110
color_image = cv2.cvtColor(cv2.cvtColor(
67111
np.frombuffer(color, np.uint8).reshape(self.person_camera.getHeight(), self.person_camera.getWidth(), 4),

IROS_experiments/person_controller_webots/src/specificworker.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@
4343

4444
class SpecificWorker(GenericWorker):
4545
def __init__(self, proxy_map, startup_check=False):
46+
"""
47+
initializes a SpecificWorker instance with a proxy map and performs necessary
48+
actions, including setting environment variables, creating a Person object,
49+
and starting a timer for computation tasks.
50+
51+
Args:
52+
proxy_map (dict): mapping of processes to threads in the worker process,
53+
allowing for efficient communication between the worker and its proxies.
54+
startup_check (bool): whether to execute the startup check during the
55+
initialization of the SpecificWorker object, with `True` indicating
56+
execution and `False` indicating skipping it.
57+
58+
"""
4659
super(SpecificWorker, self).__init__(proxy_map)
4760
self.Period = 16
4861
if startup_check:
@@ -65,12 +78,33 @@ def setParams(self, params):
6578
# except:
6679
# traceback.print_exc()
6780
# print("Error reading config params")
81+
"""
82+
sets inner model path based on configuration parameters provided as input.
83+
84+
Args:
85+
params (dict): configuration parameters to be set for the inner model,
86+
which are passed as a dictionary object.
87+
88+
Returns:
89+
`True`.: a boolean value indicating whether the parameter loading was
90+
successful.
91+
92+
- `True`: The method was successful in setting the parameters.
93+
94+
95+
"""
6896
return True
6997

7098

7199
@QtCore.Slot()
72100
def compute(self):
73101
# print(self.person.step(self.person.timeStep), self.person.timeStep)
102+
"""
103+
executes a motion step on the character model, updates the time using the
104+
timeStep attribute, and then runs the BVH animation functions, gets a
105+
camera image, and sets the character's speed based on a queue if it exists.
106+
107+
"""
74108
if self.person.step(self.person.timeStep) != -1:
75109
t1 = time.time()
76110
# self.person.bvh_animation_functions.motion_step()
@@ -82,6 +116,12 @@ def compute(self):
82116

83117

84118
def startup_check(self):
119+
"""
120+
performs various tests on a `RoboCompJoystickAdapter`, including testing
121+
its `AxisParams`, `ButtonParams`, and `TData` properties, and then quits
122+
the application after 200 milliseconds.
123+
124+
"""
85125
print(f"Testing RoboCompJoystickAdapter.AxisParams from ifaces.RoboCompJoystickAdapter")
86126
test = ifaces.RoboCompJoystickAdapter.AxisParams()
87127
print(f"Testing RoboCompJoystickAdapter.ButtonParams from ifaces.RoboCompJoystickAdapter")

0 commit comments

Comments
 (0)