Go to Post You should qualify the same way you eliminate if you ask me. - sircedric4 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-01-2017, 22:33
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
CAN Interface Examples?

I'm in search of examples of how to write an interface to a device on the CAN bus.

We would like to build an interface to our Raspberry Pi using CAN.

I'm digging through the WPILib code and any other examples I can get my hands on.

Any suggestions or pointers would be great!
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2017, 22:42
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is online now
Not Allowed Near Power Tools
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 162
nickbrickmaster is an unknown quantity at this point
Re: CAN Interface Examples?

Here's marshall's list of stuff from another CAN thread.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #3   Spotlight this post!  
Unread 16-01-2017, 10:28
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: CAN Interface Examples?

Thank you for the references. I'll read closer, but I'm looking for source code examples. I found some of the code in wpilib.

I'll dig more to workout how the code works for these different devices.
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote
  #4   Spotlight this post!  
Unread 16-01-2017, 10:59
Jaci's Avatar
Jaci Jaci is offline
Registered User
AKA: Jaci R Brunning
FRC #5333 (Can't C# | OpenRIO)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Perth, Western Australia
Posts: 265
Jaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond repute
Re: CAN Interface Examples?

Generally, you don't want to communicate with your coprocessor via CAN, for a few reasons.

The Raspberry Pi doesn't natively support CAN, in fact, most processors don't. CAN is generally a pain to bit-bang, so you're going to want to use some extra circuitry to control and communicate with the CAN bus. This, combined with the lower speed and lower bandwidth, makes CAN less desirable over something more like ethernet.

If, however, you still want to pursue the project, you will have to use "HAL/CAN.h" header, or the "CANJNI.java" file. These contain the message sending, receiving and (for c++) the packing / unpacking of data.

CAN.h https://github.com/wpilibsuite/allwp...lude/HAL/CAN.h

CANJNI.java https://github.com/wpilibsuite/allwp...an/CANJNI.java
__________________
Jacinta R

Curtin FRC (5333+5663) : Mentor
5333 : Former [Captain | Programmer | Driver], Now Mentor
OpenRIO : Owner

Website | Twitter | Github
jaci.brunning@gmail.com
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2017, 11:48
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: CAN Interface Examples?

Quote:
Originally Posted by Jaci View Post
The Raspberry Pi doesn't natively support CAN, in fact, most processors don't.
We're using a card on the Pi to interface with CAN.

Quote:
Originally Posted by Jaci View Post
If, however, you still want to pursue the project, you will have to use "HAL/CAN.h" header, or the "CANJNI.java" file. These contain the message sending, receiving and (for c++) the packing / unpacking of data.
Thank you for the references! This is very helpful.

We're programming in C++. How does CANJNI.java come into play?

I was looking at CtreCanNode.h as base class, as that seems common for many of the CAN interfaces already available (PCM, PDP, CANTalon)
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote
  #6   Spotlight this post!  
Unread 16-01-2017, 21:32
Jaci's Avatar
Jaci Jaci is offline
Registered User
AKA: Jaci R Brunning
FRC #5333 (Can't C# | OpenRIO)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Perth, Western Australia
Posts: 265
Jaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond reputeJaci has a reputation beyond repute
Re: CAN Interface Examples?

Quote:
Originally Posted by duane View Post
Thank you for the references! This is very helpful.

We're programming in C++. How does CANJNI.java come into play?

I was looking at CtreCanNode.h as base class, as that seems common for many of the CAN interfaces already available (PCM, PDP, CANTalon)
CANJNI.java is the CAN.h equivalent for the Java language, if you're coding in C++ you won't need it.

CtreCanNode.h should function just fine for your needs
__________________
Jacinta R

Curtin FRC (5333+5663) : Mentor
5333 : Former [Captain | Programmer | Driver], Now Mentor
OpenRIO : Owner

Website | Twitter | Github
jaci.brunning@gmail.com
Reply With Quote
  #7   Spotlight this post!  
