求曲柄滑块机构的matlab程序,已知杆长以及滑块行程,要优化一下各个参数,好的话会另外加分

求曲柄滑块机构的matlab程序,已知杆长以及滑块行程,要优化一下各个参数,好的话会另外加分,第1张

%Matlab仿真程序如下:

r1=36 %单位mm

r2=140

omiga1=60%单位d/sec

x11=1:720

for i=1:720

x1(i)=i*pi/180

%sin(x2(i))=-r1/r2*sin(x1(i))

x2(i)=asin(-r1/r2*sin(x1(i)))

x22(i)=x2(i)*180/pi

r3(i)=r1*cos(x1(i))+r2*cos(x2(i))

B=[-r1*omiga1*sin(x1(i))

r1*omiga1*cos(x1(i))]

A=[r2*sin(x2(i)) 1-r2*cos(x2(i)) 0] X=inv(A)*B

omiga2(i)=X(1,1)

v3(i)=X(2,1)

end

plot(x11/60,0.5*r1*sin(x1))

xlabel('时间 t/sec')

ylabel('连杆质心在Y轴上位置/mm')

figure(2)

plot(x11/60,r3)

xlabel('时间 t/sec')

ylabel('滑块位移r3/mm')

figure(3)

plot(x11/60,omiga2)

xlabel('时间 t/sec')

ylabel('连杆角速度omiga2/rad/sec')

figure(4)

plot(x11/60,v3*pi/180)

xlabel('时间 t/sec')

ylabel('滑块速度v3/mm/sec')

'新建窗体,添加command1,label1,hscroll1,timer1,picture1

Const

pi

=

3.1415926

Dim

angle

As

Integer

Private

Sub

Form_Load()

'调整空间尺寸,位置及初始参数

Me.ScaleMode

=

3

Me.Caption

=

"曲柄滑块机构的演示"

Me.Width

=

5000

Me.Height

=

3500

Picture1.ScaleMode

=

3

Picture1.AutoRedraw

=

True

Picture1.Move

0,

0,

Me.ScaleWidth,

150

Command1.Caption

=

"开始(&B)"

Command1.Move

20,

160,

70,

30

Label1.Caption

=

"速度:"

Label1.Move

120,

170,

100,

30

HScroll1.Min

=

1

HScroll1.Max

=

20

HScroll1.Move

160,

160,

140,

30

Timer1.Interval

=

20

Timer1.Enabled

=

False

End

Sub

Private

Sub

Command1_Click()

Timer1.Enabled

=

Not

Timer1.Enabled

If

Timer1.Enabled

Then

Command1.Caption

=

"暂停(&S)"

Else

Command1.Caption

=

"开始(&B)"

End

If

End

Sub

Sub

draw(ByVal

ox

As

Integer,

ByVal

oy

As

Integer,

ByVal

orad

As

Integer)

'ox,oy圆心坐标,orad半径

angle

=

(angle

+

HScroll1.Value)

Mod

360

xo

=

ox

+

orad

*

Cos(angle

*

pi

/

180)

'圆周上的铰链点坐标(xo,yo)

yo

=

oy

+

orad

*

Sin(angle

*

pi

/

180)

xs

=

Sqr((4

*

orad)

^

2

-

10

^

2)

+

xo

'滑块的左边界x坐标,连杆长度取4*orad,滑块高度取20(像素)

Picture1.BackColor

=

Picture1.BackColor

Picture1.DrawStyle

=

0

'实线

Picture1.DrawWidth

=

2

'线宽2

Picture1.Line

(ox

+

2

*

orad,

oy)-(ox

+

6

*

orad,

oy)

'壁面

Picture1.Line

(ox,

oy)-(xo,

yo)

'连接圆心与圆周上的铰链点

Picture1.Line

(xs,

oy

-

10)-(xo,

yo),

vbBlue

'连接滑块与圆周上的铰链点

Picture1.FillStyle

=

1

'透明填充

Picture1.Circle

(ox,

oy),

orad

'画圆

Picture1.FillStyle

=

0

'实体填充

Picture1.FillColor

=

vbWhite

'圆心

Picture1.Circle

(ox,

oy),

5

Picture1.FillColor

=

vbGreen

'圆周上的铰链点

Picture1.Circle

(xo,

yo),

4

Picture1.FillColor

=

vbRed

'滑块

Picture1.Line

(xs,

oy

-

20)-(xs

+

30,

oy),

,

B

Picture1.DrawStyle

=

2

'虚线

Picture1.DrawWidth

=

1

'线宽1

For

i

=

0

To

9

'表示壁面的虚线

Picture1.Line

(i

*

4

*

orad

/

10

+

ox

+

2

*

orad,

oy)-(i

*

4

*

orad

/

10

+

ox

+

2

*

orad

+

20,

oy

+

20)

Next

End

Sub

Private

Sub

Timer1_Timer()

'画

draw

60,

60,

40

End

Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12062448.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存