Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is...

28
Lecture VI: Constraints and Controllers

Transcript of Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is...

Page 1: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

LectureVI:ConstraintsandControllers

Page 2: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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

Page 3: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Descriptionofallowedmovementbyspecifyingdegreesoffreedom(DOF)• Translational(3DOFmax)• Rotational(3DOFmax)

3

DegreesofFreedom

Page 4: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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

Page 5: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Energyofcomponentsonconstrainedd.o.f.canbelost.• Convertedintoheatandsound(𝐸")• Asopposedtoputtingpressureonthejoint,causingdegradation.

• Projectnetforceontheunconstrained degreesoffreedom.• Nottrueforsoftbodies!• Deformingaccordingly…

• (Lagrangian)Approximation:nolossofenergy.

5

ConstraintsIntegration

https://www.youtube.com/watch?v=t_ZB0JViW68

Page 6: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

ConstraintRepresentation

• Oftenwithanimplicitfunction𝐶 𝑝, 𝑝′, 𝑝′′ = 0.• Example:positionconstraintonacurve:𝐶 𝑥, 𝑦 = 0

Page 7: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

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.

𝐶 𝑝 = 𝑝 − 𝐿

Page 8: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

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

Page 9: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

TheConstraintForce

• Principleofvirtualwork:𝐹8 doesnoworkon�⃗�.• Motivation:assumingnoenergylossbytheconstraint.• Also:sinceitnevercausesillegalmovement!• Wherehaveweseenthis?

Page 10: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

TheConstraintForce

• Principleofvirtualwork:𝐹8 = �⃗� = 0.• WehavethatJ�⃗� = 0• �⃗� isintherightnullspaceofJ.

•è 𝐹8 isspannedbytherowsofJ:

𝐹8 =Q𝜆SJS,.S

= 𝐽U𝜆

• 𝜆:theLagrangeMultiplier.• Geometricintuition:constraintforce“kills”invalidmovementandnothingelse.

Page 11: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

DirectSolution

• WecansolveforLagrangeMultiplier:𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀

OE 𝐹P + 𝐹8 =𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀

OE 𝐹P + 𝐽U𝜆• Weget:

𝐽𝑀OE𝐽U𝜆 =𝑑𝐽𝑑𝑡 �⃗� + 𝐽𝑀

OE𝐹P

• Disadvantages:• Expensivelinearsolve• 𝐽 changesineachpoint𝑝!• Discreteintegrationcombinedwiththiswillmakeaninexactsolution.

𝐹8 = 𝐽U𝜆

Square 𝐶 × 𝐶 matrix

Page 12: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Assolvingaconstraintforabodymayinfluencethesolvingforanotherone,weneedaniterativeprocess• while (!done) {

for all constraints c do solve c;}

• Convergenceisusuallyensuredbyreachingeitheramaximalamountofiterationsoraminimalchangeineveryconstraints

• Similartocollisions!

12

SequentialIntegration

Page 13: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Sequentialimpulses(SI)• Applyingimpulsesateachconstrainttocorrectvelocity.• Quitestableandconvergestoaglobalsolution.

• Whyimpulses?• Easiertodealwithfriction andcollision.• Workwithvelocityratherthanacceleration.• Giventhetimestep,impulseandforce areinterchangeable.

• Con: velocityconstraintsarenotprecise=>mightproducepositiondrift=>breakingtheconstraint.

13

Sequentialimpulses

Page 14: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

14

SequentialimpulsesStep1

Integrateappliedforces,yieldingtotentativevelocities

Step2

Applyimpulsessequentiallyforallconstraintstocorrectthevelocityerrors

Step3

Usethenewvelocitiestoupdatethepositionshttp://allenchou.net/wp-content/uploads/ 2013/12contacts/-figure.png

Page 15: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

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

Page 16: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Insteadofbreaking&correcting=>onlyproduceforce/torquealongaspecificDOF.• Reducingpossiblemovement.

• impulse-basedisafullcoordinatesimulation.• Pro: fastersimulation.• lesscalculations.• lesstuning.

• Con:morevulnerabletonumericalinstability.• mightbedifficulttoparameterizetheDOFsystem.

• Forinstance:𝐽𝑣 = 0 =>useonlynullspaceof𝐽!

16

ReducedCoordinateSimulation

Page 17: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

PositionDrift

• Evenifvelocitiesarefixed,thepositionintegrationmightdrift• Sincediscretetimestep.

• Solution:nothingsimple• Likeinterpenetrationresolution

• Possibleeasyfix:projectpositionsaswell!• Moreonthatinposition-baseddynamics…

Page 18: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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

Page 19: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Animatedbodiesarecontrolledusingamixofkinematics anddynamics.• Kinematics:replayandslightlyadaptpre-recordedmotions.• Dynamics:passivelyanimateobjectsreactingtoexternalforces(e.g.humanragdoll).• Areal-timecontrollerswitchesfromonetotheotheraccordingtoevents,forces,posesetc.

19

MotionControl

Page 20: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Imaginethatyouwanttoactivelyactuaterigidbodiesusingforcesandtorques.• notyetingamesbutwillprobablyinanearfuture…

• Actuatorsgenerate motionfromwithinthebodies• Jointtorques• Externalforces• Virtualforces• Muscleforces• contractileelements

20

MotionControl

continuummechanics.org/cm/index.html

Page 21: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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

Page 22: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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

Page 23: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Notreallyanactuationmethod.• Emulatetheeffectofapplyinganexternalforcebycomputingtheequivalentjointtorque.• Usetherelationbetweenjointrotationandposition whereaforceisapplied(bytheJacobianofthesystem).

23

VirtualForces

Page 24: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• 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”

Page 25: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Joint-spacemotioncontrol.• definesandtrackskinematicstarget.

• Stimulus-responsenetworkcontrol• geneticallyevolvescontrollersaccordingtoobjectives.

• Constraineddynamicsoptimizationcontrol.• findsoptimaltorquesthroughonlineoptimization.

25

Controllerdesign

Page 26: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• ProportionalDerivative(PD)controller• Usedtocomputejointtorqueslinearlyproportionaltothedifferencebetweenthecurrentstateandthetargetstate.• Basedonjointorientationandangularvelocity.

26

PDController

http://www.gamedev.net/uploads/monthly_ 10_2014ccs/-1414694390-48143500-0-224713jpg.

Page 27: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

𝜏 = 𝑘< 𝜃1 − 𝜃 + 𝑘^ �̇�1 − �̇�

Where:• 𝜏 isthegeneratedjointtorque,• 𝜃1 and𝜃 thedesiredandcurrentjointangles.• �̇�1 and�̇� thedesiredandcurrentjointangularvelocity.• 𝑘< and𝑘^ arethecontrollergain.• Regulatinghowresponsivethecontrolleristodeviation.

27

PDController

Page 28: Lecture 6 - Constraints and Controllers 6... · forall constraints c dosolve c;} •Convergence is usually ensured by reaching either a maximal amount of iterations or a minimal change

• Con:Themotion-controllerdesignerneedstocarefullydefinethegainvalues.• toohigh𝑘<:producingstiffunresponsivemotions.• toolow𝑘<:nottracktargetcorrectly.• toohigh𝑘^:convergingtooslowlytothetarget.• toolow𝑘^:producingoscillations.

• …Expecttospendtimefinetuninggains!

28

PDController

𝜏 = 𝑘< 𝜃1 − 𝜃 + 𝑘^ �̇�1 − �̇