Exemple #1
0
    def Connect(self):

        # now try to start our services
        try:

            i = 0
            while i < 3:
                # set the camera led off
                self.led_flash.setPixelColor(0, Color(0, 0, 0))
                self.led_flash.show()
                sleep(0.25)
                i += 1
                # set the camera led to warn
                self.led_flash.setPixelColor(0, Color(255, 255, 0))
                self.led_flash.show()
                sleep(0.25)

            if self.script_cfg['debug']:
                print(' run all of our prechecks ')

            # cleanup any old jobs
            FileStruct.CleanUp(FileStruct, self.script_cfg)

            # create our directories
            FileStruct.CreateStructure(FileStruct, self.script_cfg)

            # init connection to a new sqlite database
            self.process['connection'] = DBLite.StartDB(
                DBLite, self.script_cfg)

            #create a new databse table
            DBLite.InitDB(DBLite, self.process['connection'], self.script_cfg)
            if self.script_cfg['debug']:
                print(' new database connection successful ')

            # get the IMU data
            self.process['pid'] = IMUDevice.StartIMU(IMUDevice, self.imu_cfg,
                                                     self.script_cfg)

            # if this fails so should the script
            if not self.process['pid']:

                if self.script_cfg['debug']:
                    print(' new imu connection failed ')

                # close the database connection we no longer need it
                DBLite.CloseDB(DBLite, self.process['connection'],
                               self.script_cfg)
                return False

            else:
                if self.script_cfg['debug']:
                    print(' new imu connection started ')

            print("| connection(s) successful, waiting on",
                  self.script_cfg['triggers'], "trigger(s) |")
            return True

        except:
            # something went bad halt
            print("| connection(s) failed |")
            # fail
            return False
