Controlling CAN motors with a Rasperry Pi

Hey guys. My team is working on a t-shirt shooter robot and we were wondering if we could use CAN bus with the Rpi. Obviously, there is no CAN bus included but here is a CAN board for the Pi. Can anyone shed some light on how it would be used and / or if it would be better to use a PWM board like this. Thanks :]

I don’t know about the PI, but the CTRE Hero board supports CAN, is relatively inexpensive and might work for you.

Boom:

README.md

# Phoenix-Linux-SocketCAN-Example

General example using CTRE Phoenix class library on Linux/RaspPi platforms.

Requires libsdl2-dev (sudo apt-get install libsdl2-dev) for USB Gamepad interface.

Simple example here, we use libSDL2 to get gamepad values...
- [example.cpp](example.cpp)

Library binaries here
- [Raspberry PI (linux-armhf) ](lib/raspberry)
- [Linux Desktop (linux-arm64)](lib/x86-64)

This is the requisite platform interface for the integrator to provide for other platforms.
- [include/ctre/phoenix/Platform/Platform.h](include/ctre/phoenix/Platform/Platform.h)

If you link in phoenix-can-utils, you don't need to implement   CANComm_* , just implement   CANbus_*.  Conversely you can just implement the mid-level and don't bother with the low-level.
- [include/ctre/phoenix/Platform/Platform.h#L27](include/ctre/phoenix/Platform/Platform.h#L27)

#### Binaries
| Name        |  Notes |
| ------------- | ------------- |
| libCTRE_PhoenixPlatformLinuxSocketCan.a | Platform implementation to support USB-to-CANbus adapters in Linux (see parent folder for arch).|
| libCTRE_PhoenixCanutils.a | Implements CANComm_* routines so you don't have to.  But if you want to, remove this from the link list. |
| libCTRE_PhoenixCCI.a | Phoenix Common C Interface, leave this be. |
| libCTRE_Phoenix.a | Class library, this is built from Phoenix-frc-lib. |

#### CAN USB Adapter
SocketCAN USB adapter used below.
- Firmware : https://github.com/HubertD/candleLight_fw
- Hardware : http://canable.io/

Or alternatively deploy the SocketCAN firmware to a HERO
- Firmware : https://github.com/CrossTheRoadElec/HERO-STM32F4
- Hardware : http://www.ctr-electronics.com/control-system/hro.html

Thanks Omar! …and Ryan - we miss you dude!

Thanks. What hardware should I get for that? Should I use the PiCan I linked to in the original post or should I use something else?

https://www.tindie.com/products/protofusion/canable-usb-to-can-bus-adapter/ is the item referenced in the linked source code. Presumably with a stock Pi.

Andrew said it above but read the doc. It’s all there.

The very link you provided in the original post mentions a SocketCAN driver for the PiCan. So if you have a PiCan already, it is worth trying. See if you can get the “can0” network initialized. There is lots of documentation online for SocketCAN if you look.

Otherwise, the CANable worked for us.