def detect_lines(frame): #print ('lines') if frame == 0: pixy.change_prog ("line") line_get_all_features () i_count = line_get_intersections (100, intersections) v_count = line_get_vectors (100, vectors) try: max_vectors = filter_vectors(vectors, v_count) if max_vectors: move(degrees(get_angle(add_vectors(max_vectors)))) except KeyboardInterrupt: stop()
def run(self): try: server_socket.bind(address) except: print colored("Address already in use", "red") server_socket.close() sys.exit(0) print colored("Socket ready", "blue") while True: recv_data, addr = server_socket.recvfrom(2048) hostIP = addr[0] try: host = gethostbyaddr(hostIP)[0] except: host = hostIP port = addr[1] # print("Address: " + str(addr)) # print("Host's IP: " + str(hostIP) + ", Hostname: " + str(host) + ", Port: " + str(port)) if host == "Xav'sPad" or "BenPiOne" or "Guspi" or "snail" or "localhost" or "fxapi": pass else: # It's malicious print colored("Unauthorised connection attempted - " + str(host) + " - closing socket", "red") server_socket.close() print colored("Socket closed to everyone", "red") break if recv_data == "Client connected": print colored("Client " + str(host) + " connected - and is friendly", "red") sendToUI("Welcome!") if recv_data == "Client disconnected": print colored("Client " + str(host) + " disconnected", "red") sendToUI("Goodbye!") if (recv_data in CMDS) == True: motors.move(recv_data) cam.camera(recv_data) cam.servo(recv_data) if recv_data == " ": pass elif recv_data not in CMDS: # if it's not any of the above, it's something else and we need to know what print colored("Received: %s" % recv_data, "blue") # print out the message # print colored("Length: %.0f" % len(recv_data), 'blue') # print out the length of the message print colored("Sender hostname: " + str(host), "blue") # print out the sender's IP
def moveDirection(req, time=3): direction = req["direction"] print("Moving: " + direction) move(direction) print("Finished Moving")
("m_reserved", c_uint), ("m_angle", c_uint) ] vectors = VectorArray(100) intersections = IntersectionLineArray(100) frame = 0 while 1: line_get_all_features () i_count = line_get_intersections (100, intersections) v_count = line_get_vectors (100, vectors) ''' if i_count > 0 or v_count > 0: print ('frame %3d:' % (frame)) frame = frame + 1 for index in range (0, i_count): print ('[INTERSECTION: INDEX=%d ANGLE=%d]' % (intersections[index].m_index, intersections[index].m_angle)) for index in range (0, v_count): print ('[VECTOR: (%3d %3d) (%3d %3d)]' % (vectors[index].m_x0, vectors[index].m_y0, vectors[index].m_x1, vectors[index].m_y1)) ''' try: max_vectors = filter_vectors(vectors, v_count) if max_vectors: move(degrees(get_angle(add_vectors(max_vectors)))) except KeyboardInterrupt: stop() #print(max_vectors)
from flask import Flask, render_template, Response, flash, request, redirect, url_for, make_response import motors import os import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) #set up GPIO GPIO.setwarnings(False) # Raspberry pi camera module (reqires picamera package) from camera_pi import Camera app = Flask(__name__) #set up flask server app.secret_key = os.urandom(24) motor = motors.move() #create motor object ############# routes ############ @app.route('/') def index(): return render_template('index.html') @app.route('/video_feed') def video_feed(): return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame') #Uses methods from motors.py to send commands to the GPIO to operate the motors
def navigate(self): lastOrientationDegree = 0; turn_degrees_needed = 0; turn_degrees_accum = 0; imu = Imu(); #clean angle; imu.get_delta_theta(); #Condition distance more than 2 meters. while distance > 2 and self.stopNavigation != False: #print("degrees: ", imu.NORTH_YAW); #print("coords: ", imu.get_gps_coords()); #print("orientation degrees", orientationDegree); if(lastOrientationDegree != orientationDegree): turn_degrees_needed = orientationDegree; turn_degrees_accum = 0; #clean angle; imu.get_delta_theta(); lastOrientationDegree = orientationDegree; #If same direction, keep route #while math.fabs(turn_degrees_needed) > 10: imu_angle = imu.get_delta_theta()['z']%360; if(imu_angle > 180): imu_angle = imu_angle - 360; #print("grados imu: ", imu_angle); #threshold if(math.fabs(imu_angle) > 1): turn_degrees_accum += imu_angle; #print("grados acc: ", turn_degrees_accum); turn_degrees_needed = (orientationDegree + turn_degrees_accum)%360; if(turn_degrees_needed > 180): turn_degrees_needed = turn_degrees_needed - 360; elif (turn_degrees_needed < -180): turn_degrees_needed = turn_degrees_needed + 360; #print("grados a voltear: ", turn_degrees_needed); if(math.fabs(turn_degrees_needed) < 10): print("Tengo un margen menor a 10 grados"); velocity = destiny['distance'] * 10; if (velocity > 300): velocity = 200; motors.move(velocity, velocity); else: #girar if(turn_degrees_needed > 0): print("Going to move left") motors.move(70, -70); else: print("Going to move right") motors.move(-70, 70); #ir derecho; #recorrer 2 metros destiny = imu.get_degrees_and_distance_to_gps_coords(latitude2, longitud2); #time.sleep(1); motors.move(0,0); print("End thread Navigation");