Arduino CAN Shield

Discussion forum for the CAN-FIX protocol. This is a CANBus based communications protocol specifically suited for experimental aviation.

Moderators: John Nicol, birkelbach

birkelbach
Posts: 193
Joined: 04 Sep 2012, 14:42

Arduino CAN Shield

Post by birkelbach »

I finally managed to get my little hacked together CAN shield working. It's not pretty but it allows the Arduino to communicate on the CAN bus. You can find the details at http://www.madsciencenotebook.com/ardui ... interface/ (Shamless blog plug alert).

The next step is to write the code to turn this into a generic USB<->CAN interface. Then I'll try to build an actual CAN-FIX device with it.
Phil Birkelbach
Waller, Texas
RV-7 727WB
www.myrv7.com
User avatar
John Nicol
Posts: 611
Joined: 23 Nov 2011, 12:17
Contact:

Re: Arduino CAN Shield

Post by John Nicol »

Nice! Can't wait to see progress on the hardware side! I have a spare proto shield, so would be able to get something up and running to assist with testing once you are happy with an initial design.

Which reminds me, I still owe you some comments on the latest draft. My only ones so far are the inclusion of the regular mechanism to review and maintenance of the spec as discussed separately. I know that you have that in hand and are still working it. I will attempt to review the rest over the next day or so.

John
-----
John Nicol
Founder, MakerPlane
birkelbach
Posts: 193
Joined: 04 Sep 2012, 14:42

Re: Arduino CAN Shield

Post by birkelbach »

The hardware seems to work pretty well "as-is" no reason not to go ahead and "proto" one up. The real problem is that you have to have two of them to do anything. With CAN you can't even pretend to communicate because part of the protocol requires that there be another node on the bus to send the ACK bit at the end of the message.

That's the reason I'm doing the USB<->CAN interface first. I've got a working Python/PyQt program that can send a bit of data but it needs an interface to the CAN bus. That's what I want to do with this. The hope is to lower the cost of entry to folks that want to play around with it. We'll see how far I get with the interface over the next couple of days.

I thought I had the review and maintenance stuff in the new spec. I moved it to it's own section in the back. Let me know if that's not what you were talking about.
Phil Birkelbach
Waller, Texas
RV-7 727WB
www.myrv7.com
User avatar
John Nicol
Posts: 611
Joined: 23 Nov 2011, 12:17
Contact:

Re: Arduino CAN Shield

Post by John Nicol »

I had started from the front of the document, so didn't get to the revision at the back yet, so my bad. I will continue to review and let you know if I pick anything up.

I was thinking that it would be great to put together two CAN modules with one having a TFT or LCD display to show results of the message traffic. It might also serve as a proto environment to start looking at instrument displays. Something like the 4D Systems TFT displays: http://blog.littlebirdelectronics.com/t ... nd-tft-lcd

What do you think, or am I jumping ahead too much?

As an aside, I also saw that 4D systems has a transparent OLED panel with interfaces to Raspberry Pi and Arduino which they are saying could be used for a HUD. Far too small for that unless you hung it from your hat, but very interesting technology:

http://www.youtube.com/watch?feature=pl ... G8fiff2qB4

Image

John
-----
John Nicol
Founder, MakerPlane
birkelbach
Posts: 193
Joined: 04 Sep 2012, 14:42

Re: Arduino CAN Shield

Post by birkelbach »

I don't think you'd be jumping ahead at all. The more people involved, the better. I have a serial graphic LCD around here somewhere from Sparkfun that I was thinking about building something with. For now I'll concentrate on the interface and the software. At least then, people that want to play around could have something to test with. It's really difficult to know that you have the protocol right when you have to build two devices. It's better to test against something that is already tested.

The 4d stuff is really cool. They have a lot of new products since the last time I checked them out. That transparent display could make a pretty good HUD. You could't put a lot of information on it but you may be able to put airspeed, altitude and heading (or x-track error) and it still be legible. It'd sure be interesting to try.

The rest of the 4d line is really interesting too. I think a lot of really neat little instruments could be easily made with them.
Phil Birkelbach
Waller, Texas
RV-7 727WB
www.myrv7.com
birkelbach
Posts: 193
Joined: 04 Sep 2012, 14:42

Re: Arduino CAN Shield

Post by birkelbach »

Okay so I have the thing functional. It can read and write standard and extended frames. It's missing a few features. I haven't done the mask/filter setting commands yet and I haven't done the MCP2515 Raw command yet. Those shouldn't take too long.

It has a bug that I'm having a hard time sorting out. If you try to send more than 8 data bytes with the 'W' command it goes off the reservation. I think it must be some kind of stack overflow or some such thing. I stared at it for far too long last night so I may be missing something obvious. It may only be a Leonardo thing because it seems to affect the serial port and the serial port code is quite different in the Leonardo. If somebody has an Uno or another type of Arduino let me know if it works on those.

I also spent very little time optimizing this thing. It's quite slow. There's little hope that anybody is going to use this to saturate a CAN network with traffic. I used the strtoul() and sprintf() functions so I know they are using up a lot of code space. Those could probably be eliminated with some custom code and the performance would improve. I'm sure there are a dozen other places for performance improvements but I don't know that I'm all that interested in tweaking it right now.

You can always get the latest version on GitHub...

https://github.com/birkelbach/ArduinoCAN

If you don't want to mess with Git you can click on the 'ZIP' button and download an archive. To load it up, just put the 'usbcan' directory in the same directory where the rest of your sketches are located and open the Arduino software. It should be in your Sketchbook. A better way (especially if you are using Git) is to put a symbolic link from your sketchbook directory to the 'usbcan' directory.

