Exemple #1
0
def init_socket():
    my_client = client_socketio(Server.ServerClass.get_server_ip(),
                                Server.ServerClass.get_server_port())

    @socketio.on('chat message')
    def handle_message(message):
        print('received message init: ' + message)

    def socket_receiver(data):
        try:
            print(data)
            #vehicle = mpstate.get_vehicles()[0]
            #obj_data = json.loads(data.replace('\r\n', '\\r\\n'),strict=False)
            #obj_data = json.loads(data,strict=False)
            #obj_data = json.loads(data)
            #sender_user = obj_data['u']

        except Exception as error:
            print(error)
        #set_command(data)

    my_client.on('chat message', socket_receiver)
    my_client.wait()
Exemple #2
0
def send_message(send_msg):
    my_client_send = client_socketio(
        ProjectConstant.ProjectConstantClass.get_host(),
        ProjectConstant.ProjectConstantClass.get_port())
    my_client_send.emit('chat message', send_msg)
Exemple #3
0
# allow the camera to warmup
time.sleep(0.1)
pwm_enabled_code = 2001

left_or_right = 0
control_pwm = 420
control_time = 1

app = Flask(__name__)
app.config['SECRET_KEY'] = ProjectConstant.ProjectConstantClass.get_secrer_key(
)
socketio = SocketIO(app)

from socketIO_client import SocketIO as client_socketio, BaseNamespace

my_client = client_socketio(ProjectConstant.ProjectConstantClass.get_host(),
                            ProjectConstant.ProjectConstantClass.get_port())
fl_mode_stabilize = 1
fl_mode_loiter = 2
fl_mode_rtl = 3
fl_mode_land = 4
fl_mode_alt_hold = 5
fl_mode_auto = 6


def send_message(send_msg):
    my_client_send = client_socketio(
        ProjectConstant.ProjectConstantClass.get_host(),
        ProjectConstant.ProjectConstantClass.get_port())
    my_client_send.emit('chat message', send_msg)
    #print(str)
Exemple #4
0
                    # print("while Error: "+str(error))
                    pwm = Adafruit_PCA9685.PCA9685()
                    # print(pwm)
                    reconnect_io = False
                    return pwm
                except Exception as error:
                    # print((error))
                    reconnect_io = True


servo_min = 150  # Min pulse length out of 4096
servo_max = 600  # Max pulse length out of 4096
pwm = reconnect_io_func()
from socketIO_client import SocketIO as client_socketio, BaseNamespace

my_client = client_socketio('184.72.95.87', 3000)
str = ""


@socketio.on('chat message')
def handle_message(message):
    x = 0
    # print('received message: ' + message)


# my_client.emit('chat message', str)
# print(str)
def doSomething(data):
    alphabet = data
    dataStr = alphabet.split(":")  # split string into a list
    i = 0
