Skip to content

Commit

Permalink
refactor+doc future steps
Browse files Browse the repository at this point in the history
I need to add Hz for the threads to limit their steps.
  • Loading branch information
Ahelsamahy committed Sep 23, 2024
1 parent 98f7fd8 commit a47f056
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions coms/coms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def main():

if __name__ == "__main__":
# Declaring the logger
# TODO: Add thread number here
logging.basicConfig(format="%(levelname)s: %(asctime)s %(filename)s %(funcName)s %(message)s", datefmt="%Y%m%d:%H:%M:%S %p %Z")
logging.getLogger().setLevel(logging.INFO)
logger = logging.getLogger(__name__)
Expand Down
2 changes: 2 additions & 0 deletions coms/coms/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def __init__(self, distance=1.35):
self.steering_queue = deque() # Queue to store steering values
self.time_now = 0.0 # Timestamp when steering was first received
self.delay = 0.0 # Delay before applying steering, calculated based on velocity
# TODO: Add it as part of the parse config function
self.distance = distance # Distance between the motors of the current segment and the LD segment in m
self.use_steering_queue = False # Flag to indicate when to use the steering queue
self.started_counting_down = False # Flag to indicate if the delay countdown has started

@staticmethod
def process(self, movement_command):
"""
Processes the movement command from the LD segment.
Expand Down
9 changes: 5 additions & 4 deletions coms/coms/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from byodr.utils.ssh import Nano

from .client import SegmentClient
from .command_processor import process
from .command_processor import MovementProcessor
from .server import SegmentServer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,14 +65,14 @@ def start_communication(self, socket_manager):
Returns:
0 if all threads started close gracefully.
"""
# This function is the entry point to this whole file. I would need to have shared data between all these functions and the threads they are starting. The quit event I passed must be used instead of the quit event that is used here
# TODO: This function is the entry point to this whole file. I would need to have shared data between all these functions and the threads they are starting. The quit event I passed must be used instead of the quit event that is used here
# A deque that will store messages received by the server of the segment
msg_from_server_queue = deque(maxlen=1)

segment_client = SegmentClient(self.follower_ip, self.nano_port, 0.10) # The client that will connect to a follower
segment_server = SegmentServer(self.local_ip, self.nano_port, 0.10) # The server that will wait for the lead to connect

# I need to implement some sort of HZ here on these functions
# TODO: I need to implement some sort of HZ here on these functions
command_receiver_thread = threading.Thread(target=self.command_receiver, args=(socket_manager, segment_client, self.local_ip, self.head_ip, msg_from_server_queue))
client_interface_thread = threading.Thread(target=self.client_code, args=(socket_manager, segment_client))
server_interface_thread = threading.Thread(target=self.server_code, args=(segment_server, msg_from_server_queue))
Expand Down Expand Up @@ -238,6 +238,7 @@ def server_code(self, segment_server, msg_from_server_queue):
"""

counter_server = 0
movement_processor = MovementProcessor()

while not self.quit_event.is_set():

Expand All @@ -263,7 +264,7 @@ def server_code(self, segment_server, msg_from_server_queue):
# Processing the command before sending it to the FL.
# Since we might receive a status message instead of a movement command, we check if its a normal movement command first
if "throttle" in command_to_process:
segment_server.processed_command = process(command_to_process)
segment_server.processed_command = movement_processor.process(command_to_process)

# Placing the message from the server in the queue
msg_from_server_queue.append(segment_server.processed_command)
Expand Down
1 change: 1 addition & 0 deletions coms/coms/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Declaring the logger
logger = logging.getLogger(__name__)


class SegmentServer:
"""Encapsulate the server functionalities of the segment.
Expand Down

0 comments on commit a47f056

Please sign in to comment.