Skip to content

Commit daeda55

Browse files
committed
docs and comments
1 parent 73de94b commit daeda55

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
11
# uPy-genpy
2+
3+
This is a little similar implementation of `genpy` for uPy. In order to use rosserial with it, having messages classes. For that and automation purposes, this package has been done so that this classes can be done easily. This has been done to be used with [uPy rosserial](https://github.com/FunPythonEC/uPy-rosserial).
4+
5+
## Features
6+
7+
- [x] uPy files gen with publish availability
8+
- [ ] uPy files gen with subscribe availability
9+
- [ ] Actions
10+
- [ ] Services
11+
12+
## Installation
13+
In order to use this package the folder `ugenpy` from `src` must be copied to the flash memory. I strongly recommend using [rshell](https://github.com/dhylands/rshell) for this task.
14+
15+
There is also a folder called `std_msgs` which has all default `*.msg` files, this folder can also be copied or any other folder with the wanted message types. For memory purposes not all the `msg` files in that folder must be copied, only the ones that are going to be used.
16+
17+
>Note: Soon this will be available to be installed with upip.
18+
19+
## Usage
20+
21+
Suppose there is already the dir `std_msgs/ColorRGB.msg` and we want to create the uPy file for it, then a script like below can be run:
22+
23+
``` python
24+
from ugenpy.message import MessageGenerator
25+
msg=MessageGenerator('std_msgs/ColorRGBA.msg')
26+
msg.create_message()
27+
```
28+
29+
You could verify it has been created with the following:
30+
``` python
31+
import os
32+
os.listdir('std_msgs')
33+
```
34+
=======
235
Here everything needed in order to generate the python files for message usage can be found.
36+
>>>>>>> 73de94b4ea4c44f58ebda99e238657cef2698260

src/ugenpy/message.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from . import md5
22

3+
"""
4+
Message class copied from:
5+
https://github.com/ros/genpy
6+
"""
37
class Message(object):
48

59
__slots__ = ['_connection_header']
@@ -25,13 +29,20 @@ def __init__(self, *args, **kwds):
2529
else:
2630
setattr(self, k, None)
2731

32+
"""
33+
Since a Python file with the message class is nedeed
34+
this class is responsible about writing that file
35+
"""
2836
class MessageGenerator(object):
2937

3038
def __init__(self, addr):
3139

3240
self.addr=addr
3341

42+
# method to create message
3443
def create_message(self):
44+
45+
#struct primitive data types and default types
3546
def_types={'bool':'<B', 'byte':'<b', 'char':'<B', 'float32':'<f', 'float64':'<d', 'int8':'<b', 'int16':'<h', 'int32':'<i',
3647
'int64':'<q', 'string':'<I%ss', 'uint8':'<B', 'uint16':'<H', 'uint32':'<I', 'uint64':'<Q'}
3748

@@ -87,10 +98,9 @@ def __init__(self, *args, **kwds):
8798
if args or kwds:
8899
super({}, self).__init__(*args, **kwds)\n""".format(slots, slots_type, script_name)
89100
script.write(initdef)
90-
print(len(slots))
91-
print(slots_type)
92101

93-
102+
103+
#asigning self attributes
94104
for i in range(0,len(data)-1):
95105
temp=[data[i].split(' ')[0],data[i].split(' ')[1]]
96106
if 'bool' in temp[0]:
@@ -101,8 +111,6 @@ def __init__(self, *args, **kwds):
101111
val='0.'
102112
else:
103113
val='0'
104-
105-
106114
script.write("""
107115
if self.{} is None:
108116
self.{} = {}""".format(temp[0], temp[0], val))
@@ -115,6 +123,7 @@ def _get_types(self):
115123
def serialize(self, buff):
116124
try:""")
117125

126+
#serialization part
118127
for i in range(0,len(data)-1):
119128
temp=data[i].split(' ')[1]
120129
if 'string' in data[i].split(' ')[0]:
@@ -128,5 +137,4 @@ def serialize(self, buff):
128137
script.write("""
129138
except Exception as e:
130139
print(e)""")
131-
132-
script.close()
140+
script.close()

tests/colorrgba.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ugenpy.message import MessageGenerator
2+
msg=MessageGenerator('std_msgs/ColorRGBA.msg')
3+
msg.create_message()

0 commit comments

Comments
 (0)