-
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
added github workflow #29
Conversation
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.
Also modify these files to remove pytest.skip
:
tests/test_qr_input.py
"""
Tests functionality for qr_input.
"""
from modules import qr_input
CAMERA = 0
if __name__ == '__main__':
result, qr_string = qr_input.qr_input(CAMERA)
assert result
assert qr_string is not None
print(f"Decoded QR code with string value: {qr_string}")
print("Done!")
tests/test_upload_commands.py
"""
Integration test for upload_commands.
"""
import math
import dronekit
from modules import upload_commands
ALTITUDE = 40
MAVLINK_FRAME = dronekit.mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
MAVLINK_WAYPOINT = dronekit.mavutil.mavlink.MAV_CMD_NAV_WAYPOINT
MAVLINK_TAKEOFF = dronekit.mavutil.mavlink.MAV_CMD_NAV_TAKEOFF
MAVLINK_LANDING = dronekit.mavutil.mavlink.MAV_CMD_NAV_LAND
MAVLINK_LOITER = dronekit.mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME
DELAY = 3
TOLERANCE = 0.0001
CONNECTION_ADDRESS = "tcp:localhost:14550"
def retrieve_commands(drone: dronekit.Vehicle) -> dronekit.CommandSequence:
"""
Retrieves latest version of commands.
"""
command_sequence = drone.commands
command_sequence.download()
drone.wait_ready()
return command_sequence
def upload_and_check_command_list(drone: dronekit.Vehicle,
commands: "list[dronekit.Command]"):
"""
Test the case of a list of waypoint commands.
"""
result = upload_commands.upload_commands(drone, commands)
assert result
# Retrieve current drone commands and see if they match with inputs
command_sequence = retrieve_commands(drone)
for i, command in enumerate(command_sequence):
assert command.frame == commands[i].frame
assert command.command == commands[i].command
assert command.param1 == commands[i].param1
# Parameters 2,3,4 not being tested since Mission Planner ignores them
assert math.isclose(command.x, commands[i].x, abs_tol = TOLERANCE)
assert math.isclose(command.y, commands[i].y, abs_tol = TOLERANCE)
assert math.isclose(command.z, commands[i].z, abs_tol = TOLERANCE)
def upload_and_check_empty_command_list(drone: dronekit.Vehicle):
"""
Test the case of an empty command list.
"""
# Retrieve current drone commands and add them to a list
command_sequence = retrieve_commands(drone)
commands = []
for command in command_sequence:
commands.append(command)
# Upload empty command list
empty_command_list = []
result = upload_commands.upload_commands(drone, empty_command_list)
assert not result
# Retrieve new commands and compare them with previous list
command_check = retrieve_commands(drone)
for i, command in enumerate(command_check):
assert command.frame == commands[i].frame
assert command.command == commands[i].command
assert command.param1 == commands[i].param1
# Parameters 2,3,4 not being tested since Mission Planner ignores them
assert math.isclose(command.x, commands[i].x, abs_tol = TOLERANCE)
assert math.isclose(command.y, commands[i].y, abs_tol = TOLERANCE)
assert math.isclose(command.z, commands[i].z, abs_tol = TOLERANCE)
if __name__ == "__main__":
# Drone setup
# Wait ready is false as the drone may be on the ground
dronekit_vehicle = dronekit.connect(CONNECTION_ADDRESS, wait_ready=False)
# Example waypoints list, converted to waypoint commands
waypoints_input = [(39.140, 22.23), (25.123, -76.324)]
# Test a command sequence with a variety of commands
commands_input = []
for waypoint in waypoints_input:
lat_input, lon_input = waypoint
dronekit_command = dronekit.Command(
0,
0,
0,
MAVLINK_FRAME,
MAVLINK_WAYPOINT,
0,
0,
DELAY,
0,
0,
0,
lat_input,
lon_input,
ALTITUDE,
)
commands_input.append(dronekit_command)
takeoff_command = dronekit.Command(
0,
0,
0,
MAVLINK_FRAME,
MAVLINK_TAKEOFF,
0,
0,
0,
0,
0,
0,
0,
0,
ALTITUDE,
)
commands_input.append(takeoff_command)
landing_command = dronekit.Command(
0,
0,
0,
MAVLINK_FRAME,
MAVLINK_LANDING,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
commands_input.append(landing_command)
loiter_command = dronekit.Command(
0,
0,
0,
MAVLINK_FRAME,
MAVLINK_LOITER,
0,
0,
0,
0,
0,
0,
0,
0,
ALTITUDE,
)
commands_input.append(loiter_command)
# Test with the command sequence
upload_and_check_command_list(dronekit_vehicle, commands_input)
# Test with empty command sequence
upload_and_check_empty_command_list(dronekit_vehicle)
print("Done!")
This will probably get rid of the CI errors.
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.
Reviewed.
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.
Reviewed.
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.
Reviewed.
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.
Approved.
No description provided.