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

Using message_encode_decode to send MAVlink messages #245

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

Conversation

HermanG05
Copy link

Used the following functions in data_encoding and flight_controller.py to send MAVlink messages to the flight controller via the flight interface worker:

  • encode_metadata()
  • encode_position_global()
  • send_statustext_msg()

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

Comment on lines 13 to 16
from ..common.modules.mavlink import flight_controller
from ..common.modules.data_encoding import message_encoding_decoding
from ..common.modules.data_encoding import metadata_encoding_decoding
from ..common.modules import position_global
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 them in alphabetical order

Comment on lines 67 to 82
result, message_flight_controller = flight_controller.FlightController.create(
address, baud_rate
)
if not result:
local_logger.error("Worker failed to create class object", True)
return

result, metadata = metadata_encoding_decoding.encode_metadata(
f"{worker_name}", coordinates_input_queue.queue.qsize()
)
if not result:
local_logger.error("Failed to encode metadata", True)
return

message_flight_controller.send_statustext_msg(f"{metadata}")

Copy link
Member

Choose a reason for hiding this comment

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

We cannot create another instance of FlightController here, you need to add an input in the FlightInterface.run() method, input the list, and then do this in the FlightInterface class' run() which has a FlightController already.

Comment on lines 88 to 105
coordinate = coordinates_input_queue.queue.get()
if coordinate is None:
local_logger.info("Received type None, exiting")
break

if not isinstance(coordinate, position_global.PositionGlobal):
local_logger.warning(f"Skipping unexpected input: {coordinate}")
continue

result, message = message_encoding_decoding.encode_position_global(
f"{worker_name}", coordinate
)
if not result:
local_logger.error("Failed to encode PositionGlobal object", True)
continue

message_flight_controller.send_statustext_msg(f"{message}")

Copy link
Member

Choose a reason for hiding this comment

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

The way this works is communications will send a list, and you need to edit the last line in communcations.py to return objects_in_world_global rather than the same thing it got as input. This list will be the input into FlightInterface. Then, the metadata message is on how long this list is, and then you send each element of this list (GPS coords) one by one.

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

@@ -182,6 +182,10 @@ def main() -> int:
mp_manager,
QUEUE_MAX_SIZE,
)
communications_to_flight_interface_queue = queue_proxy_wrapper.QueueProxyWrapper(
Copy link
Member

Choose a reason for hiding this comment

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

Add this queue to communication's output queue

if not result:
continue

output_queue.queue.put(value)
result, metadata = metadata_encoding_decoding.encode_metadata(
f"{worker_name}", len(list_of_messages)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using a worker_name input, just hard code "communications_worker" here. It's my bad that the common's function doesn't take in the enum as an input, I forgot about that part. We'll change that later, or you can do that right now?

result = self.controller.send_statustext_msg(message)
if not result:
self.__logger.error("Failed to send statustext message", True)
return False, None
Copy link
Member

Choose a reason for hiding this comment

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

Don't need to fail here, just log error. This will make data merge think we didn't get a odometry object

@@ -62,7 +65,16 @@ def flight_interface_worker(

time.sleep(period)

result, value = interface.run()
coordinate = coordinates_input_queue.queue.get()
Copy link
Member

Choose a reason for hiding this comment

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

I think there is a get_no_wait(), and then if it's None, means queue is empty. If queue is empty, skip getting and just run with inputting None for coordinate. Then, flight interface will be able to run without stalling for communications worker.

coordinate = coordinates_input_queue.queue.get()
if coordinate is None:
local_logger.info("Received type None, exiting")
break
Copy link
Member

Choose a reason for hiding this comment

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

Don't exit, just get odometry only (see above) since we'll need to get many odometries before we can send 1 message

local_logger.error("Failed to encode metadata", True)
continue

output_queue.queue.put(metadata)
Copy link
Member

Choose a reason for hiding this comment

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

Add a period (worker period) parameter, and wait that much time between placing things into queue (after this and in between the things in the loop)

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.

3 participants