Skip to content

Commit 9223cf5

Browse files
committed
slight performance improvement, updated documentation, example, ready for version 1.0.5
1 parent 6cd1255 commit 9223cf5

6 files changed

Lines changed: 24 additions & 26 deletions

File tree

docs/source/index.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
PyVESC Documentation
2-
====================
2+
********************
3+
4+
.. toctree::
5+
:titlesonly:
6+
7+
38
PyVESC is aimed at being a easy to use and robust python implementation of the
49
communication protocol used by the
510
`VESC - Open Source ESC <http://vedder.se/2015/01/vesc-open-source-esc/>`_
@@ -32,7 +37,7 @@ PyVESC can be used to go from a message (VESCMessage) to a packet (bytes).
3237
.. code-block:: python
3338
3439
# make a SetDutyCycle message
35-
my_msg = pyvesc.SetDutyCycle(255)
40+
my_msg = pyvesc.SetDutyCycle(1e5)
3641
print(my_msg.duty_cycle) # prints value of my_msg.duty_cycle
3742
my_packet = pyvesc.encode(my_msg)
3843
# my_packet (type: bytes) can now be sent over your UART connection
@@ -64,7 +69,7 @@ PyVESC serves two purposes:
6469
#. Performs message encoding (to packet) and robust message decoding (to message object)
6570

6671
Messages
67-
--------
72+
========
6873
Here is a list of the messages currently supported in PyVESC. Note that not all
6974
of VESC's messages are implemented. This is because we have only implemented the
7075
messages we use as we don't want to distribute anything that hasn't been tested.
@@ -79,7 +84,7 @@ It should be noted that all message objects can be created in 3 ways:
7984
#. From decoding the next packet in a buffer
8085

8186
Setter Messages
82-
^^^^^^^^^^^^^^^
87+
===============
8388
These are the setter messages which are currently implemented.
8489

8590
.. autoclass:: pyvesc.SetDutyCycle
@@ -90,14 +95,14 @@ These are the setter messages which are currently implemented.
9095
.. autoclass:: pyvesc.SetRotorPositionMode
9196

9297
Getter Messages
93-
^^^^^^^^^^^^^^^
98+
===============
9499
These are the getters that are currently implemented.
95100

96101
.. autoclass:: pyvesc.GetValues
97102
.. autoclass:: pyvesc.GetRotorPosition
98103

99104
Implementing Additional Messages
100-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105+
================================
101106
Here we'll take a look at how to implement your own messages. You're message
102107
class must have the metaclass `pyvesc.VESCMessage`. In addition to this you must
103108
define two static attributes:
@@ -116,16 +121,16 @@ the SetDutyCycle message.
116121
class SetDutyCycle(metaclass=pyvesc.VESCMessage):
117122
id = 5
118123
fields = [
119-
('duty_cycle', 'f')
124+
('duty_cycle', 'i')
120125
]
121126
122127
That's it! Taking a look at the declaration we see:
123128

124129
* The message's ID is 5
125-
* The message has a single field with a name `duty_cycle` and type float32 (this
130+
* The message has a single field with a name `duty_cycle` and type int (this
126131
is what the
127132
`format characters <https://docs.python.org/3.5/library/struct.html#format-characters>`_
128-
`'f'` is)
133+
`'i'` is)
129134

130135
If you are interested in the details of how this works, the `pyvesc.VESCMessage`
131136
metaclass has a registry of all its children this registry is a dictionary
@@ -135,7 +140,7 @@ unique.
135140

136141

137142
Encoding
138-
--------
143+
========
139144
The following is the function call you should use to get a
140145
packet for your message.
141146

@@ -145,7 +150,7 @@ Encoding is done by first serializing the message object and then framing it
145150
in a VESC packet.
146151

147152
Decoding
148-
--------
153+
========
149154
The following is the function you should call to decode messages from the
150155
buffer.
151156

pyvesc/examples/simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
def simple_example():
44
# lets make a SetDuty message
5-
my_msg = pyvesc.SetDutyCycle(255)
5+
my_msg = pyvesc.SetDutyCycle(1e5)
66

77
# now lets encode it to make get a byte string back
88
packet = pyvesc.encode(my_msg)

pyvesc/interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pyvesc.messages.base
22
import pyvesc.packet.codec
33

4+
45
def decode(buffer):
56
"""
67
Decodes the next valid VESC message in a buffer.

pyvesc/messages/base.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ def __init__(cls, name, bases, clsdict):
3333
cls._field_scalars = []
3434
for field, idx in zip(cls.fields, range(0, len(cls.fields))):
3535
cls._field_names.append(field[0])
36-
try:
36+
if len(field) >= 3:
3737
cls._field_scalars.append(field[2])
38-
except IndexError:
39-
pass
4038
if field[1] is 's':
4139
# string field, add % so we can vary the length
4240
cls._fmt_fields += '%u'
@@ -96,12 +94,6 @@ def pack(instance, header_only = None):
9694
return struct.pack(VESCMessage._endian_fmt + VESCMessage._id_fmt, instance.id)
9795

9896
field_values = []
99-
#for field_name,field_scalar in zip(instance._field_names, instance._field_scalars):
100-
#print(field_name, field_scalar)
101-
#if instance._field_scalars:
102-
# for field_name, field_scalar in zip(instance._field_names, instance._field_scalars):
103-
# field_values.append(getattr(instance, field_name*field_scalar))
104-
#else:
10597
if not instance._field_scalars:
10698
for field_name in instance._field_names:
10799
field_values.append(getattr(instance, field_name))

pyvesc/messages/setters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class SetRPM(metaclass=VESCMessage):
2424

2525

2626
class SetCurrent(metaclass=VESCMessage):
27-
""" Set the current to the motor.
27+
""" Set the current (in milliamps) to the motor.
2828
29-
:ivar current: Value to set the current to.
29+
:ivar current: Value to set the current to (in milliamps).
3030
"""
3131
id = 6
3232
fields = [
@@ -35,9 +35,9 @@ class SetCurrent(metaclass=VESCMessage):
3535

3636

3737
class SetCurrentBrake(metaclass=VESCMessage):
38-
""" Set the current brake.
38+
""" Set the current brake (in milliamps).
3939
40-
:ivar current_brake: Value to set the current brake to.
40+
:ivar current_brake: Value to set the current brake to (in milliamps).
4141
"""
4242
id = 7
4343
fields = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
VERSION = '1.0.4'
3+
VERSION = '1.0.5'
44

55
setup(
66
name = 'pyvesc',

0 commit comments

Comments
 (0)