From 0656adfe2aea3f86fb430a70bd1edc1767fb5684 Mon Sep 17 00:00:00 2001 From: Brendon Thorne Date: Sun, 27 Sep 2020 21:02:00 -0230 Subject: [PATCH 1/3] My code implementation for software challenge --- fall-2020/navigation.py | 85 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/fall-2020/navigation.py b/fall-2020/navigation.py index 3cdf661..b91cf7d 100644 --- a/fall-2020/navigation.py +++ b/fall-2020/navigation.py @@ -70,12 +70,13 @@ def set_desired_position(self, desired_position): Note: assume the user will pass in the desired_position parameter when using the interface """ - pass + self.desired_position = desired_position def update_current_position(self): """ Updates the current position of the TBM """ - pass + self.GPS.pollsensor() + self.current_position = self.GPS.getPos() def navigate(self): @@ -87,7 +88,85 @@ def navigate(self): Returns: True if actuation requests were successful, False if not Note: It may be good to notify the user if something unexpected happens! """ - pass + # Getting current position of the TBM. + self.update_current_position() + + if self.current_position == self.desired_position: + print("Current position is already at desired position.") + return True + + # Looping through and comparing each corresponding coordinate in the two position tuples. + for coordinate_index in range(3): + # If x => check if TBM is behind, if y => check if TBM is left, if z => check if TBM is below. + if self.current_position[coordinate_index] < self.desired_position[coordinate_index]: + # Distance between the two corresponding x, y, or z values. + steer_distance = self.desired_position[coordinate_index] - self.current_position[coordinate_index] + + # x value. + if coordinate_index == 0: + if self.steering.move_forward(): + print("Actuation successful.") + + else: + print("Forward actuation unsuccessful.") + + # y value. + elif coordinate_index == 1: + if self.steering.move_right(steer_distance): + print("Actuation successful.") + + else: + print("Right actuation unsuccessful.") + + # z value. + elif coordinate_index == 2: + if self.steering.move_up(steer_distance): + print("Actuation successful.") + + else: + print("Up actuation unsuccessful.") + + # If x => check if TBM is in front, if y => check if TBM is right, if z => check if TBM is above. + elif self.current_position[coordinate_index] > self.desired_position[coordinate_index]: + steer_distance = self.current_position[coordinate_index] - self.desired_position[coordinate_index] + + if coordinate_index == 0: + print("Unexpected input for x coordinate. Should be behind target not in front of target.") + + elif coordinate_index == 1: + if self.steering.move_left(steer_distance): + print("Actuation successful.") + + else: + print("Left actuation unsuccessful.") + + elif coordinate_index == 2: + if self.steering.move_down(steer_distance): + print("Actuation successful.") + + else: + print("Down actuation unsuccessful.") + + # Getting new current position of the TBM. + self.update_current_position() + + if self.current_position == self.desired_position: + if self.steering.stop(): + print("Stop successful. All actuation's successful.") + return True + + else: + print("All actuation's successful but failed to stop.") + return False + + else: + if self.steering.stop(): + print("Actuation's unsuccessful desired destination not reached.") + return False + + else: + print("Actuation's unsuccessful and failed to stop.") + return False # Code below is provided for you, YOU DO NOT NEED TO IMPLEMENT THIS From 8f4a38c1779ec5a50c9c2c9243103eb8b8f541c9 Mon Sep 17 00:00:00 2001 From: Brendon Thorne Date: Mon, 19 Oct 2020 19:39:04 -0230 Subject: [PATCH 2/3] Addressed question from initial code review --- fall-2020/navigation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fall-2020/navigation.py b/fall-2020/navigation.py index b91cf7d..4f8e675 100644 --- a/fall-2020/navigation.py +++ b/fall-2020/navigation.py @@ -131,7 +131,8 @@ def navigate(self): steer_distance = self.current_position[coordinate_index] - self.desired_position[coordinate_index] if coordinate_index == 0: - print("Unexpected input for x coordinate. Should be behind target not in front of target.") + raise ValueError("Unexpected input for x coordinate. " + "Should be behind target not in front of target.") elif coordinate_index == 1: if self.steering.move_left(steer_distance): From f810c88028b5bffbb0a676fae4398adc91d41446 Mon Sep 17 00:00:00 2001 From: Brendon Thorne Date: Tue, 27 Oct 2020 17:10:55 -0230 Subject: [PATCH 3/3] Addressed request to change formatting of code --- fall-2020/navigation.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/fall-2020/navigation.py b/fall-2020/navigation.py index 4f8e675..ec2fe04 100644 --- a/fall-2020/navigation.py +++ b/fall-2020/navigation.py @@ -52,7 +52,6 @@ class Navigation: update_current_position() navigate() """ - def __init__(self, GPS, steering): # Instances of the two classes defined below for use to complete the navigation method @@ -62,7 +61,6 @@ def __init__(self, GPS, steering): # These will be tuples of the form (x, y, z) self.current_position = None self.desired_position = None - def set_desired_position(self, desired_position): """ Sets the desired position the TBM will attempt to move to. @@ -72,13 +70,11 @@ def set_desired_position(self, desired_position): """ self.desired_position = desired_position - def update_current_position(self): """ Updates the current position of the TBM """ self.GPS.pollsensor() self.current_position = self.GPS.getPos() - def navigate(self): """ Navigate to the desired position from the current position @@ -106,7 +102,6 @@ def navigate(self): if coordinate_index == 0: if self.steering.move_forward(): print("Actuation successful.") - else: print("Forward actuation unsuccessful.") @@ -114,7 +109,6 @@ def navigate(self): elif coordinate_index == 1: if self.steering.move_right(steer_distance): print("Actuation successful.") - else: print("Right actuation unsuccessful.") @@ -122,7 +116,6 @@ def navigate(self): elif coordinate_index == 2: if self.steering.move_up(steer_distance): print("Actuation successful.") - else: print("Up actuation unsuccessful.") @@ -137,14 +130,12 @@ def navigate(self): elif coordinate_index == 1: if self.steering.move_left(steer_distance): print("Actuation successful.") - else: print("Left actuation unsuccessful.") elif coordinate_index == 2: if self.steering.move_down(steer_distance): print("Actuation successful.") - else: print("Down actuation unsuccessful.") @@ -155,7 +146,6 @@ def navigate(self): if self.steering.stop(): print("Stop successful. All actuation's successful.") return True - else: print("All actuation's successful but failed to stop.") return False @@ -164,14 +154,12 @@ def navigate(self): if self.steering.stop(): print("Actuation's unsuccessful desired destination not reached.") return False - else: print("Actuation's unsuccessful and failed to stop.") return False # Code below is provided for you, YOU DO NOT NEED TO IMPLEMENT THIS - class GPS: """ Mock GPS sensor interface class """ @@ -187,8 +175,7 @@ def pollSensor(self): Updates the current position by reading the gps sensor """ self.x, self.y, self.z = self.GPS.read() - - + def getPos(self): """ Returns the TBM position """ return self.x, self.y, self.z @@ -212,7 +199,6 @@ class Steering: def __init__(self, actuation_component): self.act = actuation_component - def move_left(self, left_distance): """ Steers the TBM left @@ -234,7 +220,6 @@ def move_down(self, down_distance): """ return self.act.steer_down(down_distance) - def move_up(self, up_distance): """ Steers the TBM to the right @@ -242,7 +227,6 @@ def move_up(self, up_distance): """ return self.act.steer_up(up_distance) - def move_forward(self): """ Moves the TBM forward @@ -250,7 +234,6 @@ def move_forward(self): """ return self.act.forward() - def stop(self): """ Stops the TBM from moving