Matlab animation simulation for Simple Harmonic System

1 visualización (últimos 30 días)
Faryal Tariq
Faryal Tariq el 23 de Mayo de 2015
Comentada: Ognjen el 27 de Mayo de 2015
I have this Matlab project for relation between SHM and the motion of a wheel but I don't quite understand the question. Can anyone please read the details below and explain to me what exactly has to be done and whats's the mechanism of the figure below.
a spring, a weight and a driving wheel that converts rotational to linear motion in the vertical plane. As the wheel rotates, a pin engages a horizontal slotted bar to which the spring and weight are attached. The position of the pin in either X or Y directions as a function of time or angle is a sinusoid. Depending on the characteristics of the spring plus the mass of the weight and the rotational frequency, the weight will follow the driving motion up and down, but with potentially different relative amplitude and phase. Write a Matlab function shm (with a nested sub function and optional additional function files) to generate and animate a wheel/bar/spring/weight configuration over at least a full cycle. The function accepts just two parameters: the relative amplitude of the oscillation and the phase of the oscillation in degrees (by how much the weight movement is delayed relative to the top of the spring). Amplitude can range from 0 to 2, phase from -180 degrees to +180 degrees, all limits inclusive. It should then follow these steps: 1. If the data is invalid, use the error function to report the problem (it also stops the function). 2. Generate 360 equally spaced 1-degree values starting at 0. This assignment uses mathematical angles but in degrees, not radians. 3. Calculate the positions of the pin on the wheel, the top of the spring and the bottom of the spring. Assume at zero degrees the pin is at its rightmost position. The bottom spring position (or top of the weight) is calculated by imagining there is a second wheel at the bottom of the spring. The wheel's radius is scaled by the amplitude and lags by the phase angle (you may have to think about this a bit).
To calculate absolute positions you'll need to plan the figure layout, assuming the origin is the bottom left of the drawing window. The table below has suggested ranges for the dimensions of the various objects. Units are in pixels. The Matlab functions sind and cosd will be handy.
These positions are of course vectors. The spring cannot be compressed to less than 15% of its resting length (a problem parameter). 4. Use the supplied newfigs function to create two figure windows. References to them are returned as a 2-element array so you can activate each as needed. The first has dimensions as specified, and is the main display and animation (or drawing) window. The second is a default plot window. The windows are reused when you rerun the program (as you will many times during testing). 5. Plot the positions of the top and bottom spring positions and the spring length against theta. That's three plots on the same axes, labelled. To activate a figure, issue the command/statement figure(fig); % fig is one of the two figure handles returned by newfig. 6. Activate the drawing window and create each of the four graphical objects in their resting position, using the supplied functions pinwheel, slottedbar, spring and weight. The function definitions tell you what the parameters mean. They give you some control over sizes and appearance. 7. In a subfunction called at this point, write the labelled amplitude and phase on the display window, using the supplied showtext function. This part and the next should be defined in a nested subfunction to keep detail out of the main function. Nested functions can use problem parameters etc from the main function. You should use the sprintf function to format the numbers. 8. (This is Part B and can be written last, but it's part of the nested function.) Calculate the spring stiffness and damper coefficient (using a function defined in a separate file) and display them on the window. 9. Animate the system using the precalculated object positions. The available functions are rotatewheel, moveslottedbar, movespring and moveweight. The file rollingwheel.m contains a sample animation that demonstrates the use of newfigs, some drawing elements and the global variable ANIM_RUNNING to maintain the animation, except that positions are calculated during the animation rather than being stored in vectors. This is the only loop in the assignment, and it's not very complicated once you understand how animation of this kind works.
  1 comentario
Ognjen
Ognjen el 27 de Mayo de 2015
Hello!
If you are still looking to solve this question, I can help you with some pointers. Since this is obviously a school assignment, I would rather not write it here, but if you leave an email I am sure I can get you started with some explanations.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by