Exemple #1
0
    def _printNode(self,
                   key,
                   val,
                   padding='',
                   last=False,
                   maxdepth=None,
                   maxcount=None):
        from fabulous.color import highlight_blue, red, blue, green, cyan, yellow, bold
        from tables import Array

        if isinstance(val, H5Node):
            val.printTree(padding=padding,
                          last=last,
                          maxdepth=maxdepth,
                          maxcount=maxcount)
        else:
            if isinstance(val, Array):
                val = yellow('Array(%s,__dtype__=%s)' %
                             (','.join(str(i) for i in val.shape), val.dtype))
            elif isinstance(val, Table):
                val = green(val)
            else:
                val = red('%s,__dtype__=%s' % (str(val), type(val).__name__))
            if last:
                print '%s `%s [%s]' % (padding[:-1], cyan(key), val)
            else:
                print '%s`%s [%s]' % (padding, cyan(key), val)
Exemple #2
0
    def switch_task(self, task):
        '''Reads out the task topic and switches to the desired task.
        '''
        if task.data not in self.task_dict:
            print highlight_red(
                ' Not a valid task, drone will remain in standby state.')

        self.state_sequence = self.task_dict.get(task.data, [])
        self.new_task = True
        print cyan(' Core received a new task: ', task.data)
Exemple #3
0
 def take_off_land(self, pressed):
     '''Check if menu button is pressed and switch to take-off or land
     sequence depending on last task that was executed.
     '''
     if pressed.data:
         if self.airborne:
             self.state_sequence = self.task_dict.get("land", [])
         else:
             self.state_sequence = self.task_dict.get("take-off", [])
         self.new_task = True
         print cyan(' Bebop_core received a new task: ',
                    self.state_sequence[0])
    def switch_p2p(self, pressed):
        ''' Function to switch easily to p2p
        '''

        if pressed.data and not self.gripButtonPressed_held:
            self.state_sequence = self.task_dict.get("point to point", [])
            self.new_task = True
            print cyan(' Bebop_core received a new task: ',
                       self.state_sequence[0])
            self.gripButtonPressed_held = True
        elif not pressed.data and self.gripButtonPressed_held:
            self.gripButtonPressed_held = False
Exemple #5
0
def make(items):
    for name, props in items:
        print
        print "make: %s" % (cyan(name))
        print "-"*30

        # move to this files parent directory and then to the bundle directory
        os.chdir(dirname + "/..")
        os.chdir(props["dir"])

        for cmd in props["make"]:
            print yellow(cmd)
            c = subprocess.call(cmd_gen(cmd))
            if c != 0:
                print red("Error encountered (%s: %s)" % (cyan(name), yellow(cmd)))
                sys.exit()
Exemple #6
0
    def _printNode(self, key, val, padding= '', last=False,maxdepth=None,maxcount=None):
        from fabulous.color import highlight_blue,red,blue,green,cyan,yellow,bold
        from tables import Array

        if isinstance(val,H5Node):
            val.printTree(padding=padding,last=last,maxdepth=maxdepth,maxcount=maxcount)
        else:
            if isinstance(val,Array):
                val = yellow('Array(%s,__dtype__=%s)'% (','.join(str(i) for i in val.shape),val.dtype))
            elif isinstance(val,Table):
                val = green(val)
            else:
                val = red('%s,__dtype__=%s' % (str(val),type(val).__name__))
            if last:
                print '%s `%s [%s]' % (padding[:-1], cyan(key), val )
            else:
                print '%s`%s [%s]' % (padding, cyan(key), val )
    def switch_task(self, task):
        '''Reads out the task topic and switches to the desired task.
        '''
        if task.data in [
                "home inspection", "home count", "home inventory",
                "home guide", "home picture", "home events",
                "home smart inspection"
        ]:
            self.task_str = task.data
        else:
            if task.data not in self.task_dict:
                print highlight_red(
                    ' Not a valid task, drone will remain in standby state.')

            self.state_sequence = self.task_dict.get(task.data, [])
            self.new_task = True
            print cyan(' Bebop_core received a new task: ', task.data)
Exemple #8
0
def clean(items):
    for name, props in items:
        # only attempt if the clean method exists
        if props["clean"]:
            print
            print "clean: %s" % (cyan(name))
            print "-"*30

            # move to this files parent directory and then to the bundle directory
            os.chdir(dirname + "/..")
            os.chdir(props["dir"])

            print yellow(props["clean"])
            subprocess.call(props["clean"].split())
Exemple #9
0
 def cyan(self):
     return ansi(c.cyan(self.txt))
