Example #1
0
def podium(MiroSystem, pos, spin=0):
    foot_h = 0.01
    foot_r = 0.9
    leg_h = 0.005
    leg_r = 0.02
    podium_r= 0.9
    podium_h = 0.01

    foot_pos = [pos[0], pos[1]+foot_h/2, pos[2]]
    leg_pos = [pos[0], pos[1]+foot_h+leg_h/2, pos[2]]
    podium_pos = [pos[0], pos[1]+foot_h+leg_h+podium_h/2, pos[2]]

    # Foot
    foot = MiroAPI.add_cylinderShape(MiroSystem, foot_r, foot_h, 1000, foot_pos, texture='black.jpg', Fixed=False)
    # Pole
    leg = MiroAPI.add_cylinderShape(MiroSystem, leg_r, leg_h, 500, leg_pos, texture='gammal5kr.png', Fixed=False)
    # Sign
    podium = MiroAPI.add_cylinderShape(MiroSystem, podium_r, podium_h, 1000, podium_pos, texture='podium-logo.jpg', Fixed=False)
    # Hinges
    h1 = [pos[0], pos[1]+foot_h, pos[2]]
    h2 = [pos[0], pos[1]+foot_h+leg_h, pos[2]]
    MiroAPI.LinkBodies_Hinge(foot, leg, h1, [0,1,0], MiroSystem)
    MiroAPI.LinkBodies_Hinge(leg, podium, h2, [0,1,0], MiroSystem)
    if spin:
        MiroAPI.SetBodyAngularFrequency(podium, spin)
Example #2
0
def sponsorFlag(MiroSystem, pos, logo, spin=0):
    foot_h = 0.08
    foot_r = 0.3
    leg_h = 0.4
    leg_r = 0.02
    sign_h = 1.6
    sign_w = 0.6
    sign_t = 0.03

    foot_pos = [pos[0], pos[1]+foot_h/2, pos[2]]
    leg_pos = [pos[0], pos[1]+foot_h+leg_h/2, pos[2]]
    sign_pos = [pos[0], pos[1]+foot_h+leg_h+sign_h/2, pos[2]]

    # Foot
    foot = MiroAPI.add_cylinderShape(MiroSystem, foot_r, foot_h, 1000, foot_pos, texture='black_smere.jpg', Fixed=False, scale=[1,-1])
    # Pole
    leg = MiroAPI.add_cylinderShape(MiroSystem, leg_r, leg_h, 500, leg_pos, texture='black_smere.jpg', Fixed=False, scale=[1,-1])
    # Sign
    sign = MiroAPI.add_boxShape(MiroSystem, sign_w, sign_h, sign_t, sign_pos, density=30, texture=logo, Fixed=False)
    # Hinges
    h1 = [pos[0], pos[1]+foot_h, pos[2]]
    h2 = [pos[0], pos[1]+foot_h+leg_h, pos[2]]
    MiroAPI.LinkBodies_Hinge(foot, leg, h1, [0,1,0], MiroSystem)
    MiroAPI.LinkBodies_Hinge(leg, sign, h2, [0,1,0], MiroSystem)
    if spin:
        MiroAPI.SetBodyAngularFrequency(sign, spin)
Example #3
0
    def MarkLinkpoint(self,
                      component_name,
                      linkpoint_name,
                      color='red',
                      marking_radius=0.01):
        '''Add a colored sphere to the linkpoint of a component to identify it during simulation. \nUse 'red', 'blue' or 'green'.'''
        if not self.use_helpers:
            return

        if color != 'blue' and color != 'green':
            color = 'red'

        if MiroAPI.API == 'AGX' and self.warning_print:
            print(
                'Warning: MiroModule.MarkLinkPoint is not stable in the AGX api, may cause unstable systems. Consider using MiroModule.DisableHelpers().'
            )

        texture = 'textures/markpattern_' + color + '.png'
        backup_color = [(color == 'red') * 1, (color == 'green') * 1,
                        (color == 'blue') * 1]

        comp = self.components[component_name]
        pos = comp.GetLinkPoint(linkpoint_name)
        ball = MiroAPI.add_sphereShape(False,
                                       marking_radius,
                                       pos,
                                       texture=texture,
                                       Collide=False,
                                       Fixed=False,
                                       color=backup_color)
        link = MiroAPI.LinkBodies_Hinge(comp.GetBody(), ball, pos, [0, 1, 0])

        self.hidden_bodies.append(ball)
        self.hidden_links.append(link)
