Tuesday, March 31, 2015

Machinekit To Aid With Heart Research

Recently I was contacted by a Professor Andreas Lueger of Medical University of Graz, Austria, Dept. of Internal Medicine, probing me with some rather intricate questions on Machinekit. Andreas is head of the emergency room there, helipad on the roof and all. So if you drive recklessly around here, you stand a chance for a helicopter ride and being stitched up by Andreas and his team, but that is certainly not “motion control” as we know it. That made me curious, and I visited Andreas to probe what he is up to:


Andreas in business attire, as found in his professional habitat
Beyond stitching up patients, Andreas is deeply involved in heart research - investigating atrial fibrillation, a precursor of heart attacks. And that is some very geeky project  - for his research, he develops the electronics based on a TI MSP430, as well as the software for his own Wifi-enabled pacemakers - a whole new meaning of “embedded” for me. Andreas brought down current consumption to a couple of hundred nanoampĂ©res, and does solder the parts under his own stereo microscope:


What can I say? at last an MD who talks our language! And when I visited him, he had a bug report for Machinekit, including a screenshot from his oscilloscope. I was impressed.

Now that pacemaker certainly is not running Machinekit, so where do we come in? Well, in the next iteration of the project, Andreas plans to integrate acceleration sensors in the setup, to measure actual mechanical performance of heart muscles. And for manufacturing these sensor attachments Andreas is designing a custom CNC machine with FreeCAD:


Now we’re talking.. that machine will run Machinekit! Here comes the twist: Andreas plans to use Trinamic servo stepper motors. Those are very smart motors with an embedded controller and power stages attached; among other features, these motors can detect and report a stall, and autonomously compensate for lost steps:

Trinamic motors can be controlled through various methods: Step/Direction pins, RS232, RS485, USB, and CANbus. Now out of these options, CANbus is the most interesting one because it operates on a much higher level than the other options; the motor can report back (heartbeat, stall, position, velocity etc).  It’s really a much more intelligent motor subsystem than we usually use in Machinekit, like servos or stepgens.

I found all this terribly geeky, and beyond that also valuable for the project overall: if we investigate and collectively learn how to integrate CANbus, we open up Machinekit to literally thousands of peripherals with a professional bus system - as opposed to homegrown methods like hooking up an Arduino over RS232 or USB. The Beaglebone's TI3359 chip comes with two CAN devices on board - add MCP2562 bus drivers and you are done; or use an appropriate cape. For other platforms, PCI cards and USB adapters do the trick.

CANbus peripherals come in many shapes and forms - like this controller used by Claudio Lorini with support for the zedboard which he recently merged into machinekit; but also more mundane devices like your car's windshield wipers and power windows: yes - your car is a one extensive CANbus installation (provided your car was built in the current millennium). And if you research that topic, you will find there’s a whole “car CANbus” hacking scene out there, using Arduinos and whatnot to tap into their car’s CANbus, like this example

Where does this leave us? I have decided to support Andreas with this project, and while it is not absolutely certain the Trinamics will work as motion units as planned, it will be a very interesting expedition. And along the journey, Machinekit will learn to support CANbus peripherals.

And that exciting story is the background why you saw references to CANbus in my recent postings to the Machinekit list!




14 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello,

    We're really excited about CANbus developments and have started working on it ourselves. Perhaps it would be wise to get in touch and work together.

    Feel free to contact me.

    ReplyDelete
  3. Check out canopennode. Its an open source canopen master stack. I have no affiliation with it. Canopen on machinekit would be awesome.
    Thanks for the hard work

    ReplyDelete
  4. interesting codebase

    unfortunately canopennode is GPLv3, which is impossible to use in machinekit
    we'd reconsider if the authors relicense

    ReplyDelete
    Replies
    1. According to the CANopenNode homepage the license is GNU Library or Lesser General Public License version 3.0 (LGPLv3)

      Delete
    2. the problem is with GPL2 vs GPL3 incompatibility, see for instance http://nmav.gnutls.org/2013/03/the-perils-of-lgplv3.html

      Delete
    3. Ok, thank you - I did not even know until now, that there is such an incompatibility. But thanks to Janez at least this problem is gone now :O)

      Delete
  5. That sounds really interesting. In our company all our single and multi axis device are based on CANopen motion controllers like the Trinamic three axis stepper controller and driver TMCM-343 (http://www.trinamic.com/products/modules/controller-driver-stepper/tmcm-343) or the maxon EPOS CANopen positioning controllers (http://www.maxonmotorusa.com/maxon/view/content/EPOS-Detailsite). We also use the BeagleBone Black with its 2 CAN interfaces and an internal CANopen master stack to control these devices.

    I already thought about using Machinekit as a control software for our multi axis devices. So it would be interesting for me to know or to see, how to integrate a CANopen stack as a machinekit HAL driver. We already used the CANopenNode stack in an internal project and contributed a driver for the open source RTOS eCos to the CANopenNode project.

    If you talk about CAN-Bus it is important for readers to know, which higher level protocol you are talking about. Simply supporting CAN-Bus would not mean something special. But if you are talking about CANopen, the the internationally standardized (EN 50325-4) CAN-based higher-layer protocol for embedded control system, and especially about the CANopen profile DS402 - motion control devices, then this would be really great for machinekit. It would open up the door to the world of professional CANopen motion controllers like:


    http://www.trinamic.com/products/modules/controller-driver-stepper/tmcm-351
    http://en.nanotec.com/products/1023-smci12-schrittmotorsteuerung/
    http://www.maxonmotorusa.com/maxon/view/content/EPOS-Detailsite
    http://www.elmomc.com/products/elmo-digital-servo-drives-main.htm
    http://www.kocomotion.de/produkte/schrittmotoren-mit-integrierter-steuerung-mdrive.html

    ReplyDelete
    Replies
    1. yes, I think along these lines; I outlined it a but here: https://sourceforge.net/p/canopennode/discussion/387151/thread/246eaa49/?limit=25#cb4b/1e75

      Delete
    2. Thank you Michael. I outlined here, how to coordinate CANopen drives with Machinekit: http://sourceforge.net/p/canopennode/discussion/387151/thread/246eaa49/#2574

      I tested both: CANfestival and CANopenNode. I chose CANopenNode because I liked its design, it was easier to support CAN message filtering (really important for slave devices) and because the support by Janez was so much better than the support for CANfestival. But this is only my personal opinion.

      Delete
    3. thanks, that was very informative and lots of useful hints; and that was the method Andreas suggested

      Can I encourage you to engage a bit on the machinekit mailing list? we do need adult supervision, especially in this phase ;) and.. we're spreading the discussion over three channels

      Delete
    4. Ok, I will try to help if I can.

      I checked CANfestival again, and I think, if you need a CANopen master stack, then CANfestival is the better choice, because it provides more master functionality. The CANfestival homepage also claims that CANfestival supports Xenomai.

      CANopenNode is a good choice, if you need to implement a slave device.

      Delete
  6. As the author of the CANopenNode I will change the License from LGPLv3 to LGPLv2.1.
    It would be very interesting to me, if Machinekit will have CANopen capbilities.

    ReplyDelete
    Replies
    1. Janez - I would like to thank you for your generosity!

      let's see what can be made out of it

      Delete