def find_board(): """ Lists serial port names :raises EnvironmentError: On unsupported or unknown platforms :returns: A list of the serial ports available on the system """ if sys.platform.startswith('win'): ports = ['COM%s' % (i + 1) for i in range(256)] elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'): # this excludes your current terminal "/dev/tty" ports = glob.glob('/dev/tty[A-Za-z]*') elif sys.platform.startswith('darwin'): ports = glob.glob('/dev/tty.*') else: raise EnvironmentError('Unsupported platform') for port in ports: board = None try: s = serial.Serial(port) s.close() board = MultiWii(port) board.getData(MultiWii.RC) return board except (OSError, serial.SerialException): if board: board.disconnect() pass return None
def __init__(self): #INIT MULTIWII self.WiiProtocol = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.USBPort = "COM4" self.Board = MultiWii(self.USBPort) self.Board.arm() print("ARMED")
def run(self): global RUNNING values = { 'roll': INITIAL_ROLL, 'pitch': INITIAL_PITCH, 'yaw': INITIAL_YAW, 'throttle': INITIAL_THROTTLE } board = MultiWii(SERIAL, PRINT=False) last_command = time.time() armed = False try: while RUNNING: command = None try: command = QUEUE.get_nowait() QUEUE.task_done() # we don't retry commands except Empty: if (time.time() - last_command) > 2: #fail safe - if no commands stop the drone board.disarm() armed = False continue if armed: data = [values['roll'], values['pitch'], values['yaw'], values['throttle']] board.sendCMD(8,MultiWii.SET_RAW_RC,data) time.sleep(0.05) continue last_command = time.time() if not command or not 'action' in command: continue print "got command: %s" % command if command['action'] == 'arm': board.arm() armed = True elif command['action'] == 'disarm': board.disarm() armed = False elif command['action'] == 'update': try: values.update(command['data']) except: logging.exception('error update values') else: logging.debug('invalid command %s' % command) except: logging.exception("Error") board.disarm()
def __init__(self): self.rcData = RCData() self.cam = CameraData() self.cmdManager = CommandManager() self.actionManager = ActionManager() self.heightController = heightControl(self.rcData) #self.recog = Recognition(self.cam) self.symbolList = [] self.currentCommand = None self.board = MultiWii('/dev/ttyUSB0') #self.loadActions() #self.loadCommands() #self.loadSymbols() self.Load.loadAction() self.Load.loadCommands() self.Load.loadSymbols() time.sleep(1)
def __init__(self, attitude_reader_port, anchor_configs): self.locations = [] for anchor_config in anchor_configs: self.anchors.append( SerialDistanceReader(anchor_config["serial_port"], anchor_config["bias"])) self.locations.append([ float(anchor_config["x"]), float(anchor_config["y"]), float(anchor_config["z"]) ]) print("Initializing anchor " + anchor_config["serial_port"] + " with locations: " + str(self.locations[-1])) thread = Thread(target=bg_update_distances, args=(self.anchors, self.thread_lock)) thread.daemon = True thread.start() time.sleep(5) self.trilateration = Trilateration(self.locations, 100) self.attitude_reader = MultiWii(attitude_reader_port) print("Initialized multiwii on " + attitude_reader_port)
"""test-send.py: Test script to send RC commands to a MultiWii Board.""" __author__ = "Aldo Vargas" __copyright__ = "Copyright 2016 Altax.net" __license__ = "GPL" __version__ = "1" __maintainer__ = "Aldo Vargas" __email__ = "*****@*****.**" __status__ = "Development" from pyMultiwii import MultiWii if __name__ == "__main__": #board = MultiWii("/dev/ttyUSB0") board = MultiWii("/dev/tty.usbserial-A801WZA1") try: while True: #example of 8 RC channels to be send data = [1500, 1550, 1600, 1560, 1000, 1040, 1000, 1000] # Old function #board.sendCMD(16,MultiWii.SET_RAW_RC,data) #New function that will receive attitude after setting the rc commands board.sendCMDreceiveATT(16, MultiWii.SET_RAW_RC, data) print board.attitude except Exception, error: print "Error on Main: " + str(error)
import socket import sys from pyMultiwii import MultiWii # Some Gloabals host = 'localhost' if __name__ == '__main__': # Initiate the MWC board = MultiWii("/dev/ttyUSB0") # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind and listen for connections server_address = (host, 10001) print >>sys.stderr, 'starting up on %s port %s' % server_address sock.bind(server_address) sock.listen(1) print >>sys.stderr, 'waiting for a connection' connection, client_address = sock.accept() print >>sys.stderr, 'client connected:', client_address data = 'init' try: while data!="": data = connection.recv(19) print >>sys.stderr, 'received "%s"' % data pwmValues = data.split() board.sendCMD(8,MultiWii.SET_RAW_RC,pwmValues)
class App(): def __init__(self): self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_path = '/tmp/foo.pid' self.pidfile_timeout = 5 def run(self): main() if __name__ == '__main__': flight_obj = FLIGHTBOARD() can_obj = can() bat_obj = bat() XBEE = "/dev/ttyUSB0" BATTERY = "/dev/ttyUSB0" CAN = "/dev/ttyUSB0" FLIGHT = "/dev/ttyUSB0" path_can = "/dev/ttyUSB0" try: ########################## Configure USB ports ################################# list1 = serial.tools.list_ports.comports() # battery_cable = "USB VID:PID=0403:6001 SNR=A50285BI" # Xbee1 = "USB VID:PID=0403:6001 SNR=AH03I7PP" Flight = "USB VID:PID=0403:6001 SNR=AM016X60" Xbee = "USB VID:PID=0403:6001 SNR=AH03I79P" Device = "Linux 3.13.0-24-generic ehci_hcd EHCI Host Controller 0000:00:1a.0" Device_ = 'Linux 3.13.0-24-generic xhci_hcd xHCI Host Controller 0000:02:00.0' VID = 'USB VID:PID=1a86:7523' #print(list(serial.tools.list_ports.comports()))s for a in range(0,len(list1) ): if((Device == list1[a][1]) & (VID == list1[a][2]) ): BATTERY = list1[a][0] if( (Xbee == list1[a][2]) & (Device == list1[a][1]) ): XBEE = list1[a][0] if(Flight == list1[a][2]): FLIGHT = list1[a][0] if(Device_ == list1[a][1]): CAN = list1[a][0] print "\n----------Com Port Configuration--------------" print 'Battery :'+BATTERY print 'can :'+CAN print 'xbee :'+XBEE print 'Flight :'+FLIGHT +'\n' # ----------Open Xbee Serial Port---------------------- ser2 = serial.Serial(XBEE, 115200, timeout=2, xonxoff=True, rtscts=True, dsrdtr=False ) #Tried with and without the last 3 parameters, and also at 1Mbps, same happens. ser2.flushInput() ser2.flushOutput() # ------------Open Flight Board Serial Port------------- try: flight_obj.board = MultiWii(FLIGHT) t_flight = Thread(target=flight_obj.Accelerometer, args=()) t_flight_G = Thread(target=flight_obj.GPS, args=()) t_flight.start() t_flight_G.start() except Exception,e: print 'ERROR t_flight : '+str(e) try: can.path_can = CAN t_can = Thread(target=can_obj.read_can, args=()) t_can.start() except Exception,e: print 'ERROR t_can : '+str(e)
print 'Battery :'+BATTERY print 'can :'+CAN print 'xbee :'+XBEE print 'Flight :'+FLIGHT +'\n' # ----------Open Xbee Serial Port---------------------- ser2 = serial.Serial(XBEE, 115200, timeout=2, xonxoff=True, rtscts=True, dsrdtr=False ) #Tried with and without the last 3 parameters, and also at 1Mbps, same happens. ser2.flushInput() ser2.flushOutput() # ------------Open Flight Board Serial Port------------- path_ = '/dev/ttyUSB1' # board = MultiWii(path_) try: board = MultiWii(FLIGHT) t_flight = Thread(target=Accelerometer, args=(board,)) t_flight_G = Thread(target=GPS, args=(board,)) t_flight.start() t_flight_G.start() except Exception,e: print 'ERROR : '+str(e) print "-----------------------------------------------" if t_flight.isAlive(): print "Flight started state : Alive" print "-----------------------------------------------" # ------------Start Main Threads------------------------- try:
__author__ = "Aldo Vargas" __copyright__ = "Copyright 2016 Altax.net" __license__ = "GPL" __version__ = "1" __maintainer__ = "Aldo Vargas" __email__ = "*****@*****.**" __status__ = "Development" from pyMultiwii import MultiWii import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui #board = MultiWii("/dev/tty.usbserial-A801WZA1") board = MultiWii("/dev/tty.SLAB_USBtoUART") win = pg.GraphicsWindow() win.setWindowTitle('MultiWii IMU plotting') p1 = win.addPlot() win.nextRow() p2 = win.addPlot() data1 = [0] * 300 data2 = [0] * 300 data3 = [0] * 300 data4 = [0] * 300 data5 = [0] * 300 data6 = [0] * 300 curve1 = p1.plot(data1, name="ax", pen=(255, 0, 0)) curve2 = p1.plot(data2, name="ay", pen=(0, 255, 0)) curve3 = p1.plot(data3, name="az", pen=(0, 0, 255))
label='GX') plt.plot([self.sb, self.senses], [self.gybuf, gy], color='black', label='GY') plt.plot([self.sb, self.senses], [self.gzbuf, gz], color='pink', label='GZ') self.fig.canvas.draw() self.sb, self.axbuf, self.aybuf, self.azbuf, self.gxbuf, self.gybuf, self.gzbuf = self.senses, ax, ay, az, gx, gy, gz if __name__ == "__main__": chart = Chart() serialPort = "/dev/tty.usbserial-A801WZA1" #serialPort = "/dev/tty.SLAB_USBtoUART" board = MultiWii(serialPort) try: while True: board.getData(MultiWii.RAW_IMU) #print board.rawIMU t = float(board.rawIMU['timestamp']) ax = board.rawIMU['ax'] ay = board.rawIMU['ay'] az = board.rawIMU['az'] gx = board.rawIMU['gx'] gy = board.rawIMU['gy'] gz = board.rawIMU['gz'] chart.plot(ax, ay, az, gx, gy, gz) except Exception, error: print "Error on Main: " + str(error)
from pyMultiwii import MultiWii import time import sys """ In config.h of the multiwii source code, there is a parameter called ESC_CALIB_CANNOT_FLY. Enabling that will pass the raw throttle values through to the ESCs. This is useful for calibrating the ESCs all at once. This script will set the PWM range on the ESCs and allow you to test motor speeds after calibrating. """ THROTTLE_MIN = 1000 THROTTLE_MAX = 2000 board = MultiWii("/dev/ttyACM0") print 'Setting throttle to', THROTTLE_MAX start = time.time() board.sendCMD(8, MultiWii.SET_RAW_RC, [1500, 1500, 1500, THROTTLE_MAX]) raw_input('Press enter to advance.') print time.time() - start, 'seconds elapsed.' print 'Setting throttle to', THROTTLE_MIN start = time.time() board.sendCMD(8, MultiWii.SET_RAW_RC, [1500, 1500, 1500, THROTTLE_MIN]) raw_input('Press enter to advance.') print time.time() - start, 'seconds elapsed.' while True:
class Main(object): if __name__ == '__main__': flight_obj = FLIGHTBOARD() can_obj = can() bat_obj = bat() XBEE = "/dev/ttyUSB0" BATTERY = "/dev/ttyUSB0" CAN = "/dev/ttyUSB0" FLIGHT = "/dev/ttyUSB0" path_can = "/dev/ttyUSB0" try: ########################## Configure USB ports ################################# list1 = serial.tools.list_ports.comports() # battery_cable = "USB VID:PID=0403:6001 SNR=A50285BI" # Xbee1 = "USB VID:PID=0403:6001 SNR=AH03I7PP" Flight = "USB VID:PID=0403:6001 SNR=AM016X60" Xbee = "USB VID:PID=0403:6001 SNR=AH03I79P" Device = "Linux 3.13.0-24-generic ehci_hcd EHCI Host Controller 0000:00:1a.0" Device_ = 'Linux 3.13.0-24-generic xhci_hcd xHCI Host Controller 0000:02:00.0' VID = 'USB VID:PID=1a86:7523' #print(list(serial.tools.list_ports.comports()))s for a in range(0,len(list1) ): if((Device == list1[a][1]) & (VID == list1[a][2]) ): BATTERY = list1[a][0] if( (Xbee == list1[a][2]) & (Device == list1[a][1]) ): XBEE = list1[a][0] if(Flight == list1[a][2]): FLIGHT = list1[a][0] if(Device_ == list1[a][1]): CAN = list1[a][0] print "\n----------Com Port Configuration--------------" print 'Battery :'+BATTERY print 'can :'+CAN print 'xbee :'+XBEE print 'Flight :'+FLIGHT +'\n' # ----------Open Xbee Serial Port---------------------- ser2 = serial.Serial(XBEE, 115200, timeout=2, xonxoff=True, rtscts=True, dsrdtr=False ) #Tried with and without the last 3 parameters, and also at 1Mbps, same happens. ser2.flushInput() ser2.flushOutput() # ------------Open Flight Board Serial Port------------- try: flight_obj.board = MultiWii(FLIGHT) t_flight = Thread(target=flight_obj.Accelerometer, args=()) t_flight_G = Thread(target=flight_obj.GPS, args=()) t_flight.start() t_flight_G.start() can.path_can = CAN t_can = Thread(target=can_obj.read_can, args=()) t_can.start() bat.path_can = BATTERY # t_bat = Thread(target=bat_obj.read_battery, args=()) # t_bat.start() except Exception,e: print 'ERROR : '+str(e) print 'Pass' # ----------------Run and print-------------------- count=0 past_load='' while True: count = count + 1 load = data_H.q.get() x = len(load) # print "length : "+str(x)+" Size : "+str(sys.getsizeof(q.get()))+" bytes Pht No : "+str(count)+"\n"+ q.get() # print data_H.q.get() send = "####,"+str(x)+","+str(count)+","+load+"!!" print send if load != past_load: ser2.write(send) past_load = load # print str(data_H.q.get()) except Exception,e: print 'ERROR : '+str(e)
import zmq from pyMultiwii import MultiWii import time IP = '0.0.0.0' port = '8080' c = zmq.Context() s = c.socket(zmq.REP) s.bind("tcp://" + IP + ":" + port) drone = MultiWii("/dev/ttyUSB0") drone_state = {} goon = True while goon: reply = s.recv_json() if reply.has_key("pad"): att = drone.getData(MultiWii.ATTITUDE) mot = drone.getData(MultiWii.MOTOR) vbat = drone.getData(MultiWii.ANALOG) if not att is None: drone_state["angx"] = float(att['angx']) drone_state["angy"] = float(att['angy']) drone_state["heading"] = float(att['heading']) if not mot is None: drone_state["m1"] = float(mot['m1']) drone_state["m2"] = float(mot['m2']) drone_state["m3"] = float(mot['m3']) drone_state["m4"] = float(mot['m4']) if not vbat is None: