-
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
fixed waypoints_to_spline_commands #31
Open
applepie7864
wants to merge
5
commits into
main
Choose a base branch
from
waypoints_to_spline_commands
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
5 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 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,56 @@ | ||
""" | ||
Function to convert list of waypoints to dronekit commands. | ||
""" | ||
|
||
import dronekit | ||
|
||
from . import waypoint | ||
|
||
|
||
MAVLINK_FRAME = dronekit.mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT | ||
MAVLINK_COMMAND = dronekit.mavutil.mavlink.MAV_CMD_NAV_SPLINE_WAYPOINT | ||
ACCEPT_RADIUS = 10 | ||
|
||
|
||
def waypoints_to_spline_commands(waypoints: "list[waypoint.Waypoint]", | ||
altitude: int) -> "tuple[bool, list[dronekit.Command] | None]": | ||
""" | ||
Convert list of waypoints to dronekit commands. | ||
|
||
Parameters | ||
---------- | ||
waypoints: list[Waypoint] | ||
list of Waypoint objects containing names and coordinates in decimal degrees. | ||
altitude: int | ||
altitude in meters to command the drone to. | ||
Returns | ||
------- | ||
tuple[bool, list[dronekit.Command] | None]: | ||
(False, None) if empty waypoints list, | ||
(True, dronekit commands that can be sent to the drone) | ||
""" | ||
if len(waypoints) == 0: | ||
return False, None | ||
|
||
dronekit_command_list = [] | ||
|
||
for point in waypoints: | ||
command = dronekit.Command( | ||
0, | ||
0, | ||
0, | ||
MAVLINK_FRAME, | ||
MAVLINK_COMMAND, | ||
0, | ||
0, | ||
0, # param1 | ||
ACCEPT_RADIUS, | ||
0, | ||
0, | ||
point.latitude, | ||
point.longitude, | ||
altitude, | ||
) | ||
dronekit_command_list.append(command) | ||
|
||
return True, dronekit_command_list |
This file contains 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,61 @@ | ||
""" | ||
Test process. | ||
""" | ||
|
||
import dronekit | ||
|
||
from modules import waypoint | ||
from modules import waypoints_to_spline_commands | ||
|
||
|
||
def test_waypoints_to_spline_commands_empty_input(): | ||
""" | ||
Tests functionality correctness of waypoints_to_spline_commands on empty input. | ||
""" | ||
waypoints = [] | ||
altitude = 100 | ||
|
||
result, commands_actual = waypoints_to_spline_commands.waypoints_to_spline_commands( | ||
waypoints, | ||
altitude | ||
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. Add comma at end of this line. |
||
) | ||
|
||
assert not result | ||
assert commands_actual is None | ||
|
||
|
||
def test_waypoints_to_spline_commands(): | ||
""" | ||
Tests functionality correctness of waypoints_to_spline_commands. | ||
""" | ||
waypoints = [ | ||
waypoint.Waypoint("Waypoint 1", 42.123, -73.456), | ||
waypoint.Waypoint("Waypoint 2", 42.789, -73.987), | ||
waypoint.Waypoint("Waypoint 3", 42.555, -73.321), | ||
] | ||
altitude = 100 | ||
|
||
result, commands_actual = waypoints_to_spline_commands.waypoints_to_spline_commands( | ||
waypoints, | ||
altitude | ||
Comment on lines
+39
to
+40
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. Same as above. |
||
) | ||
|
||
assert result | ||
|
||
assert isinstance(commands_actual, list) | ||
assert len(commands_actual) == len(waypoints) | ||
|
||
for i, command in enumerate(commands_actual): | ||
lat_expected = waypoints[i].latitude | ||
lng_expected = waypoints[i].longitude | ||
|
||
assert isinstance(command, dronekit.Command) | ||
assert command.frame == waypoints_to_spline_commands.MAVLINK_FRAME | ||
assert command.command == waypoints_to_spline_commands.MAVLINK_COMMAND | ||
assert command.param1 == 0 | ||
assert command.param2 == waypoints_to_spline_commands.ACCEPT_RADIUS | ||
assert command.param3 == 0 | ||
assert command.param4 == 0 | ||
assert command.x == lat_expected | ||
assert command.y == lng_expected | ||
assert command.z == altitude |
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.
Remove extra space after the comma.