Exemple #2
0
    def End(self, camera):

        # set th flash processing
        self.led_flash.setPixelColor(0, Color(255, 255, 0))
        self.led_flash.show()

        # if the process count matches the trigger count, we succeeded
        if self.process['count'] == self.script_cfg['triggers'] or path.isfile(
                self.script_cfg['path'] + '/tmp/stop.proc'):

            i = 0
            while i < 3:
                # set the camera led off
                self.led_flash.setPixelColor(0, Color(0, 0, 0))
                self.led_flash.show()
                sleep(0.25)
                i += 1
                # set the camera led to warn
                self.led_flash.setPixelColor(0, Color(255, 255, 0))
                self.led_flash.show()
                sleep(0.25)

            # close the camera
            camera.close()

            # kill the imu process
            IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)

            # if we have reached the end, report
            rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                    self.script_cfg)

            # get the name of our archive before we close the database
            archive = DBLite.GetArchiveName(DBLite, self.process['connection'],
                                            self.script_cfg)

            # if we are in ascii then process the imu information
            if self.imu_cfg['stream'] == 'ascii':
                IMUDevice.ProcessIMU(IMUDevice, self.process['connection'],
                                     self.script_cfg, rows)

                # get the updated rows
                rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                        self.script_cfg)

                # export a processed imu file
                FileStruct.ProcessedCSV(FileStruct, self.script_cfg, rows)

            # close our db connection
            DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

            # write a friendly csv file
            FileStruct.WriteCSV(FileStruct, self.script_cfg, rows)

            # move the database/imu data to a new store location
            FileStruct.Save(FileStruct, self.script_cfg, archive)

            # pretty print the final results
            # if we are in ascii print the telemetry
            if self.imu_cfg['stream'] == 'ascii':
                output = tabulate(rows,
                                  headers=[
                                      "Trigger", "Trigger Lapse",
                                      "Camera Lapse", "Byte", "Image", "Size",
                                      "Telemetry"
                                  ],
                                  floatfmt=".12f")

                print(output)

                with open(self.script_cfg['path'] + '/tmp/results.txt',
                          "w") as text_file:
                    print(output, file=text_file)

            else:
                output = tabulate(rows,
                                  headers=[
                                      "Trigger", "Trigger Lapse",
                                      "Camera Lapse", "Byte", "Image", "Size"
                                  ],
                                  floatfmt=".12f")

                print(output)

                with open(self.script_cfg['path'] + '/tmp/results.txt',
                          "w") as text_file:
                    print(output, file=text_file)

            print("| done, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "success |")

            self.led_flash.setPixelColor(0, Color(0, 255, 0))
            self.led_flash.show()

            self.process['start'] = False
            exit()

        else:

            # close the camera
            camera.close()

            # kill the imu process
            IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)
            # close our db connection
            DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

            print("| done, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "failed |")

            self.led_flash.setPixelColor(0, Color(0, 0, 0))
            self.led_flash.show()

            self.process['start'] = False
            exit()
Exemple #3
0
    def Connect(self):

        # now try to start our services
        try:

            if self.script_cfg['debug']:
                print(' run all of our prechecks ')

            # create our directories
            FileStruct.CreateStructure(FileStruct, self.script_cfg)

            # cleanup any old jobs
            FileStruct.CleanUp(FileStruct, self.script_cfg)

            # init connection to a new sqlite database
            self.process['connection'] = DBLite.StartDB(
                DBLite, self.script_cfg)

            #create a new databse table
            DBLite.InitDB(DBLite, self.process['connection'], self.script_cfg)
            if self.script_cfg['debug']:
                print(' new database connection successful ')

            # get the IMU data
            self.process['pid'] = IMUDevice.StartIMU(IMUDevice, self.imu_cfg,
                                                     self.script_cfg)

            # if this fails so should the script
            if not self.process['pid']:

                if self.script_cfg['debug']:
                    print(' new imu connection failed ')

                # close the database connection we no longer need it
                DBLite.CloseDB(DBLite, self.process['connection'],
                               self.script_cfg)
                return False

            else:
                if self.script_cfg['debug']:
                    print(' new imu connection started ')

            # try to open the camera
            camera = CameraDevice.Connect(CameraDevice, self.camera_cfg,
                                          self.script_cfg)
            if not camera:

                # close the database connection we no longer need it
                #DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)
                # hault the imu device
                #IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)
                self.End()

                if self.script_cfg['debug']:
                    print(' new camera connection failed ')

            else:

                # set the camera process
                self.process['camera'] = camera

            # CameraDevice.ClearImages(CameraDevice, camera, self.camera_cfg, self.script_cfg)

            print("| connection(s) successful, waiting on",
                  self.script_cfg['triggers'], "trigger(s) |")
            return True

        except:
            # something went bad halt
            print("| connection(s) failed |")
            # fail
            return False
Exemple #4
0
    def Start(self):

        print("| starting, autotigger -", self.script_cfg['headless'], "|")

        # report the start
        if self.script_cfg['debug']:
            print('start looking for ',
                  self.script_cfg['path'] + '/tmp/trigger.proc')
            print('process start ', self.process['loop'], ' will run ',
                  self.script_cfg['max'], ' or ', self.script_cfg['triggers'],
                  ' triggers')

        # run some basic tests and conenct our script
        # these script hault on fail, see logs details
        self.process['start'] = self.Connect()

        # run the process if our tests are valid
        while self.process['start']:  # constructs our process loop

            # start monitoring our process
            try:

                # if we have hit the max amount of loops then we need to stop
                if self.script_cfg['max'] != 0 and self.process[
                        'loop'] >= self.script_cfg['max']:
                    # stop the process and exit
                    self.End()
                    break

                # if we have hit the max amount of triggers then we need to stop
                elif self.script_cfg['triggers'] != 0 and self.process[
                        'count'] >= self.script_cfg['triggers']:
                    # stop the process and exit
                    self.End()
                    break

                # runs some triggers
                else:

                    # if we are set to run headless then do not wait for the tigger file
                    if self.script_cfg['headless']:

                        # run the tigger process, now
                        result = self.Event(True)

                        if not result:
                            print(" trigger was not valid ")

                        else:
                            print(" trigger was valid ")
                            # send the result to the database
                            DBLite.InsertDB(DBLite, self.process['connection'],
                                            self.script_cfg, result)

                    # otherwise lets see if a tigger file exists
                    else:

                        # look for the tigger file in the following path
                        if path.isfile(self.script_cfg['path'] +
                                       '/tmp/trigger.proc'
                                       ):  # does the trigger file exists fire

                            # run the tigger process, now
                            result = self.Event(True)

                            if not result:
                                print(" trigger is not ready ")

                            else:
                                print(" trigger recorded storing ")
                                # send the result to the database
                                DBLite.InsertDB(DBLite,
                                                self.process['connection'],
                                                self.script_cfg, result)

                            # remove the trigger file
                            remove(self.script_cfg['path'] +
                                   '/tmp/trigger.proc')

                        else:
                            # run the tigger process, fail
                            self.Event(False)

            except KeyboardInterrupt:
                print("| bye early exit, closing connections |")
                # close our connections
                DBLite.CloseDB(DBLite, self.process['connection'],
                               self.script_cfg)
                IMUDevice.StopIMU(IMUDevice, self.process['pid'],
                                  self.script_cfg)
                exit()
Exemple #5
0
    def End(self):

        # kill the imu process
        IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)

        # set some thing we will need
        display = {}
        archive = None

        # if the process count matches the trigger count
        if self.process['count'] == self.script_cfg['triggers']:

            # if we have reached the end, should we report
            rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                    self.script_cfg)

            # switch the camera to USB Mode
            CameraDevice.USBMode(CameraDevice, self.process['camera'],
                                 self.script_cfg)

            # update the rows with their binary telemetry
            IMUDevice.ProcessIMU(IMUDevice, self.process['connection'],
                                 self.script_cfg, rows)

            # test the mount is ready
            Test = CameraDevice.TestMount(CameraDevice, self.camera_cfg, 0)

            # get the name of our archive before we close the database
            archive = DBLite.GetArchiveName(DBLite, self.process['connection'],
                                            self.script_cfg)

            # copy the images off the camera
            if Test:
                CameraDevice.CopyImages(CameraDevice, self.camera_cfg,
                                        self.script_cfg)
                images = CameraDevice.GetImages(CameraDevice, self.camera_cfg,
                                                self.script_cfg)
                DBLite.UpdateImages(DBLite, self.process['connection'],
                                    self.script_cfg, rows, images)

            CameraDevice.CameraMode(CameraDevice, self.process['camera'],
                                    self.script_cfg)

            print("| closing, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "success |")

        else:

            print("| closing ", self.process['count'], "/",
                  self.script_cfg['triggers'], "failed |")

        # if we have reached the end, should we report
        display = DBLite.DisplayDB(DBLite, self.process['connection'],
                                   self.script_cfg)

        # write a friendly csv file
        FileStruct.WriteCSV(FileStruct, self.script_cfg, display)

        # close our connections
        DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

        # if we have result to display and save
        if self.process['count'] == self.script_cfg['triggers']:

            # pretty print the final results
            print(
                tabulate(display,
                         headers=[
                             "Trigger", "Start", "Byte", "Stop", "Byte",
                             "Runtime", "Segment (size)", "BLOB (size)",
                             "Image"
                         ],
                         floatfmt=".12f"))

            # move the database/imu data to a new store location
            FileStruct.Save(FileStruct, self.script_cfg, archive)

        if self.script_cfg['debug']:
            print(' process end ', self.process['loop'])

        self.process['start'] = False
        exit()