def go(self, move_l, wait=True, poll_limit_seconds=30): """ commands robot to move into position linear way :param move_l: MoveL object describing target position and move settings :param wait: wait for move to complete or not :param poll_limit_seconds: functions as a timeout of wait is enabled :return: boolean """ self.stopped = False Commands.write_hold('0') # disable hold if currently enabled Commands.write_linear_move( move_l=move_l) # execute wanted move command current = 0 if not wait: return True for x in range(poll_limit_seconds): if self.stopped: return False time.sleep(1) cp = Commands.read_current_specified_coordinate_system_position( # returns CurrentPos object str(move_l.get_coordinate_specification()), '0') if Utils.is_in_position(move_l, cp): return True else: current = current + 1 if current == poll_limit_seconds: return False
def _html(self, message): try: if str(self.path) == '/': filename = 'index.html' html_content = f"<html><body><h1>{message}</h1></body></html>" job_name = Commands.read_current_job_details().job_name() status = Commands.read_status() c_pos = get_position() with open(os.path.join(base_path, filename)) as f: html_content = f.read() html_content = html_content \ .replace('{{jobName}}', job_name) \ .replace('{{commandRemote}}', str(status.is_command_remote())) \ .replace('{{playMode}}', str(status.is_play())) \ .replace('{{isHold}}', str( status.is_command_hold() or status.is_command_hold() or status.is_programming_pendant_hold())) \ .replace('{{teachMode}}', str(status.is_teach())) \ .replace('{{running}}', str(status.is_running())) \ .replace('{{servoOn}}', str(status.is_servo_on())) \ .replace('{{isError}}', str(status.is_error_occurring())) \ .replace('{{x}}', str(c_pos.x)) \ .replace('{{y}}', str(c_pos.y)) \ .replace('{{z}}', str(c_pos.z)) \ .replace('{{tx}}', str(c_pos.tx)) \ .replace('{{ty}}', str(c_pos.ty)) \ .replace('{{tz}}', str(c_pos.tz)) return html_content.encode( "utf8") # NOTE: must return a bytes object! else: return "".encode('utf-8') except Exception as e: return html_content.encode("utf8")
def gripper_is_closed(): gripper_status = Gripper.Gripper() res = Commands.read_io_signals(IO.IO(GRIPPER_ACKNOWLEDGE_SIGNAL, 1)).get_response() logging.info('Gripper ack decimal: ' + res) gripper_status.set_closed_status(res) return gripper_status.is_gripper_closed()
def test_linear_motion_move(self): move_l = MoveL.MoveL( MoveL.MoveL.motion_speed_selection_posture_speed, 5, MoveL.MoveL.coordinate_specification_base_coordinate, 352.769, 202.779, 120.658, -1.34, 35.78, 27.84, Utils.binary_to_decimal(0x00000001), 0, 0, 0, 0, 0, 0, 0) res = Commands.write_linear_move(move_l=move_l) self.assertEqual(res.get_response(), '0000')
def test_joint_motion_move(self): move_j = MoveJ.MoveJ( 25, # speed % MoveJ.MoveJ.coordinate_specification_base_coordinate, 352.769, 202.779, 120.658, -1.34, 35.78, 27.84, Utils.binary_to_decimal(0x00000001), 0, 0, 0, 0, 0, 0, 0) res = Commands.write_joint_motion_move(move_j=move_j) self.assertEqual(res.get_response(), '0000')
def read_gripper_hit(): gripper_status = Gripper.Gripper() gripper_status.set_closed_status( Commands.read_io_signals(IO.IO(GRIPPER_HIT_SIGNAL, 4))) return gripper_status
def read_gripper_closed_command_register(): gripper_status = Gripper.Gripper() gripper_status.set_closed_status( Commands.read_io_signals(IO.IO(GRIPPER_OPEN_CLOSE_SIGNAL, 4))) return gripper_status
def test_write_hold(self): res = Commands.write_hold('1') self.assertEqual(res.get_response(), '0000')
def get_position(): return Commands.read_current_specified_coordinate_system_position( str(COORDINATE_SYSTEM), '0')
def test_read_all_job_names(self): res = Commands.read_all_job_names() self.assertEqual(res.get_response(), '')
def test_write_master_job(self): res = Commands.write_master_job('test_job') self.assertEqual(res.get_response(), '0000')
def test_write_io_signals(self): io = IO.IO(4) res = Commands.write_io_signals(io) self.assertEqual(res.get_response(), '0')
def test_write_servo_power(self): res = Commands.write_servo_power('1') self.assertEqual(res.get_response(), '0000')
def test_write_cancel(self): res = Commands.write_cancel() self.assertEqual(res.get_response(), '0000')
def stop(self): """ stop upper go function """ self.stopped = True Commands.write_hold('1') # only way to stop robot from executing move
def test_read_alarms(self): alarms = Commands.read_alarms() self.assertEqual(alarms.get_alarms(), ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0'])
def get_position(): return Commands.read_current_specified_coordinate_system_position( str(COORDINATE_SYSTEM), '0') while not done: # event handling for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == pygame.JOYBUTTONDOWN: if event.button == xbox360_controller.START: Commands.write_servo_power('1') print('servo on') if event.button == xbox360_controller.BACK: Commands.write_servo_power('0') print('servo off') if event.button == xbox360_controller.PAD_LEFT: Commands.write_start_job('') print('start default job') # handle events for specific controllers if event.joy == controller.get_id(): if event.button == xbox360_controller.A: if ball_color == WHITE: ball_color = RED else: ball_color = WHITE
def start_app(): logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) nx100_remote_control.MOCK_RESPONSE = False # WebServer.run(addr="localhost", port=8080) # Commands.read_alarms() # Commands.read_current_joint_coordinate_position() # Commands.read_current_specified_coordinate_system_position('0', '0') # Commands.read_status() # Commands.read_current_job_details() # Commands.write_hold('0') # 1 on, 0 off # Commands.write_reset() # Commands.write_cancel() # Commands.write_servo_power('0') # 1 on, 0 off # Commands.write_start_job('') # empty means default set execution job # Commands.write_linear_move(MoveL.MoveL( # MoveL.MoveL.motion_speed_selection_posture_speed, # 5, # MoveL.MoveL.coordinate_specification_base_coordinate, # 353.769, 202.779, 120.658, # -1.34, 35.78, 27.84, # Utils.binary_to_decimal(0x00000001), # 0, 0, 0, 0, 0, 0, 0 # )) # Commands.read_all_job_names() # Commands.write_master_job('job_name_here') # Gripper.write_gripper_close() # Gripper.write_gripper_open() # Gripper.read_gripper_closed_command_register() # Gripper.write_gripper_close() # print(Gripper.gripper_is_closed()) # Gripper.read_gripper_hit() # move_l = MoveL.MoveL( # MoveL.MoveL.motion_speed_selection_posture_speed, # 5, # MoveL.MoveL.coordinate_specification_base_coordinate, # 353.769, 202.779, 120.658, # -1.34, 35.78, 27.84, # Utils.binary_to_decimal(0x00000001), # 0, 0, 0, 0, 0, 0, 0 # ) # Commands.robot_in_target_point_callback( # move_l=move_l, timeout=10, _callback_success=callback_success, _callback_failed=callback_failed # ) # move_l = MoveL.MoveL( # MoveL.MoveL.motion_speed_selection_posture_speed, # 5, # MoveL.MoveL.coordinate_specification_base_coordinate, # 352.769, 202.779, 120.658, # -1.34, 35.78, 27.84, # Utils.binary_to_decimal(0x00000001), # 0, 0, 0, 0, 0, 0, 0 # ) # linear_move = LinearMove.LinearMove() # linear_move.go(move_l=move_l, wait=True, poll_limit_seconds=10) # print('finished') position = Commands.read_current_specified_coordinate_system_position('0') sp = [-70.888, 836.813, 281.496, 0.21, 36.59, 90.14] # 542.553,-229.522,416.749,12.32,6.74,-27.25,0,0 # -70.888,836.813,281.496,0.21,36.59,90.14,0,0 """
def get_position(): return Commands.read_current_specified_coordinate_system_position('0', '0')
def write_gripper_open(): io_out = IO.IO(GRIPPER_OPEN_CLOSE_SIGNAL_INPUT, 4) # each signal line has 8 bits, write them all io_out.set_first_eight_io_contracts('00000000') # Todo, value not decided return Commands.write_io_signals(io_out)
def do_POST(self): content_length = int( self.headers['Content-Length']) # <--- Gets the size of data post_data = self.rfile.read( content_length) # <--- Gets the data itself # logging.info("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n", str(self.path), str(self.headers), # post_data.decode('utf-8')) command = post_data.decode("utf-8") if command == 'start_job': Commands.write_start_job('') elif command == 'hold_on': Commands.write_hold('1') elif command == 'hold_off': Commands.write_hold('0') elif command == 'servo_on': Commands.write_servo_power('1') elif command == 'servo_off': Commands.write_servo_power('0') elif command == 'move_s_l' or command == 'move_s_r': c_pos = get_position() Commands.write_linear_move( MoveL.MoveL( 0, SPEED, 0, (c_pos.get_x() - MOVE_MM) if command == 'move_s_l' else (c_pos.get_x() + MOVE_MM), c_pos.get_y(), c_pos.get_z(), c_pos.get_tx(), c_pos.get_ty(), c_pos.get_tz(), Utils.binary_to_decimal(0x00000001))) elif command == 'move_l_l' or command == 'move_l_r': c_pos = get_position() Commands.write_linear_move( MoveL.MoveL(0, SPEED, 0, c_pos.get_x(), (c_pos.get_y() - MOVE_MM) if command == 'move_l_l' else (c_pos.get_y() + MOVE_MM), c_pos.get_z(), c_pos.get_tx(), c_pos.get_ty(), c_pos.get_tz(), Utils.binary_to_decimal(0x00000001))) elif command == 'move_u_l' or command == 'move_u_r': c_pos = get_position() Commands.write_linear_move( MoveL.MoveL(0, SPEED, 0, c_pos.get_x(), c_pos.get_y(), (c_pos.get_z() - MOVE_MM) if command == 'move_u_l' else (c_pos.get_z() + MOVE_MM), c_pos.get_tx(), c_pos.get_ty(), c_pos.get_tz(), Utils.binary_to_decimal(0x00000001))) # Todo, do not use, ultra dangerous # Todo, implement these some day with posture speed option # elif command == 'move_r_l' or command == 'move_r_r': # c_pos = get_position() # Commands.write_linear_move(MoveL.MoveL( # 0, 1, 0, # c_pos.get_x(), c_pos.get_y(), c_pos.get_z(), # (c_pos.get_tx() - 5.00) if command == 'move_r_l' else (c_pos.get_tx() + 5.0), # c_pos.get_ty(), c_pos.get_tz(), # Utils.binary_to_decimal(0x00000001) # )) self._set_headers() self.wfile.write("".format(self.path).encode('utf-8'))
def test_read_current_joint_coordinate_position(self): position = Commands.read_current_joint_coordinate_position() self.assertEqual(position, '45411,-59646,-55567,667,-1077,-1260,0,0,0,0,0,0')