Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is...
Transcript of Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is...
LectureVI:ConstraintsandControllers
• Inpractice,norigidbodyisfreetomovearound‘onitsown’.• Movementisconstrained:• wheelsonachair• humanbodyparts• triggerofagun• openingdoor• actuallyalmostanythingyoucanthinkofinagame...
2
MotionConstraints
http://i2.cdn.turner.com/cnnnext/dam/assets/140813101135-best-biking-cities-utrecht-horizontal-large-gallery.jpg
http://static4.gamespot.com/uploads/scale_medium/mig/2/4/7/7/2282477-Garrys_13231_screen.jpg
• Descriptionofallowedmovementbyspecifyingdegreesoffreedom(DOF)• Translational(3DOFmax)• Rotational(3DOFmax)
3
DegreesofFreedom
• Kinematicpair:connectionbetweentwobodiesthatimposesconstraints ontheirrelativemovement.• Lowerpair:constraintonapoint,lineorplane• Revolutepair,orhingedjoint:1rotationalDOF.• Prismaticjoint,orslider:1translationalDOF.• Screwpair:1coordinatedrotation/translationDOF.• Cylindricalpair:1translational+1rotationalDOF.• Sphericalpair,orball-and-socketjoint:3rotationalDOF.• Planarpair:3translationalDOF.
• Higherpair:constraintonacurveorsurface.
4
KinematicPair
• Energyofcomponentsonconstrainedd.o.f.canbelost.• Convertedintoheatandsound(𝐸")• Asopposedtoputtingpressureonthejoint,causingdegradation.
• Projectnetforceontheunconstrained degreesoffreedom.• Nottrueforsoftbodies!• Deformingaccordingly…
• (Lagrangian)Approximation:nolossofenergy.
5
ConstraintsIntegration
https://www.youtube.com/watch?v=t_ZB0JViW68
ConstraintRepresentation
• Oftenwithanimplicitfunction𝐶 𝑝, 𝑝′, 𝑝′′ = 0.• Example:positionconstraintonacurve:𝐶 𝑥, 𝑦 = 0
Differentialconstraints• Ourpurpose:Movefrom�⃗�(𝑡) to�⃗�(𝑡 + ∆𝑡) andconserve:
𝐶 �⃗�(𝑡) = 𝐶 �⃗�(𝑡 + ∆𝑡) = 0• Algebraicinterpretation:thefollowingareconserved:• 𝐶 �⃗�(𝑡) = 0 (position)• 12 13⁄ = 0 (constraint velocity)• 152 1356 = 0 (constraint acceleration)
• Because function is constant zero!• Dynamicprinciple:constraints enforced by constraint forces 𝐹8.
𝐶 𝑝 = 𝑝 − 𝐿
EquationsofMotion• Chainrule:12
13= ;2
;<= 1<13= ;2
;<= �⃗� = 0
• Formultipleconstraints:JacobianJ = ;2@;<A
• Fornobjects:�⃗�BCDE• Massmatrix:𝑀BCDBC = 𝑑𝑖𝑎𝑔(𝑚E,𝑚E,𝑚E,⋯ ,𝑚C,𝑚C,𝑚C)
• Kinematic equation:J�⃗� = 0• Accelerationequation:1
52135
= 1M13�⃗� + 𝐽�⃗� = 0
• Force-based(dynamic)equation:𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀
OE 𝐹P + 𝐹8
𝐶 𝑝, 𝑝′, 𝑝′′ = 0
TheConstraintForce
• Principleofvirtualwork:𝐹8 doesnoworkon�⃗�.• Motivation:assumingnoenergylossbytheconstraint.• Also:sinceitnevercausesillegalmovement!• Wherehaveweseenthis?
TheConstraintForce
• Principleofvirtualwork:𝐹8 = �⃗� = 0.• WehavethatJ�⃗� = 0• �⃗� isintherightnullspaceofJ.
•è 𝐹8 isspannedbytherowsofJ:
𝐹8 =Q𝜆SJS,.S
= 𝐽U𝜆
• 𝜆:theLagrangeMultiplier.• Geometricintuition:constraintforce“kills”invalidmovementandnothingelse.
DirectSolution
• WecansolveforLagrangeMultiplier:𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀
OE 𝐹P + 𝐹8 =𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀
OE 𝐹P + 𝐽U𝜆• Weget:
𝐽𝑀OE𝐽U𝜆 =𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀
OE𝐹P
• Disadvantages:• Expensivelinearsolve• 𝐽 changesineachpoint𝑝!• Discreteintegrationcombinedwiththiswillmakeaninexactsolution.
𝐹8 = 𝐽U𝜆
Square 𝐶 × 𝐶 matrix
• Assolvingaconstraintforabodymayinfluencethesolvingforanotherone,weneedaniterativeprocess• while (!done) {
for all constraints c do solve c;}
• Convergenceisusuallyensuredbyreachingeitheramaximalamountofiterationsoraminimalchangeineveryconstraints
• Similartocollisions!
12
SequentialIntegration
• Sequentialimpulses(SI)• Applyingimpulsesateachconstrainttocorrectvelocity.• Quitestableandconvergestoaglobalsolution.
• Whyimpulses?• Easiertodealwithfriction andcollision.• Workwithvelocityratherthanacceleration.• Giventhetimestep,impulseandforce areinterchangeable.
• Con: velocityconstraintsarenotprecise=>mightproducepositiondrift=>breakingtheconstraint.
13
Sequentialimpulses
14
SequentialimpulsesStep1
Integrateappliedforces,yieldingtotentativevelocities
Step2
Applyimpulsessequentiallyforallconstraintstocorrectthevelocityerrors
Step3
Usethenewvelocitiestoupdatethepositionshttp://allenchou.net/wp-content/uploads/ 2013/12contacts/-figure.png
ComputingtheImpulses
• Asingleconstraint𝑖 currentlyhas𝐽S𝑣 ≠ 0.• 𝐽S - rowvector,normaltoconstraintatclosestpoint.
• ChangevelocitybyΔ𝑣:• Pushitalong𝐽S withLag.Multiplier𝜆S toget:𝐽S 𝑣 + Δ𝑣 = 0è• Needtoapplyimpulses𝑃 = 𝑀Δ𝑣 = 𝐽SU𝜆S.
• Wecompute𝜆S:𝐽S 𝑣 + 𝑀OE𝐽SU𝜆S = 0
𝜆S =−𝐽S𝑣
𝐽S𝑀OE𝐽SU
• Insteadofbreaking&correcting=>onlyproduceforce/torquealongaspecificDOF.• Reducingpossiblemovement.
• impulse-basedisafullcoordinatesimulation.• Pro: fastersimulation.• lesscalculations.• lesstuning.
• Con:morevulnerabletonumericalinstability.• mightbedifficulttoparameterizetheDOFsystem.
• Forinstance:𝐽𝑣 = 0 =>useonlynullspaceof𝐽!
16
ReducedCoordinateSimulation
PositionDrift
• Evenifvelocitiesarefixed,thepositionintegrationmightdrift• Sincediscretetimestep.
• Solution:nothingsimple• Likeinterpenetrationresolution
• Possibleeasyfix:projectpositionsaswell!• Moreonthatinposition-baseddynamics…
• Imagineyouhaverigidbodiesmovingandconstrainedcorrectlyaccordingtotheforcesyouapply.• Lettingthem‘live’ontheirownisfineforpassiveobjects.• projectile,furniture,environmentalobjectsetc.
• Livingbeingsproducemotion!• Theywilljustfallontothegroundatthebeginningofthegame
18
Motioncontrol
http://img 13/deviantart.net.8 e3c/i/ 2015/333/d/7a_falling_puppet_by_xxxblakexxx/-d9 ii9wq.jpg
• Animatedbodiesarecontrolledusingamixofkinematics anddynamics.• Kinematics:replayandslightlyadaptpre-recordedmotions.• Dynamics:passivelyanimateobjectsreactingtoexternalforces(e.g.humanragdoll).• Areal-timecontrollerswitchesfromonetotheotheraccordingtoevents,forces,posesetc.
19
MotionControl
• Imaginethatyouwanttoactivelyactuaterigidbodiesusingforcesandtorques.• notyetingamesbutwillprobablyinanearfuture…
• Actuatorsgenerate motionfromwithinthebodies• Jointtorques• Externalforces• Virtualforces• Muscleforces• contractileelements
20
MotionControl
continuummechanics.org/cm/index.html
• Moststraightforwardactuationmodel.• JointtorquesdirectlygeneratetorquesforeachactuatedDOF.• Assumingthatthereisa‘fake’motoratthelocationofthejointthatcanproducetorque.• e.g.increaseajointangleó positivetorque.• Veryusefulfortrackingpre-recordedmotionsoranyothererror-basedposes(e.g. balancepose)• Amountofappliedtorquedependsdirectlyontheerror
21
JointTorques
http://files.maartenbaert.be/extremephysics/illustration-hinge-joint.png
https://www.youtube.com/watch?v=wuJwwHdAD9Q
• Applyingexternalforcesontherightobject,localposition,andfortherightamountoftime.• Difficulttoproducerealisticmotions.• Doesnotreallyfitnaturalmotions.
• Motionoriginatesfrominside!
• Similartoapuppetrytechnique.• Systemcontrolmustbemastered.
• Butveryusefulforthecontroloftheglobalorientationandpositionofacomplexsystem(rootnode).
22
ExternalForceshttps://www.youtube.com/watch?v=nONBRvKjEUQ
http://previews.123rf.com/images/pkdinkar/pkdinkar 1109pkdinkar/110900022/10551395-employee-as-a-puppet-on-strings-Stock-Vector-puppet-man-marionere.jpg
• Notreallyanactuationmethod.• Emulatetheeffectofapplyinganexternalforcebycomputingtheequivalentjointtorque.• Usetherelationbetweenjointrotationandposition whereaforceisapplied(bytheJacobianofthesystem).
23
VirtualForces
• Motionactuallycomesfromthecontractionofmuscles.• theyalsoproducetorquesatjoints,butnotina‘fakemotor’way.
• Emulatingphysicalbehaviortothemodel=>“realistic”actuationofrigidbodies.• commonlyusedinbiomechanics/motionanalysis• themusclemodelisusuallyacombinationofnon-linearspringsanddampers.
24
MuscleForces
https://jonbarron.org/sites/default/files/arm-muscle.jpg
[Louetal. 2013]“Physics-basedHumanNeckSimulation”
• Joint-spacemotioncontrol.• definesandtrackskinematicstarget.
• Stimulus-responsenetworkcontrol• geneticallyevolvescontrollersaccordingtoobjectives.
• Constraineddynamicsoptimizationcontrol.• findsoptimaltorquesthroughonlineoptimization.
25
Controllerdesign
• ProportionalDerivative(PD)controller• Usedtocomputejointtorqueslinearlyproportionaltothedifferencebetweenthecurrentstateandthetargetstate.• Basedonjointorientationandangularvelocity.
26
PDController
http://www.gamedev.net/uploads/monthly_ 10_2014ccs/-1414694390-48143500-0-224713jpg.
𝜏 = 𝑘< 𝜃1 − 𝜃 + 𝑘^ �̇�1 − �̇�
Where:• 𝜏 isthegeneratedjointtorque,• 𝜃1 and𝜃 thedesiredandcurrentjointangles.• �̇�1 and�̇� thedesiredandcurrentjointangularvelocity.• 𝑘< and𝑘^ arethecontrollergain.• Regulatinghowresponsivethecontrolleristodeviation.
27
PDController
• Con:Themotion-controllerdesignerneedstocarefullydefinethegainvalues.• toohigh𝑘<:producingstiffunresponsivemotions.• toolow𝑘<:nottracktargetcorrectly.• toohigh𝑘^:convergingtooslowlytothetarget.• toolow𝑘^:producingoscillations.
• …Expecttospendtimefinetuninggains!
28
PDController
𝜏 = 𝑘< 𝜃1 − 𝜃 + 𝑘^ �̇�1 − �̇