Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to connect to Stepper using python #2

Open
packetfocus opened this issue Apr 28, 2020 · 5 comments · May be fixed by #6
Open

Error trying to connect to Stepper using python #2

packetfocus opened this issue Apr 28, 2020 · 5 comments · May be fixed by #6

Comments

@packetfocus
Copy link

New install. I configured the WS to use station wireless, and verified I can connect through the website and run commands on my nema 17 stepper.

Having problems running python commands. Using python 3.7, and imported the library in the directory.

Also changed the host name using IP in the py code.

C:\code\WifiStepper2>python ws.py
Traceback (most recent call last):
File "ws.py", line 12, in
MOTOR.connect()
File "C:\code\WifiStepper2\goodrobotics.py", line 452, in connect
return self.__comm.connect()
File "C:\code\WifiStepper2\goodrobotics.py", line 211, in connect
return self.cmd_ping(0, 0)
File "C:\code\WifiStepper2\goodrobotics.py", line 228, in cmd_ping
return self._waitreply(self._send(self._OPCODE_PING, self._SUBCODE_CMD, target, queue), self._SUBCODE_ACK)
File "C:\code\WifiStepper2\goodrobotics.py", line 367, in _send
self.sock.send(self._preamble(self._TYPE_STD) + self._header(opcode, subcode, target, queue, packetid, len(data)) + data)
TypeError: can't concat str to bytes

C:\code\WifiStepper2>python --version
Python 3.7.0

@packetfocus
Copy link
Author

================ EXAMPLE PYTHON CODE - Use chunks as needed ================

For full documentation see https://www.wifistepper.com/interfaces

import goodrobotics as gr

host = "192.168.1.107"

Create motor object

MOTOR = gr.WifiStepper(host=host)

MOTOR = gr.WifiStepper(proto=gr.ComCrypto, host=host, key="<AUTH_KEY>") # For crypto auth

Connect (will throw exception on failure)

MOTOR.connect()

Write motor configuration

MOTOR.setconfig({
'mode': "current", 'stepsize': 8,
'ocd': 500, 'ocdshutdown': True,
'maxspeed': 10000, 'minspeed': 0, 'accel': 1000, 'decel': 1000,
'cm_kthold': 1.7000000000000002, 'cm_ktrun': 1.7000000000000002, 'cm_ktaccel': 1.7000000000000002, 'cm_ktdecel': 1.7000000000000002,
'fsspeed': 2000, 'fsboost': False,
'cm_switchperiod': 44, 'cm_predict': True,
'cm_minon': 21, 'cm_minoff': 21, 'cm_fastoff': 4, 'cm_faststep': 20,
'reverse': False, 'save': True
})

Read configuration

config = MOTOR.getconfig()

config is a dict() of configuration map

Send speed command

rpm = gr.RPM()
MOTOR.run(dir=MOTOR.FORWARD, stepss=rpm(30))

Emergency stop motor

MOTOR.estop()

Read status

state = MOTOR.getstate()

state is a dict() with keys: busy, stepss, hiz, vin, pos, mark, dir, movement, stepclock, switch,

flags=dict( switch, commanderror, overcurrent, undervoltage, thermalwarning,

thermalshutdown, stalldetect )

@packetfocus
Copy link
Author

this is the function that seems to be throwing the error.

self.sock.send(self._preamble(self._TYPE_STD) + self._header(opcode, subcode, target, queue, packetid, len(data)) + data)

return packetid

is this an issue connecting, or possible issue with the "data" variable string type?

@packetfocus
Copy link
Author

I can issue commands with curl without issues:

C:\code\WifiStepper>curl -sS "http://192.168.1.107/api/motor/run?dir=forward&stepss=100"
{"status":"ok","id":27}
C:\code\WifiStepper>curl -sS "http://192.168.1.107/api/motor/state"
{"stepss":0,"pos":15539,"mark":0,"vin":13.28125,"dir":"forward","movement":"idle","hiz":true,"busy":false,"switch":false,"stepclock":false,"alarms":{"commanderror":false,"overcurrent":fa
lse,"undervoltage":false,"thermalshutdown":false,"thermalwarning":false,"stalldetect":false,"switch":false},"signal":{"value":0,"modified":0},"command":{"thisid":0,"lastid":27,"completed
":2920524},"now":2947616,"status":"ok"}
C:\code\WifiStepper>

@aklofas
Copy link
Contributor

aklofas commented Apr 29, 2020

Ah, this must be an issue with python 3.7 not auto-converting between bytes and strings.

@alexrudd2 alexrudd2 linked a pull request Jan 19, 2024 that will close this issue
@alexrudd2
Copy link

alexrudd2 commented Jan 24, 2024

Ah, this must be an issue with python 3.7 not auto-converting between bytes and strings.

@aklofas Yes, that's exactly it - the code does not work on Python 3. The pull request I have linked fixes it, while maintaining Python 2 compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants