I'm trying to make a driver that will communicate with the robot via serial com and send g code.
https://github.com/egehandulger/robodkdriver
There is a study at the address I shared above that will make this job easier. I tried to create a driver based on this study. Connected seamlessly. The problem is that I couldn't convert the robot position in g code. Actually, the GCode_A3200.py post processor approximately meets my needs. (I just need to add g0 or g1 instead of linear.) Instead, the driver tries to send the robot's current xyz coordinates and throws an error. I am using a stm32 based motherboard at this time and it has marlin firmware in it. I am sharing my code and error log of the error I got with you. I would be very happy if someone can help me with where I made a mistake.
Error Log:
UPDATE!
I've updated the code I'm using, but I'm still getting the error. Here is the updated code and error message.
CODE:
ERROR MESSAGE:
https://github.com/egehandulger/robodkdriver
There is a study at the address I shared above that will make this job easier. I tried to create a driver based on this study. Connected seamlessly. The problem is that I couldn't convert the robot position in g code. Actually, the GCode_A3200.py post processor approximately meets my needs. (I just need to add g0 or g1 instead of linear.) Instead, the driver tries to send the robot's current xyz coordinates and throws an error. I am using a stm32 based motherboard at this time and it has marlin firmware in it. I am sharing my code and error log of the error I got with you. I would be very happy if someone can help me with where I made a mistake.
Error Log:
Code:
Sending command...
Received command: CONNECT ['COM3', '250000', '4']
Working...
Ready
Sending command...
Received command: MOVJ ['0.000000', '0.000000', '0.000000', '0.000000', '216.178000', '-0.000000', '232.867000', '-180.000000', '0.000000', '180.000000']
Working...
Unexpected error: Traceback (most recent call last):
Unexpected error: File "C:/RoboDK/api/robot/myrobot.py", line 60, in <module>
Unexpected error: RoboDK(MyRobot()).run_driver()
Unexpected error: File "C:\RoboDK\Python37\lib\site-packages\robodkdriver\robodk.py", line 33, in run_driver
Unexpected error: status = self._robot.run_command(**command)
Unexpected error: File "C:/RoboDK/api/robot/myrobot.py", line 26, in run_command
Unexpected error: x, y, z = args # Assuming args[0] is x, args[1] is y, and args[2] is z
Unexpected error: ValueError: too many values to unpack (expected 3)
Stopped
Code:
from robodkdriver import RoboDK, RobotSerial
class MyRobot(RobotSerial):
def run_command(self, cmd: str, args: tuple):
print("Received command:", cmd, args) # Hata ayıklama için komut ve argümanları yazdırın
RoboDK.update_status('working')
if cmd == 'CONNECT':
connected = self._connect(port=args[0], baud_rate=int(args[1]))
if not connected:
return 'connection_problems'
return 'ready'
if cmd == 'DISCONNECT' or cmd == 'STOP':
disconnected = self._disconnect()
if disconnected:
return 'disconnected'
return 'ready'
if cmd == 'MOVJ':
x, y, z = args # Assuming args[0] is x, args[1] is y, and args[2] is z
# Generate the G code command
print("Sending command: G1 X{} Y{} Z{}".format(x, y, z)) # Hata ayıklama için komutu yazdırın
self._send_message('G1 X{} Y{} Z{}'.format(x, y, z))
# Assuming the robot responds with 'DONE' when it's done
if self._get_message('DONE'):
print("Command executed successfully")
return 'ready'
else:
print("Error executing command")
return 'error'
def ProcessGCode(self, cmd, args):
if cmd == 'GCODE':
command = args[0] # G-kod komutunu alın
command_args = args[1:] # G-kod argümanlarını alın
if command == 'MOVJ':
x, y, z = command_args
# Generate the G code command
print("Sending command: G1 X{} Y{} Z{}".format(x, y, z)) # Hata ayıklama için komutu yazdırın
self._send_message('G1 X{} Y{} Z{}'.format(x, y, z))
# Assuming the robot responds with 'DONE' when it's done
if self._get_message('DONE'):
print("Command executed successfully")
return 'ready'
else:
print("Error executing command")
return 'error'
if __name__ == '__main__':
RoboDK(MyRobot()).run_driver()
UPDATE!
I've updated the code I'm using, but I'm still getting the error. Here is the updated code and error message.
CODE:
Code:
from robodkdriver import RoboDK, RobotSerial
class MyRobot(RobotSerial):
def run_command(self, cmd: str, args: list):
print("Received command:", cmd, args) # Hata ayıklama için komut ve argümanları yazdırın
RoboDK.update_status('working')
if cmd == 'CONNECT':
connected = self._connect(port=args[0], baud_rate=int(args[1]))
if not connected:
return 'connection_problems'
return 'ready'
if cmd == 'DISCONNECT' or cmd == 'STOP':
disconnected = self._disconnect()
if disconnected:
return 'disconnected'
return 'ready'
if cmd == 'MOVJ':
if len(args) != 3:
print("Hatalı argüman sayısı. MOVJ komutu, x, y ve z koordinatlarını bekler.")
return 'error'
x, y, z = args
# Generate the G code command
print("Sending command: G1 X{} Y{} Z{}".format(x, y, z)) # Hata ayıklama için komutu yazdırın
self._send_message('G1 X{} Y{} Z{}'.format(x, y, z))
# Assuming the robot responds with 'DONE' when it's done
if self._get_message('DONE'):
print("Command executed successfully")
return 'ready'
else:
print("Error executing command")
return 'error'
if __name__ == '__main__':
RoboDK(MyRobot()).run_driver()
ERROR MESSAGE:
Code:
Sending command...
Received command: CONNECT ['COM3', '250000', '4']
Working...
Ready
Sending command...
Received command: MOVJ ['0.000000', '0.000000', '0.000000', '0.000000', '216.178000', '-0.000000', '232.867000', '-180.000000', '0.000000', '180.000000']
Working...
Incorrect number of arguments. The MOVJ instruction expects x, y, and z coordinates.
error