A PX4 based camera pointer

filter_test.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "testing"
  18. "github.com/stretchr/testify/assert"
  19. )
  20. func TestLowpass(t *testing.T) {
  21. tau := 0.3
  22. l := &Lowpass{}
  23. // Moves towards the input in diminishing steps.
  24. assert.InDelta(t, l.StepEx(3, tau), 0.9, 0.1)
  25. assert.InDelta(t, l.StepEx(3, tau), 1.6, 0.1)
  26. assert.InDelta(t, l.StepEx(3, tau), 2.0, 0.1)
  27. assert.InDelta(t, l.StepEx(3, tau), 2.3, 0.1)
  28. assert.InDelta(t, l.StepEx(3, tau), 2.5, 0.1)
  29. }
  30. func TestLinPred(t *testing.T) {
  31. l := &LinPred{}
  32. // Returns initial value.
  33. l.SetEx(5, 1, 1)
  34. assert.InDelta(t, l.GetEx(1), 5, 0.001)
  35. // Initial value continues.
  36. assert.InDelta(t, l.GetEx(2), 5, 0.001)
  37. l.SetEx(5.5, 2, 2)
  38. // Initially returns the same value.
  39. assert.InDelta(t, l.GetEx(2), 5.5, 0.001)
  40. // Velocity is 0.5/s
  41. assert.InDelta(t, l.GetEx(2.5), 5.75, 0.001)
  42. assert.InDelta(t, l.GetEx(3.0), 6.0, 0.001)
  43. // Negative velocity also works.
  44. l.SetEx(4, 3, 3)
  45. assert.InDelta(t, l.GetEx(3), 4, 0.001)
  46. assert.InDelta(t, l.GetEx(4), 2.5, 0.001)
  47. }