Package ckbot :: Module dynamixel :: Class Bus
[hide private]
[frames] | no frames]

Class Bus

source code


( concrete )
DESCRIPTION: 
  -- The Bus class serves as an interface between the dynamixel RS485 bus and Protocol
RESPONSIBILITIES: 
  -- intialize a serial newConnection at the desired baudrate. default: 1000000
  -- format packets into dynamixel understanble messages
  -- write packets
  -- read in valid packets, throw out others
     - maintain error counts from read attempts
  -- provide syncronous write then read capability
OWNERSHIP:
  -- owned by the dynamixel module
THEORY: 
  -- builds and writes Dynamixel EX packets as per EX-106 section 3-2 pp. 16
  -- reads packets and parses for valid ones as per EX-106 section 3-3 pp. 17
CONSTRAINTS: 
  -- requires valid baudrate setting for communication
  -- writes and reads limited by pyserial->termios 

Instance Methods [hide private]
 
__init__(self, port=None, *args, **kw)
Initialize Dynamixel Bus
source code
 
getSupportedBaudrates(self)
List of supported baud rates
source code
 
reset(self)
The purpose of this method is to reset the state of the Bus to initial values
source code
 
flush(self)
Flush software and hardware buffers
source code
 
statsMsg(self)
returns the current Bus statistics
source code
 
reconnect(self, **changes) source code
 
_dropByte(self, error=None)
(private) Drop a single byte from the input buffer .buf and reset .expect If error is provided, increment that error counter
source code
 
_testForEcho(self, pkt) source code
 
recv(self, maxlen=10)
reads a single packet off of the RS485 or serial bus
source code
 
send(self, nid, cmd, pars='')
Build a message and transmit, update rxPkts, and return message string
source code
 
send_sync_write(self, nid, addr, pars)
Build a SYNC_WRITE message writing a value
source code
 
ping(self, nid)
Send a low level ping command to a given nid
source code
 
reset_nid(self, nid)
Send a low level reset command to a given nid
source code
 
send_cmd_sync(self, nid, cmd, pars, timeout=0.1, retries=5)
Send a command in synchronous form, waiting for reply
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
_chksum(cls, dat)
(private) Compute checksum as per EX-106 section 3-2 pp.
source code
 
parseErr(cls, pkt, noRaise=False)
(private) Parse and output error returned from dynamixel servos as per 3-4-1 pp.
source code
 
dump(cls, msg)
Parses a message into human readable form...
source code
Static Methods [hide private]
 
splitReply(reply)
Unpack reply header and payload...
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, port=None, *args, **kw)
(Constructor)

source code 

Initialize Dynamixel Bus

INPUT: 
  port -- serial port string or None to autoconfig

ATTRIBUTES:
  ser -- serial handle
  buf -- buffer string '
  expect -- number of expected bytes. default: 6
  eSync -- number of SYNC errors
  eChksum -- number of checksum errors  
  eLen -- number of length errors   
  eID -- number of ID errors 
  count -- a count of bytes received  
  rxPkts -- a count of valid packets received
  txPkts -- a count of packets sent

Overrides: object.__init__

statsMsg(self)

source code 

returns the current Bus statistics 

OUTPUTS:
  -- list -- strings indicating current counts, error, etc ...

_chksum(cls, dat)
Class Method

source code 
(private)
Compute checksum as per EX-106 section 3-2 pp. 17  

INPUTS:
  dat -- string -- data from which to compute checksum
OUTPUTS:
  return -- int -- value of checksum between 0 and 0xFF

THEORY OF OPERATION:
  Compute checksum using not bit operator for only the lowest
  byte of the sum

parseErr(cls, pkt, noRaise=False)
Class Method

source code 

(private) Parse and output error returned from dynamixel servos as per 3-4-1 pp. 25

dump(cls, msg)
Class Method

source code 

Parses a message into human readable form
INPUT:
  msg -- one or more message in a string
OUTPUT:
  the messages in human-readable form

recv(self, maxlen=10)

source code 

reads a single packet off of the RS485 or serial bus 

INPUTS:
  None
OUTPUTS:
  pkt -- string -- valid packet from Dynamixel hardware bus
PRECONDITIONS:
  existence of serial object
  reset() has been called at least once
POSTCONDITIONS:
  pkt is returned given that all values of packet check OUTPUTS

THEORY OF OPERATION:
  Parse for valid packets as per EX-106 section 3-3 pp. 17
  - While there are bytes to be read from serial buffer or from buf
    - Read in expected number of bytes if available
    - Check for start frame, otherwise drop byte
    - Check for valid ID, otherwise drop byte
    - Check for valid Length, otherwise drop byte
    - Once Length bytes arrive, check if CRC is valid, otherwise drop byte
  - If there are no more bytes to read or parse then return None

send(self, nid, cmd, pars='')

source code 

Build a message and  transmit, update rxPkts, and return message string

INPUTS:
  nid -- int -- node ID of module
  cmd -- int -- command value. ie: CMD_PING, CMD_WRITE_DATA, etc ...
  pars -- string -- parameter string
OUTPUTS: 
  msg -- string -- transmitted packet minus sync          
PRECONDITIONS:
  existance of serial object        
POSTCONDITIONS:
  None

THEORY OF OPERATION:
  Assemble packet as per EX-106 section 3-2 pp. 16,
  Compute checksum, transmit and then return string

send_sync_write(self, nid, addr, pars)

source code 

Build a SYNC_WRITE message writing a value

INPUTS:
  nid -- int -- node ID of module
  addr -- string -- address
  pars -- string -- value (after marshalling)
OUTPUTS: 
  msg -- string -- transmitted packet minus sync          
PRECONDITIONS:
  existance of serial object        
POSTCONDITIONS:
  None

THEORY OF OPERATION:
  Set a value remotely, without expecting a reply

ping(self, nid)

source code 

Send a low level ping command to a given nid 

INPUTS:
  nid -- int -- node ID of module
OUTPUTS: 
  None 
PRECONDITIONS:
  instantiation of dynamixel.Bus
POSTCONDITIONS:
  No response occurs 

THEORY OF OPERATION:
  Send CMD_PING for given nid as per section 3-5-5 pp. 37

reset_nid(self, nid)

source code 

Send a low level reset command to a given nid 

INPUTS:
  nid -- int -- node ID of servo to reset 

THEORY OF OPERATION:
  Send CMD_RESET for given nid as per section 3-5-6 pp. 38
  Resets all values in the servo's control table to factory
  defaults, INCLUDING the ID, which is reset to 0x01. 

  By convention, we reserve ID 0x01 for configuration purposes

send_cmd_sync(self, nid, cmd, pars, timeout=0.1, retries=5)

source code 

Send a command in synchronous form, waiting for reply

INPUTS:
  nid, cmd, pars -- same as for .send()
  timeout -- float-- maximal wait per retry
  retries -- number of allowed retries until giving up
  rate -- wait time between retries
OUTPUTS: 
  pkt -- string -- response packet's payload          

THEORY OF OPERATION:
  Plan out sending times for all retries. When a retry goal time is passed
  sends out the message. In between, poll for a reply for that message at a
  hard coded rate (currently 100Hz)

splitReply(reply)
Static Method

source code 

Unpack reply header and payload
OUTPUT: nid, len, cmd, tail
  nid -- node ID
  len -- message length 
  cmd -- command code in message
  tail -- remainder of the message, as a string