Exemple #5
0
def init_socket():
    my_client = client_socketio(Server.ServerClass.get_server_ip(), Server.ServerClass.get_server_port())
    @socketio.on('chat message')
    def handle_message(message):
        print('received message init: ' + message)

    def socket_receiver(data):
        try:
            #print (data)
            #vehicle = mpstate.get_vehicles()[0]
            obj_data = json.loads(data.replace('\r\n', '\\r\\n'),strict=False)
            #obj_data = json.loads(data,strict=False)
            #obj_data = json.loads(data)
            sender_user = obj_data['u']
            if(sender_user==User.UserClass.ground_user()):
                val = obj_data['action']
                if (val == CommandConstant.CommandConstantClass.is_equal_wp()):
                    #DbInitilize.DbInitializeClass.dbInit()
                    wp_data = obj_data['data']
                    SdCard.SdCardClass.file_write(wp_data)
                    time.sleep(1)
                    if(DroneMission.DroneMissionClass.upload_mission(CommandConstant.CommandConstantClass.get_wp_file_name(),vehicle)):
                        DbInitilize.DbInitializeClass.update_wp_status_true()
                        send_message(JsonBuilder.JsonBuilderClass.get_waypoint_received_response())
                elif (val == CommandConstant.CommandConstantClass.is_equal_start_drone()): ## Start
                    init_aircraft()
                    send_message(JsonBuilder.JsonBuilderClass.get_start_information(vehicle))
                elif (val == CommandConstant.CommandConstantClass.is_equal_arm()):
                    vehicle.armed=True
                    send_message(JsonBuilder.JsonBuilderClass.get_is_arm())
                elif (val == CommandConstant.CommandConstantClass.is_equal_disarm()):
                    vehicle.armed = False
                elif (val == CommandConstant.CommandConstantClass.is_equal_mode()):
                    mode_str = obj_data['data']
                    vehicle.mode = VehicleMode(mode_str)
                elif (val == CommandConstant.CommandConstantClass.is_equal_takeoff()):
                    aTargetAltitude = obj_data['data']
                    send_message(JsonBuilder.JsonBuilderClass.get_is_takeoff())
                    arm_and_takeoff(aTargetAltitude,True)
                elif (val == CommandConstant.CommandConstantClass.is_equal_takeoff_land()):
                    aTargetAltitude = obj_data['data']
                    print "takeoff land"
                    DbInitilize.DbInitializeClass.get_data_wp_status()
                    if(DbInitilize.DbInitializeClass.get_data_wp_status()==0):
                        send_message(JsonBuilder.JsonBuilderClass.get_is_no_waypoint())
                    elif(DbInitilize.DbInitializeClass.get_data_wp_status()==1):
                        DbInitilize.DbInitializeClass.update_wp_status_false()
                        send_message(JsonBuilder.JsonBuilderClass.get_is_takeoff())
                        #arm_and_takeoff(aTargetAltitude,False)
                elif (val == CommandConstant.CommandConstantClass.is_equal_rc_03()):
                    rc_value = int(obj_data['data'])
                    vehicle.channels.overrides['3'] = rc_value
                elif (val == CommandConstant.CommandConstantClass.is_equal_battery_info()):
                    try:
                        voltage=vehicle.battery.voltage
                        current=vehicle.battery.current
                        level=vehicle.battery.level
                    except:
                        print('An error occurred.')
                        voltage = 0.00
                        current = 0.00
                        level = 0
                    send_message(JsonBuilder.JsonBuilderClass.get_battery_information(voltage,current,level))
                elif (val == CommandConstant.CommandConstantClass.is_equal_reboot()):
                    vehicle.reboot()
                    time.sleep(1)
                elif (val == CommandConstant.CommandConstantClass.is_equal_store_param()):
                    #print "\nPrint all parameters (iterate `vehicle.parameters`):"
                    append_string = ""
                    for key, value in vehicle.parameters.iteritems():
                        #print " Key:%s Value:%s" % (key, value)
                        append_string = append_string + str(key)+":"+str(value)+"\n"
                    SdCard.SdCardClass.param_write(append_string)
                    print append_string
                elif (val == CommandConstant.CommandConstantClass.is_equal_home_location()):
                    #home_lat,home_lng = LatLngCalculation.LatLngCalculationClass.get_home_location(vehicle)
                    #print " ",home_lat," ",home_lng
                    init_aircraft()
                elif (val == CommandConstant.CommandConstantClass.is_equal_read_channels()):
                    DroneChannels.DroneChannelsClass.read_channels(vehicle)
            elif sender_user==User.UserClass.self_user():
                cvb=0
                #print ("self message")
        except Exception as error:
            print (error)
        #set_command(data)
    my_client.on('chat message', socket_receiver)
    my_client.wait()
Exemple #6
0
def init_sender_socket():
    global my_client_send
    my_client_send = client_socketio(ProjectConstant.ProjectConstantClass.get_host(),ProjectConstant.ProjectConstantClass.get_port())
