spinning: partial turns - massachusetts institute of...

15
Spinning: Par+al Turns

Upload: others

Post on 14-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Spinning:  Par+al  Turns  

Page 2: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Par+al  Turns  

•  Spinning  doesn’t  always  require  making  full  revolu+ons.  For  instance,  some  ZR  compe++ons  will  ask  you  to  rotate  90°  to  pick  up  an  item.    

•  In  this  tutorial,  you  will:  –  prac+ce  using  dot  product  in  calcula+ons  –  implement  the  func+on  mathVecInner  –  use  trigonometric  func+ons  in  code  –  monitor  changes  in  angular  displacement    

2  

Page 3: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Dot  Product  •  To  measure  your  satellite’s  angular  displacement  (θ),  you  will  need  to  use  the  dot  product.  Dot  product  is  a  scalar  quan+ty  that  can  be  used  to  find  the  angle  between  two  vectors.  

•  To  find  the  dot  product,  also  known  as  inner  product,  mul+ply  the  corresponding  components  of  the  two  vectors  and  add  the  sums.  –  ex:  [3,  2,  -­‐5]  ●  [1,  4,  6]  =  (3*1)  +  (2*4)  +  (-­‐5*6)                          =  3  +  8  –  30  =  -­‐19    

•  For  par+al  turns,  the  two  vectors  will  be  your  ini+al  a^tude  and  current  a^tude  unit  vectors.    

3  

Page 4: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Dot  Product  

•  As  you  can  see,  the  dot  product  is  a  scalar  quan+ty,  not  a  vector.  We  can  use  the  dot  product  to  find  the  angular  displacement  using  this  formula:  

 •  a  and  b  are  vectors.  Treat  a  as  your  ini+al  a^tude  vector  and  b  as  your  current  a^tude  vector.    

•  The  equa+on  is  more  useful  if  we  isolate  θ.    

|)|)(|)(|(cos baba θ=•

)|)|)(|(|

(cos 1baba•

= −θ

4  

Page 5: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Dot  Product  

•  Let’s  calculate  the  angle  between  the  vectors  in  the  previous  example.  

   

o09.115)424.0(cos

cos424.0)28.7)(16.6)((cos19

28.736161||

16.62549||

1

=

−=

=−

=−

=++=

=++=

θ

θ

θ

θ

b

a

5  

Page 6: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Try  It  •  Let’s  try  the  scenario  in  which  we  have  to  pick  up  an  item  by  rota+ng:  –  90°  clockwise  –  15  deg/sec  on  the  body  z-­‐axis.    

•  Open  Project17  from  the  Spinning:  Angular  Velocity  tutorial  and  save  it  as  Project18.  Alter  the  ini+al  values  of  targetRate  to  match  the  above  specifica+ons.  

•  Revisit  previous  tutorials  on  spinning  if  you  don’t  understand  how  to  determine  the  values  for  the  targetRate  array.  Try  to  figure  it  out  before  you  see  the  solu+on  on  the  next  slide.  

6  

Page 7: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Solu+on  

7  

Page 8: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Prep  •  We  need  to  create  a  few  variables.  Create  the  arrays  myState[12],  initA2[3],  and  myA2[3],  and  the  floats  dot  and  angle.  None  of  them  need  to  be  ini+alized.    

•  In  loop(),  start  by  retrieving  myState  and  wri+ng  your  a^tude  vector  to  myAj.    

•  Also,  if  it  is  the  first  itera+on  (counter  equals  0),  store  your  a^tude  in  initAj.  Remember  that  a^tude  is  stored  in  the  sixth,  seventh,  and  eighth  elements  of  the  state  array.  

•  This  for  loop  contains  mul+ple  lines  of  code.  Can  you  recall  the  rules  of  bracket  syntax?  

8  

Page 9: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Code  

9  

Page 10: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

mathVecInner  •  The  first  step  in  finding  angular  displacement  is  to  calculate  the  dot  product  between  the  ini+al  and  current  a^tude  vectors.  

•  To  calculate  the  dot  product,  use  the  func+on  mathVecInner.  It  takes  the  two  vectors  and  the  length  of  the  vectors  as  arguments  and  returns  the  dot  product.      

•  Call  mathVecInner  to  find  the  dot  product  of  initAj  and  myAj  and  store  the  returned  float  in  dot.    

10  

Page 11: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Find  the  Angle  •  Now  we  need  to  use  our  formula  to  find  the  angle  between  

initAj  and  myAj.  Use  the  func+on  acosf  to  find  the  arccosine  of  dot.    

•  The  formula  requires  you  to  divide  the  arccosine  by  the  magnitudes  of  the  two  vectors.  We  can  skip  this  step  because  both  are  a^tude  vectors  and  therefore  unit  vectors,  so  the  magnitudes  equal  1.    

•  acosf,  like  all  other  trig  func+ons  in  math.h,  returns  a  float  in  radians.  The  angle  is  easier  to  comprehend  in  degrees,  so  mul+ply  it  by  180/π.  

•  We  want  to  monitor  angular  displacement,  so  debug  angle.  

11  

Page 12: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Condi+onal  

•  The  only  thing  len  to  do  is  to  change  our  “if”  statement  so  it  is  condi+onal  on  angle,  not  counter.  Set  the  a^tude  rate  target  to  targetRate  if  the  angular  displacement  is  less  than  90°.    

   

•  Compile  and  run.  Make  sure  the  console  is  open  so  you  can  monitor  angle.  

12  

Page 13: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Results  

•  We  didn’t  take  into  account  the  +me  it  takes  to  stop  moving,  so  we  overshot  the  target  angle.  As  an  improvement,  fine  tune  the  condi+onal  angle  so  you  stop  at  90°.    

•  But  remember,  versa+lity  is  everything.  Your  target  angle  won’t  always  be  90°  and  you  won’t  always  be  spinning  at  15  deg/sec.  Use  your  math  and  physics  skills  to  create  a  solu+on  that  works  in  every  situa+on.  

•  You  may  find  the  equa+ons  on  the  next  slides  helpful.  Good  luck!  

13  

Page 14: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Mo+on  Equa+ons  Revisited  

•  The  five  essen+al  mo+on  equa+ons  of  transla+onal  kinema+cs  can  be  modified  for  their  rota+onal  counterparts.  

•  Keep  in  mind  that  these  mo+on  equa+ons  are  only  valid  for  constant  angular  accelera+on  (α).  

•  Remember  that  the  subscript  0  indicates  an  ini+al  value,  and  the  lack  of  a  subscript  indicates  a  final  value.    

14  

Page 15: Spinning: Partial Turns - Massachusetts Institute of ...static.zerorobotics.mit.edu/docs/tutorials/PartialTurns.pdfmathVecInner’ • The’firststep’in’finding’angular’displacementis’to’

Mo+on  Equa+ons  Revisited  

αθωω

αωθ

αωθ

ωωθ

ωωα

22121

2

20

2

2

20

0

0

=−

−=

+=

+=

−=

tt

tt

t

t

15