This document discusses using callbacks to control a drone. It describes how callbacks are used by the Crazyflie API middleware to connect to and disconnect from the drone. It also explains how callbacks are used to control the drone with keyboard keys by notifying the copter commander of actions. Finally, it discusses using voice commands to control the drone by converting voice to text and sending notifications to the message listener to trigger callback actions.
8. Control Copter With Keys
def send_commands(self):
self.check_values_range()
if self.copter_commander:
self.copter_commander.send_setpoint(
self.roll,
self.pitch,
self.yaw,
self.thrust)
9. Controlling Copter
Connect to copter
Using Pygame for key listeners
On key press, send notifications to callback (callback.notify(ACTION))
Callback handle action accordingly (Here by sending commands to copter)
10. Voice Control
class MessageHandler(socketserver.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).decode('utf-8').strip()
print("SERVER: received:" + self.data)
global message_listener
copter_response = message_listener.notify(self.data)
self.request.sendall(copter_response.encode('utf-8'))
11. Voice Control
def notify(self, command):
response_from_action =
self.voice_config.get_command_action(command).__call__()
return response_from_action or self.voice_config.get_message(command)
12. Voice Control
class VoiceControlConfig:
def __init__(self, voice_controlled_actions):
self.copter_commands = {
"connect": (voice_controlled_actions.connect_to_copter,
"I am trying to connect sir."),
"disconnect": (voice_controlled_actions.disconnect_copter,
"good bye."),
"fly": (voice_controlled_actions.fly, "at your service."),
...
}
def get_message(self, command):
return self.copter_commands.get(command)[1]
def get_command_action(self, command):
return self.copter_commands.get(command)[0]
13. Voice control
Convert Voice commands to Text (use google, wit.ai etc)
The input sentences (easy to recognise) are converted to predefined commands.
Send the text ‘Command’ to Message Listener
Message Listener convert the commands to proper actions
Based on actions invoke callbacks
14. Goals
Autopilot
Use Machine Learning to get commands from environment
(eg: Direction to move from an image, altitude to fly)
Seamless Interactive Flying Copter
Network of Copter