def interpret_hierarchy(contours, hierarchy): hierarchy = hierarchy[0] rod_list = [] for i, c in enumerate(contours): if cv2.contourArea(c) < 20: # Noise continue if hierarchy[i][3] == -1: # Image contour continue if hierarchy[i][3] == 0: # Rod contour # Check the eccentricity of the contour to discard round figures ellipse = cv2.fitEllipse(c) (center,axes,orientation) = ellipse majoraxis_length = max(axes) minoraxis_length = min(axes) eccentricity=(np.sqrt(1-(minoraxis_length/majoraxis_length)**2)) if (eccentricity < 0.7): continue rod = Rod(c, i) rod_list.append(rod) else: # Hole contour hole = Hole(c) index = hierarchy[i][3] # Find the parent rod, None if there isn't (round object instead of a rod) rod = next((x for x in rod_list if x.label == index), None) try: rod.append_hole(hole) except: # If hole of round object continue # This will remove "rods" without holes rod_list = [rod for rod in rod_list if (len(rod.holes) != 0)] return rod_list
def build(n=4, config=DEFAULT_CONFIG): # Parse config length = config["Length"] offset_len = config["Offset"] unstr_len_v = config["UnstretchedLengthV"] unstr_len_h1 = config["UnstretchedLengthH1"] unstr_len_h2 = config["UnstretchedLengthH2"] stiffness = config["Stiffness"] viscosity = config["Viscosity"] # Degree/radian of rotation for every rod rot_deg = 360 / n rot_rad = radians(rot_deg) # Configure the first rod rot = Rotation.from_euler("xyz", [0, -30, 0], degrees=True) * Rotation.from_euler("xyz", [0, 90, 0], degrees=True) offset = (offset_len*cos(pi/n), offset_len*sin(pi/n)) rods = [Rod(mass=1, inertia=np.eye(3), length=length, state=RodState(r=np.array([offset[0], offset[1], 0]), q=rot))] # Configure other rods with respect to the first rod for i in range(1, n): rot = Rotation.from_euler("xyz", [0, 0, rot_deg], degrees=True) * rot offset = (offset_len*cos(i*rot_rad+pi/n), offset_len*sin(i*rot_rad+pi/n)) rods.append(Rod(mass=1, inertia=np.eye(3), length=length, state=RodState(r=np.array([offset[0], offset[1], 0]), q=rot))) # Attach the cables cabs = [] for i in range(n): ind_to = (i + 1) % n cabs.append(Cable(end_point1=rods[i].get_endpoint_a(), end_point2=rods[i-1].get_endpoint_a(), stiffness=stiffness, unstretched_length=unstr_len_h1, viscosity=viscosity)) cabs.append(Cable(end_point1=rods[i].get_endpoint_b(), end_point2=rods[ind_to].get_endpoint_b(), stiffness=stiffness, unstretched_length=unstr_len_h2, viscosity=viscosity)) cabs.append(Cable(end_point1=rods[i].get_endpoint_a(), end_point2=rods[ind_to].get_endpoint_b(), stiffness=stiffness, unstretched_length=unstr_len_v, viscosity=viscosity)) # Build the robot robot = TensegrityRobot() robot.add_rods(rods) robot.add_cables(cabs) return robot
rc.x = 0 rc.y = 0 a.interior.append((ch, rc)) # insert fuel pins into the assembly Imin = -1 Imax = 1 for i in range(Imin, Np + Imax): x = pp * i for j in range(Imin, Np + Imax): if (i, j) != (-10, -10): y = pp * j r = Relation() r.x = x + uniform(-0.1 * rr, 0.1 * rr) r.y = y + uniform(-0.1 * rr, 0.1 * rr) p = Rod() p.radius = 0.3 + 0.05 * i + 0.15 * j p.color = 'red' a.interior.append((p, r)) plt = a.plot(order='ioptc') plt.get_figure().savefig('mini_bwr.pdf') for (e, r, s, c) in a.visible_interior(): print e, r, c ax = None Nch = 0 for ch in a.own_subchannels(): ax = ShapelyToAxis(ch, axis=ax, order='b', label=(Nch, ch.area)) Nch += 1
OFFSET = LENGTH / 8.0 UNSTRETCHED_LENGTH_v = 0.2 UNSTRETCHED_LENGTH_h = 0.1 STIFFNESS = 10 VISCOSITY = 1 q0 = Rotation.from_euler("xyz", [0, 90, 0], degrees=True) q1 = Rotation.from_euler("xyz", [0, -30, 0], degrees=True) * q0 q2 = Rotation.from_euler("xyz", [0, 0, 120], degrees=True) * q1 q3 = Rotation.from_euler("xyz", [0, 0, 120], degrees=True) * q2 rod1 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(0 * pi / 3 + pi / 3), OFFSET * sin(0 * pi / 3 + pi / 3), 0 ]), q=q1)) rod2 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(2 * pi / 3 + pi / 3), OFFSET * sin(2 * pi / 3 + pi / 3), 0 ]), q=q2)) rod3 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([
from scipy.spatial.transform import Rotation np.set_printoptions(precision=5) np.set_printoptions(suppress=True) LENGTH = 0.2 OFFSET = LENGTH / 8.0 UNSTRETCHED_LENGTH = 0.05 STIFFNESS = 100 VISCOSITY = 0.1 MASS = 1 DELTA_L = UNSTRETCHED_LENGTH / 8 rod1 = Rod(mass=MASS, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([0, 0, -OFFSET]), q=Rotation.from_euler("xyz", [0, 0, 0], degrees=True))) rod2 = Rod(mass=MASS, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([0, 0, OFFSET]), q=Rotation.from_euler("xyz", [0, 0, 0], degrees=True))) rod3 = Rod(mass=MASS, inertia=np.eye(3), length=LENGTH * 3, state=RodState(r=np.array([-OFFSET, 0, 0]), q=Rotation.from_euler("xyz", [0, 0, 90], degrees=True)))
UNSTRETCHED_LENGTH_h1 = 0.03 UNSTRETCHED_LENGTH_h2 = 0.15 STIFFNESS = 500 VISCOSITY = 5 q0 = Rotation.from_euler("xyz", [0, 90, 0], degrees=True) q1 = Rotation.from_euler("xyz", [0, -30, 0], degrees=True) * q0 q2 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q1 q3 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q2 q4 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q3 rod1 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(0 * pi / 2 + pi / 4), OFFSET * sin(0 * pi / 2 + pi / 4), 0 ]), q=q1)) rod2 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(1 * pi / 2 + pi / 4), OFFSET * sin(1 * pi / 2 + pi / 4), 0 ]), q=q2)) rod3 = Rod(mass=1, inertia=np.eye(3), length=LENGTH, state=RodState(r=np.array([
# assembly bundle a = Bundle.box(ll=(0,0), ur=(pp*(Np-1), pp*(Np-1)), r=1.3*r) a.wt =1. a.color = 'blue' # channel ch = Bundle.box(ll=(0, 0), ur=(2*pp, 3*pp), r=0.8*r) ch.color = 'green' ch.wt = 0.2 rc = Relation() rc.x = 5*pp rc.y = 3*pp a.interior.append((ch, rc)) # fuel pin master model p = Rod() p.radius = r p.color = 'red' # insert fuel pins into the assembly chsh = a.shapely([0]) if points_on_walls: Imin = 0 Imax = 0 else: Imin = -1 Imax = 1 for i in range(Imin, Np+Imax): x = pp * i for j in range(Imin, Np+Imax): y = pp * j
MASS = 1 INERTIA = np.diag([(1 / 12) * MASS * LENGTH**2, (1 / 12) * MASS * LENGTH**2, (1 / 12) * MASS * LENGTH**2]) q0 = Rotation.from_euler("xyz", [0, 90, 0], degrees=True) q1 = Rotation.from_euler("xyz", [0, 0, 0], degrees=True) * q0 q2 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q1 q3 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q2 q4 = Rotation.from_euler("xyz", [0, 0, 90], degrees=True) * q3 rod1 = Rod(mass=MASS, inertia=INERTIA, length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(0 * pi / 2 + pi / 4), OFFSET * sin(0 * pi / 2 + pi / 4), 0 ]), q=q1), viscosity_w=VISCOSITY_W) rod2 = Rod(mass=1, inertia=INERTIA, length=LENGTH, state=RodState(r=np.array([ OFFSET * cos(1 * pi / 2 + pi / 4), OFFSET * sin(1 * pi / 2 + pi / 4), 0 ]), q=q2), viscosity_w=VISCOSITY_W) rod3 = Rod(mass=1, inertia=INERTIA,