How to program a simple CANopen layer

可紊 提交于 2019-11-28 23:26:01

问题


We have a robot project where the motor controllers use CANopen for communication. I need to communicate with these motor controllers using a master microcontroller. The problem is that I need to develop a CANopen layer in this microcontroller, but I only know how to send and receive at the low level (CAN).

I don't know much about the CANopen (PDO, SDO, Heartbeat, object dictionary, etc.). I tried to read the CiA specifications, but it was very complicated. I would appreciate it if someone could point me in the right direction or give me a good tutorial to program a simple CANopen layer.


回答1:


Since this seems to be a topic of general interest - I agree that understanding the full original specs can be a somewhat painful experience. So here is a suggestion for "get your drive going", as opposed to "implementing the whole thing":

  • Check if your CANopen drives can be operated via the CiA 402 standard objects and for performance reasons it would be perfectly fine to NOT configure and use PDOs, and you don't really need heartbeat, a.s.o. It's usually switching the drive's state machine (object 6040h, control word), setting operation mode (object 6060h), and setting additional parameters like "profile position velocity".

  • Then implement expedited SDO transfers only. (See http://en.wikipedia.org/wiki/CANopen.) SDO download is for writing/changing an object in your drive. SDO upload is for reading an object.

  • I suggest to take a PC software that can read and write SDOs and has a CAN Bus Monitor. (Our Kickdrive Zero freeware can do that, but really, any other PC tool for CANopen should work.) Do some example reads and writes for the data types and objects you need. Look how this translates into frames on a CAN level. For basic integer data types, it's always just one frame for the request, one for the answer.

  • Now build a simplistic protocol stack on your microcontroller that can send the SDO download/upload requests and process the answers.

Disclaimer - the above is not even close to "implementing CANopen", or "supporting CANopen", or even "CANopen compliant". It's about "make your drive move ASAP and without third-party code". Which is sometimes the right thing to do.




回答2:


We have implemented our CANopen layer from scratch for both embedded ARM and Windows PC devices. It's not impossible, unlike previous answers might make you think. If you need only basic functionality of CANopen and can quickly learn the concepts of the protocol, you can get things up and running rather quickly.

You will have to read CiA specification, there is no way to avoid it, but at first it might turn out to be somewhat overwhelming. I recommend that you start by reading "Embedded Networking with CAN and CANopen" by Pfeiffer, Ayre and Keydel. It explains the basic concepts nicely, which in turn helps understanding the specification better.




回答3:


Try using the CanFestival stack - it's free, and it ports easily from OSes like Linux down to bare machines that just have a tick timer.

4-6 months seems a bit of a stretch - you may only need a master or a slave, and we did a master-only implementation in C++ in 3-4 weeks.




回答4:


We're using the MicroCANopen stack with the Manager add-on, from here: http://www.canopenstore.com/pip/microcanopen.html

It's relatively cheap compared to other stacks, although we're using it on all nodes in our network so I can't offer a testimonial as to how it operates with other CANOpen-compliant devices.




回答5:


Unfortunately, there is no simple CANopen layer. To support CANopen, you have to implement the whole thing.

I suggest you buy a CANopen library from a third-party vendor. Usually they're not cheap, but considering the time you would need to implement this yourself it's cheaper than your salary for that time.

We've been using PORT GmbH's ANSI-C CANopen Library library, which is moderately priced and has very few bugs, compared to other libraries we tried.




回答6:


If this is something commercial I would not consider implementing CANopen. This is going to take you (even for a subset) somewhere between four and six months (if you actually want it to work). I don't know what your salary per hour is and what your time to market requirements are. You need to do the maths yourself.




回答7:


Another commercial solution I worked with is IXXAT's CANopen software. They offer ports for many different platforms.

As already said before: you don't get it for free nor is it cheap. But what are a few thousand USDs compared to several months of development time?



来源:https://stackoverflow.com/questions/1232624/how-to-program-a-simple-canopen-layer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!