Ejemplo n.º 1
0
HERE = os.path.dirname(__file__)
DATA = os.path.abspath(os.path.join(HERE, "..", "data"))
PATH_FROM = os.path.join(DATA, 'stretcher_bond.json')

ASSEMBLY_PATH = os.path.abspath(os.path.join(HERE, "..", "src"))
sys.path.append(ASSEMBLY_PATH)

#PATH_TO = os.path.join(DATA, os.path.splitext(os.path.basename(__file__))[0] + ".json")
PATH_TO = os.path.join(DATA, 'stretcher_bond_interfaces.json')
print(PATH_TO)

from assembly_information_model.assembly import Assembly
from assembly_information_model.assembly.interfaces_numpy import assembly_interfaces_numpy

# parameters

NMAX = 100
AMIN = 0.0001

# load assembly from JSON
assembly = Assembly.from_json(PATH_FROM)

# identify the interfaces
assembly_interfaces_numpy(assembly, nmax=100, amin=0.0001)

# serialise
assembly.to_json(PATH_TO)

print(list(assembly.network.edges()))
DATA = os.path.abspath(os.path.join(HERE, "..", "data"))
PATH_FROM = os.path.join(DATA, 'stretcher_bond.json')

ASSEMBLY_PATH = os.path.abspath(os.path.join(HERE, "..", "src"))
sys.path.append(ASSEMBLY_PATH)

#PATH_TO = os.path.join(DATA, os.path.splitext(os.path.basename(__file__))[0] + ".json")
#print(PATH_TO)
PATH_TO = os.path.join(DATA, 'stretcher_bond_interfaces.json')

from assembly_information_model.assembly import Assembly
from assembly_information_model.assembly.interfaces_numpy import assembly_interfaces_numpy_fromtojson

# parameters

NMAX = 100
AMIN = 0.0001

# load assembly from JSON
# assembly = Assembly.from_json(PATH_FROM)

# identify the interfaces
assembly_interfaces_numpy_fromtojson(PATH_FROM, PATH_TO, nmax=100, amin=0.0001)

# serialise
# assembly.to_json(PATH_TO)

assembly = Assembly.from_json(PATH_TO)

print(list(assembly.network.edges()))
    print(r'| \ \__/|__)\__/ |   \__\__/| \| | | \ \__/|__ ')
    print()

    username = input_non_empty_string('Please enter your name: ')

    filename = input_non_empty_string(
        'Please enter the assembly file name [{}]: '.format(DEFAULT_FILENAME),
        DEFAULT_FILENAME)
    filepath = os.path.join(DATA, filename)
    if not os.path.isfile(filepath):
        raise FileNotFoundError('Could not file assembly json file: ' +
                                filepath)

    # Load assembly
    print('\n[  ] Loading assembly...', end='\r')
    assembly = Assembly.from_json(filepath)
    print('[OK] Assembly loaded: {} '.format(filename))

    planned_elemement_keys = get_planned_element_keys(assembly)
    print('[OK] Found {} planned elements out of {} total elements'.format(
        len(planned_elemement_keys), assembly.number_of_elements()))
    print('[OK] Planned sequence: {}'.format(planned_elemement_keys))

    # Connect client
    print('[  ] Connecting to ROS {}:{}'.format(args.ros_host,
                                                int(args.ros_port)),
          end='\r')
    with RosClient(host=args.ros_host, port=int(args.ros_port)) as client:
        print('[OK] Connected to ROS: \n')

        # Start UI loop to send elements
tolerance_vector = Vector.from_data(data['tolerance_vector'])
safelevel_vector = Vector.from_data(data['safelevel_vector'])
safelevel_picking_frame = picking_frame.copy()
safelevel_picking_frame.point += safelevel_vector
picking_frame.point += tolerance_vector
# collision_meshes
scene_collision_meshes = [
    CollisionMesh(Mesh.from_data(m), name)
    for m, name in zip(data['collision_meshes'], data['collision_names'])
]

# load assembly from file or from existing if calculation failed at one point...
filepath = os.path.join(DATA, "assembly.json")

if LOAD_FROM_EXISTING and os.path.isfile(PATH_TO):
    assembly = Assembly.from_json(PATH_TO)
else:
    assembly = Assembly.from_json(filepath)

# create an attached collision mesh to be attached to the robot's end effector.
T = Transformation.from_frame_to_frame(element0._tool_frame, tool.frame)
element0_tool0 = element0.transformed(T)
attached_element_mesh = AttachedCollisionMesh(
    CollisionMesh(element0_tool0.mesh, 'element'), 'ee_link')

# ==============================================================================
# From here on: fill in code, whereever you see this dots ...

# NOTE: If you run Docker Toolbox, change `localhost` to `192.168.99.100`
with RosClient('localhost') as client: