summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jet tsang zeon-git <zeon-git@jettsang.com> 2020-08-05 15:41:15 +0800
committerGravatar jet tsang zeon-git <zeon-git@jettsang.com> 2020-08-05 15:41:15 +0800
commit937730f54a68281dccfcb06629342e5259f00aad (patch)
tree1fcd9abdc9125e18017a8657323e95c010e8f16c
parentAdd set-position example. (diff)
downloadlobot-937730f54a68281dccfcb06629342e5259f00aad.tar.gz
lobot-937730f54a68281dccfcb06629342e5259f00aad.tar.bz2
lobot-937730f54a68281dccfcb06629342e5259f00aad.zip
Add lobotctl for debug instruction bytes
Signed-off-by: jet tsang zeon-git <zeon-git@jettsang.com>
-rw-r--r--.gitignore1
-rw-r--r--cmd/lobotctl/lobotctl.go69
2 files changed, 70 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a50fb76
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+cmd/lobotctl/lobotctl
diff --git a/cmd/lobotctl/lobotctl.go b/cmd/lobotctl/lobotctl.go
new file mode 100644
index 0000000..c5533df
--- /dev/null
+++ b/cmd/lobotctl/lobotctl.go
@@ -0,0 +1,69 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "os"
+ "strconv"
+ "strings"
+
+ "git.jettsang.com/drivers/lobot/network"
+ "git.jettsang.com/drivers/lobot/servo"
+ "git.jettsang.com/drivers/lobot/servo/lx"
+ "github.com/jacobsa/go-serial/serial"
+)
+
+var (
+ portName = flag.String("port", "/dev/tty.usbserial-A9ITPZVR", "the serial port path")
+ servoID = flag.Int("id", 1, "the ID of the servo")
+ instruction = flag.String("instruction", "", "instruction")
+ argument = flag.String("arguments", "1,1000", "uint16 txt break on comma")
+ debug = flag.Bool("debug", false, "show serial traffic")
+)
+
+func main() {
+ flag.Parse()
+
+ options := serial.OpenOptions{
+ PortName: *portName,
+ BaudRate: 115200,
+ DataBits: 8,
+ StopBits: 1,
+ MinimumReadSize: 0,
+ InterCharacterTimeout: 100,
+ }
+
+ serial, err := serial.Open(options)
+ if err != nil {
+ fmt.Printf("open error: %s\n", err)
+ os.Exit(1)
+ }
+
+ network := network.New(serial)
+ if *debug {
+ network.Logger = log.New(os.Stderr, "", log.LstdFlags)
+ }
+
+ network.Flush()
+
+ // var servo *servo.Servo
+ srv, err := lx.New(network, *servoID)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ var params []uint16
+ textArguments := strings.Split(*argument, ",")
+ for _, v := range textArguments {
+ value, _ := strconv.Atoi(v)
+ params = append(params, uint16(value))
+ }
+
+ instRun := servo.GetInstName(*instruction)
+ log.Println(instRun.String(), params)
+ if err = srv.SendInstruction(instRun, params); err != nil {
+ log.Fatalln(err)
+ }
+
+}