Add UR5 control test, datasheet JSON output
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
| venv | venv | ||||||
| __pycache__ | __pycache__ | ||||||
| cables | cables | ||||||
|  | .vscode | ||||||
| @@ -7,6 +7,7 @@ import camelot | |||||||
| import numpy as np | import numpy as np | ||||||
| from PIL import Image | from PIL import Image | ||||||
| import io | import io | ||||||
|  | import json | ||||||
|  |  | ||||||
| def parse(filename, output_dir): | def parse(filename, output_dir): | ||||||
|  |  | ||||||
| @@ -43,10 +44,11 @@ def parse(filename, output_dir): | |||||||
|  |  | ||||||
|             page.extract_text(visitor_text=visitor_body) |             page.extract_text(visitor_text=visitor_body) | ||||||
|             text_body = "".join(parts).strip('\n') |             text_body = "".join(parts).strip('\n') | ||||||
|  |             if len(text_body) == 0: | ||||||
|  |                 text_body = str(n) | ||||||
|             #print(text_body) |             #print(text_body) | ||||||
|              |              | ||||||
|  |  | ||||||
|  |  | ||||||
|             table_list[text_body] = table.df |             table_list[text_body] = table.df | ||||||
|             #table.to_html("table" + str(n) + ".html") |             #table.to_html("table" + str(n) + ".html") | ||||||
|              |              | ||||||
| @@ -55,7 +57,7 @@ def parse(filename, output_dir): | |||||||
|             n=n+1 |             n=n+1 | ||||||
|     #camelot.plot(tables[0], kind='grid').savefig("test.png") |     #camelot.plot(tables[0], kind='grid').savefig("test.png") | ||||||
|      |      | ||||||
|     tables.export(output_dir + '/techdata.json', f='json') |     #tables.export(output_dir + '/techdata.json', f='json') | ||||||
|  |  | ||||||
|     # print(table_list) |     # print(table_list) | ||||||
|     # Extract Basic details - part name & description, image, etc |     # Extract Basic details - part name & description, image, etc | ||||||
| @@ -81,7 +83,95 @@ def parse(filename, output_dir): | |||||||
|                 with open(output_dir + "/brand.png", "wb") as fp: |                 with open(output_dir + "/brand.png", "wb") as fp: | ||||||
|                     fp.write(image_file_object.data) |                     fp.write(image_file_object.data) | ||||||
|                     count += 1 |                     count += 1 | ||||||
|     return table_list |  | ||||||
|  |     # Table parsing and reordring | ||||||
|  |     tables = dict() | ||||||
|  |     previous_table = "" | ||||||
|  |     for table_name in table_list.keys(): | ||||||
|  |         # determine shape: horizontal or vertical | ||||||
|  |         table = table_list[table_name] | ||||||
|  |         rows = table.shape[0] | ||||||
|  |         cols = table.shape[1] | ||||||
|  |         vertical = None | ||||||
|  |         if rows > 2 and cols == 2: | ||||||
|  |             vertical = True | ||||||
|  |         elif cols == 1: | ||||||
|  |             vertical = False | ||||||
|  |         elif rows == 1: | ||||||
|  |             vertical = True | ||||||
|  |         elif cols == 2: # and rows <= 2 | ||||||
|  |             # inconsistent | ||||||
|  |             if table.iloc[0, 0].find(":") == len(table.iloc[0, 0]) - 1: # check if last character is ":" indicating a vertical table | ||||||
|  |                 vertical = True | ||||||
|  |             else: | ||||||
|  |                 vertical = False | ||||||
|  |  | ||||||
|  |         elif cols > 2: # and rows <= 2 | ||||||
|  |             vertical = False | ||||||
|  |         elif rows > 2 and cols > 2: # big table | ||||||
|  |             vertical = False | ||||||
|  |         else: # 1 column, <= 2 rows | ||||||
|  |             vertical = False | ||||||
|  |  | ||||||
|  |         # missing name check | ||||||
|  |         for table_name_2 in table_list.keys():  | ||||||
|  |             if table_name_2.find(table.iloc[-1, 0]) >= 0: | ||||||
|  |                 # Name taken from table directly above - this table does not have a name | ||||||
|  |                 table_list["Specs " + str(len(tables))] = table_list.pop(table_name_2, None) # rename table to arbitrary altername name | ||||||
|  |                 break | ||||||
|  |  | ||||||
|  |         if vertical: | ||||||
|  |             out = dict() | ||||||
|  |             for row in table.itertuples(index=False, name=None): | ||||||
|  |                 out[row[0].replace("\n", " ").replace(":", "")] = row[1] | ||||||
|  |  | ||||||
|  |         else: # horizontal | ||||||
|  |             out = dict() | ||||||
|  |             for col in table.columns: | ||||||
|  |                 col_data = tuple(table[col]) | ||||||
|  |                 out[col_data[0].replace("\n", " ")] = col_data[1:] | ||||||
|  |          | ||||||
|  |         tables[table_name] = out | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         # multi-page table check | ||||||
|  |         if table_name.isdigit() and len(tables) > 1: | ||||||
|  |             print(table_name) | ||||||
|  |             print(previous_table) | ||||||
|  |              | ||||||
|  |              | ||||||
|  |              | ||||||
|  |              | ||||||
|  |             main_key = previous_table | ||||||
|  |             cont_key = table_name | ||||||
|  |             print(tables) | ||||||
|  |             if vertical == False: | ||||||
|  |                 main_keys = list(tables[main_key].keys()) | ||||||
|  |                 for i, (cont_key, cont_values) in enumerate(tables[cont_key].items()): | ||||||
|  |                     if i < len(main_keys): | ||||||
|  |                         print(tables[main_key][main_keys[i]]) | ||||||
|  |                         tables[main_key][main_keys[i]] = (tables[main_key][main_keys[i]] + (cont_key,) + cont_values) | ||||||
|  |  | ||||||
|  |                 del tables[table_name] | ||||||
|  |  | ||||||
|  |             else: | ||||||
|  |                 for key in tables[cont_key].keys(): | ||||||
|  |                     tables[main_key][key] = tables[cont_key][key] | ||||||
|  |                 del tables[table_name] | ||||||
|  |  | ||||||
|  |         previous_table = table_name | ||||||
|  |      | ||||||
|  |  | ||||||
|  |     print(tables) | ||||||
|  |     with open(output_dir + "/tables.json", 'w') as json_file: | ||||||
|  |         json.dump(tables, json_file) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     return tables | ||||||
|  |  | ||||||
|      |      | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ opencv-python | |||||||
| pypdf2==2.12.1 | pypdf2==2.12.1 | ||||||
| alive-progress | alive-progress | ||||||
| requests | requests | ||||||
|  | git+https://github.com/Byeongdulee/python-urx.git | ||||||
|  |  | ||||||
| # Development | # Development | ||||||
| matplotlib | matplotlib | ||||||
							
								
								
									
										67
									
								
								ur5_control.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										67
									
								
								ur5_control.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,67 @@ | |||||||