I'll try to finish up the little loose ends in the next couple of days and then I'll get started on CAN-FIX specific libraries and frameworks for the Arduino. Let me know what you guys think. Send patches and bug reports.
Phil Birkelbach
Waller, Texas
RV-7 727WB
www.myrv7.com
User avatar
John Nicol
Posts: 611
Joined: 23 Nov 2011, 12:17
Contact:

Re: Arduino CAN Shield

Post by John Nicol »

Just waiting on my CAN chips and then I will be testing as well. I have received my displays from 4D systems and have been playing with those in the meantime.

Here is a static image I have uploaded onto one of the displays. The good thing about these displays is that they have their own graphics chip and a micro-SD card. That means the displays and code to make them run are stored on the SD card. The arduino, or other microcontroller just needs to send the data to the display, not draw it as well.

Next step will be to make stuff move. After that, I will hook up to Prepar3D and get data coming from that flight sim. Once the chips arrive, I will download the files from Git and start looking at sending CAN-FIX data.

Image
-----
John Nicol
Founder, MakerPlane
User avatar
jeff54il
Posts: 229
Joined: 30 Nov 2011, 12:36
Location: Holon Israel

Re: Arduino CAN Shield

Post by jeff54il »

Hi Guys,

I have particles of air - not electrons - floating around in my skull, so I only see the the end product and I have absolutely no idea of how it works. In my mind the things you're doing are some sort of miracle. Please excuse my Boorishness :? but I have a question:
Assuming we have some sort of integrated redundant central control computer for the pilot. This system is connected via CAN-FIX to the (among others) control stick, autopilot servo actuators and various flight sensors. It is polling and sampling the status of all these devices, crunching some numbers and then issueing commands and/or reports. OK, OK I'm getting there: What sort of polling/sampling/command rate can we expect from the whole system? 50 Hz? 100 Hz? Maybe we should set a goal or minimum sampling rate to be achieved? Maybe Arduinos are not fast enough? Maybe my question is just generating background noise?

BTW R/C model radios cycle at 50 Hz and I haven't heard complaints that it's not fast enough. R/C models also react an order of magnitude faster than full sized aircraft. So, if 50 Hz is fast enough for R/C then it will almost certainly be fast enough for us.

Jeffrey
Bring them home NOW :cry: :shock:
birkelbach
Posts: 193
Joined: 04 Sep 2012, 14:42

Re: Arduino CAN Shield

Post by birkelbach »

Not background noise. Good questions. What you are describing is a fly-by-wire flight control system. We are not really trying to design a flight control system. CAN-FIX is a communication protocol that could be used in a larger control system but it's not really meant to specify one. I suspect that the vast majority of systems will simply be an EFIS display connected to the bus with airdata, engine data and maybe some control over flaps, trim and lights. Some might want to put sensors on flight controls and log them, but I doubt that there will be more than a few that will want a full fly-by-wire control system in their home built airplane. I know that I have little interest in it, personally.

A fly-by-wire control system is a whole 'nother thing. If I were going to design a flight control system I'd start with three computers, three dedicated CAN-FIX buses, three sets of control position sensors and at least two servos. All input or calculating devices should be tripple redundant, otherwise you have a more difficult time deciding which one failed. In a double redundant system you might just have two systems giving you different answers. How do you know which one is right? In a tripple redundant system they get to vote. With dedicated buses I think you could easily achieve 50Hz or greater. Even on a bus with other data on it, you should be able to achieve these sample rates, because of the arbitration inherent in CAN. This is why we gave flight control inputs such low identifiers. This however, is part of the flight control system design, not necessarily the CAN-FIX protocol spec. If the flight control specifications wind up requiring determinism that can't be gained with CAN-FIX then they'll have to use something else.

I may be speaking out of turn on this one, but I don't think there's any intention to put a fly-by-wire primary flight control system in MakerPlane V1. There are some folks that want to work on designing one (and that's great) but it may be a little ambitious for MPv1. I could be wrong.
Phil Birkelbach
Waller, Texas
RV-7 727WB
www.myrv7.com
User avatar
davecove
Posts: 38
Joined: 06 Feb 2013, 18:11
Location: Houston, Tx

Re: Arduino CAN Shield

Post by davecove »

but it may be a little ambitious for MPv1. I could be wrong.
Agreed... it probably is. That's Ok tho... there is always v2! :D (maybe we should name these designs so that no one thinks that v2 is somehow better than v1, it wouldn't be, it would just be different)
I doubt that there will be more than a few that will want a full fly-by-wire control system in their home built airplane
Also very true, for now. But just like in the military and the airlines, FBW will someday come to GA and there are those of us goofy enough to want to advance that day, and this is just the place to gather and work in that direction.

Jeff, CAN uses a daisy chain arrangement on a 1Mbps bus so if one node goes bonkers it could pull the wire to ground and shut down the entire network. Not the greatest event for sensors to start with, but catastrophic for FBW. I think for FBW a better choice will be FIX/IP... the same FIX data frames Phil is working on, just over 802.3 (ethernet) instead of CAN. It is 10-100 times faster and is not daisy chained (tho a bonkers node could flood the network with traffic).

Even with all that speed, it isn't imagined that this will be a polling network by default. FIX is 'announcement based' so each node would sit there chirping its data at its programmed rate. It would be like a pond of frogs in the spring, each node burping and chirping its song at its rate with listening nodes picking the interesting frames out as they pass by. That said, there is a polling command so you could ask a node to reply to a poll if you wanted something.
Dave
~~~~~~~~~~~~~~~~~~~~~~~
Flying should be easy.
WhereIsMyFlyingCar.info
Post Reply