Vector Loops Matlab

download Vector Loops Matlab

of 16

Transcript of Vector Loops Matlab

  • 5/14/2018 Vector Loops Matlab

    1/16

    CHAPTER 2

    VECTOR Loop AND VECTORCHAIN EQUATIONS

    2.1 IntroductionAt the core of nearly all attempts to automate kinematic analyses lies the vector loopequation. The vector loop equation is a very compact and elegant expression of theconstraints that exist between the various bodies of a mechanism. Vector loop equa-tions are easy to formulate and are the necessary first step in computerized analysis ofmechanisms.

    Similarly, vector chains can be used to indicate the position of a point, such as acenter of mass of a link, which is important for the analysis, but not at one of themechanism joints. Vector chains are also used to analyze mechanisms that are open-chain-that is, those that have only one joint with the fixed link or ground.

    The methods summarized here are very similar to techniques found elsewhere.Kinematic analysis with complex numbers as well as "rotating vectors" are closely re-lated and, indeed, provide the same mathematical relationships as vector loop equa-tions. It is the opinion of the author that this presentation is more accessible than theother methods.

    2.2 The PlanarVectorA vector, as all undergraduate engineering students know, is a mathematical conceptused to represent physical quantities which have both magnitude and direction. Simplystated, a displacement vector represents a directed distance between two points inspace. For mechanism analysis, it can be seen that each link in a mechanism can be rep-resented as a displacement vector, the tail of which is at the center of one joint and thehead at the center of the other. The magnitude of this displacement vector is the linklength while the angle the base of the vector makes with the positive x-direction is theangle of the link (counterclockwise positive). Figure 2-1 illustrates these points.

    Note that the vector is represented in bold, uppercase notation, R, while the lengthof the vector, r, is in lowercase and not boldface. This notation will be used consistentlythroughout the book.

    Given the coordinate frame shown in Figure 2-1, the x- and y-components of thevector R can easily be written in terms of the vector length r and the angle with respectto the positive x-axis; rx = r cos(O) and ry = r sin(O).

    5

  • 5/14/2018 Vector Loops Matlab

    2/16

    2.3 Single Loop Equations

    6 Chapter 2

    F IG UR E 2-1 Single link of length r with coordinate frame and displacement vector, R, shown.

    Now the concept of the vector loop equation (or loop closure equation) is presented.Figure 2-2 shows a four-bar mechanism that is a common example in kinematic texts.The numbering system adopted here numbers the ground link as 1, so the movable linksstart at number 2.

    F IGURE 2 -2 Four-bar mechanism with x- y coordinate frame attached at the leftmost base pivot.Note that the x-axis lies along the line that passes through both base pivots.

  • 5/14/2018 Vector Loops Matlab

    3/16

    Vector Loop and Vector Chain Equations _ 7

    As seen in Figure 2-2, a coordinate system is assigned to the system. Conventionholds that a coordinate system is placed at the ground joint, which is leftmost in thedrawing, although this is completely arbitrary. The coordinate system can be placedanywhere as long as subsequent operations are performed in a manner that is consistentwith it.

    Each link (including the ground link) is represented by a displacement vector, asdescribed in the previous section. Figure 2-3 shows the same four-bar mechanism withfour displacement vectors drawn in place.

    A few comments are in order concerning the placement of the vectors. As with thecoordinate system, there are a number of ways in which these vectors may be drawn. Aswe will see, any set of displacement vectors will lead to a valid vector loop equation aslong as the equation is derived in a manner that is consistent with the vectors.

    Note that vectors R2 and R3 are aligned in a "head-to-tail" fashion that is requiredfor the addition of two vectors. Vectors R, and R4 also have that configuration. Finally,note that vectors R3 and R4 terminate at the same point of the mechanism (point B).That these two pairs of vectors, when added head to tail, end in the same point indicatesthat the results of these additions must be equal. Equation (2-1) expresses this observa-tion mathematically.

    (2-1)Equation (2-1) indicates that the displacement achieved when vectors R2 and R3

    are added is the same as that achieved when vectors R, and R4 are added. This vectorloop equation must be satisfied by this mechanism, regardless of the pose it takes, aslong as it remains assembled as a mechanism.

    F IGURE 2 -3 Displacement vectors drawn along the links of the four-bar mechanism.Note that the link angles are the same as the angles of the displacement vectors

    relative to the coordinate frame.

  • 5/14/2018 Vector Loops Matlab

    4/16

    8 Chapter 2

    2.4 Derivatives ofVectorsThe vector loop equation derived in the previous section is a compact, elegant expres-sion of the simple fact the various links of the mechanism are constrained in some man-ner. In other words, since the four-bar is a single degree-of-freedom mechanism, the ar-bitrary specification of anyone joint angle automatically specifies the other twothrough the vector equation (2-1). Since a large portion of the analyses will include thecomputation of velocities and accelerations of the mechanism, it is logical that the de-rivatives with respect to time be taken of this equation.

    It should be clear that the vectors are time-varying since, even though the linklengths remain constant, their orientation (and hence vector directions) change as themechanism moves. In other mechanisms, both the magnitude and directions maychange.

    It is easier to take these derivatives if the vector loop equation is broken downinto its two scalar components, one dealing with x-components and the other with y-components. Recall the definition of the angle of the vector in Figure 2-1. Figure 2-4shows the graphical representation of the vector loop equation with the angles of thevector drawn in. Note that the angles are defined as counterclockwise positive from thepositive x-direction and drawn to the tail of each vector. Note also that the manner inwhich the vectors are drawn ensures that the vector angle and the angle of the link thatvector represents are the same.

    If the above convention is rigorously adhered to, the vector loop equation readilybreaks down into its two component equations by using the sines and cosines of thevectors' angles.

    r2 cos 92 + r3 cos93 = Iicos9, + r4 cos O,r2sin92 +r3sin93 =lisin9, +r4sin94

    (2-2)(2-3)

    Take a moment to consider these equations. For this particular mechanism, the fourr values are link lengths and hence remain constant throughout our analyses. There arefour link angles, one of which can be taken to be constant and zero since the coordinate

    F IGURE 2 -4 Vec to r lo op d iag ra m o f th e fo ur-b ar lin ka ge in F ig ure 2 -3 .N ote th at th e a ng les o f th e v ec to rs (m easu re d from th e p ositiv e x -a xis to

    th e v ec to r a t its tail) a re th e sa me a s th e co rre sp on din g lin k a ng le.

  • 5/14/2018 Vector Loops Matlab

    5/16

    Vector Loop and Vector Chain Equations _ 9

    system may be drawn at an arbitrary orientation. This fact allows the problem to besimplified somewhat by drawing the x-axis coincident with one of the vectors. In thisexample, 91 is always zero because it lies along the x-axis.The other three angles are time-varying, and that must be taken into account whentaking the derivatives. Equations (2-4) and (2-5) show the results of taking the first de-rivative with respect to time of these two component equations. Note that in these equa-tions and throughout the book, we maintain the convention that the time derivative ofan angle, 9i, is represented by the variable O>i ' Likewise, the time derivative of an angu-lar velocity, O>i ' is represented by the angular acceleration < X j .

    (2-4)0>2'2cos92 + 0>3'3cosu, = 0>4'4cos 94 (2-5)

    These two equations specify the relationship that must exist among the rotational ratesof the three moving links as long as the mechanism remains assembled.

    In many analyses, it is assumed that one of the links is caused to move at a constantrotational rate. For example, it can be assumed that link 2 is attached to a large motorthat is capable of providing enough torque so that the ~ is relatively constant. Underthese conditions, ~ is said to be the input to the system, and the equations can be re-arranged.

    -0>3'3 sin 93 + 0>4'4sin 94 = 0>2'2sin 920>3'3cos 93 - 0>4'4cos 94 = -0>2'2 cos 92

    (2-6)(2-7)

    In traditional kinematic analyses, the velocity solution, which is embodied in equa-tions (2-6) and (2-7), takes place after the position problem is solved. In other words,the values of all the link angles are known at this point in the analysis. Chapter 3 dis-cusses the solution of the position problem in some detail, but at this point it will be as-sumed that the link angles are known. Therefore, equations (2-6) and (2-7) can be re-written in matrix form:

    [-'3 sin 93 '4 sin 94 ][0>3] [0>2'2sin92]

    '3 cos93 -'4 cos 94 0>4 = -0>2'2 cos 92The second derivative of the loop equation is also useful and is easily carried out.

    One need only keep in mind that the terms in the velocity equations are the products oftwo time-varying parts (0) and cos(9 and the product rule for differentiation applies.

    (2-8)

    ~'4 cos 94 ]-r4cos94 hsin93-0>~'4sin94

    (2-11)

  • 5/14/2018 Vector Loops Matlab

    6/16

    10 Chapter 2

    F IGURE 2 -5 Four-bar mechanism for Example 2-1.

    Example 2-1Use equation (2-8) to solve for the velocities of links 3 and 4 of the four-bar mechanismshown in Figure 2-5. Use the link lengths and angles shown in Table 2-1. Assume thatthe velocity of the input link, link 2, is 100 rad/s.TABLE 2 -1 Link Lengths and Angles for Four-Bar Linkage in Example 2-1Link Length, r(cm) Angle, e (degrees)1234

    12.04 . 010.07 . 0

    o4524.6590.68

    The problem is solved by using equation (2-8) in MATLAB. A transcript of the inter-active session to solve this problem follows: r2=4; r3=10i r4=7i th2=45*pi/180i th3=24.652*pi/180i th4=90.6794*pi/180i % % Note that the angles are in radians %J=[-r3*sin(th3) r4*sin(th4)ir3*cos(th3) -r4*cos(th4)]J =

    -4.1711 6.99959.0886 0.0830

  • 5/14/2018 Vector Loops Matlab

    7/16

    Vector Loop and Vector Chain Equations _ 11

    b=[100*r2*sin(th2); 100*r2*cos(th2)]

    b

    282.8427-282.8427

    om34=inv(J)*b

    om34 =

    -31.31921. 745

    So the solution of this position of the mechanism is that link 3 is rotating clockwiseat 31.32 rad/s, and link 4 is rotating counterclockwise at 21.74 rad/s.

    MATLAS HINTTrigonometric functions in MATLAB assume that the arguments are in radians. Sincemost of us are more accustomed to using the unit of degree, you can easily convertbetween the two by multiplying an angle in degrees by x/I80 to get radians, orconversely, multiply an angle in radians by 180/x to get degrees. MATLAB makesthis a little easier by providing the permanent, global constant, pi, which is a nu-merical representation of x, carried out to the maximum precision of the program.

    It is left to the student to verify these results with traditional vector polygon methods.

    2.5 Other Common MechanismsThe proper use of the vector loop equation and its derivatives takes practice. To thisend, the following table contains several common mechanisms with consistent vectorloop equations along with their first two derivatives. Note that the assignment of a vec-tor loop equation is not unique since the placement of the coordinate frame and vectororientations is somewhat arbitrary. As long as these methods are used in a consistentmanner, then the results will be correct. By rederiving these equations, the analyticaland mathematical skills required to apply this important technique will be greatlystrengthened.

    2.6 Vector ChainsSometimes it is important to explicitly define the motion of a point or points on amechanism that do not coincide with a joint. Other times, we need to analyze mecha-nisms that do not form closed loops with the ground link. In these instances, vector

  • 5/14/2018 Vector Loops Matlab

    8/16

    _0L---I

    - 0L---I

    ~II

    _0L---I

    _0'---

    +'"DC. : ; ;N,9

    : : >+

  • 5/14/2018 Vector Loops Matlab

    9/16

    Vector Loop and Vector Chain Equations 13

    loops are not possible, but similar relationships can be derived by specifying the vectorchains which relate the important coordinates with the link coordinates. In this section,we explore two important uses of vector chains: the two-link planar robot and specify-ing the location of a point on the coupler link of a four-bar mechanism.

    2.6.1 Two-LinkPlanarRobotFigure 2-6 shows a schematic diagram of a two-link planar robot. This example is oftenused in the robotics literature as the simplest form of a robot made up of two links andtwo revolute joints. Note that the two joint angles, 81 and 82, are measured to the baseof each link, as previously defined. Note also that the coordinate system is placed at thejoint between the ground (link 1) and the first robot link. In this example, it is importantthat we relate the linkage coordinates, 81 and 82, to the location of the end effector,given by the vector, RE. It's easy to see that the vector drawn from the center of the co-ordinate system to the center of the robot gripper is the sum of the two-link displace-ment vectors.

    (2-12)

    F IGURE 2 -6 Two-link manipulator mechanism showing two degrees of freedomand a displacement vector drawn to the end effector.

    There exists an important distinction between the vector RE shown above and thepreviously defined displacement vectors. RE is not attached to, or moving with, one ofthe links in the mechanism. In this case, the vector simply indicates the position of thepoint in the center of the robot gripper. In cases such as these, the angle of the vector isof little significance and we represent the .r- and y-components simply as xE and Y E o

    XE = r2 cos82 + r3 cos83Y E = r2 sin 82 + r3 sin 83

    (2-13)(2-14)

    As before, we can easily take the derivatives of these scalar equations and put theresulting equations in matrix form to find the relationship known as the Jacobian trans-formation.

  • 5/14/2018 Vector Loops Matlab

    10/16

    14 Chapter 2

    [ ~ E ] = [ - r 2 sin02 - r 3 sin03 ] [ ( 0 2 ]Y E r 2 cos O , r 3 cos O ; ( 0 3As a final observation, it should be noted that the robotics literature uses a slightly

    different angle convention, leading to a different form of the Jacobian transformation.In robotics, joint angles are used, which differ from link angles in that they are mea-sured relative to the previous link. This is done because the sensors used in robotic sys-tems measure this relative angle directly. On the other hand, the convention in kinemat-ics literature is to use the absolute angle.

    (2-15)

    2.6.2 Vector Chains to Describe Motion of an Arbitrary PointIn Figure 2-7, a four-bar linkage is shown in which the coupler link, link 3, carries apoint labeled C. There are occasions in which it is important to describe the motion ofsuch a point using vectors. One common application of this method would be to de-scribe "coupler curves." Coupler curves are the curves traced by particular points on thecoupler of a four-bar mechanism during its motion. Another common usage of thistechnique is to describe the constraints between the link angles and the motion of thecenter of mass (COM) of a particular link. Ineither case, the approach is the same.

    4

    FIGURE 2-7 Four-bar linkage with designated point of interest on link 3.

    The first step is to define a displacement vector to the point of interest on the l inkitself. This vector should originate at the same vertex where the link's displacementvector starts. In our examples to date, the vertex between the crank (link 2) and the cou-pler (link 3) is the location. Figure 2-8 below shows the correct displacement vector .

    . ~ . 0 . .FIGURE 2-8 Displacement vector indicating the position of the point of interest.

  • 5/14/2018 Vector Loops Matlab

    11/16

    Vector Loop and Vector Chain Equations _ 15

    Note that two angles are shown in Figure 2-8. Angle 93 is defined relative to thehorizontal, or x-axis, as was shown previously. The second angle, 9p' is the angle of thenew displacement vector relative to the link's displacement vector. This angle is con-stant and does not change value while the link is moving. On the other hand, the abso-lute angle of orientation of the displacement vector is the sum of the link's angle andthe relative angle of the newly defined displacement vector.Figure 2-9 shows the mechanism with the vectors drawn in the appropriatelocations.

    F IGURE 2 -9 Four-bar mechanism showing the vectors required to track the motionof a point that is not specifically at one of the joints.

    The vector equation that is used to track the location of the point can be easilywritten.

    ( 2 - 1 6 )Keeping in mind the angle that was defined in Figure 2-8, the equation can be brokendown into x - and y-components.

    xp = r2 cos92 + rp3 cos(93 +9p3)yp = r2 sin 92 + rp3 sin(93 + 9p3)

    ( 2 - 1 7 )(2-18)

    Ifit is desired that the velocity of the point be known, then simply taking the derivativeof these equations leads to the following equations. Note that, while 93 is time-varying,9p3 is not, so it does not contribute to the time derivative.

    xp =-r20>2sin92 -rp30>3sin(93 +9p3) (2-19)y p = r20>2 cos 92 + rp30>3cos(93 + 9p3) (2-20)

    And similarly, the accelerations can be tracked as well:x p = -r2u2 sin 92 - r20>~cos 92 - rp3u3 sin(93 +9p3) - rp30>j cos(93 + 9 p3) ( 2 - 2 1 )Yp = r2u2 cosrx, - r20>~sin92 + rp3u3 cos(93 +9p3)- rp30>j sin(93 +9p3) (2-22)

  • 5/14/2018 Vector Loops Matlab

    12/16

    CHAPTER 3

    SOLUTIONS OF THEPOSITION PROBLEM

    3.1 OverviewIn th e co urse o f m ech an ism a na ly sis, th e first s te p i s t he s o- ca ll ed po si ti on s ol uti on . Fo ra s in gle d eg re e-o f-fre ed om mec ha nism th e p ro blem a nswe rs th e q ue stio n: IfI know thepo sition o f on e of the links (relative to th e groun d) th en w hat are the positio ns of theo th er lin ks in th e m ec ha nism ? A s w as sh ow n in C ha pter 2 , th e v ec to r lo op e qu atio n c anbe u se d to s olv e th is p ro blem. F or e xam ple , e qu atio ns ( 2-2 ) a nd (2 -3 ) c on ta in s uffic ie ntin fo rm atio n to a llo w o ne to so lv e fo r 93 and 94, given 92 and all of the link l en g th s. Un -fo rtu na te ly , th e e qu atio ns a re n on lin ea r, tra ns ce nd en ta l e qu atio ns in 93 and 94 and areth ere fo re n ot e asily so lv ed . In th is c hap te r, a n um erica l m eth od fo r th e so lu tio n o f th ep os itio n p ro blem w ill be p re sen ted a nd th e im plem en ta tio n o f th is m eth od in MATLABp rogr am s cr ip ts w il l be d is cu ss ed . I t s houl d be no te d t ha t th is c ha pt er is i nc lu d ed f or t hesake of com pleteness only. M any kinem atics textbooks discuss this m ethod, andMATLABs p ar tic ula rly w ell-s uite d fo r th e s olu tio n o f th e e qu atio ns d eriv ed h ere . O n th eo th er h an d, th e m aterial d iscu sse d in th is c ha pte r is n ot u se d in th e su bseq uen t c hap te rsan d ca n be s af ely s kip p ed w it hou t l os s o f c on tin u it y.

    3.2 Numerical Solutions of Nonlinear Algebraic Equations

    18

    T he N ew to n-R aphson m ethod for the so lutio n o f nonlin ear equations is briefly pre-sen ted here, alth ough a m ore tho roug h discussio n can be fo un d e ls ewh ere .! S im plysta te d, th e N ewto n-R a ph so n m eth od is a n ite ra tiv e m e th od fo r th e s olu tio n o f n on lin ea ra lg eb ra ic e qu atio ns th at s ta rts w ith a n in itia l g ue ss a t th e u nk nowns a nd in crem en ta llyim pro ves th e g ue ss u ntil th e so lu tio n is "c lo se e no ug h" to th e c orre ct so lu tio n. T he in -crem ental im pro vem ents are co mp uted b y usin g a series expansio n o f the non linearequations and the concept of "close enough" is usually defined in the context of nu-me ric al t ole ra nc e a nd e ng in ee ri ng a pp li ca ti on s.W ith out lo ss of g enerality, the problem is sh ow n for tw o equations w ith tw o un-k nown s, th ou gh it is e asily ex pan ded as n ee de d. A ssume th at th e p ro blem is e xp ressedin th e fo llow in g fo rm :

    IMabie. H . H . and C. F. Reinholtz, M ec ha nis ms a nd M ec ha nic s o f M ac hin er y. 4t h ed. New Yo rk : John Wtley& Sons. 1987.

  • 5/14/2018 Vector Loops Matlab

    13/16

    S olutio ns o f the P ositio n P rob le m _ 19

    f i(Qj,q2)=Of2(Qj,Q2)=O

    ( 3 - 1 )(3-2)

    where Q j an d Q2 are th e u nkn ow ns to be fo un d. T he firs t s te p is to e xp re ss th e v aria ble sin term s o f an e stim atio n o f th e so lu tio n (d en oted by a n ov erb ar) a nd a sm all c orre ctio nfactor (denoted by a I : ! . prefix) that is the difference betw een the estim ation and thesolution.

    ( 3 - 3 )T he T ay lo r S erie s ex pan sio n is a w ell-k nown m ath em atic al to ol to rep resen t n on -

    lin ea r fu nctio n o f v ariab les th at h ave b een d ecomp osed as sh ow n in eq ua tio n (3 -3 ). T heex pan sio n say s th at a fun ctio n can be re pre se nte d a s a n in fin ite s erie s s ta rtin g w ith th ef un cti on e va lu ate d a t t he e stima te (ql ,q2)' The e xp an sio n fo r th e firs t fu nc tio n is s hownbelow:

    T he h ig he r-o rd er te rm s a re u su ally n eg le cte d, b ec au se th e s erie s w ill be used in anite ra tiv e fa sh io n to a pp ro xim ate th e fu nc tio n a nd it is d es ira ble th at th e e qu atio n be lin-ear in the d elta-term s, w hich w ou ld n ot b e th e case if h ig he r-o rd er term s w ere in clu ded .It's im po rta nt to n ote tha t th e p artial d eriv ativ e term s in e qu atio n (3 -4 ) a re ev alu ate d atth e estim ated v alu es o f th e u nkn ow ns a nd are th erefo re comp uta ble to a sim ple numeri-ca l v alu e. T hey b ec om e n um erical c oefficien ts in th e ex pressio n. A pp ly in g th e ex pan -sio n to b oth fu nctio ns, w e can rep resen t th e resu lts inma tr ix f orm:

    (3-5)

    E xam ination of equation (3 -5) leads to a m ethod of com puting the difference be-tw een an estim ate of the unknow ns (q's) and the correct angle. S olving equation (3 -5)f or t he d if fe rence ( I:!.q 's):

    (3-6)

    S olution of this class of nonlinear problem is then reduced to the m ethod show n inth e flo w ch art o f F igu re 3 -1 .

  • 5/14/2018 Vector Loops Matlab

    14/16

    -- - . . . . . . . _ , . . . . . . . . . . . . . . . . . .Estim a te s olu tio n b as ed oneducat ed gues s: ( ii I' i i2). . .Use e stim ate to so lv e fo r

    ~~ co rr ec ti ons ( equat ion 3-6)

    . . .Add corr ec tio n f ac to rs toestim ates to come up w ith n ew

    estimates: ii ; = ii ; + llq;. . .Eva lu ate th e fu nc tio ns a t th e

    new values: .t ;(i i l' ii 2). . -Ift.,!; c lo se to z ero , th en. . . te rm in ate w it h s olu ti on , e ls er ecompu te e st ima te

    FIGURE 3-1 Schematic representation of Newton-Raphson algorithmapplied to the solution of the position problem in kinematics.

    3.3 The Position Problem of a Four-Bar LinkageIn the p rev io us chap ter, th e v ector loo p equ ation for a fou r-b ar link age w as d erived an dit w as broken dow n into x- an d y -com po nen ts-see eq uation s (2-2) an d (2-3). Takingadv antag e of th e fact that a referen ce fram e can alw ays be cho sen to align w ith th e b asel ink ( li nk 1) a nd re arra ng in g th e e qu atio ns, th e fo llowin g two fu nc tio ns a re d efin ed :

    Jj(93,9 4) = r2 cos 92 + r3 cos 93 -Ij - r4 cos94 = 0/2(9 3,94)= r2 sin 92 + r3 s in 93 - r4 s in 94 =0

    (3-7)(3-8)

    Now the po sitio n p rob lem can be stated as follo ws: F or a g iv en set of lin k len gth sand for a given value of 92, find those values of 93 and 94 fo r wh ic h f un ctio ns j] and/2e va lu ate to z ero . Slncej] andh are nonlinear and transcendental (the unknow ns areco ntain ed w ith in transcend ental fun ctio ns), linear m atrix m eth ods do no t app ly. T heNew to n-R a ph so n m eth od fo r so lv in g n on lin ea r e qu atio ns work s w ell fo r th is p ro blem.

    F irst, red efin e th e v ariab les in term s of some n om in al v alue of th e answ er, w hich isc on sid ere d " clo se " to th e a nsw er a nd th e c orre ctio n fa cto r th at m ak es u p th e d iffere nc e:

    93 = 93+A93 (3-9)(3-10)

    w here 93 and 94 re pre se nt th e so lu tio n to th e p ro blem, th e o ve rb ars in dic ate th e n om in alvalues that are close to the solution. and the A 's indicate the correction factors. U singthe Taylor Series as described above, and putting the results in the form of equation(3 -6 ), th e fo llowin g m atrix e qu atio n is o bta in ed :

    [A93J=[-r3sin~3 r4sin9 ,i J-I[_Jj(~3'~4)J (3-11)A94 r3c o s 9 3 -r4c o s 9 4 - /2(9 3,9 4)

  • 5/14/2018 Vector Loops Matlab

    15/16

    The MATLAB c om pu ta tio na l e nv iro nm en t is w ell-s uite d to th e so lu tio n o f th e p ositio np ro blem a s o utlin ed a bo ve . T he fo llow in g f un ctio n s how s o ne p os sib le imp lemen ta tio nof the use of MA1LAB fo r so lv in g th e n on lin ear tra nsc en de nta l eq ua tio ns th at a ris e in atyp ica l posi ti on prob lem.

    3.4 MATLAB Solution of the PositionProblem of a Four-Bar Linkage

    MAT lA B H IN TMA1LAB allo ws yo u to k eep g rou ps of comm an ds th at m ay be rep eatedly executedin separate tex t files. T he filenam es fo r th ese hav e th e ex ten sio n ".m ."an d h enceare know n as "m-files," (Ima gin e if th e p ro gramme rs h ad c l1 o$ en th ee xte ns io n".x "!) T here a re tw o d istin ct types of m-files, The s cr ip t f il e is s in lp ly aCQ ll e6 tiono f co mm and s that can b e ex ecu ted fro m the comm and proJD ptby ty ping t l lc . l l a m eo f th e f ile . T h es e c ommand s e xe cu te e xa ctly ! lS tb ey would .i! ity pe diO c :liV fj:b uilly .T h e s ec on d type o f m -f ile is th e fu nc tio n f ile th at o pe ra te s l i k e a func ti on . inCot as ub ro utin e in FORTRAN. T he fu nctio n accep ts arguments and returns values, an dw hile executing, the function does not have access to the variables in the w ork-sp ace (un less they h av e b een defin ed as glob al). W hen w ritin g a fu nctio n file, th efirst lin e m ust h av e th e form at sho wn b elo w, w ith the ''fun ction '' k eyw ord , th e re-turn v ar ia ble s, a nd th e a rg uments o f th e fu nc tio n.

    FIG UR E 2 -5 Four-bar m echanism for E xam ple 2 -1.

    T AB LE 2 -1 L ink Lengths and A ngles for Four-B ar L inkage in E xam ple 2 -1L i n k Length, r (em) Angle, e (degrees)

    1 12.0 02 4.0 453 10.0 24.654 7. 0 90.68

  • 5/14/2018 Vector Loops Matlab

    16/16

    f un ct io n [ th 3, t h4 ]= po ss o1 4( th ,r s)%posso14 position solution of a 4-bar mechanism%% script used to implement Newton-Raphson% method for solving nonlinear% position problem of a 4-bar mechanism.%% Co py ri gh t 2 00 1%J ohn F. G ard ne r%%%%i npu ts of f un ct ion%%t h (1)%th(2)%th(3)

    theta-2t he ta -3 -b ar ( st ar ti ng g ue ss )t he ta -4 -b ar ( st ar ti ng g ue ss )

    %%rs(l) r-1%rs(2) r-2%rs(3) r-3%rs(4) = r-4%th2=th(1);th3bar=th(2) ;th4bar=th(3);%% set condition for convergence%aps i.Lone L, OE-6;% In ti al iz e t he f -v ec to r%% Compute the functions as a two-element vector:%f=[rs(3)*cos(th3bar)-rs(4)*cos(th4bar)+rs(2)*cos(th2)-rs(1);rs(3)*sin(th3bar)-rs(4)*sin(th4bar)+rs(2)*sin(th2)];

    %% Re pe at edl y co mpu te th e c or re ct ion f ac tor s% as per equation (3-11)%while norm(fepsilonJ=[-rs(3)*sin(th3bar) rs(4)*sin(th4bar);rs(3)*cos(th3bar) -rs(4)*cos(th4bar)];dth=inv(J)*(-1.0*f);th3bar=th3bar+dth(1);th4bar=th4bar+dth(2);f=[rs(3)*cos(th3bar)-rs(4)*cos(th4bar)+rs(2)*cos(th2)-rs(1);rs(3)*sin(th3bar)-rs(4)*sin(th4bar)+rs(2)*sin(th2)];norm t fl

    end;th3=th3bar;th4=th4bar;

    As an example, consider the four-bar first encountered in Example 2-1. The flowing is a record of a MATLAB session in which the function is used to solve for tposition:

    rs(1)=12; rs(2)=4; rs(3)=10; rs(4)=7; th(l)=O; th(2)=45*pi/180; th(3)=135*pi/180; posso14(th,rs)ans =0.7688 1.6871

    which corresponds to e3 of 44.05 degrees and e4 of 96.66 degrees.