Controlling stepper motor using python


#1

Hi, I’m trying to control the stepper motors on the Dobot magician using serial commands to the Dobot. The code packs a struct and then sends this over serial to the Dobot. Until now, this has worked for all commands. However, I am unable to control the stepper motors. The communication works by packing the the command into a struct, and then serializing it.

This is how the params are packed:
struct.pack(’<BBf’, index, isEnabled, speed)

Note that I am using BBf as the formating, ie a 8 bit int for both index and is enabled, and a four byte float for the speed. Theis is the only code that is spesific to this command. Sending this command with id = 135, r/w = 1 and isQueued = 0 or 1 produces no results.

The resulting hex data sent to the dobot with speed set to 10.000 is: As far as I can see, this should be the correct value to enable stepper motor 1 with speed = 10000.
aa:aa:08:87:03:00:01:00:40:1c:46:d3

What is wrong with the command, or is there something I am not seeing as to the resulting output of the command? How, in hex, should a command to enable the steppermotor look?


#2

I figured it out, and thought I’d post the answer here.

The protocol spesification(v1.0.4) states that speed is a float, while it should be an 32bit signed integer. A value of 10000 will give a speed of approx 62mm/s. A valid command to turn on the stepper motor will look like this:

AA AA 08 87 03 00 01 F0 D8 FF FF AF

This enables Stepper 1 with a speed of -10000.