Example #4
0
def MIT_chair(MiroSystem, pos_chair,rotation):
    #dimensions of the chair
    size_chair_x = 0.5
    size_chair_y = 0.1
    size_chair_z = 0.5
    size_chair_leg_h = 0.42
    size_leg_r = 0.02 
    size_back_cylinder_r = 0.015 # the back of the chair
    size_back_cylinder_h = 0.38
    size_back_x = size_chair_x/7
    size_back_y = 0.2
    size_back_z = size_chair_z + 0.05 
    seat = MIT_table(MiroSystem, pos_chair, size_chair_x, size_chair_y, size_chair_z, size_chair_leg_h, size_leg_r) # making the bottom of the chair
    
    if rotation == 0:
        pos_back  = pos_chair + np.array([-size_chair_x/2.3, size_back_cylinder_h + size_chair_leg_h,0])
    elif rotation == 1:
        pos_back  = pos_chair + np.array([0, size_back_cylinder_h + size_chair_leg_h,size_chair_z/2.3])
        temp = size_back_x
        size_back_x = size_back_z
        size_back_z = temp
    elif rotation == 2:
        pos_back  = pos_chair + np.array([size_chair_x/2.3,size_back_cylinder_h + size_chair_leg_h,0])
    else:
        pos_back  = pos_chair + np.array([0, size_back_cylinder_h + size_chair_leg_h,-size_chair_z/2.3])
        temp = size_back_x
        size_back_x = size_back_z
        size_back_z = temp 
   
    pos_back = pos_back + np.array([0, size_chair_y+size_back_y/2, 0])
    neck = chair_back(MiroSystem, pos_back, size_back_x,size_back_y, size_back_z)
    length_0 = np.sqrt((size_chair_x/2)**2 + (size_chair_z/2)**2) - 2*size_back_cylinder_r
    theta_0 = rotation*0.5*np.pi - np.pi/4
    
    for i in range(6):
        theta = theta_0 + i*np.pi/10
        length = length_0 - (i*(5-i)*(1-1/np.sqrt(2))*length_0)/6.25 
        n = np.array([- length*np.cos(theta), size_back_cylinder_h/2 + size_chair_leg_h + size_chair_y, length*np.sin(theta)])
        pos_back = pos_chair + n
        leg = table_leg(MiroSystem,pos_back, size_back_cylinder_r, size_back_cylinder_h)
        if not FIXED:
            MiroSystem.Add(MiroAPI.LinkBodies_Hinge(seat, leg, pos_back-np.array([0,size_back_cylinder_h,0]), [0,1,0]))
            MiroSystem.Add(MiroAPI.LinkBodies_Hinge(neck, leg, pos_back+np.array([0,size_back_cylinder_h,0]), [0,1,0]))
Example #5
0
def sodacan(MiroSystem, target, text = 'schrodbull.png', angle = 0, SPEEDMODE = False):
    h = 0.22
    r = 0.04
    eps = 0.003
    epsvec = np.array([0, eps/2, 0])
    
    pos_can = np.array([target[0], target[1]+h/2+eps, target[2]])

    # Create Can Hitbox
    can = MiroAPI.add_cylinderShape(MiroSystem, r, h, 50, pos_can, rotY=angle, texture=text, Fixed=False, scale=[1,-1])

    # Create lid and bottom
    pos_lid = np.array([target[0], target[1]+eps*3/2+h, target[2]])
    lid = MiroAPI.add_cylinderShape(MiroSystem, r, eps, 150, pos_lid, rotY=angle, texture='sodacan_lid.png', Fixed=False, scale=[1,1])
    
    pos_bot = np.array([target[0], target[1]+eps/2, target[2]])
    bot = MiroAPI.add_cylinderShape(MiroSystem, r, eps, 200, pos_bot, rotY=angle, texture='sodacan_bot.png', Fixed=False, scale=[1,1])

    MiroSystem.Add(MiroAPI.LinkBodies_Hinge(can, lid, pos_lid-epsvec, [0, 1,0]))
    MiroSystem.Add(MiroAPI.LinkBodies_Hinge(can, bot, pos_bot+epsvec, [0,-1,0]))
Example #6
0
def MIT_table(MiroSystem, table_pos, size_table_x, size_table_y, size_table_z,size_leg_h, size_leg_r):    
    size_table = np.array([size_table_x, size_table_y, size_table_z, size_leg_h])
    top = tabletop(MiroSystem, table_pos, size_table)
    length = np.sqrt((size_table_x/2)**2 + (size_table_z/2)**2) - 2*size_leg_r
    for i in range(4):
        theta = i*0.5*np.pi + np.pi/4
        n = np.array([length*np.cos(theta), size_leg_h/2, length*np.sin(theta)])
        leg_pos = table_pos + n
        leg = table_leg(MiroSystem,leg_pos, size_leg_r, size_leg_h)
        if not FIXED:
            MiroSystem.Add(MiroAPI.LinkBodies_Hinge(top, leg, leg_pos+np.array([0,size_leg_h,0]), [0,1,0]))
    return top
