4-bar mechanism

6 messages
Open this post in threaded view
|

4-bar mechanism

This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hi everyone,

I am coding a program to simulate

4-bar mechanisms

, I am using a Function to generate a vector of 6 elements, this vector[6] has the input parameter for a module named "buildLink"  (the module buildLink has these input variables (posZ, posX, posY, slope_in_degrees, length_of_Link, thickness_of_link) ),   however: while I am trying to generate the Coupler and its inclination slope  in degrees, the variables are not working, I have tried using assign, I have used nested functions, nested modules, and nothing sems to be working. SO,, Would somebody like to take a look to my code, and give me a little tiny hint?

```/////  Mechanism Settings -- Crank-Rocker -----
m=0; angle =0;

posX_fixed_crank=10;
posY_fixed_crank=10;
crank=30;
thickness_crank=5;

posX_fixed_rocker= 90;
posY_fixed_rocker= 10;
rocker=50;
thickness_rocker=7;

coupler=70;
thickness_coupler=6;

slope=0;

///////////////////////////////////

//function computeSomeVariables(t) = [
//    2*coupler*(crank*sin(360*t)-sin(360*t)),  			   // E

///////////////////////////////////////////////////
//       Grashoff	 Condition			 							 ///
//            S + L <= P + Q										///
///////////////////////////////////////////////////

function turningCrank(t) =
[ 0,
posY_fixed_crank,
posX_fixed_crank,
360*t+30.134,    // Crank start at 30.134 degrees until 210.134 degrees
crank,           //  so rocker goes from right to left
thickness_crank ]
;

function bouncingRocker(t) =
[0,
posX_fixed_rocker,
posY_fixed_rocker,
2*tan(
)
)
-sqrt(
)
)
/
)
)
),
// computing inclination of coupler
//				  2*tan(
//								(-B-sqrt(
//												pow(A,2)+pow(B,2)-pow(C,2)
//												)
//								)
//									/
//								(C-A))
//						  ),
rocker,
thickness_rocker ];

function movingCoupler(t) =
[ thickness_crank/2,                           		// posZ
cos(360*t+30.134) * crank + posX_fixed_crank,  // posX
sin(360*t+30.134) * crank + posY_fixed_crank,  // posY

2*tan((-(2*coupler*(crank*sin(360*t+30.134)-sin(360*t)
)
)+
sqrt(
pow(
)
),2)
+pow((2*coupler*(crank*sin(360*t+30.134)-sin(360*t+30.134+30.134)
)
),2)
)
),2)
)
)
/
(
)
)
-(2*coupler*(crank*cos(360*t+30.134)
)
)
)
),

//  computing inclination of rocker
//				    2*tan(
//									 (-E+sqrt(
//													  pow(D,2)+pow(E,2)-pow(F,2)
//													 )
//									 )
//									/
//									(F-D)
// 								 )

coupler,
thickness_coupler];

parameterCrank = turningCrank(\$t);
color("red")
parameterCrank[0],
parameterCrank[1],
parameterCrank[2],
parameterCrank[3],
parameterCrank[4],
parameterCrank[5]
);

parameterRocker = bouncingRocker(\$t);
color("blue")
parameterRocker[0],
parameterRocker[1],
parameterRocker[2],
parameterRocker[3],
parameterRocker[4],
parameterRocker[5]
);

parameterCoupler = movingCoupler(\$t);
color("green")
parameterCoupler[0],
parameterCoupler[1],
parameterCoupler[2],
parameterCoupler[3],
parameterCoupler[4],
parameterCoupler[5]
);

///////////    Module to Build a LINK ////////////
posX,
posY,
posZ,
inclinationDegrees,
thickness
)

translate([posX,posY,posZ])
{
rotate(inclinationDegrees,[1,0,0])
difference()
{
union()
{
rotate(0,[1,0,0])
translate([posX, -1, 0])
rotate(90,[0,1,0])
rotate(90,[0,1,0])
}
union()
{
translate([posX, 0, 0])
rotate(90,[0,1,0])
cylinder(r = radiusPin,  h = thickness+1+1, center = true);

rotate(90,[0,1,0])
cylinder(r = radiusPin,  h = thickness+1+1, center = true);
} // closing second union()
}    // closing the difference()
}		  // closing first translate()

```
Open this post in threaded view
|

Re: 4-bar mechanism

Welcome to the forum. Your post is still flagged as "This post has NOT been accepted by the mailing list yet", so nobody gets it unless they look.
You need to subscribe to the mailing list, and CLICK THE LINK in the registration email.

Hi everyone,

I am coding a program to simulate

4-bar mechanisms

