Code Monkey home page Code Monkey logo

dynamixel's Introduction

Dynamixel

PkgGoDev

This packages provides a Go interface to Dynamixel servos.

Example

package main

import (
  "log"
  "fmt"
  "github.com/jacobsa/go-serial/serial"
  "dynamixel/network"
  "dynamixel/servo"
  "dynamixel/servo/xl430"
)

func GoalAndTrack(s *servo.Servo, pos int) error{
  curPos, err := s.PresentPosition()
  if err != nil {
    return err
  }
  if curPos == pos{
    fmt.Println("Already at ", pos, " nothing to do")
  }else{
    err = s.SetGoalPosition(pos)
    if err != nil {
      return err
    }
    for(curPos != pos){
      curPos, err = s.PresentPosition()
      if err != nil {
        return err
      }
      fmt.Println("Goal: ", pos, " currently at: ", curPos)
    }
  }
  return nil
}

func main() {
  options := serial.OpenOptions{
    PortName: "/dev/ttyUSB1",
    BaudRate: 1000000,
    DataBits: 8,
    StopBits: 1,
    MinimumReadSize: 0,
    InterCharacterTimeout: 100,
  }

  serial, err := serial.Open(options)
  if err != nil {
    log.Fatalf("error opening serial port: %v\n", err)
  }

  network := network.New(serial)
  servo, err := xl430.New(network, 2)
  if err != nil {
    log.Fatalf("error initializing servo: %v\n", err)
  }

  err = servo.Ping()
  if err != nil {
    log.Fatalf("error pinging servo: %v\n", err)
  }
  var ver int
  ver, err = servo.ModelNumber()
  if err != nil {
    log.Fatalf("error getting model num: %v\n", err)
  }
  fmt.Println(ver)

  err = servo.SetTorqueEnable(true)
  if err != nil {
    log.Fatalf("error setting Torque on\n", err)
  }
  err = GoalAndTrack(servo, 950)
  if err != nil {
    log.Fatalf("error setting goal position: %v\n", err)
  }

  err = GoalAndTrack(servo, 850)
  if err != nil {
    log.Fatalf("error setting goal position: %v\n", err)
  }
  err = servo.SetTorqueEnable(false)
}

More examples can be found in the examples examples directory of this repo.

Documentation

The docs can be found at [godoc.org] docs, as usual. The API is based on the Dynamixel [v1 protocol] proto docs.

License

[MIT] license, obv.

Author

[Adam Mckaig] [adammck] made this just for you. [Peter LoVerso] [biotinker] updated it so that it works on things made this decade.

dynamixel's People

Contributors

adammck avatar biotinker avatar edaniels avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.