Lobot 的系列舵機的 golang 驅動

最近在製作一些座標與電機控制相關的東西,其中有一個功能需要扭矩很大且精確動作的 Trigger 以控制一個手動設備實現自動化,最終我選擇了這個 lobot 牌子的總線舵機 LX-16A

重要的是,價格相當實惠!

我已經為它編寫了一個 golang 驅動了,可以在這裡找到 :
https://git.jettsang.com/drivers/lobot/

用法相當簡單:

package main

import (
    "flag"
    "fmt"
    "log"
    "os"

    "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 to move")
    position = flag.Int("position", 512, "the goal position to set")
    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
    servo, err = lx.New(network, *servoID)
    err = servo.MoveTimeWrite(uint16(*position), 500)
    if err != nil {
        fmt.Printf("move error: %s\n", err)
        os.Exit(1)
    }
}


More from VOID IF TAMPERED