A PX4 based camera pointer

cycle.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "juju.net.nz/x/pipoint/param"
  19. "juju.net.nz/x/pipoint/util"
  20. )
  21. // CycleState cycles the pan/tilt in a circle.
  22. type CycleState struct {
  23. pi *PiPoint
  24. cycle float64
  25. }
  26. func (s *CycleState) Name() string {
  27. return "Cycle"
  28. }
  29. // Update reacts to changes in parameters.
  30. func (s *CycleState) Update(param *param.Param) {
  31. switch param {
  32. case s.pi.tick:
  33. s.cycle += 0.02
  34. s.pi.pan.Set(util.Scale(math.Cos(s.cycle), -1, 1, -math.Pi/2, math.Pi/2))
  35. s.pi.tilt.Set(util.Scale(math.Sin(s.cycle), -1, 1, -math.Pi/2, 0))
  36. }
  37. }