Skip to content

Commit

Permalink
chat: add get_vehicle_state support
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Dec 8, 2023
1 parent bb64f30 commit 06cfc7a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions MAVProxy/modules/mavproxy_chat/chat_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ def handle_function_call(self, run):
)
return

# get vehicle state including armed, mode
if tool_call.function.name == "get_vehicle_state":
run_reply = self.client.beta.threads.runs.submit_tool_outputs(
thread_id=run.thread_id,
run_id=run.id,
tool_outputs=[{
"tool_call_id": tool_call.id,
"output": json.dumps(self.get_vehicle_state())
}]
)
return

# get vehicle location
if tool_call.function.name == "get_vehicle_location":
run_reply = self.client.beta.threads.runs.submit_tool_outputs(
thread_id=run.thread_id,
Expand Down Expand Up @@ -218,6 +231,17 @@ def handle_function_call(self, run):
def get_formatted_date(self):
return datetime.now().strftime("%A, %B %d, %Y %I:%M:%S %p")

# get vehicle state including armed, mode
def get_vehicle_state(self):
# get mode from latest HEARTBEAT message
hearbeat_msg = self.mpstate.master().messages.get('HEARTBEAT', None)
if hearbeat_msg is None:
return "vehicle mode is unknown"
return {
"armed": self.mpstate.master().motors_armed(),
"mode": hearbeat_msg.custom_mode
}

# return a string of the vehicle's location
def get_vehicle_location(self):
gpi = self.mpstate.master().messages.get('GLOBAL_POSITION_INT', None)
Expand Down

0 comments on commit 06cfc7a

Please sign in to comment.