본문 바로가기
로봇 프로그래밍

모듈 파일 목록 - (3) Dobot Magician Python 프로그래밍

by edblab 2023. 3. 29.
728x90

Windows에서 Dobot Magician 로봇 파이썬 프로그램 개발에 필요한 파일은 그림과 같다.

DobotPythonDevCore 파일 목록

이 중 DobotControl.py가 예제파일이다.

이 파일을 임의의 디렉터리에 저장하면 파이썬 로봇 프로그램을 개발할 수 있다.

다음은test010.py로써 Dobot connection과 homing 기능을 test한다.

# 2023/3/29 test010
# Connetion and Homing Test
import threading
import DobotDllType as dType
CON_STR = {
    dType.DobotConnect.DobotConnect_NoError:  "DobotConnect_NoError",
    dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
    dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}

#Load Dll and get the CDLL object
api = dType.load()

#Connect Dobot
state = dType.ConnectDobot(api, "", 115200)[0]
print("Connect status:",CON_STR[state])

if (state == dType.DobotConnect.DobotConnect_NoError):
    
    #Clean Command Queued
    dType.SetQueuedCmdClear(api)
    
    #Async Motion Params Setting
    # home 좌표 설정, x, y, z, r
    dType.SetHOMEParams(api, 200, 200, 200, 200, isQueued = 1)
    dType.SetPTPJointParams(api, 200, 200, 200, 200, 200, 200, 200, 200, isQueued = 1)
    dType.SetPTPCommonParams(api, 100, 100, isQueued = 1)

    #Async Home
    print("homing...",dType.GetQueuedCmdCurrentIndex(api)[0])
    #마지막 실행 명령의 Queue Index를 저장
    lastIndex = dType.SetHOMECmd(api, temp = 0, isQueued = 1)[0]
    print("homing completed.",dType.GetQueuedCmdCurrentIndex(api)[0],lastIndex)
    
    dType.SetQueuedCmdStartExec(api)
    # 특정 명령어의 index 보다 queue에서 지금까지 실행된 수를 비교하여 
    # 해당 명령어가 실행될 때까지 기다림 
    while lastIndex > dType.GetQueuedCmdCurrentIndex(api)[0]:
        dType.dSleep(100)

    # Stop to Execute Command Queued
    dType.SetQueuedCmdStopExec(api)
#Disconnect Dobot
dType.DisconnectDobot(api)

 

2023 EDBLab