Skip to content
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

Initial commit for statustext branch #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Initial commit for statustext branch #2

wants to merge 9 commits into from

Conversation

tqmsh
Copy link

@tqmsh tqmsh commented Dec 22, 2024

No description provided.

Copy link
Member

@maxlou05 maxlou05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@@ -0,0 +1,63 @@
import time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring at the top of this file briefly explaining what this code/module does

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Comment on lines 1 to 7
import time
from pymavlink import mavutil
from modules.common.data_encoding.message_encoding_decoding import decode_bytes_to_position_global
from modules.common.data_encoding.metadata_encoding_decoding import decode_metadata
from modules.common.data_encoding.worker_enum import WorkerEnum
from modules.common.kml.kml_conversion import positions_to_kml
from pathlib import Path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our import convention is to have Python imports first, then outside library imports, then our own module imports. There is a space between each section. We only import modules (files), so no importing classes or functions directly (ie no import WorkerEnum, instead import worker_enum). Finally, everything needs to be in alphabetical order, and two spaces after all of the imports

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Comment on lines 9 to 10
CONNECTION_ADDRESS = "tcp:localhost:14550"
DELAY = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our convention is to place 2 spaces after global constants. Also, for your script you would not need a DELAY variable, since recv_match is blocking

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

f"Unsuccessful or Non-communications worker message (worker_id: {worker_id})"
)
# After collecting all positions, generate KML
save_directory = Path("path/to/save/kml/files")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a global constant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

)
# After collecting all positions, generate KML
save_directory = Path("path/to/save/kml/files")
document_name_prefix = "drone_gps_data"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save this in a global constant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

print("Failed to save KML file.")
else:
print(f"Unsuccessful or Non-communications worker message (worker_id: {worker_id})")
time.sleep(DELAY)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

vehicle.wait_heartbeat()
print("connected")

positions = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to declare this inside the infinite loop, so you don't have to do it again later below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put the entire thing in a main() function, and then use a main guard (if __name__ == "__main__"), and use argparse to optionally take in save directory and document name prefix. Defaults are save directory = logs, document name prefix = IR hotspot locations

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Copy link
Member

@maxlou05 maxlou05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

import argparse
import time
from pathlib import Path
from pymavlink import mavutil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put 1 space above this line (this is a external library)

from modules.common.data_encoding import worker_enum
from modules.common.kml.kml_conversion import positions_to_kml

CONNECTION_ADDRESS = "tcp:localhost:14550"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put one more space above this line (2 spaces between imports and constants)

CONNECTION_ADDRESS = "tcp:localhost:14550"


def main(save_directory, document_name_prefix):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make main return a int, 0 for success and -1 (negative numbers) for errors and accordingly update the running part? (Just copy C++ standards)

Comment on lines +11 to +14
from modules.common.data_encoding.message_encoding_decoding import decode_bytes_to_position_global
from modules.common.data_encoding.metadata_encoding_decoding import decode_metadata
from modules.common.data_encoding import worker_enum
from modules.common.kml.kml_conversion import positions_to_kml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these imports, can you import modules only, and not specific functions/classes? Just a convention thing. ie import message_encoding_decoding, then use message_encoding_decoding.decode_bytes_to_position_global.

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Collect drone GPS positions and save as KML.")
parser.add_argument(
"--save-directory", type=str, default="logs", help="Directory to save KML files."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably make the default value a constant

parser.add_argument(
"--document-name-prefix",
type=str,
default="IR hotspot locations",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably make the default value a constant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants