-
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
First challenge #7
base: master
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -32,27 +32,27 @@ class will interface with our onboard GPS sensor to get thecurrent position, and | |
| | ||
| | ||
below target | ||
|
||
Misc: | ||
TBM - Tunnel Boring Machine | ||
""" | ||
|
||
# Implement this class - this code will not actually be run, it is more of a thought exercise! | ||
class Navigation: | ||
""" Class to control position based on GPS input | ||
""" Class to control position based on GPS input | ||
|
||
Attributes: | ||
GPS - GPS Interface object, used to obtain GPS coordinates | ||
steering - Steering object | ||
current_position - The current position of the TBM in 3-D space (x, y, z) | ||
desired_position - The desired position of the TBM in 3-D space (x, y, z) | ||
|
||
Methods: | ||
set_desired_position() | ||
update_current_position() | ||
set_desired_position() | ||
update_current_position() | ||
navigate() | ||
""" | ||
|
||
def __init__(self, GPS, steering): | ||
|
||
# Instances of the two classes defined below for use to complete the navigation method | ||
|
@@ -62,39 +62,85 @@ 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. | ||
|
||
Note: assume the user will pass in the desired_position parameter when using | ||
the interface | ||
the interface | ||
""" | ||
self.desired_position = desired_position | ||
pass | ||
|
||
|
||
Comment on lines
75
to
+76
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. AS per PEP8 - all methods are surrounded only by a single line of whitespace |
||
def update_current_position(self): | ||
""" Updates the current position of the TBM """ | ||
self.current_position = self.GPS.getPos() | ||
pass | ||
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 line serves no purpose right now, all uses of pass should be removed when the method is implemented. 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. It just serves as a placeholder |
||
|
||
|
||
def navigate(self): | ||
""" Navigate to the desired position from the current position | ||
|
||
Based on the current position tuple, compared to the desired position tuple, | ||
make decisions on steering, and ensure that the actuations are successful | ||
|
||
Returns: True if actuation requests were successful, False if not | ||
Note: It may be good to notify the user if something unexpected happens! | ||
""" | ||
currentX, currentY, currentZ = current_position | ||
wantedX, wantedY, wantedZ = desired_position | ||
|
||
moveX = wantedX - currentX | ||
moveY = wantedY - currentY | ||
moveZ = wantedZ - currentZ | ||
|
||
success = true | ||
|
||
# Assume all move commands with distance esentially finish instintaniously and | ||
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. *essentially, *instantaneously |
||
# place the drill in the correct location | ||
if moveY > 0: | ||
success = self.steering.move_right(moveY) | ||
if !success: | ||
print("Move right did not execute properly") # print used as a substitute for any place that we'd want to print to | ||
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. The comment explaining print as a placeholder for a log is good but could have been placed above the call to print to adhere to the 80 char line length limit |
||
return success | ||
else: | ||
success = self.steering.move_left(-moveY) | ||
if !success: | ||
print("Move left did not execute properly") | ||
return success | ||
|
||
if moveZ > 0: | ||
success = self.steering.move_up(moveZ) | ||
if !success: | ||
print("Move up did not execute properly") | ||
return success | ||
else: | ||
success = self.steering.move_down(-moveZ) | ||
if !success: | ||
print("Move down did not execute properly") | ||
return success | ||
|
||
# Assume it only has to move forward in the X direction. | ||
if self.current_position != self.desired_position: | ||
Comment on lines
+125
to
+126
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 understand that this code is only reached when Z and Y have both been adjusted, but it would make it easier to read if you specified that you are checking x here. Also, moveX is an unused variable |
||
success = self.steering.move_forward() | ||
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. move_forward probably should have an argument for how far to move. |
||
if !success: | ||
print("Move forward did not execute properly") | ||
return success | ||
|
||
while self.current_position != self.desired_position: | ||
self.update_current_position() | ||
Comment on lines
+132
to
+133
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 this will be an infinite while loop that just reads the GPS, this would block the application when navigate is called. |
||
|
||
self.steering.stop() | ||
pass | ||
|
||
|
||
# Code below is provided for you, YOU DO NOT NEED TO IMPLEMENT THIS | ||
|
||
class GPS: | ||
""" Mock GPS sensor interface class """ | ||
|
||
def __init__(self, GPSSensor): | ||
self.GPS = GPSSensor | ||
self.x = GPSSensor.pos.x | ||
|
@@ -107,16 +153,16 @@ 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 | ||
|
||
|
||
class Steering: | ||
""" Interfaces with the actuator which steers the TBM, and controls its speed | ||
|
||
Attributes: | ||
act - Placeholder actuation component (could be a motor for example, or some other actuator related to steering) | ||
|
||
|
@@ -128,7 +174,7 @@ class Steering: | |
move_forward() | ||
stop() | ||
""" | ||
|
||
def __init__(self, actuation_component): | ||
self.act = actuation_component | ||
|
||
|
@@ -139,15 +185,15 @@ def move_left(self, left_distance): | |
Returns: True if the actuation is successful, False if it is not | ||
""" | ||
return self.act.steer_left(left_distance) | ||
|
||
def move_right(self, right_distance): | ||
""" Steers the TBM to the right | ||
|
||
Returns: True if the actuation is successful, False if it is not | ||
""" | ||
return self.act.steer_right(right_distance) | ||
|
||
def move_down(self, down_distance): | ||
def move_down(self, down_distance): | ||
""" Steers the TBM down | ||
|
||
Returns: True if the actuation is successful, False if it is not | ||
|
@@ -177,4 +223,4 @@ def stop(self): | |
Returns: True if the motor stops the TBM, False if it does not | ||
""" | ||
return self.act.stop() | ||
|
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.
Is there any reason there is a lot of lines removed and then added - just wondering if your ide is telling you to indent with tabs or something
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.
@Akashf I'm assuming you ran a linter or something over the code and it picked up some trailing whitespace. For future reference, if you make any linting changes, try to put them in their own commit. Makes it easier for the reviewer to actually see your code changes.