Moving motors from a Python script

Since last time I've been pretty busy with some work related projects, so the CANopen safari has suffered a bit. Luckily I've got a little bit more time lately so I have picked up the CANopen stuff.

It's been a pretty heavy learning curve. I've spent a lot of time looking at the console and trying to understand what is going on. I received a lot of help from various people (thanks for showing me correct messages Uwe!) getting to understand the DS402 state engine. As well as (thanks Michael!) getting new programming-related knowledge.

In hindsight the combination of picking the tools (libraries) and understanding these conbines with getting to grips with the CANopen internals was pretty "heavy". For example; If you send an SDO message with the wrong amount of bytes, you get an unexpected response. So you not only have to understand using the library, but you have to understand the library correctly.

So, past days, pieces of the puzzle fall into place, and I have a nice video to show for it.

Libcanopen has python bindings (extended by Michael, thanks for making the MNT commands available in the python bindings). So with the cycanopen-402-prepare.py python script:

  • the various states of the DS402 state engine have to be processed.
  • a profile position mode is chosen
  • a target position is set

Then after the first scrip "initializing" the device,  the cycanopen-positionmove.py script toggles the bit to start the previous set-up travel order.

Now that this is in place I'll work towards gluing Machinekit and CANopen together with Python. First creating some userland components and get the motor running from a Machinekit GUI button.

Better to first understand what we need to do before writing RT components. Long live the Python glue!

Some additional links:

  • Working towards Machinekit Issue #589
  • USB to socketcan USBTin device.
  • node 2 and 3 Maxon Epos 24/1 CANopen devices.
  • node 5 Nanotec CL3-E CANopen device.
  • My fork of libcanopen and the installation instructions:
    bas@jessie:~$ sudo apt-get install python-dev cython pkg-config
    bas@jessie:~$ git clone https://github.com/luminize/libcanopen
    bas@jessie:~$ cd libcanopen
    bas@jessie:~/libcanopen$ git fetch origin
    bas@jessie:~/libcanopen$ git checkout machinekit-prep
    bas@jessie:~/libcanopen$ sh build.sh
    bas@jessie:~/libcanopen$ sudo make install
    bas@jessie:~/libcanopen$ cd cycanopen
    bas@jessie:~/libcanopen/cycanopen$ make
    bas@jessie:~/libcanopen/cycanopen$ cd ..
    bas@jessie:~/libcanopen$ sudo ldconfig
Share/Bookmark