-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My code implementation for software challenge #3
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,86 @@ 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 | ||
Comment on lines
+90
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to deal with this case first, well done! |
||
|
||
# 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. | ||
Comment on lines
+94
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your comments here really do help explain exactly what is happening in the code. Great work! |
||
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.") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think you need to put a blank line between the if and else statement blocks - also applies to all other if else's you have in this submission. It is a little more justified for the outer level of if/else, however for the nested ones I think it would be cleaner to not have a blank line. |
||
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: | ||
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): | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice logical sequence of the possible outcomes of the code, makes it very easy to understand what is going on. Great work here! |
||
|
||
|
||
# Code below is provided for you, YOU DO NOT NEED TO IMPLEMENT THIS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python methods should be separated by a single line blank line.