Skip to content

Commit

Permalink
Move constructors docstring to the classes docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiedecock committed Aug 21, 2015
1 parent 0428fc7 commit c560d20
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 49 deletions.
15 changes: 7 additions & 8 deletions pyax12/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@
from pyax12 import utils

class Connection(object):
"""Create a serial connection with dynamixel actuators."""
"""Create a serial connection with dynamixel actuators.
def __init__(self, port='/dev/ttyUSB0', baudrate=57600, timeout=0.1):
"""Create a serial connection with dynamixel actuators.
:param str port: the serial device to connect with (e.g. '/dev/ttyUSB0'
for Unix users or 'COM1' for windows users).
:param int baudrate: the baudrate speed (e.g. 57600).
:param float timeout: the timeout value for the connection.
"""

:param str port: the serial device to connect with (e.g. '/dev/ttyUSB0'
for Unix users or 'COM1' for windows users).
:param int baudrate: the baudrate speed (e.g. 57600).
:param float timeout: the timeout value for the connection.
"""
def __init__(self, port='/dev/ttyUSB0', baudrate=57600, timeout=0.1):

self.port = port
self.baudrate = baudrate
Expand Down
18 changes: 8 additions & 10 deletions pyax12/instruction_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,17 @@ class InstructionPacket(pk.Packet):
+----+----+--+------+-----------+----------+---+-----------+---------+
|0XFF|0XFF|ID|LENGTH|INSTRUCTION|PARAMETER1|...|PARAMETER N|CHECK SUM|
+----+----+--+------+-----------+----------+---+-----------+---------+
:param int dynamixel_id: the the unique ID of the Dynamixel unit which
have to execute this instruction packet.
:param int instruction: the instruction for the Dynamixel actuator to
perform.
:param bytes parameters: a sequence of bytes used if there is
additional information needed to be sent other than the instruction
itself.
"""

def __init__(self, dynamixel_id, instruction, parameters=None):
"""Create an "instruction packet".
:param int dynamixel_id: the the unique ID of the Dynamixel unit which
have to execute this instruction packet.
:param int instruction: the instruction for the Dynamixel actuator to
perform.
:param bytes parameters: a sequence of bytes used if there is
additional information needed to be sent other than the instruction
itself.
"""

# Check the parameters byte.
# "TypeError" and "ValueError" are raised by the "bytes" constructor if
Expand Down
38 changes: 18 additions & 20 deletions pyax12/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,21 @@ class Packet(object):
+----+----+--+------+-------+---------+
|0xFF|0xFF|ID|LENGTH|DATA...|CHECK SUM|
+----+----+--+------+-------+---------+
This class has been made for debugging purpose and is not intended to be
used widely to create packets.
Instead, it is recommanded to use `InstructionPacket` or `StatusPacket`
classes to build `Packet` instances.
:param int dynamixel_id: the unique ID of a Dynamixel unit (from 0x00
to 0xFD), 0xFE is a broadcasting ID.
:param bytes data: a sequence of byte containing the packet's data: the
instruction to perform or the status of the Dynamixel actuator.
This `data` argument contains the fifth to the penultimate byte of
the full built packet.
"""

def __init__(self, dynamixel_id, data):
"""Create a raw packet.
This constructor has been made for debugging purpose and is not intended
to be used widely to create packets.
Instead, it is recommanded to use `InstructionPacket` or `StatusPacket`
classes to build `Packet` instances.
:param int dynamixel_id: the unique ID of a Dynamixel unit (from 0x00
to 0xFD), 0xFE is a broadcasting ID.
:param bytes data: a sequence of byte containing the packet's data: the
instruction to perform or the status of the Dynamixel actuator.
This `data` argument contains the fifth to the penultimate byte of
the full built packet.
"""

# Check the data bytes.
# "TypeError" and "ValueError" are raised by the "bytes" constructor if
Expand Down Expand Up @@ -207,7 +205,7 @@ def to_bytes(self):
bytes).
This function returns something like::
b'\xff\xff\xfe\x04\x03\x03\x01\xf6'
"""

Expand All @@ -218,7 +216,7 @@ def to_integer_tuple(self):
"""Return the packet as a tuple of integers.
This function returns something like::
(255, 255, 254, 4, 3, 3, 1, 246)
"""

Expand Down Expand Up @@ -255,7 +253,7 @@ def dynamixel_id(self):
r"""The unique ID of a Dynamixel unit concerned with this packet.
This byte either:
- has a value between 0x00 and 0xFD to affect the corresponding
Dynamixel unit
- or has the value 0xFE to affect all connected units (0xFE is the
Expand All @@ -271,11 +269,11 @@ def length(self):
This is not the actual length of the full packet (`self._bytes`) but
its number of bytes after its fourth byte, i.e.::
len(self._bytes[4:])
or in other words::
len(self._bytes) - 4
This value (so called "LENGTH") defines the fourth byte of each packet.
Expand Down
20 changes: 9 additions & 11 deletions pyax12/status_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,18 @@ class StatusPacket(pk.Packet):
+----+----+--+------+-----+----------+---+-----------+---------+
|0XFF|0XFF|ID|LENGTH|ERROR|PARAMETER1|...|PARAMETER N|CHECK SUM|
+----+----+--+------+-----+----------+---+-----------+---------+
"""
def __init__(self, packet):
"""Create a "status packet".
StatusPacket is not intended to be instancied by users (except maybe
for testing and debugging prupose). Under normal conditions of use,
`StatusPacket`'s instances are automatically created by the
`Connection` class.
StatusPacket is not intended to be instancied by users (except maybe
for testing and debugging prupose). Under normal conditions of use,
`StatusPacket`'s instances are automatically created by the
`Connection` class.
:param bytes packet: a sequence of bytes containing the full status
packet returned by Dynamixel units. It must be compatible with the
"bytes" type.
"""

:param bytes packet: a sequence of bytes containing the full status
packet returned by Dynamixel units. It must be compatible with the
"bytes" type.
"""
def __init__(self, packet):

# Check the argument and convert it to "bytes" if necessary.
# Assert "packet" items are in range (0, 0xff).
Expand Down

0 comments on commit c560d20

Please sign in to comment.