Unread 16-01-2017, 22:17
wesleyac's Avatar
wesleyac wesleyac is offline
Registered User
AKA: Wesley Aptekar-Cassels
FRC #1678
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Davis, CA
Posts: 55
wesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to behold
Re: CAN Interface Examples?

I'm going to second the caution that CAN may not be what you're looking for. Ethernet is very likely more robust and easier than CAN. I'd recommend taking a critical look at what your use case is and if there's an easier or better way to achive it.

That being said, if you do decide to go with CAN, people would be able to help more if they knew which card you were using - there may be specific resources or advice for it.
__________________
Quote:
Originally Posted by The programming team
Define "works."
Reply With Quote
  #8   Spotlight this post!  
Unread 16-01-2017, 22:59
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: CAN Interface Examples?

Quote:
Originally Posted by wesleyac View Post
I'm going to second the caution that CAN may not be what you're looking for. Ethernet is very likely more robust and easier than CAN. I'd recommend taking a critical look at what your use case is and if there's an easier or better way to achieve it.
I'm quite baffled by all of the caution around CAN. Why is there so much concern? We run the entire robot on CAN now.

I find the project interesting so far.

Quote:
Originally Posted by wesleyac View Post
That being said, if you do decide to go with CAN, people would be able to help more if they knew which card you were using - there may be specific resources or advice for it.
http://copperhilltech.com/pican-2-ca...-raspberry-pi/

I'd like to understand why there would be support for a particular CAN interface. I would have expected CAN to be well defined by the standard.

Looking forward to learn more.
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote
  #9   Spotlight this post!  
Unread 17-01-2017, 00:28
wesleyac's Avatar
wesleyac wesleyac is offline
Registered User
AKA: Wesley Aptekar-Cassels
FRC #1678
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Davis, CA
Posts: 55
wesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to beholdwesleyac is a splendid one to behold
Re: CAN Interface Examples?

Quote:
Originally Posted by duane View Post
I'm quite baffled by all of the caution around CAN. Why is there so much concern? We run the entire robot on CAN now.

I find the project interesting so far.
CAN does have some quarks (as well as some nice parts). You should make sure that you understand the tradeoffs before you settle on an interface.

I prefer ethernet/TCP (or UPD), because it's more common, easier to debug (some CAN issues can be difficult to debug without some hardware designed for it), and has more throughput.

I'm not saying don't use CAN - just make sure that you have solid reasoning as to why you're doing it.

Quote:
Originally Posted by duane View Post
http://copperhilltech.com/pican-2-ca...-raspberry-pi/

I'd like to understand why there would be support for a particular CAN interface. I would have expected CAN to be well defined by the standard.

Looking forward to learn more.
CAN is a very well defined format (Well, pretty well defined. There are actually a few different versions of CAN out there, but you mostly will never see the less-standard ones), but the way to interface with a microprocessor that implements CAN can vary depending on the microprocessor.

I was under the impression that you were asking about writing the Pi-side code. If that's not the case, then the chip that you're using is not very important. Sorry if you're asking about the roborio side of the interface - if that's the case then I've misunderstood your question.

The one that you linked to uses some GPIO pins on the Pi to control the CAN controller and transceiver. It looks like it does this over SPI, but I'm not entirely sure about that. They provide example C code which should be fairly easy to adapt to C++. The links that I provide below should actually apply for both the Pi-side and Rio side as well.

Regarding the RoboRIO side of the interface, there's been some good advice about looking at WPILib. I would recommend looking at the linux kernel docs for SocketCAN (The Wikipedia page is also good, and has some example code). Looking at the can-utils source could also be helpful. This is lower-level than most of what's in WPILib. I find that that makes it easier to understand, but YMMV.
__________________
Quote:
Originally Posted by The programming team
Define "works."
Reply With Quote
  #10   Spotlight this post!  
Unread 17-01-2017, 11:08
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 98
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: CAN Interface Examples?

Thank you for your help. We are building both sides of the interface. In this case, I was looking for references for the RoboRio and WPILib.

Looks like I have some good references to go through.

Your help is appreciated!
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 23:54.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi