def add(w, is_fixed=False, create_shapes=True, create_contacts=True): """ construction of the icub robot for arboris-python: Kinematics data are from: http://eris.liralab.it/wiki/ICubForwardKinematics Inertia comes from the Icub.cpp used in the iCub_SIM program Some data are not well explained, or are badly defined """ bodies_data = get_bodies_data() bodies_shapes_data = get_bodies_shapes_data() joints_data = get_joints_data() shapes_data = get_contact_data() ## bodies creation bodies = {} for name, data in bodies_data.items(): bodies[name] = Body(name=name) mass = zeros((6, 6)) for dims, m, H in data: # get dims, mass and transformation from data sf = SubFrame(bodies[name], H) if len(dims) == 3: # check the type of shape: len =3: box M = box(dims, m) elif len(dims) == 2: # len =2:cylinder, M = cylinder(dims[0], dims[1], m) elif len(dims) == 1: # len =1:sphere, M = sphere(dims[0], m) else: raise ValueError mass += transport(M, inv(H)) # add the mass of the shape to bodies[name].mass = mass # the total mass ## check if iCub has its waist fixed on the structure (the ground) if is_fixed: bodies['waist'] = w.ground else: w.add_link(w.ground, FreeJoint(name='root'), bodies['waist']) ## joints creation for name, data in joints_data.items(): parent, Hp_l, child = data w.add_link(SubFrame(bodies[parent], Hp_l), RzJoint(name=name), bodies[child]) if create_shapes is True: ## body shapes creations for name, data in bodies_shapes_data.items(): for dims, H in data: # get dims, mass and transformation from data sf = SubFrame(bodies[name], H) if len(dims) == 3: # check the type of shape: len =3: box sh = Box(sf, dims, name + ".body_shape") elif len(dims) == 2: # len =2:cylinder, sh = Cylinder(sf, dims[0], dims[1], name + ".body_shape") elif len(dims) == 1: # len =1:sphere, sh = Sphere(sf, dims[0], name + ".body_shape") else: raise ValueError w.register(sh) if create_contacts is True: ## contact shapes creation for name, data in shapes_data.items(): parent, dims, Hpf = data sf = SubFrame(bodies[parent], Hpf, name=name) if len(dims) == 3: # check the type of shape: len =3: box sh = Box(sf, dims, name=name) elif len(dims) == 2: # len =2:cylinder, sh = Cylinder(sf, dims[0], dims[1], name=name) elif len(dims) == 1: # len =1:sphere, sh = Sphere(sf, dims[0], name=name) else: sh = Point(sf, name=name) w.register(sh) w.init()
def add(w, is_fixed=False, create_shapes=True, create_contacts=True): """ construction of the icub robot for arboris-python: Kinematics data are from: http://eris.liralab.it/wiki/ICubForwardKinematics Inertia comes from the Icub.cpp used in the iCub_SIM program Some data are not well explained, or are badly defined """ bodies_data = get_bodies_data() bodies_shapes_data = get_bodies_shapes_data() joints_data = get_joints_data() shapes_data = get_contact_data() ## bodies creation bodies = {} for name, data in bodies_data.items(): bodies[name] = Body(name=name) mass = zeros((6, 6)) for dims, m, H in data: # get dims, mass and transformation from data sf = SubFrame(bodies[name], H) if len(dims) == 3: # check the type of shape: len =3: box M = box(dims, m) elif len(dims) == 2: # len =2:cylinder, M = cylinder(dims[0], dims[1], m) elif len(dims) == 1: # len =1:sphere, M = sphere(dims[0], m) else: raise ValueError mass += transport(M, inv(H)) # add the mass of the shape to bodies[name].mass = mass # the total mass ## check if iCub has its waist fixed on the structure (the ground) if is_fixed: bodies['waist'] = w.ground else: w.add_link(w.ground, FreeJoint(name='root'), bodies['waist']) ## joints creation for name, data in joints_data.items(): parent, Hp_l, child = data w.add_link(SubFrame(bodies[parent], Hp_l), RzJoint(name=name), bodies[child]) if create_shapes is True: ## body shapes creations for name, data in bodies_shapes_data.items(): for dims, H in data: # get dims, mass and transformation from data sf = SubFrame(bodies[name], H) if len(dims) == 3: # check the type of shape: len =3: box sh = Box(sf, dims, name+".body_shape") elif len(dims) == 2: # len =2:cylinder, sh = Cylinder(sf, dims[0], dims[1], name+".body_shape") elif len(dims) == 1: # len =1:sphere, sh = Sphere(sf, dims[0], name+".body_shape") else: raise ValueError w.register(sh) if create_contacts is True: ## contact shapes creation for name, data in shapes_data.items(): parent, dims, Hpf = data sf = SubFrame(bodies[parent], Hpf, name=name) if len(dims) == 3: # check the type of shape: len =3: box sh = Box(sf, dims, name=name) elif len(dims) == 2: # len =2:cylinder, sh = Cylinder(sf, dims[0], dims[1], name=name) elif len(dims) == 1: # len =1:sphere, sh = Sphere(sf, dims[0], name=name) else: sh = Point(sf, name=name) w.register(sh) w.init()