Skip to content

Commit a8e83d1

Browse files
committed
add hcm documentation
1 parent b46e60c commit a8e83d1

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

robot_nav/models/HCM/hardcoded_model.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77

88

99
class HCM(object):
10+
"""
11+
A class representing a hybrid control model (HCM) for a robot's navigation system.
12+
13+
This class contains methods for generating actions based on the robot's state, preparing state
14+
representations, training (placeholder method), saving/loading models, and logging experiences.
15+
16+
Attributes:
17+
max_action (float): The maximum possible action value.
18+
state_dim (int): The dimension of the state representation.
19+
writer (SummaryWriter): The writer for logging purposes.
20+
iterator (int): A counter for tracking sample addition.
21+
save_samples (bool): Whether to save the samples to a file.
22+
max_added_samples (int): Maximum number of samples to be added to the saved file.
23+
file_location (str): The file location for saving samples.
24+
"""
25+
1026
def __init__(
1127
self,
1228
state_dim,
@@ -15,6 +31,16 @@ def __init__(
1531
max_added_samples=10_000,
1632
file_location="robot_nav/assets/data.yml",
1733
):
34+
"""
35+
Initialize the HCM class with the provided configuration.
36+
37+
Args:
38+
state_dim (int): The dimension of the state space.
39+
max_action (float): The maximum possible action value.
40+
save_samples (bool): Whether to save samples to a file.
41+
max_added_samples (int): The maximum number of samples to save.
42+
file_location (str): The file path for saving samples.
43+
"""
1844
self.max_action = max_action
1945
self.state_dim = state_dim
2046
self.writer = SummaryWriter()
@@ -24,6 +50,17 @@ def __init__(
2450
self.file_location = file_location
2551

2652
def get_action(self, state, add_noise):
53+
"""
54+
Compute the action to be taken based on the current state of the robot.
55+
56+
Args:
57+
state (list): The current state of the robot, including LIDAR scan, distance,
58+
and other relevant features.
59+
add_noise (bool): Whether to add noise to the action for exploration.
60+
61+
Returns:
62+
list: The computed action [linear velocity, angular velocity].
63+
"""
2764
sin = state[-3]
2865
cos = state[-4]
2966
angle = atan2(sin, cos)
@@ -58,15 +95,66 @@ def train(
5895
noise_clip=0.5,
5996
policy_freq=2,
6097
):
98+
"""
99+
Placeholder method for training the hybrid control model.
100+
101+
Args:
102+
replay_buffer (object): The replay buffer containing past experiences.
103+
iterations (int): The number of training iterations.
104+
batch_size (int): The batch size for training.
105+
discount (float): The discount factor for future rewards.
106+
tau (float): The soft update parameter for target networks.
107+
policy_noise (float): The noise added to actions during training.
108+
noise_clip (float): The clipping value for action noise.
109+
policy_freq (int): The frequency at which to update the policy.
110+
111+
Note:
112+
This method is a placeholder and currently does nothing.
113+
"""
61114
pass
62115

63116
def save(self, filename, directory):
117+
"""
118+
Placeholder method to save the current model state to a file.
119+
120+
Args:
121+
filename (str): The name of the file where the model will be saved.
122+
directory (str): The directory where the file will be stored.
123+
124+
Note:
125+
This method is a placeholder and currently does nothing.
126+
"""
64127
pass
65128

66129
def load(self, filename, directory):
130+
"""
131+
Placeholder method to load a model state from a file.
132+
133+
Args:
134+
filename (str): The name of the file to load the model from.
135+
directory (str): The directory where the model file is stored.
136+
137+
Note:
138+
This method is a placeholder and currently does nothing.
139+
"""
67140
pass
68141

69142
def prepare_state(self, latest_scan, distance, cos, sin, collision, goal, action):
143+
"""
144+
Prepare the state representation for the model based on the current environment.
145+
146+
Args:
147+
latest_scan (list): The LIDAR scan data.
148+
distance (float): The distance to the goal.
149+
cos (float): The cosine of the robot's orientation angle.
150+
sin (float): The sine of the robot's orientation angle.
151+
collision (bool): Whether a collision occurred.
152+
goal (bool): Whether the goal has been reached.
153+
action (list): The action taken by the robot, [linear velocity, angular velocity].
154+
155+
Returns:
156+
tuple: A tuple containing the prepared state and a terminal flag (1 if terminal state, 0 otherwise).
157+
"""
70158
latest_scan = np.array(latest_scan)
71159

72160
inf_mask = np.isinf(latest_scan)

0 commit comments

Comments
 (0)