Hello,
I am using my computer with a 3DR telemetry radio and running Python scripts from Mission Planner that have been controlling the copter on a set path. However, I am interested in taking that a step further and writing a Python script to control the quad via keyboard presses (ie yaw left when holding down the left arrow, throttle up when holding down the up arrow). I have written a script using the pygame library that records key presses, but it will not run in Mission Planner, giving me the error:
“Error running script No module named pygame”
I have included the code below. It runs fine as a standalone script, displaying key presses in real time (the print statements were for testing- I would change those to Script.SendRC(…) functions later). But it won’t get past the import statement in Mission Planner, so my questions are:
- Is Mission Planner able to import external libraries like pygame?
- Are there any other ways to get keyboard input into Mission Planner scripts? (I’ve tried input() and that just stalled at the input line)
- Any other suggestions to accomplish this task of controlling the quad via the keyboard?
Thanks for your time, and any input you have to share!
Code:
import pygame, sys, time
from pygame.locals import *
pygame.init()
size = width, height = 320, 240
screen = pygame.display.set_mode(size)
while 1:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_LEFT:
print(‘left’)
elif event.key == K_RIGHT:
print(‘right’)
elif event.key == K_DOWN:
pygame.quit()
sys.exit()