-
Notifications
You must be signed in to change notification settings - Fork 0
Ackerman calculations for wheel angles #155
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
Open
Andrew-Lowitt
wants to merge
4
commits into
main
Choose a base branch
from
ackerman
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,19 +6,19 @@ | |
| class Breakbeam: | ||
| ACCEPTABLE_TIME = 3 # time to wait to confirm a full break | ||
|
|
||
| class BEAM_PINS(Enum): | ||
| HALF1 = 17 | ||
| HALF2 = 22 | ||
| FULL1 = 23 | ||
| FULL2 = 24 | ||
| # class BEAM_PINS(Enum): | ||
| # HALF1 = 17 | ||
| # HALF2 = 22 | ||
|
Collaborator
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. You might want to remove this commented code if its not needed. It seems BEAM_PINS is in the class now so its not needed |
||
| # FULL1 = 23 | ||
| # FULL2 = 24 | ||
|
|
||
| def __init__(self): | ||
| def __init__(self, pins): | ||
| """ | ||
| Initializes each sensor to detect changes. Initializes beam_broken to False. | ||
| Creates an empty list for the beams that are broken. | ||
| Attribute blocked_sensors: set of sensors that have been fully blocked. | ||
| """ | ||
| for BEAM_PIN in Breakbeam.BEAM_PINS: | ||
| for BEAM_PIN in pins: | ||
| GPIO.setmode(GPIO.BCM) | ||
| GPIO.setup(BEAM_PIN.value, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
| GPIO.add_event_detect( | ||
|
|
@@ -38,7 +38,7 @@ def break_beam_callback(self, channel): | |
| # print("50% full: " + str(self.check_half())) | ||
| # print("100% full: " + str(self.check_full())) | ||
|
|
||
| def timer(self, channel): | ||
| def timer(self, pins, channel): | ||
| """ | ||
| Gets the current time and calculates the time that has passed, then compares | ||
| this to the ACCEPTABLE_TIME to determine whether the broken beam was just | ||
|
|
@@ -53,32 +53,32 @@ def timer(self, channel): | |
| if GPIO.input(channel): | ||
| break | ||
| else: | ||
| self.blocked_sensors.add(Breakbeam.BEAM_PINS(channel).name) | ||
| self.blocked_sensors.add(pins(channel).name) | ||
| self.blocked_sensors_check() | ||
| # print(self.blocked_sensors) | ||
|
|
||
| def blocked_sensors_check(self): | ||
| def blocked_sensors_check(self, pins): | ||
| """ | ||
| Checks whether the sensors in the set blocked_sensors are still blocked. | ||
| Uses list TO_BE_REMOVED to store the sensors that have been unblocked and | ||
| then remove them from the set of blocked sensors. | ||
| """ | ||
| TO_BE_REMOVED = [] # sensors to remove due to being unbroken | ||
| for sensor in self.blocked_sensors: | ||
| if GPIO.input(Breakbeam.BEAM_PINS[sensor].value): | ||
| if GPIO.input(pins[sensor].value): | ||
| TO_BE_REMOVED.append(sensor) | ||
|
|
||
| for sensor in TO_BE_REMOVED: | ||
| self.blocked_sensors.remove(sensor) | ||
|
|
||
| def check_half(self): | ||
| def check_half(self, pin_half_one, pin_half_two): | ||
| """ | ||
| Returns whether the 50% sensors are in the set of fully blocked sensors | ||
| """ | ||
| return ( | ||
| len(self.blocked_sensors) < 4 | ||
| and Breakbeam.BEAM_PINS(17).name in self.blocked_sensors | ||
| and Breakbeam.BEAM_PINS(22).name in self.blocked_sensors | ||
| and pin_half_one in self.blocked_sensors | ||
| and pin_half_two in self.blocked_sensors | ||
| ) | ||
|
|
||
| def check_full(self): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import math | ||
| import unittest | ||
| from engine.robot_logic.traversal import ( | ||
| ackerman_calculations, | ||
| ackerman_right, | ||
| ackerman_left, | ||
| ) | ||
|
|
||
|
|
||
| class TestAckermanFunctions(unittest.TestCase): | ||
| def test_ackerman_right(self): | ||
| # Test case where the robot needs to turn right | ||
| left_ang = math.radians(30) # in radians | ||
| right_ang = math.radians(45) # in radians | ||
| inside_ang = math.radians(30) # in radians | ||
| wheel_base = 1.5 # in meters | ||
| steering_ratio = 1 # arbitrary value | ||
| expected_turn_angle = math.radians(45 - inside_ang) | ||
| actual_turn_angle = math.radians( | ||
| ackerman_right(left_ang, right_ang, inside_ang, wheel_base, steering_ratio) | ||
| ) | ||
| self.assertEqual(expected_turn_angle, actual_turn_angle) | ||
|
|
||
| def test_ackerman_left(self): | ||
| # Test case where the robot needs to turn left | ||
| left_ang = math.radians(45) # in radians | ||
| right_ang = math.radians(30) # in radians | ||
| inside_ang = math.radians(45) # in radians | ||
| wheel_base = 1.5 # in meters | ||
| steering_ratio = 1 # arbitrary value | ||
| expected_turn_angle = math.radians(45 - inside_ang) | ||
| actual_turn_angle = math.radians( | ||
| ackerman_left(left_ang, right_ang, inside_ang, wheel_base, steering_ratio) | ||
| ) | ||
| self.assertEqual(expected_turn_angle, actual_turn_angle) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
breakbeam class changes not relevant to current pr; remove from current pr