astuff / kvaser_interface

A Kvaser CAN interface ROS abstraction layer.
MIT License
83 stars 51 forks source link

Is it possible to use non-standard bit rates? #90

Open Ajmoomaw opened 1 year ago

Ajmoomaw commented 1 year ago

I am working with a CAN bus that is transmitting at 33300 kbps and when launching the node I get an error for a bad input parameter. I was wondering if it is possible to setup the current code to operate at that transmission rate or if there is a recommended way to edit the code base to implement this bit rate. Any and all assistance if greatly appreciated.

icolwell-as commented 1 year ago

Did you try changing the can_bit_rate argument in the launch file? https://github.com/astuff/kvaser_interface/blob/ros1_master/launch/kvaser_can_bridge.launch

Ajmoomaw commented 1 year ago

I have. I believe the issue I am having is due to the code seemingly not supporting bit rates outside of the ones listed below in the screen shot taken from the "kvaser_interface.cpp" file. I have also included a link to the code section I show. I am uncertain if this is truly the issue, however this seems to be where the "bad param" error is originating from.

image

https://github.com/astuff/kvaser_interface/blob/4993cd44efb729a0c4793961847c508e671bae21/src/kvaser_interface.cpp#L81:~:text=switch%20(bitrate),%7D

icolwell-as commented 1 year ago

Interesting, I didn't know there were preset options like that. I'm not actually familiar with this codebase :smile: Those bitrate constants are defined here in the kvaser canlib source code: https://github.com/astuff/kvaser-linuxcan/blob/master/include/canlib.h#L393-L428 So maybe it's a limitation of canlib. Regardless, you'd probably want to look through Kvaser's canlib docs to see if/how you can use bitrates other that those defined.

For a quick test, maybe try hardcoding the input parameter freq on this line: https://github.com/astuff/kvaser_interface/blob/ros1_master/src/kvaser_interface.cpp#L101 to whatever it is you want, 333000?