, I am using a Function to generate a vector of 6 elements, this vector[6] has the input parameter for a module named "buildLink"  (the module buildLink has these input variables (posZ, posX, posY, slope_in_degrees, length_of_Link, thickness_of_link) ),   however: while I am trying to generate the Coupler and its inclination slope  in degrees, the variables are not working, I have tried using assign, I have used nested functions, nested modules, and nothing sems to be working. SO,, Would somebody like to take a look to my code, and give me a little tiny hint?

```/////  Mechanism Settings -- Crank-Rocker -----
m=0; angle =0;

posX_fixed_crank=10;
posY_fixed_crank=10;
crank=30;
thickness_crank=5;

posX_fixed_rocker= 90;
posY_fixed_rocker= 10;
rocker=50;
thickness_rocker=7;

coupler=70;
thickness_coupler=6;

slope=0;

///////////////////////////////////

//function computeSomeVariables(t) = [
//    2*coupler*(crank*sin(360*t)-sin(360*t)),  			   // E

///////////////////////////////////////////////////
//       Grashoff	 Condition			 							 ///
//            S + L <= P + Q										///
///////////////////////////////////////////////////

function turningCrank(t) =
[ 0,
posY_fixed_crank,
posX_fixed_crank,
360*t+30.134,    // Crank start at 30.134 degrees until 210.134 degrees
crank,           //  so rocker goes from right to left
thickness_crank ]
;

function bouncingRocker(t) =
[0,
posX_fixed_rocker,
posY_fixed_rocker,
2*tan(
)
)
-sqrt(
)
)
/
)
)
),
// computing inclination of coupler
//				  2*tan(
//								(-B-sqrt(
//												pow(A,2)+pow(B,2)-pow(C,2)
//												)
//								)
//									/
//								(C-A))
//						  ),
rocker,
thickness_rocker ];

function movingCoupler(t) =
[ thickness_crank/2,                           		// posZ
cos(360*t+30.134) * crank + posX_fixed_crank,  // posX
sin(360*t+30.134) * crank + posY_fixed_crank,  // posY

2*tan((-(2*coupler*(crank*sin(360*t+30.134)-sin(360*t)
)
)+
sqrt(
pow(
)
),2)
+pow((2*coupler*(crank*sin(360*t+30.134)-sin(360*t+30.134+30.134)
)
),2)
)
),2)
)
)
/
(
)
)
-(2*coupler*(crank*cos(360*t+30.134)
)
)
)
),

//  computing inclination of rocker
//				    2*tan(
//									 (-E+sqrt(
//													  pow(D,2)+pow(E,2)-pow(F,2)
//													 )
//									 )
//									/
//									(F-D)
// 								 )

coupler,
thickness_coupler];

parameterCrank = turningCrank(\$t);
color("red")
parameterCrank[0],
parameterCrank[1],
parameterCrank[2],
parameterCrank[3],
parameterCrank[4],
parameterCrank[5]
);

parameterRocker = bouncingRocker(\$t);
color("blue")
parameterRocker[0],
parameterRocker[1],
parameterRocker[2],
parameterRocker[3],
parameterRocker[4],
parameterRocker[5]
);

parameterCoupler = movingCoupler(\$t);
color("green")
parameterCoupler[0],
parameterCoupler[1],
parameterCoupler[2],
parameterCoupler[3],
parameterCoupler[4],
parameterCoupler[5]
);

///////////    Module to Build a LINK ////////////
posX,
posY,
posZ,
inclinationDegrees,
thickness
)

translate([posX,posY,posZ])
{
rotate(inclinationDegrees,[1,0,0])
difference()
{
union()
{
rotate(0,[1,0,0])
translate([posX, -1, 0])
rotate(90,[0,1,0])
rotate(90,[0,1,0])
}
union()
{
translate([posX, 0, 0])
rotate(90,[0,1,0])
cylinder(r = radiusPin,  h = thickness+1+1, center = true);

rotate(90,[0,1,0])
cylinder(r = radiusPin,  h = thickness+1+1, center = true);
} // closing second union()
}    // closing the difference()
}		  // closing first translate()

```
Which variables are not working?
Admin - PM me if you need anything,
or if I've done something stupid...

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Open this post in threaded view
|

Re: 4-bar mechanism

 In reply to this post by texada For most values of \$t, your bouncingRocker function is returning a nan in the 4th position, the inclinationDegrees. Echo it to see. For those values of \$t, the argument of sqrt is negative.
Open this post in threaded view
|

Re: 4-bar mechanism

 This post has NOT been accepted by the mailing list yet. Oh my God, so you mean the issue could be fixed using an Absolute function, am I right?