Example #7
0
    def ConnectComponents(self,
                          name_A,
                          point_A,
                          name_B,
                          point_B,
                          dist=0,
                          move=True,
                          show_warning=True,
                          link_name=False,
                          lock_link=False):
        comp_A = self.components[name_A]
        comp_B = self.components[name_B]

        if (move):
            self.GetComponent(name_B).MoveToMatch(point_B,
                                                  self.GetComponent(name_A),
                                                  point_A, dist)

        # Set Link position to the midpoint between the linkpoints
        linkpos = (comp_A.GetLinkPoint(point_A) +
                   comp_B.GetLinkPoint(point_B)) / 2

        # Get both link directions from the components
        linkdirA = comp_A.GetLinkDir(point_A)
        linkdirB = comp_B.GetLinkDir(point_B)

        # If the dot product is negative, then the angle between the links is > 180 degrees and the links are at least somewhat facing
        if np.linalg.norm(linkdirA) == 0:
            linkdir = linkdirB
        elif np.linalg.norm(linkdirB) == 0:
            linkdir = linkdirA
        elif np.dot(linkdirA, linkdirB) < 0:
            linkdir = linkdirA - linkdirB
            linkdir = linkdir / np.linalg.norm(linkdir)
        else:
            linkdir = linkdirA + linkdirB
            linkdir = linkdir / np.linalg.norm(linkdir)
            if show_warning:
                print(
                    'Warning: Non-facing links. The links between ' + name_A +
                    '.' + point_A + ' and ' + name_B + '.' + point_B +
                    ' are not facing eachother, check linkpoint and object orientation. Consider removing with MiroModule.RemoveHelpers() before running.'
                )

        hinge_link = MiroAPI.LinkBodies_Hinge(comp_A.GetBody(),
                                              comp_B.GetBody(), linkpos,
                                              linkdir)

        # Add the link to the module's dictionary of links
        if link_name:
            self.links.update({link_name: hinge_link})
        else:
            name = name_A + "." + point_A + "_TO_" + name_B + "." + point_B
            self.links.update({name: hinge_link})

        self.graph_links.append({
            'Source': name_A,
            'Target': name_B,
            'Weight': 1
        })

        if lock_link:
            rotVec = np.array([1, 1, 1])
            if np.dot(rotVec, linkdir) / (np.linalg.norm(rotVec) *
                                          np.linalg.norm(rotVec)) < 0.01:
                rotVec = np.array([1, -1, 1])
            rotVec = rotVec - np.dot(rotVec, linkdir) * linkdir
            rotVec = rotVec / np.linalg.norm(rotVec)
            # 90 degree rotated link to emulate 0-spin link
            hinge_link = MiroAPI.LinkBodies_Hinge(
                comp_A.GetBody(), comp_B.GetBody(), linkpos,
                MiroAPI.rotateVector(linkdir, 90, rotVec))
            if link_name:
                self.links.update({link_name + '_locker': hinge_link})
            else:
                name = name_A + "." + point_A + "_TO_" + name_B + "." + point_B + '_locker'
                self.links.update({name: hinge_link})
