#!/usr/bin/env python """ Test script to test sending RC input to shotManager (Used for testing shotManager in SITL) Also emulates the button server in stm32 running on Artoolink This takes user input to change rc values (use the arrow keys) Only meant for debugging purposes, so it's not production code """ #Imports import sys import os import curses import Queue import select import socket import struct import threading import time sys.path.append(os.path.realpath('..')) import app_packet sys.path.append(os.path.realpath('../../../net/usr/bin')) from sololink import rc_pkt sys.path.append(os.path.realpath('../../../flightcode/stm32')) from sololink import btn_msg #Globals state = "starting" #state of artoo emulator stringsUpdated = False Amapping = "unset" Bmapping = "unset" shotName = "unset" NUM_CHANNELS = 8 channelValues = [1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500] PORT = 5016 outputLock = threading.Lock() def main(stdscr): '''Main function that contains while loop, wrapped by curses''' #import globals global state global stringsUpdated global Amapping global Bmapping global shotName global clientQueue stringsUpdated = True activeChannel = 0 stdscr.nodelay(1) stdscr.addstr(0,10,"Hit 'q' to quit") for i in range(NUM_CHANNELS): stdscr.addstr(i+2, 20, "Channel %d : %d" % (i+1, channelValues[i])) stdscr.addstr(activeChannel+2, 18, ">>") stdscr.addstr(12, 10, "Hit up/down to change active channel") stdscr.addstr(13, 10, "Hit left/right to change stick value") stdscr.addstr(14, 10, "Hit 'c' to release sticks") stdscr.refresh() #start RC thread rc = threading.Thread(name = "sendRC", target = sendRC, args = ()) rc.daemon = True rc.start() #start artoo thread artooThread = threading.Thread(name = "ArtooButtonThread", target = ArtooButtonThread, args = ()) artooThread.daemon = True artooThread.start() key = '' while key != ord('q'): key = stdscr.getch() stdscr.refresh() if key == curses.KEY_UP: stdscr.addstr(activeChannel+2, 18, " Channel %d : %d"%(activeChannel + 1, channelValues[activeChannel])) activeChannel -= 1 if activeChannel < 0: activeChannel = 0 stdscr.addstr(activeChannel+2, 18, ">>") if key == curses.KEY_DOWN: stdscr.addstr(activeChannel+2, 18, " Channel %d : %d"%(activeChannel + 1, channelValues[activeChannel])) activeChannel += 1 if activeChannel >= NUM_CHANNELS: activeChannel = NUM_CHANNELS - 1 stdscr.addstr(activeChannel+2, 18, ">>") if key == curses.KEY_RIGHT: channelValues[activeChannel] += 10 if channelValues[activeChannel] > 2000: channelValues[activeChannel] = 2000 stdscr.addstr(activeChannel+2, 18, " Channel %d : %d"%(activeChannel + 1, channelValues[activeChannel])) if key == curses.KEY_LEFT: channelValues[activeChannel] -= 10 if channelValues[activeChannel] < 1000: channelValues[activeChannel] = 1000 stdscr.addstr(activeChannel+2, 18, " Channel %d : %d"%(activeChannel + 1, channelValues[activeChannel])) if key == ord('c'): for i in range(NUM_CHANNELS): channelValues[i] = 1500 stdscr.addstr(i+2, 20, "Channel %d : %d" % (i+1, channelValues[i])) # hit the A button if key == ord('a'): # (timestamp_us, button_id, button_event, pressed_mask) pkt = struct.pack("