CAN Jaguar

My team is having extreme difficulty in regards to using the CAN Jaguar class. The current code that we are using to initialize it is:

self.jaguar = wpilib.CANJaguar(1,4)

From this line of code we get an error saying that two values are needed but that the code is entering in three.

Please help. We are completely lost and are losing hair as well as sleep.

did you mean…
self.jaguar = new CANJaguar(1);
… your using java right?

Also I only see one param for the constructor. What is ‘4’ supposed to be. I assume ‘1’ is the device ID.

The error message is correct. In python there is an implicit first parameter called ‘self’, so when you pass it 2 parameters, you actually passed it three.

Instead, you should initialize the CANJaguar like so:


self.jaguar = wpilib.CANJaguar(1)

As referenced in the RobotPy CANJaguar documentation, there’s only a single parameter you need to pass to the CANJaguar object, which is the deviceNumber.

Make sure that you’re using the very latest version of RobotPy, as the CANJaguar object has had a lot of bugfixes this season!

This is the python forum. :slight_smile:

I am also from the TeraViks. I knew that ‘self’ was implied, but how does one specify the use of the different Control Modes without this method.

I imagine you’d probably want to call the appropriate method. Maybe… changeControlMode?

To be fair, the documentation is a bit confusing in its format. The ControlMode displayed at the top is just enumerating what types are available, and does not indicate that it’s a parameter you can pass to the constructor.

Haha oops, sorry Dustin…doing to many things at once. I’ll shut up now…

Now, when I try this:

self.jaguar = wpilib.CANJaguar(1)
self.jaguar.setVoltageModeEncoder(360)
self.jaguar.enableControl()

I get:

raise frccan.CANMessageNotFound("message not found")
hal.exceptions.CANMessageNotFound: message not found

How do I prevent this?

That sounds like a bug in RobotPy’s WPILib. Do you have a stack trace you can paste?


16:07:23:251 INFO    : wpilib              : WPILib version 2015.0.8
16:07:23:253 INFO    : wpilib              : HAL base version 2015.0.8; roboRIO platform version 2015.0.8
16:07:23:254 INFO    : wpilib              : HAL library version jenkins-stable-2015.326
16:07:23:549 WARNING : robotpy             : Robots don't quit!
16:07:23:551 ERROR   : robotpy             : ---> The startCompetition() method (or methods called by it) should have handled the exception.
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/wpilib/robotbase.py", line 185, in main
    robot.startCompetition()
  File "/usr/local/lib/python3.4/site-packages/wpilib/iterativerobot.py", line 75, in startCompetition
    self.robotInit()
  File "robot.py", line 21, in robotInit
    self.jaguar = wpilib.CANJaguar(1)
  File "/usr/local/lib/python3.4/site-packages/wpilib/canjaguar.py", line 293, in __init__
    raise frccan.CANMessageNotFound("message not found")
hal.exceptions.CANMessageNotFound: message not found


Locals at innermost frame:

{ 'data': [225, 31, 0, 0],
  'deviceNumber': 1,
  'i': 49,
  'receivedFirmwareVersion': True,
  'self': <wpilib.canjaguar.CANJaguar object at 0x42c2c810>}


Interesting. That error message is terrible – but the code seems to indicate that it can’t find the CANJaguar. Are you sure ID 1 is the right ID for the Jaguar – or that perhaps there’s another device on ID 1? Most of the time it is recommended to not use ID 1, as that’s the default ID for a lot of devices.

Though I can’t truly verify it, I checked it today and it said on the web interface that the PCM was assigned to Device ID #0 and the PDP was Device #2 and the Jaguar was assigned to Device #1. I will be back there on Tuesday.

If you do find the PDP is ID = 2, I would change the PDP back to ID = 0 in case you want to use any of the CAN features of it. ID = 0 is all that is currently supported in C++, Java and Python: http://robotpy.readthedocs.org/en/latest/wpilib/PowerDistributionPanel.html

Devices of different types do not conflict so having the PCM and PDP both at 0 is not an issue.

Another thing to check would be your CAN error counts on the last tab on the left side of the DS.

A week ago it decided to work. One of the problems was that the Jaguar Device ID # couldn’t ever be changed. We pressed the user button within 5 seconds. We just mucked with stuff, and eventually, the Jaguar worked, though we still were unable to change the ID.

I don’t have any idea why it did that, but I just know to muck around with some semblance of method from what I learned and it might work.

Thank you so much for all of your help. We were able to get it moving and moved on to bigger and better things… Like using PID :stuck_out_tongue: