Skip to content

Commit

Permalink
added docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ansarid committed Dec 27, 2022
1 parent 274ce05 commit a20726b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ddcontroller/ddcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,20 @@ def __init__(self, config_path='/opt/ddcontroller/config/default.yaml', debug=Fa
self.position_controller_thread.start() # start position contoller thread # Ideally we don't start this until it's needed

def sleep(self, start_time):
"""_summary_
"""Sleep for a specified amount of time.
This method calculates the amount of time that has passed since the start time
and subtracts that from the wait time specified in the `self._wait` attribute.
If the calculated sleep time is negative, it is set to 0 instead. The method
then calls the built-in `time.sleep()` method to pause the program for the
calculated amount of time.
Args:
start_time (_type_): _description_
start_time (int): The starting timestamp in nanoseconds.
Returns:
float: The amount of time slept in seconds.
"""
# measure time since start and subtract from sleep time
sleep_time = sorted(
[self._wait - ((time.monotonic_ns() - start_time) / 1e9), 0]
)[1]
Expand All @@ -161,8 +169,8 @@ def _odometry_loop(self):

start_time = time.monotonic_ns() # record loop start time

self.left_wheel.update() # update left wheel readings
self.right_wheel.update() # update right wheel readings
self.left_wheel.update() # update left wheel readings
self.right_wheel.update() # update right wheel readings

self.linear_velocity, self.angular_velocity = self.get_motion() # get robot linear and angular velocities

Expand Down

0 comments on commit a20726b

Please # to comment.