Help with the basics of Python with Dobot


#1

Hey there, I am a bit novice when it comes to python but I need to use it with Dobot.
I have looked through the demo python file, it runs fine and I have been trying to learn from it.
But recreating it and doing simple tasks like moving from on position to another is troublesome.

If someone could make an example code that I could have a look at, it would help immensely.

I use Pycharm.


#2

Hi,

is your connection to the dobot is already working?
Can you post some of your code so we can have a look at it?


#3

Hi Chris, I did since get it to work. I was missing a While(true) statement, makes me feel dumb.

I do have another issue, is it possible to use python to program two Dobots at the same time so they can perform a task together? I know I can open two dobotstudios but they work individually and not together.

Any help is greatly appreciated.


#4

It should be possible. The searchDobot-function will give you a list with all COM-Ports which use the driver of the Dobot. Which Dobot do you use?
The Diffence is, that the Dobot Magician works with an CH340 driver, this can be a problem in first try. The M1 driver is a FTDI driver which have an ID, so you can choose your required ID.


#5

I use two Dobot Magicians.
I found the SearchDobot function but due to my inexperience I don’t know how it works.

Is there some example code I can look at, like the downloadable DobotdemoV2.0 file on the Dobot site.


#6

I haven’t test this and I’m using C# at the moment. If you are sure that the Dobot won’t be connect to other ports in the future you can use a little work around.
The easiest way is to look in the windows device manager and connect one of the Dobots. So you get the COM-Port of first one. Then do the same with the other Dobot on the other Port.
After that you can use the connectDobot-function (like in the example):
state = dType.ConnectDobot(api, “COMX”, 115200)[0]


#7

I’m not sure if you can connect both dobots in same time. You have to try this.
If it’s not working you have to disconnect after you gave the Dobot the command.


#8

Hey Chris! using your advice I have been able to connect both Dobots to the same Python program, and at the very least make them run at the same time. Right now I want one to execute a program and set a value, and have the second one wait before that value is changed before it executes its program.

Problem is that they execute at the same time and I am not sure how I can fix it exactly

Here is images of my code so far


image

Thank you so far though, it has helped a lot!


#9

Hi Alexander!
The only idea i’ve got is to use the setqueuedcmdstartexec-function.
At first you have to call the setqueuedcmdstopexec-function. This means (my understanding) the controller stop query the queue were the commands are buffered. After that you can give your commands like setPTPcmd and so on. Finally you have to call the setqueuedcmdstartexec-function which starts the execution.
So you can connect second one --> stop it --> give commands --> disconnect —> connect first one —> do things —> wait value change (for example which a while-loop)—> disconnect first one —> connect the second —> do others things.

I don’t know if this is helpful for you.


#10

I have read your reply again :smiley:

If you want that they do it one after the other you must use the wait-function.
#Wait for Executing Last Command
while lastIndex > dType.GetQueuedCmdCurrentIndex(api)[0]:
dType.dSleep(100)

This means the program waits until every command in the queue is executed.
Your current solution give the first dobot the commands and disconnect it before he have done its movements. So the dobot is moving further and the other dobot is connected and get its command. So it seems both are starting at same time. But there is the program-execution-time between. With the wait command you can solve this problem.


#11

I made it work!
it now executes each individual robots command one after the other thanks to your help :slight_smile:
I’ll post my code here for future visitors to use as help.



#12

Was a pleasure :smiley:
Thanks for posting.