Пример #1
0
 def read_command(self, command):
     # cursor is used to keep track of how many argument we read from the users command.
     cursor = 0
     split_command = str.split(command)
     if len(split_command) == 0:
         # Empty line, we can just ignore it
         return
     # else ...
     instruction = split_command[0]
     cursor += 1
     if instruction in self.auto_list:
         return self.process_auto(split_command, cursor)
     elif instruction in self.manual_list:
         return self.process_manual()
     elif instruction in self.time_list:
         return self.process_time(split_command, cursor)
     elif instruction in self.freq_list:
         return self.process_freq(split_command, cursor)
     elif instruction in self.help_list:
         return self.process_help(split_command, cursor)
     elif instruction in self.exit_list:
         return self.exit()
     elif instruction in self.halt_list:
         cr.halt()
         self.bprint("Halting the robot ...")
         return
     else:
         self.bprint(
             f"The inputed command {command} could not be parsed, because the tool did not understand the term '{instruction}'. If you wish to you can use :\n'>> help'\nThat instruction will bring a list of the available instruction and their use cases.",
             2)
         return
Пример #2
0
 def exit(self):
     # Used to leave the tool. When triggered this will always halt the robot.
     cr.halt()
     self.bprint("Leaving the tool... The robot is being halted.")
     sys.exit(0)
Пример #3
0
 def process_manual(self):
     vector = np.zeros(8)
     # Used in unsafe mode
     old_vector = np.zeros(8)
     keep_manual = True
     halt_list = self.halt_list
     exit_list = self.exit_list
     self.bprint(
         "Manual command mode triggered.\nIn this mode you can only control a single motor at once. The syntax to use manual mode is :\n'(manual) >> <motor number>'\nThis will cause the targeted motor (numbered from 1 to 8) to start moving at the desired pace while all other motors will stay still. You can use that syntax again to move the focus to another motor. If you wish unroll the cables of that motor instead you can use :\n'(manual) >> -<motor number>'\nThat will cause the motor to start moving in reverse.\nIf you for some reason wish to halt the robot you can use :\n'(manual) >> halt'\nIn order to leave manual mode just use :\n'(manual) >> exit'"
     )
     while keep_manual:
         # Note that we will block on the following line until something is entered.
         command = input("(manual) >> ")
         vector = np.zeros(8)
         if command in halt_list or command in exit_list:
             # leaving the manual mode of courses halts the robot.
             # Note that the robot would be halted regardless at the end of the loop, but just to be sure we use the halt command.
             cr.halt()
             if command in exit_list:
                 keep_manual = False
                 self.bprint("Leaving manual mode ...")
                 # We leave the loop
                 break
             else:
                 # If we had just halted we start listening to user input again
                 continue
         elif command.startswith("help"):
             split_command = command.split()
             self.process_help(split_command, 1)
             if self.safe:
                 self.bprint(
                     "Displaying help in manual mode halts the robot", 1)
             else:
                 # We just assume that the user wants the robot to keep moving because we are running in unsafe mode.
                 vector = old_vector
         else:
             try:
                 motor = int(command)
                 if motor in range(1, 9):
                     vector[motor - 1] = 1
                 elif motor in [-i for i in range(1, 9)]:
                     vector[-(1 + motor)] = -1
                 else:
                     self.bprint(
                         f"The input {command} could not be interpreted correctly. You have to input something that is either an int between 1 and 8 (included) in order to have one of the motors move, or an integer between -8 and -1 in order to command the motors to move backwards, or a command to halt or exit the manual mode (namely 'halt' and 'exit').",
                         2)
                     if self.safe:
                         self.bprint(
                             f"The robot is being halted because of the bad input.",
                             1)
                     else:
                         self.bprint(
                             f"The robot is running in unsafe mode, hence we are assuming that you want to keep the movment going. If you in fact wish to halt the robot please input 'halt'",
                             1)
                         vector = old_vector
             except ValueError as e:
                 self.bprint(
                     f"The input {command} could not be interpreted correctly. You have to input something that is either an int between 1 and 8 (included) in order to have one of the motors move, or an integer between -8 and -1 in order to command the motors to move backwards, or a command to halt or exit the manual mode (namely 'halt' and 'exit').",
                     2)
                 if self.safe:
                     self.bprint(
                         f"The robot is being halted because of the bad input.",
                         1)
                 else:
                     self.bprint(
                         f"The robot is running in unsafe mode, hence we are assuming that you want to keep the movment going. If you in fact wish to halt the robot please input 'halt'",
                         1)
                     vector = old_vector
         # Sending the instruction to the robot.
         cr.manual(vector, self.time_step)
         old_vector = vector
     return