---
# System prepended metadata

title: ROS CAN-BUS

---

# ROS CAN-BUS

#### 1. Kvaser 
- **Hardware**:
    - [Hardware:KVASER LEAF LIGHT HS V2](https://www.kvaser.com/product/kvaser-leaf-light-hs-v2/)
    - [kvaser_leaf_light_v2_usersguide.pdf](https://www.kvaser.com/software/7330130980146/V1_2_189/kvaser_leaf_light_v2_usersguide.pdf)
    ![](https://i.imgur.com/JuUoZG0.png)

    
- **Linux driver**:
    - Download [Kvaser Linux Drivers and SDK](https://www.kvaser.com/download/) and follow instructions in README
    
- **ROS1 pkg (kinetic)**:
    - [ROS pkg by KVASER](https://github.com/astuff/kvaser_interface)
    - Clone the pkg in workspace and catkin_make
        -  `cd ~/xx_ws/src && git clone https://github.com/astuff/kvaser_interface.git`
        - `cd .. && catkin_make`
    - Get [**Hardware ID & Circuit ID**](https://autonomoustuff.atlassian.net/wiki/spaces/RW/pages/17472305/Populate+CAN+Hardware+and+Circuit+IDs)
        - `rosrun kvaser_interface list_channels`
        - ![](https://i.imgur.com/KIkG8F2.png)
        - The number following the **"s/n"** in each of these lines is the CAN **Hardware ID** (serial number).
        - The CAN **Circuit ID** is the 0-based index of the channel that you're using on a specific piece of hardware. For example, the first channel listed here would be CAN Circuit ID 0 and the 2nd would be CAN Circuit ID 1. This ordering starts over for each piece of hardware. If there were two more channels here on another Kvaser USBcan Pro, they would also be CAN Circuit ID 0 and 1 respectively.
    - Launch file
        - Change parameters in **kvaser_can_bridge.launch** for the hardware you are attempting to interface with **using the values you got above for the CAN Hardware ID and CAN Circuit ID.**
        - `roslaunch kvaser_interface kvaser_can_bridge.launch`
        - ![](https://i.imgur.com/4pQh3Dl.png)
        - Or simply assign hardware_id thro command
        `roslaunch kvaser_interface kvaser_can_bridge.launch can_hardware_id:=74771`
        - Use **/can_rx** to send messages
        `rostopic pub -r 1 /can_rx can_msgs/Frame "header:
      seq: 0
      stamp: {secs: 0, nsecs: 0}
      frame_id: ''
    id: 0x7FF
    is_rtr: false
    is_extended: false
    is_error: false
    dlc: 6
    data: "hello"" `
        - Use **/can_tx** to recieve messages
        `rostopic echo /can_tx`
        - To view all messages with IDs
        ` rosrun kvaser_interface canmonitor`
        ![](https://i.imgur.com/HE2dzi4.png =300x300) ![](https://i.imgur.com/lt55GCK.png =320x300)

- **ROS2 pkg (foxy)**:
    - [ROS pkg (dashing-devel) by KVASER](https://github.com/astuff/kvaser_interface/tree/dashing-devel)
    - *Since the offical package on ROS2 is only supported to dashling-devel (we're using foxy), we need to modify some lines in the packages.*
    - Clone the pkg in workspace and catkin_make
        -  `cd ~/xx_ws/src && git clone -b dashing-devel https://github.com/astuff/kvaser_interface.git`
        - `cd .. && colcon_build`
    - `ros2 run kvaser_interface list_channels` 
    - `ros2 launch kvaser_interface kvaser_bridge.py`
    - ![](https://i.imgur.com/tdDFe6q.png)
    - Publish data on ROS2 **(uint8[8] data)** 
        ```
        ros2 topic pub -r 10 /can_rx can_msgs/Frame "header:
          stamp:
            sec: 0
            nanosec: 0
          frame_id: ''
        id: 151
        is_rtr: false
        is_extended: false
        is_error: false
        dlc: 4
        data: [1,20,30,40,5,6,7,8]" 
        ```
        
        


#### 2. Topics on devices
- VESC 6+
    - [VESC 6+ CAN bus](https://vesc-project.com/node/889)
- Mid-drive
    - [Bafang MM G330.250](https://bafang-e.com/oem-area/components/component/motor/mm-g330250c/)
    - [BAFANG dealer manual - MAX Drive System](https://head-bike.s8.cdn-upgates.com/m/m5c9e3634ddc94-max-manual.pdf)
    - ![](https://i.imgur.com/MuUft7z.png)
    - ![](https://i.imgur.com/fkQeiLA.png)
    - ![](https://i.imgur.com/dDecafE.png)
    - [VESC6_CAN_CommandsTelemetry.pdf](https://vesc-project.com/sites/default/files/imce/u15301/VESC6_CAN_CommandsTelemetry.pdf)
    - ![](https://i.imgur.com/EJ78drX.jpg)
    - VESC_TOOL setting
    ![](https://i.imgur.com/vypYrR5.png)
        ```cmd=
        rostopic pub -r 1 /can_rx can_msgs/Frame "header:
      seq: 0
      stamp: {secs: 0, nsecs: 0}
      frame_id: ''
        id: 0x0D
        is_rtr: false
        is_extended: true
        is_error: false
        dlc: 4
        data: 0x00 0x00 0x4E 0x20"
        ```
        > id: 13 = 0x0D
        > dutycycle: 20% (0.2*10^5 = 0x4E20)

#### 3. CAN-BUS format
![](https://i.imgur.com/BkChtUu.png)


---
:::warning
:brain: **TODO:**: 
- [x] Testing of CAN Signals(tx thro rostopic /can_tx and rx thro rostopic /can_rx)
:::