Log in

View Full Version : CAN Example


dcarr
18-01-2011, 20:05
Can someone please post a working code example for CAN, it can be Java or C++. We're having some trouble.

Thanks,
James from Team 3309

jtdowney
18-01-2011, 22:28
There are some examples in the CANJaguar project (http://firstforge.wpi.edu/sf/projects/canjaguar) on FIRST Forge (http://firstforge.wpi.edu/). Specifically we were looking at this file (http://firstforge.wpi.edu/integration/viewcvs/viewcvs.cgi/CANJaguar%20for%20Java/src/edu/wpi/first/samples/CANJaguarRobotExample.java?root=canjaguar&system=exsy1002&view=markup) to get started. The CANJaguar project is deprecated since the library is now part of WPILib but it still gives a good example with a similar API.

imac256
18-01-2011, 23:54
My team used CAN last year, so our C++ code from 2010 contains examples. That code can be here (http://coolhub.imsa.edu/cybercollab/web/robotics-documentation/programming-documents).

I have attached excerpts of our code from last year which deal specifically with using the CAN bus. At the end of the file there is also an excerpt from the 2011 C++ RobotDrive class which shows how to use synchronization. (found in CANExamples.txt)

Synchronization uses an 8-bit mask which is sent to the motors when the output speed is set, and then a later function is used to send a packet to the Jaguars telling them to execute the previously sent command. A enumerated list of the synchronization groups can be found in the other attached file (synchronization.txt).

If you have any questions about any of the code examples I gave feel free to ask me.
Hope this helps.