def revolute_door(MiroSystem, d, l, spin, pos):
    # Revolving door bottom ring
    pos_down = np.array([pos[0], 0.0, pos[2]])
    disk_bot = MiroAPI.add_cylinderShape(MiroSystem,
                                         l,
                                         0.01,
                                         1000,
                                         pos_down,
                                         'MITentrance_floor.png',
                                         Collide=False)

    # Revolving door top ring
    pos_up = np.array([pos[0], pos[1] + 0.1 / 2 + d / 2, pos[2]])
    disk_top = MiroAPI.add_cylinderShape(MiroSystem, l, 0.1, 1000, pos_up,
                                         'MITentrance.png')

    l = l - 0.03
    eps = 0.004
    top = pos[1] - eps
    mid = pos[1] / 2 + d / 4
    bot = d / 2 + eps
    dh = np.array([0, d / 2, 0])

    # middle pole
    pos[1] = mid
    mid_pole = greenpole(MiroSystem,
                         d,
                         top - bot - d,
                         spin,
                         0,
                         pos,
                         Fixed=FIXED)

    # top cross
    pos[1] = top
    top_x = greenpole(MiroSystem, d, 2 * (l - d), spin, 90, pos, Fixed=FIXED)
    top_y = greenpole(MiroSystem,
                      d,
                      2 * (l - d),
                      spin + 90,
                      90,
                      pos,
                      Fixed=FIXED)

    if not FIXED:
        dir1 = [np.cos(np.deg2rad(spin)), 0, np.sin(np.deg2rad(spin))]
        dir2 = [
            np.cos(np.deg2rad(spin + 90)), 0,
            np.sin(np.deg2rad(spin + 90))
        ]
        MiroAPI.LinkBodies_Hinge(top_x, top_y, pos, dir1, MiroSystem)
        MiroAPI.LinkBodies_Hinge(top_x, top_y, pos, dir2, MiroSystem)
        MiroAPI.LinkBodies_Hinge(top_x, mid_pole, pos - dh, dir1, MiroSystem)
        MiroAPI.LinkBodies_Hinge(top_x, disk_top, pos + dh, [0, 1, 0],
                                 MiroSystem)
        MiroAPI.LinkBodies_Hinge(top_y, disk_top, pos + dh, [0, 1, 0],
                                 MiroSystem)

    # bottom cross
    pos[1] = bot
    bot_x = greenpole(MiroSystem, d, 2 * (l - d), spin, 90, pos, Fixed=FIXED)
    bot_y = greenpole(MiroSystem,
                      d,
                      2 * (l - d),
                      spin + 90,
                      90,
                      pos,
                      Fixed=FIXED)

    if not FIXED:
        MiroAPI.LinkBodies_Hinge(bot_x, bot_y, pos, dir1, MiroSystem)
        MiroAPI.LinkBodies_Hinge(bot_x, bot_y, pos, dir2, MiroSystem)
        MiroAPI.LinkBodies_Hinge(bot_x, mid_pole, pos + dh, dir1, MiroSystem)
        MiroAPI.LinkBodies_Hinge(bot_x, disk_top, pos - dh, [0, -1, 0],
                                 MiroSystem)
        MiroAPI.LinkBodies_Hinge(bot_y, disk_top, pos - dh, [0, -1, 0],
                                 MiroSystem)

    cross = [[top_x, bot_x], [top_y, bot_y]]
    p = np.array([pos[0], mid, pos[2]])
    for phi in [0, 90, 180, 270]:
        angle = spin + phi
        dp = np.array([
            np.cos(np.deg2rad(angle)) * (l - d / 2), 0,
            -np.sin(np.deg2rad(angle)) * (l - d / 2)
        ])
        rod = greenpole(MiroSystem,
                        d,
                        top - bot + d,
                        angle,
                        0,
                        p + dp,
                        Fixed=FIXED)
        if not FIXED:
            dh = np.array([0, (top - bot + d) / 2, 0])
            top_bar = cross[round(phi / 90) % 2][0]
            bot_bar = cross[round(phi / 90) % 2][1]
            MiroAPI.LinkBodies_Hinge(top_bar, rod, p + dp + dh, -dp,
                                     MiroSystem)
            MiroAPI.LinkBodies_Hinge(bot_bar, rod, p + dp - dh, -dp,
                                     MiroSystem)

    # side walls
    wid = 0.4
    thick = 0.02
    angle = -13
    height = top - bot + d + 2 * eps
    p = np.array([pos[0] - (l + 0.03 + thick / 2), mid, pos[2]])
    p[0] = p[0] - np.sin(np.deg2rad(angle)) * wid / 2
    p[2] = p[2] - np.cos(np.deg2rad(angle)) * wid / 2
    MiroAPI.add_boxShape(MiroSystem,
                         thick,
                         height,
                         wid,
                         p,
                         'MITentrance.png',
                         rotY=angle,
                         color=[0.02, 0.1, 0.01])

    p[2] = p[2] + np.cos(np.deg2rad(angle)) * wid
    MiroAPI.add_boxShape(MiroSystem,
                         thick,
                         height,
                         wid,
                         p,
                         'MITentrance.png',
                         rotY=-angle,
                         color=[0.02, 0.1, 0.01])

    p[0] = p[0] + np.sin(np.deg2rad(angle)) * wid + 2 * (l + 0.03 + thick / 2)
    MiroAPI.add_boxShape(MiroSystem,
                         thick,
                         height,
                         wid,
                         p,
                         'MITentrance.png',
                         rotY=angle,
                         color=[0.02, 0.1, 0.01])

    p[2] = p[2] - np.cos(np.deg2rad(angle)) * wid
    MiroAPI.add_boxShape(MiroSystem,
                         thick,
                         height,
                         wid,
                         p,
                         'MITentrance.png',
                         rotY=-angle,
                         color=[0.02, 0.1, 0.01])