|  | #!/usr/bin/env python3 | ||||||
|  |  | ||||||
|  | import urx | ||||||
|  | import math3d as m3d | ||||||
|  | import math | ||||||
|  | import time | ||||||
|  | import logging | ||||||
|  | from urx.robotiq_two_finger_gripper import Robotiq_Two_Finger_Gripper | ||||||
|  | import sys | ||||||
|  |  | ||||||
|  | rob = urx.Robot("192.168.1.145") | ||||||
|  | robotiqgrip = Robotiq_Two_Finger_Gripper(rob) | ||||||
|  |  | ||||||
|  | rob.set_tcp((0, 0, 0.15, 0, 0, 0)) | ||||||
|  | rob.set_payload(4, (0, 0, 0.1)) | ||||||
|  | #rob.set_payload(2, (0, 0, 0.1)) | ||||||
|  | time.sleep(0.2) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def set_pos_abs(x, y, z, xb, yb, zb): | ||||||
|  |  | ||||||
|  |     new_orientation = m3d.Transform() | ||||||
|  |     new_orientation.orient.rotate_xb(xb)  # Replace rx with the desired rotation around X-axis | ||||||
|  |     new_orientation.orient.rotate_yb(yb)  # Replace ry with the desired rotation around Y-axis | ||||||
|  |     new_orientation.orient.rotate_zb(zb)  # Replace rz with the desired rotation around Z-axis | ||||||
|  |  | ||||||
|  |     # Get the current pose | ||||||
|  |     trans = rob.getl() | ||||||
|  |     # Apply the new orientation while keeping the current position | ||||||
|  |     new_trans = m3d.Transform(new_orientation.orient, m3d.Vector(trans[0:3])) | ||||||
|  |     new_trans.pos.x = x | ||||||
|  |     new_trans.pos.y = y | ||||||
|  |     new_trans.pos.z = z | ||||||
|  |     #rob.speedj(0.2, 0.5, 99999) | ||||||
|  |     rob.set_pose(new_trans, acc=5.0, vel=5.0, command="movej")  # apply the new pose | ||||||
|  |  | ||||||
|  | def set_pos_rel_rot_abs(x, y, z, xb, yb, zb): | ||||||
|  |  | ||||||
|  |     new_orientation = m3d.Transform() | ||||||
|  |     new_orientation.orient.rotate_xb(xb)  # Replace rx with the desired rotation around X-axis | ||||||
|  |     new_orientation.orient.rotate_yb(yb)  # Replace ry with the desired rotation around Y-axis | ||||||
|  |     new_orientation.orient.rotate_zb(zb)  # Replace rz with the desired rotation around Z-axis | ||||||
|  |  | ||||||
|  |     # Get the current pose | ||||||
|  |     trans = rob.getl() | ||||||
|  |      | ||||||
|  |     # Apply the new orientation while keeping the current position | ||||||
|  |     new_trans = m3d.Transform(new_orientation.orient, m3d.Vector(trans[0:3])) | ||||||
|  |     new_trans.pos.x += x | ||||||
|  |     new_trans.pos.y += y | ||||||
|  |     new_trans.pos.z += z | ||||||
|  |     #rob.speedj(0.2, 0.5, 99999) | ||||||
|  |     rob.set_pose(new_trans, acc=0.1, vel=0.4, command="movej")  # apply the new pose | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #rob.movej((0, 0, 0, 0, 0, 0), 0.1, 0.2) | ||||||
|  | #rob.movel((x, y, z, rx, ry, rz), a, v) | ||||||
|  | print("Current tool pose is: ",  rob.getl()) | ||||||
|  | #set_pos_rel_rot_abs(0, 0, -0.2, math.pi, 0, -math.pi) | ||||||
|  | set_pos_abs(0.3, -0.2, 0.5, math.pi, 0, -math.pi) | ||||||
|  | set_pos_abs(0, 0.2, 0.6, math.pi, 0, -math.pi) | ||||||
|  | set_pos_abs(-0.5, -0.2, 0.4, math.pi, 0, -math.pi) | ||||||
|  | #set_pos_rel_rot_abs(0, 0, 0, math.pi, 0, -math.pi) | ||||||
|  | print("Current tool pose is: ",  rob.getl()) | ||||||
|  | sys.exit(0) | ||||||
|  | rob.stop() | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user