Skip to content

Commit 4fe1bbc

Browse files
committed
v2.0.0
1 parent 91deee5 commit 4fe1bbc

File tree

7 files changed

+77
-468
lines changed

7 files changed

+77
-468
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ If you want to install it separately.
44

55
## Installation
66

7+
**Notes**:
8+
9+
<!-- This is the mycobot Python API package designed by Zhang Lijun([lijun.zhang@elephantrobotics.com]()) -->
10+
11+
> Make sure that `Atom` is flashed into the top Atom <br> > `Transponder` is flashed into the base Basic <br>
12+
> The firmware `Atom` and `Transponder` download address: [https://github.com/elephantrobotics/myCobot/tree/main/Software](https://github.com/elephantrobotics/myCobot/tree/main/Software)<br>
13+
714
### Pip
815

916
```bash
1017
pip install pymycobot --upgrade
1118
```
1219

20+
**Notes:**
21+
22+
> Now only the version after `Atom2.4` is supported. If you use an earlier version, please install `pymycobot 1.0.6`.
23+
24+
```bash
25+
pip install pymycobot==1.0.6
26+
```
27+
1328
### Source code
1429

1530
```bash
@@ -26,12 +41,3 @@ python3 setup.py install
2641
## Usage:
2742

2843
Please go to [here](./pymycobot/README.md).
29-
30-
**Notes**:
31-
32-
<!-- This is the mycobot Python API package designed by Zhang Lijun([lijun.zhang@elephantrobotics.com]()) -->
33-
34-
> Make sure that `Atom2.3` is flashed into the top Atom <br> > `Transponder` is flashed into the base Basic <br>
35-
> The firmware `Atom2.3` and `Transponder` download address: [https://github.com/elephantrobotics/myCobot/tree/main/Software](https://github.com/elephantrobotics/myCobot/tree/main/Software)<br>
36-
> Python 2: use mycobot.py <br>
37-
> Python 3: use mycobot3.py

pymycobot/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# ros-python-api
1+
# pymycobot
22

33
**This is python API for mycobot.**
44

5-
We support Python2, Python3.5 or later. If you want to use the api, make sure `pyserial` is installed.
5+
We support Python2, Python3.5 or later.
66

7-
```bash
8-
pip2 install pyserial
9-
# or
10-
pip3 install pyserial
11-
```
7+
<!--If you want to use the api, make sure `pyserial` is installed.-->
8+
9+
<!--```bash-->
10+
<!--pip2 install pyserial-->
11+
<!--# or-->
12+
<!--pip3 install pyserial-->
13+
<!--```-->
1214

1315
**Class**:
1416

pymycobot/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66

77
version = (platform.python_version())
88

9-
if version.startswith('2.7'):
10-
__all__ = ['mycobot', 'common']
11-
else:
12-
__all__ = ['mycobot', 'mycobot3', 'common']
9+
__all__ = ['mycobot', 'common']
1310

pymycobot/mycobot.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def send_angle(self, id, degree, speed):
100100
_hex = self._angle_to_hex(degree)
101101
speed = self._complement_zero(hex(speed)[2:], digit=2)
102102
command = 'fefe0621{}{}{}fa'.format(id, _hex, speed)
103-
# print(command)
104103
self._write(command)
105104

106105
def send_angles(self, degrees, speed):
@@ -138,12 +137,9 @@ def send_angles_by_radian(self, radians, speed):
138137
command = 'fefe0f22'
139138
speed = self._complement_zero(hex(speed)[2:], digit=2)
140139
for radian in radians:
141-
# print(radian)
142140
_hex = self._angle_to_hex(radian, is_degree=False)
143-
# print(_hex)
144141
command += _hex
145142
command += '{}fa'.format(speed)
146-
# print(command)
147143
self._write(command)
148144

149145
def get_coords(self):
@@ -167,7 +163,7 @@ def send_coord(self, id, coord, speed):
167163
168164
Args:
169165
id(common.Coord):
170-
coord(fload):
166+
coord(fload): mm
171167
speed(int):
172168
173169
'''
@@ -183,7 +179,7 @@ def send_coords(self, coords, speed, mode):
183179
'''Send all coords
184180
185181
Args:
186-
coords: [x, y, z, rx, ry, rz]
182+
coords: [x(mm), y, z, rx(angle), ry, rz]
187183
speed(int);
188184
mode(int): 0 - angluar, 1 - linear
189185
@@ -195,9 +191,11 @@ def send_coords(self, coords, speed, mode):
195191
speed = hex(speed)[2:]
196192
speed = self._complement_zero(speed, digit=2)
197193
mode = self._complement_zero(hex(mode)[2:], digit=2)
198-
for coord in coords:
199-
_hex = self._coord_to_hex(coord)
200-
194+
for i in range(3):
195+
_hex = self._coord_to_hex(coords[i])
196+
command += (_hex)
197+
for i in range(3, 6):
198+
_hex = self._angle_to_hex(coords[i])
201199
command += (_hex)
202200

203201
command += '{}{}fa'.format(speed, mode)
@@ -328,8 +326,9 @@ def _parse_data(self, data, name):
328326
data = data[-26:-2]
329327
for i in range(6):
330328
_hex = data[i * 4: (i * 4) + 4]
331-
degree = self._hex_to_degree(_hex)
332-
data_list.append(degree)
329+
_degree = self._hex_to_int(_hex) / 100.0
330+
# degree = self._hex_to_degree(_hex)
331+
data_list.append(_degree)
333332

334333
elif name == 'get_coords':
335334
if not (data.startswith('23') and data.endswith('fa')):
@@ -341,7 +340,7 @@ def _parse_data(self, data, name):
341340
data_list.append(_coord)
342341
for i in range(3, 6):
343342
_hex = data[i * 4: (i * 4) + 4]
344-
_coord = self._hex_to_int(_hex) / 1000.0
343+
_coord = self._hex_to_int(_hex) / 100.0
345344
data_list.append(_coord)
346345

347346
elif name == 'get_angles_of_radian':
@@ -350,8 +349,9 @@ def _parse_data(self, data, name):
350349
data = data[-26:-2]
351350
for i in range(6):
352351
_hex = data[i * 4: (i * 4) + 4]
353-
_radian = self._hex_to_int(_hex) / 1000.0
354-
data_list.append(_radian)
352+
_degree = self._hex_to_int(_hex) / 100.0
353+
_radian = _degree * (3.14 / 180)
354+
data_list.append(round(_radian, 2))
355355

356356
return (data_list)
357357

@@ -367,14 +367,14 @@ def _hex_to_int(self, _hex):
367367

368368
def _angle_to_hex(self, _degree, is_degree=True):
369369
if is_degree:
370-
radian = (_degree * (3140 / 180))
370+
da = (_degree * 100)
371371
else:
372-
radian = _degree * 1000
373-
radian = int(radian)
374-
if radian < 0:
375-
radian += 0x10000
376-
radian = round(radian)
377-
s = str(hex(int(radian)))[2:]
372+
da = _degree * (180 / 3.14) * 100
373+
da = int(da)
374+
if da < 0:
375+
da += 0x10000
376+
da = round(da)
377+
s = str(hex(int(da)))[2:]
378378
s = self._complement_zero(s)
379379
return s
380380

0 commit comments

Comments
 (0)