Problem with python driver


#1

Hi!

I am currently trying to use the python driver. I succeed to make the exemple with jog functions work (even if they are a lot of packet drop, and no ack back). However, I haven’t succeed to create precise (x,y,z) setter with these function (too much latency maybe), the resulte was really bad (staircase jerky movements, turn around target point with 4cm error, delay …).
Then I decided to use the playback function which seems more approriate for that. I have adapted the sample code to this function, but Dobot does not move, and I can’t figure out why … Here is my code:

import sys
from ctypes import *
import threading
import time
import msvcrt

def PeriodicTask():
    dll.PeriodicTask()
    threading.Timer(0.1, PeriodicTask).start()

def GetPoseTask():
    pose = Pose()
    dll.GetPose(byref(pose))
    print 'Pose:', pose.x, pose.y, pose.z, pose.rHead, pose.joint1Angle, pose.joint2Angle, pose.joint3Angle, pose.joint4Angle
    threading.Timer(0.5, GetPoseTask).start()

# For initial pose
class InitialPose(Structure):
    _fields_ = [("joint2Angle", c_float), ("joint3Angle", c_float)]

# For pose
class Pose(Structure):
    _fields_ = [
        ("x", c_float),
        ("y", c_float),
        ("z", c_float),
        ("rHead", c_float),
        ("joint1Angle", c_float),
        ("joint2Angle", c_float),
        ("joint3Angle", c_float),
        ("joint4Angle", c_float),
        ("isGrab", c_byte),
        ("gripper", c_float)
        ]

# For jog
class PlaybackStaticParams(Structure):
    _fields_ = [
        ("jointMaxVelocity", c_float), ("jointMaxAcceleration", c_float),
        ("servoMaxVelocity", c_float), ("servoMaxAcceleration", c_float),
        ("linearMaxVelocity", c_float), ("linearMaxAcceleration", c_float),
        ("pauseTime", c_float), ("jumpHeight", c_float)
        ]

class PlaybackDynamicParams(Structure):
    _fields_ = [("velocityRatio", c_float),
                ("accelerationRatio", c_float)]

class PlaybackBufferCmd(Structure):
    _fields_ = [("motionStyle", c_int), ("isGrab", c_int),
                ("x",c_float),("y",c_float),("z",c_float),("rHead",c_float),
                ("gripper",c_float),("pauseTime",c_float),]

sys.path.append(sys.path[0])
dll = cdll.LoadLibrary(sys.path[0] + '//DobotDll.dll');
PeriodicTask()
GetPoseTask()

errorString = [
    'Success',
    'Warning:Long arm angle not good!',
    'Warning:Short arm angle not good!',
    'Both long & short arm angle not good!',
    'Error:Dobot not found!',
    "Error:COM port occupied!",
    "Error:No data uploaded!"
    ]

result = dll.ConnectDobot()
print errorString[result]

if (result < 4):
    # Set command timeout
    dll.SetCmdTimeout(3000)
##    # Set initial pose
##    initialPose = InitialPose()
##    initialPose.joint2Angle = 45
##    initialPose.joint3Angle = 45
##    dll.SetInitialPose.argtypes = [POINTER(InitialPose)]
##    dll.SetInitialPose(byref(initialPose))

    # Set static & dynamic param
    playbackStaticParams = PlaybackStaticParams()
    playbackStaticParams.jointMaxVelocity = 200;
    playbackStaticParams.jointMaxAcceleration = 200;
    playbackStaticParams.servoMaxVelocity = 200;
    playbackStaticParams.servoMaxAcceleration = 200;
    playbackStaticParams.linearMaxVelocity = 200;
    playbackStaticParams.linearMaxAcceleration = 200;
    playbackStaticParams.pauseTime = 1;
    playbackStaticParams.jumpHeight = 1;

    playbackDynamicParams = PlaybackDynamicParams();
    playbackDynamicParams.velocityRatio = 20;
    playbackDynamicParams.accelerationRatio = 20;

    dll.SetPlaybackStaticParams(byref(playbackStaticParams))
    dll.SetPlaybackDynamicParams(byref(playbackDynamicParams))

    dll.SetPlaybackBufferCmd.argtypes = [POINTER(PlaybackBufferCmd)]
    test = PlaybackBufferCmd()
    test.motionStyle=1
    test.isGrab=0
    test.rHead=0
    test.gripper=0
    test.pauseTime=0

    test.x=150
    test.y=0
    test.z=-30
    
    dll.SetPlaybackBufferCmd(byref(test))
    print 1
    time.sleep(1)
    dll.SetPlaybackBufferCmd(byref(test))
    dll.SetPlaybackBufferCmd(byref(test))
    dll.SetPlaybackBufferCmd(byref(test))
    print 2
    
    time.sleep(10)
    
    dll.DisconnectDobot()

Do you have any idea why it doesn’t work? Or how I could have precise move to a target in python ?

Thank you very much for your help!


#2

No answer ? :confused:
I haven’t yet succeed to use dobot in any project due to poor access for developpers, bad precision and now technical issues. @DobotTeam That would be nice to give me some support, currently Dobot looks more like a simple decoration on my desk than a real working robot. I’m losing hope to realize any of my project with this arm …

Please help me! :’(


#3

Check the Playback Demo downloaded from the official website, there’s a bug in the old python demo, the playback cmd is not working. Now we have fixed it with a Dobot.Exec() interface, you just need to call it at the end of your code, and it will be working. You can try it.


#4

Thank you very much, it works!


#5

Hello Eric,

I stil have problem with DobotExec function. With using DobotExec function, python driver executes its given commands. But DobotExec fınction does not return overall. I cannot execute any additional command after DobotExec(). This makes the python driver really useless.

Is there a solution for this? Thanks.

I’m using Dobot Arm V1.0 with the latest software in following link. https://www.dobot.cc/downloadcenter/dobot-arm-v1.html?sub_cat=94#sub-download