A PX4 based camera pointer

orientate.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "juju.net.nz/x/pipoint/param"
  18. )
  19. // OrientateState runs to set the pan orientation.
  20. type OrientateState struct {
  21. name string
  22. pi *PiPoint
  23. }
  24. func (s *OrientateState) Name() string {
  25. return "Orientate"
  26. }
  27. // Update is called when a param is updated.
  28. func (s *OrientateState) Update(param *param.Param) {
  29. switch param {
  30. case s.pi.neu:
  31. s.pi.rover.Set(param.Get())
  32. case s.pi.mark:
  33. s.pi.state.Inc()
  34. }
  35. if param != s.pi.rover {
  36. return
  37. }
  38. if !s.pi.rover.Ok() || !s.pi.base.Ok() {
  39. return
  40. }
  41. rover := s.pi.rover.Get().(*NEUPosition)
  42. base := s.pi.base.Get().(*NEUPosition)
  43. offset := s.pi.baseOffset.Get().(*NEUPosition)
  44. att, err := point(rover, base, offset)
  45. if err != nil {
  46. return
  47. }
  48. current := s.pi.offset.Get().(*Attitude)
  49. s.pi.offset.Set(&Attitude{
  50. Yaw: -att.Yaw,
  51. Pitch: current.Pitch,
  52. })
  53. }