You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

direct.go 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package chocococon
  2. import (
  3. "fmt"
  4. "git.timschuster.info/stephan.graf/SanguControl"
  5. "github.com/pkg/errors"
  6. )
  7. func init() {
  8. cmds["san_home"] = manhome
  9. helpm["san_home"] = "Calibrates the position of the head"
  10. cmds["san_xyz"] = manxyz
  11. helpm["san_xyz"] = "Manually moves the head, bypassing the CHC"
  12. cmds["san_stop"] = notyetimplemented
  13. helpm["san_stop"] = "Issues an emergency stop to all devices and exits"
  14. cmds["san_con"] = mancon
  15. helpm["san_con"] = "Starts Sangu Control Console"
  16. cmds["getpos"] = getcoords
  17. helpm["getpos"] = "Prints current position"
  18. cmds["step"] = step
  19. helpm["step"] = "Single step syntax x,setpl="
  20. }
  21. func manhome(params []string) error {
  22. if curCHC == nil {
  23. fmt.Println("CHC not connected, aborting.")
  24. return nil
  25. }
  26. tdc := curCHC.GetThreeDControl()
  27. if tdc == nil {
  28. fmt.Println("Hardware Controller does not support Direct 3D Access")
  29. return nil
  30. }
  31. return tdc.Movehome()
  32. }
  33. func manxyz(params []string) error {
  34. if curCHC == nil {
  35. fmt.Println("CHC not connected, aborting.")
  36. return nil
  37. }
  38. var (
  39. x, y, z float64
  40. )
  41. x, y, z = -1, -1, -1
  42. for k := range params {
  43. if err := parseParamToFloat64("x", &x, params[k]); err != nil {
  44. return errors.Wrap(err, "Error while parsing X")
  45. }
  46. if err := parseParamToFloat64("y", &y, params[k]); err != nil {
  47. return errors.Wrap(err, "Error while parsing Y")
  48. }
  49. if err := parseParamToFloat64("z", &z, params[k]); err != nil {
  50. return errors.Wrap(err, "Error while parsing Z")
  51. }
  52. }
  53. fmt.Printf("Moving manually to %5.1f %5.1f %5.1f\n", x, y, z)
  54. tdc := curCHC.GetThreeDControl()
  55. if tdc == nil {
  56. fmt.Println("Hardware Controller does not support Direct 3D Access")
  57. return nil
  58. }
  59. return tdc.Moveto(x, y, z)
  60. }
  61. func mancon(params []string) error {
  62. if curCHC == nil {
  63. fmt.Println("CHC not connected, aborting.")
  64. return nil
  65. }
  66. SanguControl.Keyboardcontrol()
  67. return nil
  68. }
  69. func getcoords(params []string) error {
  70. if curCHC == nil {
  71. fmt.Println("CHC not connected, aborting.")
  72. return nil
  73. }
  74. tdc := curCHC.GetThreeDControl()
  75. if tdc == nil {
  76. fmt.Println("Hardware Controller does not support Direct 3D Access")
  77. return nil
  78. }
  79. x, y, z, err := tdc.Getposition(false)
  80. if err != nil {
  81. return errors.Wrap(err, "Could not get position")
  82. }
  83. fmt.Printf("Current Position: %f, %f, %f\n", x, y, z)
  84. return nil
  85. }
  86. func step(params []string) error {
  87. if curCHC == nil {
  88. fmt.Println("CHC not connected, aborting.")
  89. return nil
  90. }
  91. var (
  92. moveX, moveY, moveZ, reverse bool
  93. stepLength float64
  94. )
  95. moveX, moveY, moveZ, reverse = false, false, false, false
  96. stepLength = 1.0
  97. for k := range params {
  98. if err := parseParamToFloat64("stepl", &stepLength, params[k]); err != nil {
  99. return errors.Wrap(err, "Error while parsing X")
  100. }
  101. if params[k] == "x" {
  102. moveX = true
  103. }
  104. if params[k] == "y" {
  105. moveY = true
  106. }
  107. if params[k] == "z" {
  108. moveZ = true
  109. }
  110. if params[k] == "-" {
  111. reverse = true
  112. }
  113. }
  114. tdc := curCHC.GetThreeDControl()
  115. if tdc == nil {
  116. fmt.Println("Hardware Controller does not support Direct 3D Access")
  117. return nil
  118. }
  119. return tdc.Singlestep(moveX, moveY, moveZ, stepLength, reverse)
  120. }