Skip to content

Commit

Permalink
Fix m5 network communication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Jan 5, 2022
1 parent 557cd83 commit a74720f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# ChangeLog for pymycobot

## v2.7.2.1 (2021-12-15)
## v2.7.4 (2021-12-15)

- release v2.7.4
- Fix m5 network communication bug

## v2.7.3 (2021-12-15)

- release v2.7.3
- fix get_tof_distance() no return problem.
Expand Down
7 changes: 4 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ We support Python2, Python3.5 or later.
- [utils (Module)](#utils-module)
- [get_port_list](#get_port_list)
- [detect_port_of_basic](#detect_port_of_basic)
- [MyCobotSocket](#mycobotsocket)
- [MyCobotSocket](#mycobotsocket)
- [Client](#client)
- [Server](#server)
- [socket control](#socket-control)
Expand All @@ -89,6 +89,7 @@ We support Python2, Python3.5 or later.
- [set_gpio_out](#set_gpio_out)
- [set_gpio_output](#set_gpio_output)
- [get_gpio_in](#get_gpio_in)


<!-- vim-markdown-toc -->
</details>
Expand Down Expand Up @@ -788,10 +789,10 @@ from pymycobot import utils
mycobot = MyCobot(port, 115200)
```

## MyCobotSocket
# MyCobotSocket

> Note:
> Only supports python3
> raspberryPi version Only supports python3
> The robotic arm that uses this class of premise has a server and has been turned on.

Use TCP/IP to control the robotic arm
Expand Down
2 changes: 1 addition & 1 deletion pymycobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"MyCobotSocket"
]

__version__ = "2.7.3"
__version__ = "2.7.4"
__author__ = "Elephantrobotics"
__email__ = "[email protected]"
__git_url__ = "https://github.com/elephantrobotics/pymycobot"
Expand Down
20 changes: 14 additions & 6 deletions pymycobot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,31 @@ def _process_single(self, data):

def write(self, command, method=None):
if method == "socket":
if command[3] == 176 and len(command) > 5:
data = b""
if len(command)>3 and command[3] == 176 and len(command) > 5:
command = "'"+command[4]+"'"+"("+command[5]+")"
command = command.encode()
self.sock.sendall(bytes(command))
if command[-2] == 177:
if self.rasp:
self.sock.sendall(str(command).encode())
else:
self.sock.sendall(bytes(command))

if len(command) > 3 and command[3] == 177:
while True:
data = self.sock.recv(1024)
if b'password' in data:
break
if command[-2] == 192:
data = b''
elif len(command) > 3 and command[3] == 192:
while True:
data += self.sock.recv(1024)
if len(data) == 6:
break
else:
data = self.sock.recv(1024)
try:
self.sock.settimeout(0.1)
data = self.sock.recv(1024)
except:
data = b''
return data
else:
self.log.debug("_write: {}".format(command))
Expand Down
11 changes: 10 additions & 1 deletion pymycobot/mycobotsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@ def __init__(self, ip, netport=9000):
self.calibration_parameters = calibration_parameters
self.SERVER_IP = ip
self.SERVER_PORT = netport
self.rasp = False
self.sock = self.connect_socket()

def connect(self, serialport="/dev/ttyAMA0", baudrate="1000000", timeout='0.1'):
"""Interface to connect to the built-in system such as Raspberry Pi
Args:
serialport:
baudrate:
timeout:
"""
self.rasp = True
self._write(serialport, "socket")
self._write(baudrate, "socket")
self._write(timeout, "socket")
Expand All @@ -86,7 +95,7 @@ def _mesg(self, genre, *args, **kwargs):
MyCobotSocket, self)._mesg(genre, *args, **kwargs)
# [254,...,255]
data = self._write(self._flatten(real_command), "socket")
if data != b'None':
if data:
res = self._process_received(data, genre)
if genre in [
ProtocolCode.IS_POWER_ON,
Expand Down

0 comments on commit a74720f

Please sign in to comment.