Пример #1
0
"""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
import time

if __name__ == "__main__":

    #board = MultiWii("/dev/tty.usbserial-AM016WP4")
    board = MultiWii("/dev/tty.SLAB_USBtoUART")
    try:
        board.arm()
        print ("Board is armed now!")
        print ("In 3 seconds it will disarm...")
        time.sleep(3)
        board.disarm()
        print ("Disarmed.")
        time.sleep(3)

    except Exception,error:
        print ("Error on Main: "+str(error))
Пример #2
0
import socket
from pymultiwii import MultiWii
import time

ip = ''
port = 5003
bufflen = 19
address = ("192.168.1.33", 5000)
cmd_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mon_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dir = ('', 5003)
cmd_socket.bind((ip, port))

uav = MultiWii("/dev/ttyUSB0")
uav.arm()

time.sleep(5)

orden = []

##orden={"roll":-1,"pitch":-1,"yaw":-1,"throttle":-1}

try:
    while True:
        data, _ = cmd_socket.recvfrom(bufflen)
        data = data.split(':')

        if data == ['']:
            continue
        #print str(data)
        orden_s = [int(data[0]), int(data[1]), int(data[2]), int(data[3])]
                two = 0
                for i in range(class_number):
                    if (prediction[i] > first):
                        first = prediction[i]
                        top1 = class_dict[i]
                    elif (prediction[i] > two):
                        two = prediction[i]
                        top2 = class_dict[i]

                controller.update()

                if time.time() - console_messege_timer_start > 2:
                    console_messege = " "

                if controller.B:
                    butterfly.arm()
                    console_messege = "Armed."
                    console_messege_timer_start = time.time()
                elif controller.A:
                    butterfly.disarm()
                    console_messege = "Disarmed."
                    console_messege_timer_start = time.time()
                elif controller.Y:
                    done = True
                #example of 4 RC channels to be send
                elif controller.X:
                    pitch = 1500
                    roll = 1500
                    rotate = 1500
                    throttle = 1000
                elif controller.rb:
                elif (key.decode() == 'g'):
                    cap = cv2.VideoCapture(cam)
                    while True:
                        pitch = 1500
                        roll = 1500
                        rotate = 1500
                        t = time.time()
                        #camera show
                        ret, frame = cap.read()
                        cv2.imshow('frame', frame)

                        #press to control
                        if (msvcrt.kbhit()):
                            key = msvcrt.getch()
                            if (key.decode() == 'a'):  #arm
                                board.arm()
                                print("Drone is armed now!")
                            elif (key.decode() == 'd'):  #disarm
                                board.disarm()
                                print("Disarmed.")
                            elif (key.decode() == 'r'):  #reset
                                pitch = 1500
                                roll = 1500
                                rotate = 1500
                                throttle = 1000
                                CNN = -1
                            elif (key.decode() == 'u'):  #left
                                #pitch = 1400
                                roll = 1300
                                data = [roll, pitch, rotate, throttle]
                                board.sendCMD(8, MultiWii.SET_RAW_RC, data)
drone = MultiWii()
input("press any key to continue")
try:
    f = open("decision.txt", mode='w')
    f.write(str(init + 0.1))
    print("detected")
except Exception as e:
    print(e)
finally:
    f.close()

try:
    drone.open("/dev/rfcomm0")
    time.sleep(2)
    drone.arm()
    time.sleep(0.5)
    drone.sendCMD(8, MultiWii.SET_RAW_RC, [1500, 1500, 1500, 1000], '4h')
    print("arm")
except Exception as error:
    print(error)

# pyplot.ion()
# fig = pyplot.figure()
# imu_fig = fig.add_subplot(121)
# pyplot.xticks([1, 2],  ['roll', 'pitch'])
# rect1 = imu_fig.bar([1, 2], [-90, 90])
#
# imu_fig = fig.add_subplot(122)
# pyplot.xticks([1, 2, 3, 4],  ['roll', 'pitch', 'yaw', 'throttle'])
# rect2 = imu_fig.bar([1, 2, 3, 4], [1000, 2000, 1000, 1000])
Пример #6
0
bufer = 2048
print 'Socket udp creado con exito'
arm= 0
roll = ROLL + mando[3]
pitch = PITCH + mando[2]
yaw = YAW + mando[1]
trothle = TROTHLE + mando[0]
boton_up = mando[5]
boton_down = mando[4]

print 'Iniciando bucle principal'
while Done == False:
	
	bat = ina.read()
	if boton_up == 12 and arm == 0:
		placa.arm()
		arm = 1
	elif boton_up == 12 and arm ==1:
		placa.disarm()
		arm = 0
	if arm ==1:
		data =[roll,pitch,yaw,trothle,1000,1000,1000,1000]
		placa.sendCMDreceiveATT(16,MultiWii.SET_RAW_RC,data)
		x = int(placa.attitude['angx'])
		y = int(placa.attitude['angy'])
		z = int(placa.attitude['heading'])
		array = [x,y,z,bat]
		msg = pickle.dumps(array)
		sock.sendto(msg, (UDP_HOST,UDP_PORT))
	elif arm ==0:
		placa.getData(MultiWii.ATTITUDE)