DriveWorks SDK Reference

| 0.6.67 Release

/builds/driveav/dw/sdk/samples/sensors/canbus/interpreter/README.md
Go to the documentation of this file.
1 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
2 
3 @page dwx_canbus_message_sample CAN Message Interpreter-based on DBC File Sample
4 
5 The CAN Message Interpreter-based on DBC File sample is a simple CAN bus
6 interpreter sample. An interpreter is built based on the definition in a DBC
7 file, and input CAN messages are then decoded by the interpreter. In this
8 sample, information about car steering and speed is transmitted in CAN messages,
9 and the sample decodes and displays all received CAN messages. By default, the
10 sample demonstrates the usage with virtual CAN, using an offline message file.
11 You may also set the input arguments for real CAN message input (e.g., can0 or
12 vcan0) on Linux desktop or can.aurix on DrivePX.
13 
14 #### Usage
15 
16 Use this sample application with:
17 
18 - Virtual CAN bus defined in DriveWorks with offline binary CAN message files
19 - Virtual CAN bus defined by SocketCAN on Linux
20 - Real CAN device, which supports SocketCAN on Linux
21 
22 
23 #### Offline CAN Messages
24 
25  ./sample_canbus_interpreter
26 
27 By default, the sample reads `data/samples/sensors/can/sample.dbc` to build the
28 interpreter, and opens a virtual CAN bus with messages defined in
29 `data/samples/sensors/can/canbus_dbc.can`.
30 
31 The output on the console is the car steering and speed. For example:
32 
33  5662312708 [0x100] -> 0x9d 0xfe Car steering -0.0221875 rad at [5662312708]
34  5662312708 [0x200] -> 0x1f 0x21 Car speed 8.479 m/s at [5662312708]
35 
36 #### DBC files
37 
38 The sample can be used with a DBC file provided by the user. In order to start
39 interpreter sample using user provided DBC file, pass `--dbc` parameter to the
40 application:
41 
42  ./sample_canbus_interpreter --dbc=user_path_to/file.dbc
43 
44 #### Virtual CAN Bus on Linux
45 
46  ./sample_canbus_interpreter --driver=can.socket --params=device=vcan0
47 
48 Run it with a virtual CAN device created with:
49 
50  $ sudo modprobe vcan
51  $ sudo ip link add dev vcan0 type vcan
52  $ sudo ip link set up vcan0
53 
54 To send data from the console to the virtual CAN bus, run `cansend` (from the
55 `can-utils` package):
56 
57  $ cansend vcan0 100#fa490200
58  $ cansend vcan0 200#2e920300
59 
60 This sends a CAN message with the CAN ID and 2 bytes of data, containing: 0x11,
61 0x22
62 
63 The output is similar to:
64 
65  44798857 [0x100] -> 0xfa 0x49 0x2 0x0 Car steering 0.0937563 rad at [44798857]
66  64318678 [0x200] -> 0x2e 0x92 0x3 0x0 Car speed 2.3403 m/s at [64318678]
67 
68 
69 #### Real CAN Device on Linux
70 
71  $ ./sample_canbus_interpreter --driver=can.socket --params=device=can0
72 
73 A valid SocketCAN device must be present in the system as canX. For example, a
74 PCAN USB. The bitrate is set to 500 KB. Set the bitrate on the CAN device:
75 
76  $ sudo ip link set can0 type can bitrate 500000
77  $ sudo ip link set can0 up
78 
79 The CAN interface used to listen on a real CAN bus must have SocketCAN driver
80 implementation in the system. A SocketCAN based driver can be identified easily
81 if `:> sudo ifconfig -a` returns the default network interfaces **and** a CAN
82 based interface (i.e., canX, slcanX, etc).
83 
84 ##### AurixCAN
85 On DRIVE PX 2 and ACR, the CAN connectors marked with CAN-1..CAN-4 are reachable throught Aurix by the Tegras.
86 For this to work, a proper setup of the Aurix needs to be made prior to running the application. Please
87 refer to the EasyCAN user guide provided as part of PDK documentation to set up Aurix to filter
88 and pass a selected subset of CAN messages. In order to connect to AurixCAN, use the following arguments:
89 
90 On DRIVE PX2:
91  --driver=can.aurix --params=ip=10.42.0.83,bus=a
92 
93 On ACR:
94  --driver=can.aurix --params=ip=127.0.0.1,aport=50000,bport=50103,bus=a
95 
96 Where `ip` is the IP address from which the CAN messages are forwarded (by default, set to 10.42.0.83)
97 and `bus` points to the corresponding CAN bus connector, i.e., CAN-1->a, ..., CAN-4->d.
98 
99 The connection to AurixCAN happens using UDP sockets. Additional arguments for the remote (`aport`) and
100 local (`bport`) UDP port can be specified if AurixCAN is working in a non-default configuration. By
101 default, on DRIVE PX2, AurixCAN is reachable over `aport=50000` and communicates with the Tegra over
102 `bport=60395`. On ACR however, AurixCAN is reachable over `aport=50000` and communicates with
103 the Tegra over `bport=50103`.
104