Exemple #7
0
class ModCapture(object):
    my_client_send = client_socketio(ProjectConstant.ProjectConstantClass.get_host(),
                                     ProjectConstant.ProjectConstantClass.get_port())
    CAMERA_WIDTH = 1376
    CAMERA_HEIGHT = 768
    FRAME_RATE =20

    # camera = PiCamera()
    # camera.resolution = (CAMERA_WIDTH, CAMERA_HEIGHT)
    # camera.framerate = FRAME_RATE
    # rawCapture = PiRGBArray(camera, size=(CAMERA_WIDTH, CAMERA_HEIGHT))
    # time.sleep(0.1)

    face_cascade_path = os.getcwd() + "/AICAPTURE/haarcascade_frontalface_default.xml"
    eye_cascade_path = os.getcwd() + "/AICAPTURE/haarcascade_eye.xml"
    face_cascade = cv2.CascadeClassifier(face_cascade_path)
    eye_cascade = cv2.CascadeClassifier(eye_cascade_path)
    # #image_path = os.getcwd() + "/AWS/target-image/cam.jpg"
    image_path = "/home/pi/development/drone_control/AWS/target-image/cam.jpeg"
    faceapi = Face()
    camera_status = False
    def __init__(self):
        pass

    # def run(self, camera_status=None):
    #     try:
    #         if camera_status==True:
    #             print("Open Again")
    #             self.CAMERA_WIDTH = 1376
    #             self.CAMERA_HEIGHT = 768
    #             self.camera = PiCamera()
    #             self.camera.resolution = (self.CAMERA_WIDTH, self.CAMERA_HEIGHT)
    #             self.camera.framerate = self.FRAME_RATE
    #             self.rawCapture = PiRGBArray(self.camera, size=(self.CAMERA_WIDTH, self.CAMERA_HEIGHT))
    #             time.sleep(0.1)
    #             pass
    #         time.sleep(2)
    #         for frame in self.camera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True):
    #             try:
    #                 img = frame.array
    #                 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #                 faces = self.face_cascade.detectMultiScale(gray, 1.3, 5)
    #                 for (x, y, w, h) in faces:
    #                     self.my_client_send.emit('chat message',JsonBuilder.JsonBuilderClass.get_face_detected())
    #                     print ("detect face")
    #                     cv2.imwrite(self.image_path, img)
    #                     self.my_client_send.emit('chat message', JsonBuilder.JsonBuilderClass.get_face_captured())
    #                     person = self.faceapi.face_s3_match_multi(self.image_path)
    #                     print (person)
    #                     self.speech("hi i am detecting")
    #                     self.my_client_send.emit('chat message', JsonBuilder.JsonBuilderClass.get_aiface_response(person))
    #                 cv2.waitKey(1) & 0xFF
    #                 self.rawCapture.truncate(0)
    #             except Exception as error:
    #                 print("A1 ")
    #                 self.camera.close()
    #                 self.run(True)
    #                 #print (error)
    #     except Exception as e:
    #         print("A2 ")
    #         print (e)

    def speech(self,str):
        cmd_beg = 'espeak -g5 -ven+f4 '
        cmd_end = ' 2>/dev/null'  # To dump the std errors to /dev/null
        str = str.replace(' ', '_')
        str = str.replace(' ', '.')
        str = str.replace(' ', ',')
        call([cmd_beg + str + cmd_end], shell=True)
    def run_usb_cam(self):

        cam = cv2.VideoCapture(0)
        cam.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
        time.sleep(2)
        previous_milli = 0
        interval=1000
        while (True):
            ret, img = cam.read()
            #cv2.imshow('frame', img)
            current_milli = int(round(time.time() * 1000))
            if (current_milli - previous_milli) > interval:
                print ("interval ")
                print (current_milli)
                print (previous_milli)
                gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
                faces = self.face_cascade.detectMultiScale(gray, 1.3, 5)
                for (x, y, w, h) in faces:
                    self.my_client_send.emit('chat message', JsonBuilder.JsonBuilderClass.get_face_detected())
                    print ("detect face")
                    cv2.imwrite(self.image_path, img)
                    self.my_client_send.emit('chat message', JsonBuilder.JsonBuilderClass.get_face_captured())
                    person = self.faceapi.face_s3_match_multi(self.image_path)
                    print (person)
                    if 'John' in person:
                        self.my_client_send.emit('chat message', JsonBuilder.JsonBuilderClass.get_aiface_response_for_john())
                    else:
                        self.my_client_send.emit('chat message',JsonBuilder.JsonBuilderClass.get_aiface_response(person))
                previous_milli = current_milli
                cv2.waitKey(1) & 0xFF
        cam.release()
        cv2.destroyAllWindows()