EMT 1220 

HW1A-1C

GIF LINK: https://grabcad.com/library/crank-shaft-animation-1

Exp _1 - Slider Crank Mechanism (1).pdf
EMT-1220 lab1 - Report.pdf

https://mechanics.stackexchange.com/questions/32668/whats-gonna-happen-if-i-disconnect-single-piston

Lab 1 in EMT 1220 involved an in-depth study of the Slider-Crank Mechanism, focusing on its transformation of uniform rotational motion into linear reciprocating motion. The primary objective was to understand and analyze this mechanical system both theoretically and through simulation. The lab was structured into several key parts: the first part involved using an online simulator to visualize and measure the motion of the crank and slider, specifically determining the stroke (maximum displacement) and its relationship to the crank length. The second part required plotting the crank angle against the slider displacement, followed by an analysis of the data to identify where the slider reaches maximum and minimum velocities and accelerations. Key goals included verifying the theoretical relationship between crank length and stroke, accurately plotting motion curves, and understanding the dynamic behavior of the slider-crank mechanism. This lab provided practical insights into the physics of mechanical linkages, essential for applications in engineering design and analysis. 


1 5 0A 2 B1 EMT 1220 HW _1A, _B, _C Student Version (18 Pages) PDF 02_06_2024 08_21_2021 01_25_2024.pdf
EMT-1220 _ HW 1A-1C .pdf

code to my crank animation

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Slider Crank Mechanism with Two Configurations</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>

    <style>

        body {

            display: flex;

            flex-direction: column;

            align-items: center;

            justify-content: center;

            height: 100vh;

            margin: 0;

            background-color: #f0f0f0;

            font-family: Arial, sans-serif;

        }

        #slider-crank-container {

            border: 2px solid #333;

            background-color: #fff;

            margin-bottom: 20px;

        }

        table {

            border-collapse: collapse;

            width: 80%;

            margin-top: 20px;

        }

        table, th, td {

            border: 1px solid black;

        }

        th, td {

            padding: 8px;

            text-align: center;

        }

        th {

            background-color: #333;

            color: white;

        }

        footer {

            margin-top: 20px;

            text-align: center; 

            font-size: 14px;

            color: #333;

        }

    </style>

</head>

<body>

    <h1>Slider Crank Mechanism with Two Configurations</h1>

    <div id="slider-crank-container"></div>


    <table>

        <thead>

            <tr>

                <th>Configuration</th>

                <th>Crank Length</th>

                <th>Coupler Length</th>

                <th>Stroke (Max Displacement)</th>

                <th>Crank Angle (Degrees)</th>

                <th>Current Displacement</th>

            </tr>

        </thead>

        <tbody>

            <tr>

                <td>Configuration 1</td>

                <td id="crank-length-1">100</td>

                <td id="coupler-length-1">150</td>

                <td id="stroke-1"></td>

                <td id="crank-angle-1"></td>

                <td id="displacement-1"></td>

            </tr>

            <tr>

                <td>Configuration 2</td>

                <td id="crank-length-2">75</td>

                <td id="coupler-length-2">100</td>

                <td id="stroke-2"></td>

                <td id="crank-angle-2"></td>

                <td id="displacement-2"></td>

            </tr>

        </tbody>

    </table>


    <footer>

        <p>Made by Ramses Suarez Valerio | Student ID: 24070499<p>

        <p>Little creative version using Pokémon gifs wanted to test out IMG and gifs implementation to my code<p>

    </footer>


    <script>

        let angle = 0;

        let crankLength1 = 100; // Crank length in pixels for the first configuration

        let couplerLength1 = 150; // Coupler length in pixels for the first configuration

        let crankLength2 = 75; // Crank length in pixels for the second configuration

        let couplerLength2 = 100; // Coupler length in pixels for the second configuration


        // Variables to hold images

        let crankImage;

        let sliderImage;

        let originImage;

        let backgroundImage;


        function preload() {

            // Load the images

            crankImage = loadImage('https://i.imgur.com/VkmBAju.gif'); // Sitting Pikachu for the crank

            sliderImage = loadImage('https://i.imgur.com/cQVI8T1.gif'); // Running Pikachu for the slider

            originImage = loadImage('https://i.imgur.com/0vgE76I.gif'); // Image for the origin

            backgroundImage = loadImage('https://i.imgur.com/qBYTd4a.jpg'); // Background image

        }


        function setup() {

            let canvas = createCanvas(800, 400);

            canvas.parent('slider-crank-container');

            calculateStrokes();

        }


        function draw() {

            // Draw the background image

            if (backgroundImage) {

                background(backgroundImage);

            } else {

                background(255);

            }


            // Draw both slider-crank mechanisms

            drawSliderCrank(crankLength1, couplerLength1, width / 4, height / 2, '1');  // First mechanism

            drawSliderCrank(crankLength2, couplerLength2, (3 * width) / 4, height / 2, '2');  // Second mechanism


            updateAngle();

        }


        function drawSliderCrank(crankLength, couplerLength, pivotX, pivotY, config) {

            stroke(0);

            strokeWeight(4);


            // Draw the origin image at the pivot

            image(originImage, pivotX - 20, pivotY - 20, 40, 40);  // The origin image stays centered at pivot


            // Crank movement (sitting Pikachu spinning clockwise)

            let crankEndX = pivotX + crankLength * cos(angle);

            let crankEndY = pivotY + crankLength * sin(angle);


            // Slider movement (horizontal displacement)

            let sliderPosX = crankEndX + sqrt(sq(couplerLength) - sq(crankEndY - pivotY));


            // Draw line for the crank

            line(pivotX, pivotY, crankEndX, crankEndY);


            // Adjust crank image to center it on the crank end point

            image(crankImage, crankEndX - 20, crankEndY - 20, 40, 40);  // Adjust crank image to be centered on the crank end


            // Draw line for the coupler

            line(crankEndX, crankEndY, sliderPosX, pivotY);


            // Adjust slider image to be centered on the slider point

            image(sliderImage, sliderPosX - 20, pivotY - 20, 40, 40);  // Adjust slider image to be centered


            // Update table with current values

            document.getElementById(`crank-angle-${config}`).textContent = degrees(angle).toFixed(2);

            document.getElementById(`displacement-${config}`).textContent = (sliderPosX - pivotX).toFixed(2);

        }


        function calculateStrokes() {

            // Stroke is calculated as twice the crank length

            let stroke1 = 2 * crankLength1;

            let stroke2 = 2 * crankLength2;


            document.getElementById('stroke-1').textContent = stroke1;

            document.getElementById('stroke-2').textContent = stroke2;

        }


        function updateAngle() {

            // Update angle for crank rotation

            angle += 0.05;


            // Reset angle if it completes a full rotation

            if (angle >= TWO_PI) {

                angle = 0;

            }

        }

    </script>

</body>

</html>