Browse Source

motorcontrol added to console plus better doc for step

motorcontrol
Bin ohne name geboren 2 years ago
parent
commit
5b91d1e5f7
2 changed files with 49 additions and 24 deletions
  1. 29
    6
      chc.go
  2. 20
    18
      direct.go

+ 29
- 6
chc.go View File

@@ -2,12 +2,13 @@ package chocococon
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"git.timschuster.info/stephan.graf/Complete_hardware_Control"
5
+	"io/ioutil"
6 6
 	"log"
7 7
 	"os"
8
-	"github.com/pkg/errors"
9 8
 	"strings"
10
-	"io/ioutil"
9
+
10
+	"git.timschuster.info/stephan.graf/Complete_hardware_Control"
11
+	"github.com/pkg/errors"
11 12
 )
12 13
 
13 14
 func init() {
@@ -20,6 +21,8 @@ func init() {
20 21
 	helpm["roll"] = "Rolls the head. [angle]"
21 22
 	cmds["rotate"] = rotate
22 23
 	helpm["rotate"] = "Rotates the head. [angle]"
24
+	cmds["motor"] = motor
25
+	helpm["motor"] = "overrides the actual speed of the motor"
23 26
 
24 27
 	cmds["connect"] = connect
25 28
 	helpm["connect"] = "Connects to a Hardware Controller. [path]"
@@ -35,7 +38,7 @@ func init() {
35 38
 	helpm["nolog"] = "Disables the log for future connections"
36 39
 }
37 40
 
38
-var logger = log.New(os.Stderr, "CHC", log.Lshortfile | log.LUTC)
41
+var logger = log.New(os.Stderr, "CHC", log.Lshortfile|log.LUTC)
39 42
 
40 43
 func nolog(params []string) error {
41 44
 	logger = log.New(ioutil.Discard, "", log.LUTC)
@@ -46,7 +49,7 @@ func connect(params []string) error {
46 49
 	var path string
47 50
 
48 51
 	for k := range params {
49
-		if strings.HasPrefix(params[k],"path=") {
52
+		if strings.HasPrefix(params[k], "path=") {
50 53
 			path = strings.TrimPrefix(params[k], "path=")
51 54
 		}
52 55
 	}
@@ -137,6 +140,26 @@ func rotate(params []string) error {
137 140
 	fmt.Printf("Rotating to angle %d\n", angle)
138 141
 	return curCHC.Rotate(angle)
139 142
 }
143
+func motor(params []string) error {
144
+	if curCHC == nil {
145
+		fmt.Println("CHC not connected, aborting.")
146
+		return nil
147
+	}
148
+	var (
149
+		angle int16
150
+	)
151
+	angle = -1
152
+
153
+	for k := range params {
154
+		if err := parseParamToInt16("angle", &angle, params[k]); err != nil {
155
+			fmt.Println("Err parsing: ", err)
156
+			return nil
157
+		}
158
+	}
159
+
160
+	fmt.Printf("Setting speed to %d\n", angle)
161
+	return curCHC.OverrideMotorSpeed(angle)
162
+}
140 163
 
141 164
 func deliver(params []string) error {
142 165
 	if curCHC == nil {
@@ -186,4 +209,4 @@ func putin(params []string) error {
186 209
 	}
187 210
 
188 211
 	return curCHC.PutIn(regalNumber, fachNumber)
189
-}
212
+}

+ 20
- 18
direct.go View File

@@ -2,8 +2,9 @@ package chocococon
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"github.com/pkg/errors"
5
+
6 6
 	"git.timschuster.info/stephan.graf/SanguControl"
7
+	"github.com/pkg/errors"
7 8
 )
8 9
 
9 10
 func init() {
@@ -21,7 +22,8 @@ func init() {
21 22
 	helpm["getpos"] = "Prints current position"
22 23
 
23 24
 	cmds["step"] = step
24
-	helpm["step"] = "Single step"
25
+	helpm["step"] = "Single step syntax x,setpl="
26
+
25 27
 }
26 28
 
27 29
 func manhome(params []string) error {
@@ -43,20 +45,20 @@ func manxyz(params []string) error {
43 45
 		return nil
44 46
 	}
45 47
 	var (
46
-		x, y, z         float64
48
+		x, y, z float64
47 49
 	)
48 50
 	x, y, z = -1, -1, -1
49 51
 
50 52
 	for k := range params {
51
-	if err := parseParamToFloat64("x", &x, params[k]); err != nil {
52
-	return errors.Wrap(err, "Error while parsing X")
53
-}
54
-	if err := parseParamToFloat64("y", &y, params[k]); err != nil {
55
-	return errors.Wrap(err, "Error while parsing Y")
56
-	}
57
-	if err := parseParamToFloat64("z", &z, params[k]); err != nil {
58
-	return errors.Wrap(err, "Error while parsing Z")
59
-	}
53
+		if err := parseParamToFloat64("x", &x, params[k]); err != nil {
54
+			return errors.Wrap(err, "Error while parsing X")
55
+		}
56
+		if err := parseParamToFloat64("y", &y, params[k]); err != nil {
57
+			return errors.Wrap(err, "Error while parsing Y")
58
+		}
59
+		if err := parseParamToFloat64("z", &z, params[k]); err != nil {
60
+			return errors.Wrap(err, "Error while parsing Z")
61
+		}
60 62
 	}
61 63
 	fmt.Printf("Moving manually to %5.1f %5.1f %5.1f\n", x, y, z)
62 64
 	tdc := curCHC.GetThreeDControl()
@@ -64,7 +66,7 @@ func manxyz(params []string) error {
64 66
 		fmt.Println("Hardware Controller does not support Direct 3D Access")
65 67
 		return nil
66 68
 	}
67
-	return tdc.Moveto(x,y,z)
69
+	return tdc.Moveto(x, y, z)
68 70
 }
69 71
 
70 72
 func mancon(params []string) error {
@@ -86,7 +88,7 @@ func getcoords(params []string) error {
86 88
 		fmt.Println("Hardware Controller does not support Direct 3D Access")
87 89
 		return nil
88 90
 	}
89
-	x,y,z, err := tdc.Getposition(false)
91
+	x, y, z, err := tdc.Getposition(false)
90 92
 	if err != nil {
91 93
 		return errors.Wrap(err, "Could not get position")
92 94
 	}
@@ -100,10 +102,10 @@ func step(params []string) error {
100 102
 		return nil
101 103
 	}
102 104
 	var (
103
-		moveX,moveY,moveZ, reverse bool
104
-		stepLength float64
105
+		moveX, moveY, moveZ, reverse bool
106
+		stepLength                   float64
105 107
 	)
106
-	moveX, moveY, moveZ, reverse = false,false,false,false
108
+	moveX, moveY, moveZ, reverse = false, false, false, false
107 109
 	stepLength = 1.0
108 110
 
109 111
 	for k := range params {
@@ -130,4 +132,4 @@ func step(params []string) error {
130 132
 		return nil
131 133
 	}
132 134
 	return tdc.Singlestep(moveX, moveY, moveZ, stepLength, reverse)
133
-}
135
+}

Loading…
Cancel
Save