4-bar mechanism

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

4-bar mechanism

texada
This post has NOT been accepted by the mailing list yet.
This post was updated on .
4Bar_Crank_Rocker_Ver_3.scad
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 -----
radiusPin = 2;  radiusLink = 4;
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;
 
groundedLink=80;
slope=0;

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


//function computeSomeVariables(t) = [ 
//    2*rocker*(groundedLink*cos(0)-crank*cos(360*t)),      // A
//    2*rocker*(groundedLink*sin(0)-crank*sin(360*t)),     // B
//    pow(groundedLink,2)+pow(crank,2)-pow(coupler,2)+pow(rocker,2)-2*(groundedLink*crank*cos(-360*t)), 							         											// C
//    2*coupler*(crank*cos(360*t)-groundedLink*cos(0)),  // D
//    2*coupler*(crank*sin(360*t)-sin(360*t)),  			   // E
//    pow(groundedLink,2)+pow(crank,2)+pow(coupler,2)-pow(rocker,2)-2*(groundedLink*crank*cos(360*t))  ]; 			  		        											// F

   ///////////////////////////////////////////////////
  //       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(
							 (-(2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134)
								 )
							 						 )
							 -sqrt(
										 pow((2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134))),2)
										+pow((2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134))),2)
										-pow((2*(groundedLink*crank*cos(-360*t+30.134))),2)
					 					)
								)
									/
							 ((2*(groundedLink*crank*cos(-360*t+30.134)))
 								-(2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134) )
													 )
									)
						  ),
		// 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*coupler*(crank*cos(360*t+30.134)-groundedLink*cos(0)
															 )
										 ),2)
							 +pow((2*coupler*(crank*sin(360*t+30.134)-sin(360*t+30.134+30.134)
															)
										 ),2)
							 -pow((2*(groundedLink*crank*cos(360*t)
											 )
										),2)
								)
					 )
			     /
					 (
							(2*(groundedLink*crank*cos(360*t+30.134)
								 )
							)
							-(2*coupler*(crank*cos(360*t+30.134)
							-groundedLink*cos(0)
					 								)
       			    )
					)
				 ), 

		 //  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")
buildLink(
					parameterCrank[0], 
				  parameterCrank[1], 
					parameterCrank[2],
					parameterCrank[3],
					parameterCrank[4], 
					parameterCrank[5]
				 );

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


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



///////////    Module to Build a LINK ////////////
module buildLink(
								posX, 
								posY, 
								posZ, 
								inclinationDegrees, 
								lenghtLink, 
								thickness
							 )
 
translate([posX,posY,posZ])                
{
		rotate(inclinationDegrees,[1,0,0])	
		difference()
		{
			union()
			{    
				rotate(0,[1,0,0])
				translate([posX, lenghtLink/2, 0])
			     cube([thickness,lenghtLink,radiusLink*2], center=true);
				translate([posX, -1, 0])
				rotate(90,[0,1,0])
			     cylinder(r = radiusLink,  h = thickness, center = true);
			     	translate([posX, lenghtLink, 0])
					 	rotate(90,[0,1,0])
			     		cylinder(r = radiusLink,  h = thickness, center = true);
			}
			union()
			{		
				translate([posX, 0, 0])
				rotate(90,[0,1,0])
			    cylinder(r = radiusPin,  h = thickness+1+1, center = true);
		 		
				translate([posX, lenghtLink, 0])
				rotate(90,[0,1,0])
		    		cylinder(r = radiusPin,  h = thickness+1+1, center = true);
			} // closing second union()
		}    // closing the difference()
}		  // closing first translate() 
	

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4-bar mechanism

MichaelAtOz
Administrator
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.

texada wrote
4Bar_Crank_Rocker_Ver_3.scad
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 -----
radiusPin = 2;  radiusLink = 4;
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;
 
groundedLink=80;
slope=0;

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


