Skip to main content

A library to control dynamixel XL-320 servos with python

Project description

Code Health Latest Version Downloads License

This is still a work in progress and only supports XL-320 and only version 2.0 of their protocol.

https://raw.githubusercontent.com/walchko/pyxl320/master/pics/xl-320.jpg

The library is divided up as follows:

  • pyxl320
    • ServoSerial - half duplex hardware serial interface

    • DummySerial - for testing, doesn’t talk to any hardware

    • Packet - creates packets

    • utils - misc

    • xl320 - register/command/error definitions for Dynamixel’s XL-320 servo

Not everything is implemented, but more will be added over time.

Setup

Install

pip install pyxl320

Development

To submit git pulls, clone the repository and set it up as follows:

git clone https://github.com/walchko/pyxl320
cd pyxl320
pip install -e .

Usage

from pyxl320 import xl320
from pyxl320 import ServoSerial, Packet, utils

serial = ServoSerial('/dev/tty.usbserial')  # tell it what port you want to use
serial.open()

pkt = Packet.makeServoPacket(1, 158.6)  # move servo 1 to 158.6 degrees
serial.write(pkt)  # send packet to servo
ans = serial.read()  # get return status packet

if packet.isError(ans):
        pkt = packet.makeLEDPacket(1, pyxl320.XL320_LED_RED)
        serial.write(pkt)
        raise Exception('servo error: {}'.format(packet.errorString(ans)))

Al though I have made some packet creators (like LED and Servo), you can make your own using the basic makeWritePacket and makeReadPacket.

from pyxl320 import Packet, xl320
from pyxl320.Packet import le  # creates little endian numbers

# let's make our own servo packet that sends servo 3 to 220.1 degrees
ID = 3
reg = xl320.XL320_GOAL_POSITION
params = le(int(220.1/300*1023))  # convert 220.1 degrees to an int between 0-1023
pkt = Packet.makeWritePacket(ID, reg, params)

Packet Basics

Header

ID

Length

Instruction

Parameter

CRC

[0xFF, 0xFF, 0xFD, 0x00]

ID

[LEN_L, LEN_H]

INST

[PARAM 1, PARAM 2, …, PARAM N]

[CRC_L, CRC_H]

A status packet back from the servo follows the same format, but the instruction is always 0x55 and maybe followed by error codes if something is wrong. The length of the packet is aways the entire length minus header, id, and crc. Also remember, the packets are little-endian, so place numbers in the packet as [LSB, MSB]. You can use the function le() in Packet to accomplish this.

See the references below for more details on the instructions, error codes, etc.

Hardware

https://raw.githubusercontent.com/walchko/pyxl320/master/pics/xl320_2.png https://raw.githubusercontent.com/walchko/pyxl320/master/pics/circuit.png

References:

Unfortunately the Dynamixel references below are not written well (many typos and errors throughout), so please be careful or you will exhibit much frustration.

ToDo

  • look at using python struct for packets

  • clean up packet reading, sometimes get a 0 appended at beginning or end

  • look at using a class system instead of functions for packets

  • look at setting up a servo based on a json file

  • more helper functions in utils and or bin

Change Log

2016-09-05

0.5.0

published to PyPi

2016-08-16

0.0.1

init

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyxl320-0.5.2.tar.gz (9.7 kB view details)

Uploaded Source

File details

Details for the file pyxl320-0.5.2.tar.gz.

File metadata

  • Download URL: pyxl320-0.5.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyxl320-0.5.2.tar.gz
Algorithm Hash digest
SHA256 24315bb832e3ae41be89288e69cc941c7fdeab4cae2c38c46919d854599e9910
MD5 9ed8a1f9df9b278a1902c65437362cfb
BLAKE2b-256 b09f42a72360b7fce2daa2bab820a218d5e2399863b62763d44a36b3a20dcd01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page