Skip to content
Snippets Groups Projects
walkingRobot.jl 8.49 KiB
Newer Older
  • Learn to ignore specific revisions
  • Amira Abdel-Rahman's avatar
    Amira Abdel-Rahman committed
    # Amira Abdel-Rahman
    # (c) Massachusetts Institute of Technology 2020
    
    ######################### 1. Voxel Design ###########################
    setup = Dict()
    
    ### 1.b Draw Lattice
    
    rhino=false
    
    voxelSize=0.001
    latticeSizeX=2
    latticeSizeY=8
    latticeSizeZ=5
    
    gridSize=10
    
    setup["gridSize"]=gridSize
    
    setup["rhino"]=false
    setup["useVoxelList"]=true
    
    
    setup["latticeSizeX"]=latticeSizeX
    setup["latticeSizeY"]=latticeSizeY
    setup["latticeSizeZ"]=latticeSizeZ
    
    ######################### 2. Boundary Conditions #########################
    
    ######################### 2.a. Global Settings #########################
    
    #scaling params
    setup["voxelSize"]=voxelSize; #voxel size
    setup["scale"]=1e4; #scale for visualization
    setup["hierarchical"]=true; #hierachical simualtion
    
    
    #simulation params
    setup["numTimeSteps"]=30000; #num of saved timesteps for simulation
    
    setup["poisson"]=false; # account for poisson ration (only for hierarchical)
    setup["linear"]=true; # linear vs non-linear
    setup["thermal"]=true; #if there is change in temperature
    setup["globalDamping"]=0.15; # (usually from 0.1 to 0.4)
    
    
    #visualization params
    setup["maxNumFiles"]=200; #num of saved timesteps for visualization
    
    
    
    
    
    ######################### 2.b. Materials #########################
    
    #default material
    material1= Dict()
    material1["area"]=voxelSize*voxelSize
    material1["density"]=50
    material1["stiffness"]=1e6
    material1["poissonRatio"]=0.0
    material1["cTE"]=0.0 #coefficient of thermal expansion
    
    #large bounding box for default material
    boundingBoxMaterial1=Dict()
    boundingBoxMaterial1["min"]=Dict()
    boundingBoxMaterial1["max"]=Dict()
    
    boundingBoxMaterial1["min"]["x"]=-voxelSize*gridSize;
    boundingBoxMaterial1["min"]["y"]=-voxelSize*gridSize;
    boundingBoxMaterial1["min"]["z"]=-voxelSize*gridSize;
    
    boundingBoxMaterial1["max"]["x"]= voxelSize*gridSize;
    boundingBoxMaterial1["max"]["y"]= voxelSize*gridSize;
    boundingBoxMaterial1["max"]["z"]= voxelSize*gridSize;
    
    #second material
    material2= Dict()
    material2["area"]=voxelSize*voxelSize
    material2["density"]=50
    material2["stiffness"]=1e6
    material2["poissonRatio"]=0.0
    material2["cTE"]=0.1 #coefficient of thermal expansion
    
    #bounding box material 2
    boundingBoxMaterial2=Dict()
    boundingBoxMaterial2["min"]=Dict()
    boundingBoxMaterial2["max"]=Dict()
    
    
    boundingBoxMaterial2["min"]["x"]=voxelSize;
    boundingBoxMaterial2["min"]["y"]=0;
    boundingBoxMaterial2["min"]["z"]=0;
    
    boundingBoxMaterial2["max"]["x"]= voxelSize*(latticeSizeX);
    boundingBoxMaterial2["max"]["y"]= voxelSize*((latticeSizeY-1)/2);
    boundingBoxMaterial2["max"]["z"]= voxelSize*(latticeSizeZ);
    
    
    #third material
    material3= Dict()
    material3["area"]=voxelSize*voxelSize
    material3["density"]=50
    material3["stiffness"]=1e6
    material3["poissonRatio"]=0.0
    material3["cTE"]=0.2 #coefficient of thermal expansion
    
    #bounding box material 3
    boundingBoxMaterial3=Dict()
    boundingBoxMaterial3["min"]=Dict()
    boundingBoxMaterial3["max"]=Dict()
    
    
    boundingBoxMaterial3["min"]["x"]=0;
    boundingBoxMaterial3["min"]["y"]=voxelSize*((latticeSizeY-1)/2);
    boundingBoxMaterial3["min"]["z"]=0;
    
    boundingBoxMaterial3["max"]["x"]= voxelSize;
    boundingBoxMaterial3["max"]["y"]= voxelSize*(latticeSizeY);
    boundingBoxMaterial3["max"]["z"]= voxelSize*(latticeSizeZ);
    
    
    setup["materials"]=[
        # [boundingBoxMaterial1,material1],
        # [boundingBoxMaterial2,material2],
        # [boundingBoxMaterial3,material3]
    
    ];
    
    
    #//allowed x, yand z are from -gridSize to +gridSize (floor is at 0)
    setup["voxelList"]=[
    
        [[0,7,0],material1],#top
        [[1,7,0],material1],#top
        [[0,7,1],material1],#top
        [[1,7,1],material1],#top
        [[0,7,2],material1],#top
        [[1,7,2],material1],#top
        [[0,7,3],material1],#top
        [[1,7,3],material1],#top
        [[0,7,4],material1],#top
        [[1,7,4],material1],#top
    
        [[0,6,0],material1],#top
        [[1,6,0],material1],#top
        [[0,6,1],material1],#top
        [[1,6,1],material1],#top
        [[0,6,2],material1],#top
        [[1,6,2],material1],#top
        [[0,6,3],material1],#top
        [[1,6,3],material1],#top
        [[0,6,4],material1],#top
        [[1,6,4],material1],#top
    
        [[0,5,0],material2],#leg1
        [[1,5,0],material1],#leg1
        [[0,5,1],material2],#leg1
        [[1,5,1],material1],#leg1
    
        [[0,5,3],material1],#leg2
        [[1,5,3],material2],#leg2
        [[0,5,4],material1],#leg2
        [[1,5,4],material2],#leg2
    
    
        [[0,4,0],material2],#leg1
        [[1,4,0],material1],#leg1
        [[0,4,1],material2],#leg1
        [[1,4,1],material1],#leg1
    
        [[0,4,3],material1],#leg2
        [[1,4,3],material2],#leg2
        [[0,4,4],material1],#leg2
        [[1,4,4],material2],#leg2
    
    
        [[0,3,0],material2],#leg1
        [[1,3,0],material1],#leg1
        [[0,3,1],material2],#leg1
        [[1,3,1],material1],#leg1
    
        [[0,3,3],material1],#leg2
        [[1,3,3],material2],#leg2
        [[0,3,4],material1],#leg2
        [[1,3,4],material2],#leg2
    
    
        [[0,2,0],material1],#leg1
        [[1,2,0],material2],#leg1
        [[0,2,1],material1],#leg1
        [[1,2,1],material2],#leg1
    
        [[0,2,3],material2],#leg2
        [[1,2,3],material1],#leg2
        [[0,2,4],material2],#leg2
        [[1,2,4],material1],#leg2
        
    
        [[0,1,0],material1],#leg1
        [[1,1,0],material2],#leg1
        [[0,1,1],material1],#leg1
        [[1,1,1],material2],#leg1
    
        [[0,1,3],material2],#leg2
        [[1,1,3],material1],#leg2
        [[0,1,4],material2],#leg2
        [[1,1,4],material1],#leg2
    
    
        [[0,0,0],material1],#leg1
        [[1,0,0],material2],#leg1
        [[0,0,1],material1],#leg1
        [[1,0,1],material2],#leg1
    
        [[0,0,3],material2],#leg2
        [[1,0,3],material1],#leg2
        [[0,0,4],material2],#leg2
        [[1,0,4],material1],#leg2
            
    
    
            
    ];
    ######################### 2.c. Supports #########################
    
    #x,y,z,rx,ry,rz (default is pinned joing i.e [false,false,false,true,true,true])
    dof=[true,true,true,true,true,true]
    
    boundingBoxSupport1=Dict()
    boundingBoxSupport1["min"]=Dict()
    boundingBoxSupport1["max"]=Dict()
    
    
    boundingBoxSupport1["min"]["x"]=0;
    boundingBoxSupport1["min"]["y"]=voxelSize*(latticeSizeY-2);
    boundingBoxSupport1["min"]["z"]=0;
    
    boundingBoxSupport1["max"]["x"]=voxelSize*(latticeSizeX);
    boundingBoxSupport1["max"]["y"]=voxelSize*(latticeSizeY);
    boundingBoxSupport1["max"]["z"]=voxelSize*(latticeSizeZ);
    
    setup["supports"]=[
            [boundingBoxSupport1,dof]
        ];
    
    ######################### 2.d. Loads #########################
    #### 2.d.1 Static Loads
    load1=Dict()
    load1["x"]=0.0
    load1["y"]=0.0
    load1["z"]=0.0
    
    boundingBoxLoad1=Dict()
    boundingBoxLoad1["min"]=Dict()
    boundingBoxLoad1["max"]=Dict()
    
    boundingBoxLoad1["min"]["x"]=0
    boundingBoxLoad1["min"]["y"]=voxelSize*(latticeSizeY-1);
    boundingBoxLoad1["min"]["z"]=0;
    
    boundingBoxLoad1["max"]["x"]=voxelSize*(latticeSizeX);
    boundingBoxLoad1["max"]["y"]=voxelSize*(latticeSizeY);
    boundingBoxLoad1["max"]["z"]=voxelSize*(latticeSizeZ);
    
    
    setup["loads"]=[
            # [boundingBoxLoad1,load1]
        ];
    
    setup["fixedDisplacements"]=[];
    #### 2.d.2 Dynamic Loads
    function floorEnabled()
        return false
    end
    
    function gravityEnabled()
        return false
    end
    
    function externalDisplacement(currentTimeStep,N_position,N_fixedDisplacement)
        return N_fixedDisplacement
    end
    
    function externalForce(currentTimeStep,N_position,N_force)
        if currentTimeStep>1000
            return Vector3(0,0,0)
        else
            return N_force
        end
    end
    
    # if no temperature:
    # function updateTemperature(currentRestLength,currentTimeStep,mat)
    #     return currentRestLength
    # end
    
    # function updateTemperature(currentRestLength,currentTimeStep,mat)
    #     if currentTimeStep<1000
    #         temp=-5.0*currentTimeStep/1000
    #         currentRestLength=0.5*mat.L*(2.0+temp*mat.cTE)
    #     elseif currentTimeStep==2500
    #         temp=0
    #         currentRestLength=0.5*mat.L*(2.0+temp*mat.cTE)
    #     end
    #     return currentRestLength
    # end
    
    
    function updateTemperature(currentRestLength,currentTimeStep,mat)
        cte=mat.cTE
        factor=0.4;
        t=floor(currentTimeStep/2000)
        t1=currentTimeStep-t*2000
        if currentTimeStep<1000
            if (cte>0.01)
                currentRestLength=mat.L-factor*mat.L*(t1/1000.0);
            else
                currentRestLength=mat.L-factor*mat.L*(1.0-(t1)/1000.0);
            end
        elseif currentTimeStep<2000
            if (cte>0.01)
                currentRestLength=mat.L-factor*mat.L*(1.0-(currentTimeStep-1000.0)/1000.0);
            else
                currentRestLength=mat.L-factor*mat.L*((currentTimeStep-1000.0)/1000.0);
            end
        elseif t%2.0!=0.0
            if (cte<0.01)
                currentRestLength=mat.L-factor*mat.L*(1.0-(t1)/2000.0);
            else
                currentRestLength=mat.L-factor*mat.L*((t1)/2000.0);
            end
        else
            if (cte>0.01)
                currentRestLength=mat.L-factor*mat.L*(1.0-(t1)/2000.0);
            else
                currentRestLength=mat.L-factor*mat.L*((t1)/2000.0);
            end
        end
        return currentRestLength
    end