Exemple #10
0
    def start(self):
        '''
        Starts running of bebop_demo node. Runs along the state sequence, sends
        out the current state and returns to the standby state when task is
        completed.
        '''
        print green('----    Core running     ----')

        while not rospy.is_shutdown():
            if self.new_task:
                self.new_task = False
                self.change_state = False
                self.state_finish = False

                # Run over sequence of states corresponding to current task.
                for state in self.state_sequence:
                    self.state = state
                    print cyan(' Core state changed to: ', self.state)
                    self.fsm_state.publish(state)

                    # IRRELEVANT WHEN NOT USING OMGTOOLS
                    # # Omg tools should return to its own standby status
                    # #  unless the state_button has been pressed.
                    # if self.state in {"omg standby", "omg fly"}:
                    #     self.omg_standby = True
                    # else:
                    #     self.omg_standby = False

                    if self.state == "land":
                        self.change_state = True

                    task_final_state = (self.state == self.state_sequence[-1])
                    # Check if previous state is finished and if allowed to
                    # switch state based on controller input.
                    while not ((self.state_finish and
                                (self.change_state or task_final_state))
                               or self.new_task or rospy.is_shutdown()):
                        # Remaining in state. Allow state action to continue.
                        rospy.sleep(0.1)

                    self.change_state = False
                    self.state_finish = False

                    # OMG STUFF
                    leave_omg = False
                    #     leave_omg = (
                    #         self.state == "omg standby" and not self.omg_standby)
                    #     # User forces leaving omg with state_button or other new
                    #     # task received --> leave the for loop for the current
                    #     # task.
                    if (leave_omg or self.new_task):
                        # print cyan('---- Broke for loop ----')
                        break

                # # Make sure that omg-tools task is repeated until force quit.
                # if self.omg_standby:
                #     self.new_task = True

                # Only publish standby state when task is finished.
                # Except for repetitive tasks (back to first state in task).
                if not self.new_task:
                    self.state = "standby"
                    self.fsm_state.publish("standby")
                    print cyan(' Core state changed to: ', "standby")

            # print 'core sleeping'
            rospy.sleep(0.1)
Exemple #11
0
#!/usr/bin/env python

"""Colour theme for terminals which support only 8-bit colors.
"""

from fabulous import color as col

messagefmt = {
	None: '{asctime} {module} {levelname} {msg}'.format(
		asctime=col.highlight_blue('{r.asctime}'),
		module=col.cyan(('{r.module}')),
		levelname=col.cyan('{r.levelname}'),
		msg=col.bold(col.yellow('{r.msg}')),
		),

	'INFO': '{asctime} {module} {levelname} {msg}'.format(
		asctime=col.highlight_blue('{r.asctime}'),
		module=col.cyan(('{r.module}')),
		levelname=col.green('{r.levelname}'),
		msg=col.bold(col.yellow('{r.msg}')),
		),

	'WARNING': '{asctime} {module} {levelname} {msg}'.format(
		asctime=col.highlight_blue('{r.asctime}'),
		module=col.cyan(('{r.module}')),
		levelname=col.bold(col.magenta('{r.levelname}')),
		msg=col.bold(col.yellow('{r.msg}')),
		),

	'ERROR': '{asctime} {module} {levelname} {msg}'.format(
		asctime=col.highlight_blue('{r.asctime}'),
Exemple #12
0
def show_contacts(phone_book):
    if phone_book == {}:
        print(red("No hay contactos en Phone_book"))
    else:
        for name, phone in phone_book.items():
            print(cyan(name, ":", phone))
    def start(self):
        '''
        Starts running of bebop_demo node. Runs along the state sequence, sends
        out the current state and returns to the standby state when task is
        completed.
        '''
        print green('----    Bebop core running     ----')

        while not rospy.is_shutdown():

            if self.task_str == "home inspection":
                self.home_inspection()
            elif self.task_str == "home inventory":
                self.inventory()
            elif self.task_str == "home count":
                self.count()
            elif self.task_str == "home picture":
                self.picture()
            elif self.task_str == "home guide":
                self.guide()
            elif self.task_str == "home events":
                self.events()
            elif self.task_str == "home smart inspection":
                self.home_inspection_smart()

            if self.new_task:
                self.new_task = False
                self.change_state = False
                self.state_finish = False

                # Run over sequence of states corresponding to current task.
                for state in self.state_sequence:
                    self.state = state
                    print cyan(' Bebop_core state changed to: ', self.state)
                    self.fsm_state.publish(state)

                    # Omg tools should return to its own standby status unless
                    # the controller trackpad has been pressed.
                    if self.state in {
                            "omg standby", "omg fly", "omg fly A",
                            "omg standby A", "omg fly inspection"
                    }:
                        self.omg_standby = True
                    else:
                        self.omg_standby = False

                    if self.state == "land":
                        self.change_state = True

                    task_final_state = (self.state == self.state_sequence[-1])
                    # Check if previous state is finished and if allowed to
                    # switch state based on controller input.
                    while not ((self.state_finish and
                                (self.change_state or task_final_state))
                               or self.new_task or rospy.is_shutdown()):
                        # Remaining in state. Allow state action to continue.
                        if self.state not in {"standby", "initialization"}:
                            self.camera_actions()

                        rospy.sleep(0.1)

                    self.change_state = False
                    self.state_finish = False

                    leave_omg = (self.state == "omg standby"
                                 and not self.omg_standby)
                    # User forces leaving omg with trackpad or other new task
                    # received --> leave the for loop for the current task.
                    if (leave_omg or self.new_task):
                        # print cyan('---- Broke for loop ----')
                        break

                # Make sure that omg-tools task is repeated until force quit.
                if self.omg_standby:
                    self.new_task = True
                # Only publish standby state when task is finished.
                # Except for repetitive tasks (back to first state in task).
                if not self.new_task:
                    self.state = "standby"
                    self.fsm_state.publish("standby")
                    print cyan(' Bebop_core state changed to: ', "standby")

            rospy.sleep(0.1)