//function computeSomeVariables(t) = [ 
//    2*rocker*(groundedLink*cos(0)-crank*cos(360*t)),      // A
//    2*rocker*(groundedLink*sin(0)-crank*sin(360*t)),     // B
//    pow(groundedLink,2)+pow(crank,2)-pow(coupler,2)+pow(rocker,2)-2*(groundedLink*crank*cos(-360*t)), 							         											// C
//    2*coupler*(crank*cos(360*t)-groundedLink*cos(0)),  // D
//    2*coupler*(crank*sin(360*t)-sin(360*t)),  			   // E
//    pow(groundedLink,2)+pow(crank,2)+pow(coupler,2)-pow(rocker,2)-2*(groundedLink*crank*cos(360*t))  ]; 			  		        											// F

   ///////////////////////////////////////////////////
  //       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(
							 (-(2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134)
								 )
							 						 )
							 -sqrt(
										 pow((2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134))),2)
										+pow((2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134))),2)
										-pow((2*(groundedLink*crank*cos(-360*t+30.134))),2)
					 					)
								)
									/
							 ((2*(groundedLink*crank*cos(-360*t+30.134)))
 								-(2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134) )
													 )
									)
						  ),
		// 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*coupler*(crank*cos(360*t+30.134)-groundedLink*cos(0)
															 )
										 ),2)
							 +pow((2*coupler*(crank*sin(360*t+30.134)-sin(360*t+30.134+30.134)
															)
										 ),2)
							 -pow((2*(groundedLink*crank*cos(360*t)
											 )
										),2)
								)
					 )
			     /
					 (
							(2*(groundedLink*crank*cos(360*t+30.134)
								 )
							)
							-(2*coupler*(crank*cos(360*t+30.134)
							-groundedLink*cos(0)
					 								)
       			    )
					)
				 ), 

		 //  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")
buildLink(
					parameterCrank[0], 
				  parameterCrank[1], 
					parameterCrank[2],
					parameterCrank[3],
					parameterCrank[4], 
					parameterCrank[5]
				 );

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


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



///////////    Module to Build a LINK ////////////
module buildLink(
								posX, 
								posY, 
								posZ, 
								inclinationDegrees, 
								lenghtLink, 
								thickness
							 )
 
translate([posX,posY,posZ])                
{
		rotate(inclinationDegrees,[1,0,0])	
		difference()
		{
			union()
			{    
				rotate(0,[1,0,0])
				translate([posX, lenghtLink/2, 0])
			     cube([thickness,lenghtLink,radiusLink*2], center=true);
				translate([posX, -1, 0])
				rotate(90,[0,1,0])
			     cylinder(r = radiusLink,  h = thickness, center = true);
			     	translate([posX, lenghtLink, 0])
					 	rotate(90,[0,1,0])
			     		cylinder(r = radiusLink,  h = thickness, center = true);
			}
			union()
			{		
				translate([posX, 0, 0])
				rotate(90,[0,1,0])
			    cylinder(r = radiusPin,  h = thickness+1+1, center = true);
		 		
				translate([posX, lenghtLink, 0])
				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!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4-bar mechanism

Ronaldo
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4-bar mechanism

texada
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?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4-bar mechanism

texada
This post has NOT been accepted by the mailing list yet.
In reply to this post by MichaelAtOz
In the vector of parameters, the 4th position, this is the "Inclination-Degree" is not working.


 2*tan((-(2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134)
))-sqrt(pow((2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134))),2)
+pow((2*rocker*(groundedLink*sin(0.01)-crank*sin(360*t+30.134))),2)
-pow((2*(groundedLink*crank*cos(-360*t+30.134))),2)))/
((2*(groundedLink*crank*cos(-360*t+30.134)))-(2*rocker*(groundedLink*cos(0.01)-crank*cos(360*t+30.134) ))))
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4-bar mechanism

MichaelAtOz
Administrator
Hi texada,

I'LL REPEAT MYSELF.

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.
<<<<===
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!
Loading...