velocities.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef SOPHUS_VELOCITIES_HPP
  2. #define SOPHUS_VELOCITIES_HPP
  3. #include <functional>
  4. #include "num_diff.hpp"
  5. #include "se3.hpp"
  6. namespace Sophus {
  7. namespace experimental {
  8. // Experimental since the API will certainly change drastically in the future.
  9. // Transforms velocity vector by rotation ``foo_R_bar``.
  10. //
  11. // Note: vel_bar can be either a linear or a rotational velocity vector.
  12. //
  13. template <class Scalar>
  14. Vector3<Scalar> transformVelocity(SO3<Scalar> const& foo_R_bar,
  15. Vector3<Scalar> const& vel_bar) {
  16. // For rotational velocities note that:
  17. //
  18. // vel_bar = vee(foo_R_bar * hat(vel_bar) * foo_R_bar^T)
  19. // = vee(hat(Adj(foo_R_bar) * vel_bar))
  20. // = Adj(foo_R_bar) * vel_bar
  21. // = foo_R_bar * vel_bar.
  22. //
  23. return foo_R_bar * vel_bar;
  24. }
  25. // Transforms velocity vector by pose ``foo_T_bar``.
  26. //
  27. // Note: vel_bar can be either a linear or a rotational velocity vector.
  28. //
  29. template <class Scalar>
  30. Vector3<Scalar> transformVelocity(SE3<Scalar> const& foo_T_bar,
  31. Vector3<Scalar> const& vel_bar) {
  32. return transformVelocity(foo_T_bar.so3(), vel_bar);
  33. }
  34. // finite difference approximation of instantanious velocity in frame foo
  35. //
  36. template <class Scalar>
  37. Vector3<Scalar> finiteDifferenceRotationalVelocity(
  38. std::function<SO3<Scalar>(Scalar)> const& foo_R_bar, Scalar t,
  39. Scalar h = Constants<Scalar>::epsilon()) {
  40. // https://en.wikipedia.org/w/index.php?title=Angular_velocity&oldid=791867792#Angular_velocity_tensor
  41. //
  42. // W = dR(t)/dt * R^{-1}(t)
  43. Matrix3<Scalar> dR_dt_in_frame_foo = curveNumDiff(
  44. [&foo_R_bar](Scalar t0) -> Matrix3<Scalar> {
  45. return foo_R_bar(t0).matrix();
  46. },
  47. t, h);
  48. // velocity tensor
  49. Matrix3<Scalar> W_in_frame_foo =
  50. dR_dt_in_frame_foo * (foo_R_bar(t)).inverse().matrix();
  51. return SO3<Scalar>::vee(W_in_frame_foo);
  52. }
  53. // finite difference approximation of instantanious velocity in frame foo
  54. //
  55. template <class Scalar>
  56. Vector3<Scalar> finiteDifferenceRotationalVelocity(
  57. std::function<SE3<Scalar>(Scalar)> const& foo_T_bar, Scalar t,
  58. Scalar h = Constants<Scalar>::epsilon()) {
  59. return finiteDifferenceRotationalVelocity<Scalar>(
  60. [&foo_T_bar](Scalar t) -> SO3<Scalar> { return foo_T_bar(t).so3(); }, t,
  61. h);
  62. }
  63. } // namespace experimental
  64. } // namespace Sophus
  65. #endif // SOPHUS_VELOCITIES_HPP