A PX4 based camera pointer

run_test.go 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. package pipoint
  16. import (
  17. "math"
  18. "testing"
  19. "github.com/stretchr/testify/assert"
  20. )
  21. func TestPointEast(t *testing.T) {
  22. rover := &NEUPosition{North: 2000, East: 3100}
  23. base := &NEUPosition{North: 2000, East: 3000}
  24. at, err := point(rover, base, &NEUPosition{})
  25. if err != nil {
  26. t.Errorf("%#v", err)
  27. }
  28. assert.InDelta(t, at.Pitch, 0, 0.001)
  29. assert.InDelta(t, at.Yaw, math.Pi/2, 0.001)
  30. }
  31. func TestPointWest(t *testing.T) {
  32. rover := &NEUPosition{North: 2000, East: 2900}
  33. base := &NEUPosition{North: 2000, East: 3000}
  34. at, err := point(rover, base, &NEUPosition{})
  35. if err != nil {
  36. t.Errorf("%#v", err)
  37. }
  38. assert.InDelta(t, at.Pitch, 0, 0.001)
  39. assert.InDelta(t, at.Yaw, -math.Pi/2, 0.001)
  40. }
  41. func TestPointNorth(t *testing.T) {
  42. rover := &NEUPosition{North: 2100, East: 3000}
  43. base := &NEUPosition{North: 2000, East: 3000}
  44. at, err := point(rover, base, &NEUPosition{})
  45. if err != nil {
  46. t.Errorf("%#v", err)
  47. }
  48. assert.InDelta(t, at.Pitch, 0, 0.001)
  49. assert.InDelta(t, at.Yaw, 0, 0.001)
  50. }
  51. func TestPointSouth(t *testing.T) {
  52. rover := &NEUPosition{North: 1900, East: 3000}
  53. base := &NEUPosition{North: 2000, East: 3000}
  54. at, err := point(rover, base, &NEUPosition{})
  55. if err != nil {
  56. t.Errorf("%#v", err)
  57. }
  58. assert.InDelta(t, at.Pitch, 0, 0.001)
  59. assert.InDelta(t, at.Yaw, math.Pi, 0.001)
  60. }
  61. func TestPointUp(t *testing.T) {
  62. // ~45 degrees up.
  63. rover := &NEUPosition{North: 2000, East: 4000, Up: 1000}
  64. base := &NEUPosition{North: 2000, East: 3000, Up: 0}
  65. at, err := point(rover, base, &NEUPosition{})
  66. if err != nil {
  67. t.Errorf("%#v", err)
  68. }
  69. assert.InDelta(t, at.Pitch, math.Pi/4, 0.01)
  70. assert.InDelta(t, at.Yaw, math.Pi/2, 0.001)
  71. }
  72. func TestPointDown(t *testing.T) {
  73. // ~45 degrees down.
  74. rover := &NEUPosition{North: 2000, East: 4000, Up: 0}
  75. base := &NEUPosition{North: 2000, East: 3000, Up: 1000}
  76. at, err := point(rover, base, &NEUPosition{})
  77. if err != nil {
  78. t.Errorf("%#v", err)
  79. }
  80. assert.InDelta(t, at.Pitch, -math.Pi/4, 0.01)
  81. assert.InDelta(t, at.Yaw, math.Pi/2, 0.001)
  82. }