Skip to content
Snippets Groups Projects
Commit dc2f21ec authored by BALDIT Adrien's avatar BALDIT Adrien
Browse files

ab: version 1

parent b0478a05
No related branches found
No related tags found
No related merge requests found
*.xlsx filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
.readme_images/linkage_slider_cranck_mech.png

51.1 KiB

.readme_images/slider-cranck_mechanism.png

692 KiB

This diff is collapsed.
README.md 100644 → 100755
# python_kinematics_app_slider_cranck_mechanism Kinematics application of the slider cranck mechanism developped in python
===============================================================================
The slider cranck mechanism is a classical linkage assembly that transforms a rotational motion into a linear one. It can be found in many systems such as pumps, thermal engines, ...
The mechanism is made of a frame(0), an eccentric (1), a connecting rod (2) and a slider (3) depicted by the following figure:
## Getting started ![image](.readme_images/linkage_slider_cranck_mech.png)
To make it easy for you to get started with GitLab, here's a list of recommended next steps. This application aims to illustrate the kinematics of the mechanism. It replicates a free software that was available on MECAMEDIA but which is not maintained. It also exists a [MatLab version](https://github.com/mahmoudsamhoud/Cranck-Slider-Mechanism-Computational-Dynamics-).
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! This application gives the mechanism configuration as well as position, velocity and acceleration plots of the slider given the position and velocity of the eccentric.
Besides it illustrates some graphical kinematics tools such as trajectories, velocity vectors and equiprojectivity.
## Add your files ![image](.readme_images/slider-cranck_mechanism.png)
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files The application works with python37 and the required packages are: numpy and matplotlib
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
``` Perspectives are to show instantaneous center of rotation as well as their trajectories. The vector representation could also be improved.
cd existing_repo \ No newline at end of file
git remote add origin https://gitlab.univ-lorraine.fr/baldit1/python_kinematics_app_slider_cranck_mechanism.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.univ-lorraine.fr/baldit1/python_kinematics_app_slider_cranck_mechanism/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
# Copyright University of Lorraine - ENIM
# Contributor(s) :
# Adrien Baldit
# Contact: adrien.baldit@univ-lorraine.fr
#
# This script is a computer program whose purpose is to produce
# kinematics mechanics practicals.
#
# This script is governed under French law and abiding by the rules
# of Creative Commons distribution of free script. You can use, modify and/ or
# redistribute the script under the terms of honor
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the honor, users are provided only
# with a limited warranty and the script's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# script by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the script's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have
# had knowledge of the rules and accepted them.
#!/usr/bin/python
# -*- coding:utf8 -*-
import numpy as np
import matplotlib.pyplot as pl
import matplotlib.animation as animation
from matplotlib.widgets import Slider, Button, RadioButtons, CheckButtons
from matplotlib.patches import Rectangle, Arrow
################################
# Matplotlib display parameter #
################################
pl.rc('axes', titlesize=22) # fontsize of the axes title
pl.rc('axes', labelsize=22) # fontsize of the x and y labels
pl.rc('xtick', labelsize=17) # fontsize of the tick labels
pl.rc('ytick', labelsize=17) # fontsize of the tick labels
pl.rc('legend', fontsize=17) # legend fontsize
pl.rc('lines', linewidth=4) # legend fontsize
pl.rc('lines', markersize=10) # legend fontsize
pl.rc('figure', titlesize=18) # fontsize of the figure title
pl.rc('legend',title_fontsize=17)
##############################
# Mechanism input parameters #
##############################
# Geometrical parameters
# connecting rod length
L = 146.0
# initial value
L_init = L
# minimum
L_min = 100.0
# maximum
L_max = 200.0
# crank radius
e = 46.0
# initial value
e_init = e
# minimum
e_min = 30
# maximum
e_max = L_min*0.99
# slider length
s = 40
# initial value
s_init = s
# minimum
s_min = 20
# maximum
s_max = 100
# Kinematics parameters
# Angular position
alpha = 45.*np.pi/180.
# Initial angular position
alpha_init = alpha
# driving angular velocity [tr.min^{-1}]
dotalpha_trmin=750.
# driving angular velocity [rad.s^{-1}]
dotalpha_init=dotalpha_trmin*np.pi/30.
dotalpha=dotalpha_init
dotalpha_min = dotalpha_init*0.01
dotalpha_max = dotalpha_init*2
# Time parameters
# final time for one turn [s]
t_final =2*np.pi/dotalpha
# time sampling [s]
dt = t_final/50.
t_min = 0
t_max = t_final
t_init = 1/3*t_final
###############################
# Functions to compute motion #
###############################
# positions
def positions(e,L,s,dotalpha,t) :
alpha = dotalpha*t
beta = np.arccos(e*np.sin(alpha)/L)
dotbeta = -(e*np.cos(alpha))/(L*np.sin(beta))*dotalpha
ddotbeta = (e*np.sin(alpha)*dotalpha**2.-L*np.cos(beta)*dotbeta**2.)/(L*np.sin(beta))
x1 = e*np.cos(alpha) # x-cooridnate of the crank: Point 1
y1 = e*np.sin(alpha) # y-cooridnate of the crank: Point 1
y2 = 0 # x-coordinate of the rod: Point 2
y3 = 0 # x-coordinate of the rod: Point 2
# y-coordinate of the rod: Point 2
x2 = e*np.cos(alpha) + np.sqrt( L**2 - (e*np.sin(alpha))**2 )
x3 = x2+s
dotx2 = -e*dotalpha*np.sin(alpha)+L*dotbeta*np.cos(beta)
ddotx2 = -e*dotalpha**2*np.cos(alpha)+L*(ddotbeta*np.cos(beta)-dotbeta**2*np.sin(beta))
VBx = -e*dotalpha*np.sin(alpha)
VBy = e*dotalpha*np.cos(alpha)
return x1,y1,x2,y2,x3,y3,alpha,dotx2,ddotx2,VBx,VBy
# Motion
def motion(e,L,s,dotalpha,tmin,tmax,dt) :
list_t = np.arange(tmin,tmax+dt,dt)
list_x1 = []
list_y1 = []
list_x2 = []
list_dotx2 = []
list_ddotx2 = []
list_y2 = []
list_x3 = []
list_y3 = []
list_al = []
for tt in list_t :
x1,y1,x2,y2,x3,y3,alpha,dotx2,ddotx2,VBx,VBy = positions(e=e,L=L,s=s,dotalpha=dotalpha,t=tt)
list_x1.append(x1)
list_y1.append(y1)
list_x2.append(x2)
list_dotx2.append(dotx2)
list_ddotx2.append(ddotx2)
list_y2.append(y2)
list_x3.append(x3)
list_y3.append(y3)
list_al.append(alpha)
return list_t,list_x1,list_y1,list_x2,list_dotx2,list_ddotx2,list_y2,list_x3,list_y3,list_al
# update motion
def update(val):
# reload constant values
t = stinit.val
s = ssinit.val
e = seinit.val
L = sLinit.val
dotalpha = sdotalphainit.val
x1,y1,x2,y2,x3,y3,alpha,dotx2,ddotx2,VBx,VBy = positions(e=e,L=L,s=s,dotalpha=dotalpha,t=t)
list_t,list_x1,list_y1,list_x2,list_dotx2,list_ddotx2,list_y2,list_x3,list_y3,list_al = motion(e=e,L=L,s=s,dotalpha=dotalpha,tmin=t_min,tmax=t_max,dt=dt)
slope=(y2-y1)/(x2-x1)
intercept=y2-slope*x2
slope2 = -1/slope
intercept2 = (y1+Vscale*VBy)-slope2*(x1+VBx*Vscale)
intercept3 = -slope2*(x2+dotx2*Vscale)
xproj1 = (intercept2-intercept)/(slope-slope2)
yproj1 = slope*xproj1+intercept
xproj2 = (intercept3-intercept)/(slope-slope2)
yproj2 = slope*xproj2+intercept
xmin = -2.1*e
xmax = 1.1*(e+L+s)
ymin = -1.5*e
ymax = 1.5*e
ax.set_xlim(xmin,xmax)
ax.set_ylim(ymin,ymax)
ax2.set_xlim(t_min*1e3,t_max*1e3)
ax3.set_xlim(t_min*1e3,t_max*1e3)
ax4.set_xlim(t_min*1e3,t_max*1e3)
ax2.set_ylim(min(list_x2)*0.9e-3,max(list_x2)*1.1e-3)
ax3.set_ylim(min(list_dotx2)*1.1e-3,max(list_dotx2)*1.1e-3)
ax4.set_ylim(min(list_ddotx2)*1.1e-3,max(list_ddotx2)*1.1e-3)
line.set_data([0,x1], [0,y1])
point_p.set_data([t*1e3], [x2*1e-3])
point_v.set_data([t*1e3], [dotx2*1e-3])
point_a.set_data([t*1e3], [ddotx2*1e-3])
line2.set_data([x1,x2], [y1,y2])
line3.set_data([x2,x3], [y2,y3])
pos.set_data(np.array(list_t)*1e3, np.array(list_x2)*1e-3)
vel.set_data(np.array(list_t)*1e3, np.array(list_dotx2)*1e-3)
acc.set_data(np.array(list_t)*1e3, np.array(list_ddotx2)*1e-3)
tauB.set_data(list_x1,list_y1)
tauC.set_data(list_x2,list_y2)
VB2.set_data([x1,x1+Vscale * VBx], [y1,y1+Vscale * VBy])
VC2.set_data([x2,x2+Vscale * dotx2], [y2,y2])
equi1.set_data([xmin,xmax], [slope*xmin+intercept,slope*xmax+intercept])
equi2.set_data([xmin,xmax], [slope2*xmin+intercept2,slope2*xmax+intercept2])
equi3.set_data([xmin,xmax], [slope2*xmin+intercept3,slope2*xmax+intercept3])
equi21.set_data([x1,xproj1], [y1,yproj1])
equi31.set_data([x2,xproj2], [y2,yproj2])
# add on figure
fig2.canvas.draw_idle()
# Updates checking
def func(label):
index = labels.index(label)
lines[index].set_visible(not lines[index].get_visible())
pl.draw()
# reset function
def reset(event):
seinit.reset()
sLinit.reset()
ssinit.reset()
stinit.reset()
sdotalphainit.reset()
#########################
# Computation of motion #
#########################
# Position computation for initial condition
x1,y1,x2,y2,x3,y3,alpha,dotx2,ddotx2,VBx,VBy = positions(e=e,L=L,s=s,dotalpha=dotalpha,t=t_init)
# Motion computation for initial condition
list_t,list_x1,list_y1,list_x2,list_dotx2,list_ddotx2,list_y2,list_x3,list_y3,list_al = motion(e=e,L=L,s=s,dotalpha=dotalpha,tmin=t_min,tmax=t_max,dt=dt)
########################
# Plotting computation #
########################
# Parameters
Vscale = 1e-2
xmin = -2.1*e
xmax = 1.1*(e+L+s)
ymin = -1.75*e
ymax = 1.75*e
# lines definitions
slope=(y2-y1)/(x2-x1)
intercept=y2-slope*x2
slope2 = -1/slope
intercept2 = (y1+Vscale*VBy)-slope2*(x1+VBx*Vscale)
intercept3 = -slope2*(x2+dotx2*Vscale)
# Projections
xproj1 = (intercept2-intercept)/(slope-slope2)
yproj1 = slope*xproj1+intercept
xproj2 = (intercept3-intercept)/(slope-slope2)
yproj2 = slope*xproj2+intercept
########################
# Plotting computation #
########################
# Main figure
fig2 = pl.figure(figsize=(16,8))
fig2.subplots_adjust(left = 0.07, bottom = 0.11, right = 0.96, top = 0.96, wspace = 0.25, hspace = 0.25)
# System as function space
ax = fig2.add_subplot(221, aspect='equal', autoscale_on=False)
ax.set_xlim(xmin,xmax)
ax.set_ylim(ymin,ymax)
ax.grid()
ax.set_xlabel(r"x $[mm]$")
ax.set_ylabel(r"y $[mm]$")
line, = ax.plot([0,x1], [0,y1], 'o-', lw=5, color='red')
line2, = ax.plot([x1,x2], [y1,y2], 'o-', lw=5, color='green')
line3, = ax.plot([x2,x3], [y2,y3], 'o-', lw=5, color='blue')
equi1, = ax.plot([xmin,xmax], [slope*xmin+intercept,slope*xmax+intercept], '--', lw=2, color='black',label="projection line", visible=False)
equi2, = ax.plot([xmin,xmax], [slope2*xmin+intercept2,slope2*xmax+intercept2], '--', lw=2, color='black',label=r"$\vec{V}(B\in2/0)$ projection", visible=False)
equi3, = ax.plot([xmin,xmax], [slope2*xmin+intercept3,slope2*xmax+intercept3], '--', lw=2, color='black',label=r"$\vec{V}(C\in2/0)$ projection", visible=False)
equi21, = ax.plot([x1,xproj1], [y1,yproj1], '-', lw=3, color='cyan',label="equiprojection 1", visible=False)
equi31, = ax.plot([x2,xproj2], [y2,yproj2], '-', lw=3, color='cyan',label="equiprojection 2", visible=False)
tauB, = ax.plot(list_x1,list_y1, '--', lw=2, color='red',label = r"$\tau(B\in1/0)$", visible=False)
tauC, = ax.plot(list_x2,list_y2, '.', lw=2, color='green',label = r"$\tau(C\in3/0)$", visible=False)
VB2, = ax.plot([x1,x1+Vscale * VBx], [y1,y1+Vscale * VBy], '-', lw=2, color='red',marker="4",label=r"$\vec{V}(B\in1/0)$", visible=False)
VC2, = ax.plot([x2,x2+Vscale * dotx2], [y2,y2], '-', lw=2, color='green',marker="4",label=r"$\vec{V}(C\in3/0)$", visible=False)
# Position as function of time
ax2 = fig2.add_subplot(222, xlim=(t_min*1e3,t_max*1e3), ylim=(min(list_x2)*0.9e-3,max(list_x2)*1.1e-3))
ax2.grid('on')
ax2.set_xlabel(r"Time $[ms]$")
ax2.set_ylabel(r"Position $[m]$")
pos, = ax2.plot(np.array(list_t)*1e3,np.array(list_x2)*1e-3, 'b-x', mfc = 'w')
point_p, = ax2.plot([t_init*1e3], [x2*1e-3], 'o', color='red')
# Velocity as function of time
ax3 = fig2.add_subplot(223, xlim=(t_min*1e3,t_max*1e3), ylim=(min(list_dotx2)*1.1e-3,max(list_dotx2)*1.1e-3))
ax3.grid('on')
ax3.set_xlabel(r"Time $[ms]$")
ax3.set_ylabel(r"Velocity $[m.s^{-1}]$")
vel, = ax3.plot(np.array(list_t)*1e3,np.array(list_dotx2)*1e-3, 'b-x', mfc = 'w')
point_v, = ax3.plot([t_init*1e3],[dotx2*1e-3], 'o', color='red')
# Acceleration as function of time
ax4 = fig2.add_subplot(224, xlim=(t_min*1e3,t_max*1e3), ylim=(min(list_ddotx2)*1.1e-3,max(list_ddotx2)*1.1e-3))
ax4.grid('on')
ax4.set_xlabel(r"Time $[ms]$")
ax4.set_ylabel(r"Acceleration $[m.s^{-2}]$")
acc, = ax4.plot(np.array(list_t)*1e3,np.array(list_ddotx2)*1e-3, 'b-x', mfc = 'w')
point_a, = ax4.plot([t_init*1e3],[ddotx2*1e-3], 'o', color='red')
# Control figure
fig = pl.figure(2, figsize=(4,6))
# manipulate remote control
axcolor = 'lightgoldenrodyellow'
# definition of the slider positons and values
spreading=0.4
init_spread = 0.5
# connecting rod length
aLinit = pl.axes([0.25, 0.*spreading+init_spread, 0.6, 0.05], facecolor=axcolor)
sLinit = Slider(aLinit, r'$L\ [mm]$', L_min, L_max, valinit=L_init)
# crank radius
aeinit = pl.axes([0.25, 0.25*spreading+init_spread, 0.6, 0.05], facecolor=axcolor)
seinit = Slider(aeinit, r'$e\ [mm]$', e_min, e_max, valinit=e_init)
# slider length
asinit = pl.axes([0.25, 0.5*spreading+init_spread, 0.6, 0.05], facecolor=axcolor)
ssinit = Slider(asinit, r'$s\ [mm]$', s_min, s_max, valinit=s_init)
# time
atinit = pl.axes([0.25, 0.75*spreading+init_spread, 0.6, 0.05], facecolor=axcolor)
stinit = Slider(atinit, r'$t\ [s]$', t_min, t_max, valinit=t_init)
# angular position
adotalphainit = pl.axes([0.25, 1*spreading+init_spread, 0.6, 0.05], facecolor=axcolor)
sdotalphainit = Slider(adotalphainit, r'$\dot{\alpha}\ [rad/min]$', dotalpha_min, dotalpha_max, valinit=dotalpha_init)
# change slider values
seinit.on_changed(update)
sLinit.on_changed(update)
ssinit.on_changed(update)
stinit.on_changed(update)
sdotalphainit.on_changed(update)
# Make checkbuttons with all plotted lines with correct visibility
rax = pl.axes([0.05, 0.025, 0.6, 0.35])
lines = [tauB,tauC,VB2,VC2,equi1,equi2,equi3,equi21,equi31]
labels = [str(line.get_label()) for line in lines]
visibility = [line.get_visible() for line in lines]
# Check updates on click
check = CheckButtons(rax, labels, visibility)
check.on_clicked(func)
# reset
# button
resetax = pl.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
# function
button.on_clicked(reset)
# Show figures
pl.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment