dapperfu / python_CANape

Python Module for Vector CANape API
40 stars 9 forks source link

Feb 2023 Update.

If you want a working Python CANape tool check out pycanape by zariiii9003.

This project was a light proof of concept for my resume and to hopefully inspire others to show it's possible. It started as an unsupported side project at Eaton and Caterpillar. The bits on Github had to be re-created without a licensed version of CANape and therefore is very light.

Da Liegt der Hund beraben

Entwicklungsgeschichte

Unternehmen, die CANape (einschließlich Vector) verwenden, sind mit Open Source sehr konservativ.

Bei Caterpillar (ca. 2015-2016) wurde eine Alpha-Version entwickelt. Es war gut. Es automatisierte Stunden des dSpace HIL-Testens! Es befindet sich in der Firewall von Caterpillar.

Bei Eaton (ca. 2017) wurde eine Beta-Version entwickelt. Es war gut gut. Es befindet sich in der Firewall von Eaton.

Code hier wurde mit der Demo-Version von Vector entwickelt. Es hat Einschränkungen. Ich kann mir keine Vector-Hardware leisten.

Zukunft

Python ist die Zukunft. ADAS5 benötigt viele Tests. Python ist gut in Tests. CANape braucht Python.

PyCANape

Pythonic CFFI wrapper for CANape. This is a full Pythonic wrapper using the CANape ASAM-MCD3 Interface (CANapeAPI). It has an identical feature set to the CANape® and MATLAB® interface.

Examples

Create CANape object.

import CANape
canape = CANape.CANape()

CANape can be initialized via the init(), init2(), init3(), init4(), or init5() functions. Any one of these functions can be used to initialize CANape depending upon need. Each function requires a different set of parameters that need to be passed in. If init5 is being used, the function can be called like this:

canape.init5(timeout = 20000,
             m_WorkingDir = r"C:\Vector\Data\Experiment1",
             fifo_size = 1000,
             sample_size = 1,
             debug = True,
             clear_device_list)

After initializing the ASAP3 connection, a new module/device has to be created and a database file has to be attached. If a connection is being made to a CCP device and an ASAP2 description file is available, the AttachAsap2() function is used.

canape.attach_asap(a2l=r"C:\Vector\Data\Experiment1\TopSecret.a2l",
                    channel = 2);

To create a connection to a CAN device, the module can to be created like this:

canape.create_module (name = "CAN",
                      database= r"C:\Vector\Data\Experiment1\TopSecret.dbc",,
                      driverType=CANape(CCP,
                      channel = 1);

To use a MDF file in Python or Matlab.

canape.matlab_conversion(mdf = r"C:\Vector\Data\Experiment1\NDA_Data.mdf",
                         mat = r"C:\Vector\Data\Experiment1\NDA_Data.mat)

To list all devices currently connected to CANape:

devices = canape.get_devices()
for device in devices:
    print(device)

Create a new module, add a measurement channel, record data, process it with numpy.

canape.attach_asap(a2l=r"C:\Vector\Data\Experiment1\TopSecret.a2l",
                   channel = 2);
canape.module[0].add_measurement(name='channel2',
                                 task_index =3,
                                 save=0)
canape.start_measurement()
while True:
    data = canape.get_fifo_data(0, 2)
    if np.magic(data):
        print("Eureka!")
        break

Read and display calibration 2D Calibration Map. (Can return any calibration object data type like scalar, string, map and curve.)

data = canape.read_calibration_object(0, 'TopSecretCalibration', 1)
plt.plot(data[:,0], data[:,1])
plt.xlabel("Top Secret Dependent Axis")
plt.ylabel("Top Secret Independent Axis")
plt.title("Top Secret Calibration")
plt.show()

To close the CANape connection, the exit() function is used:

canape.exit()

Why?

Exposes all of CANape's features to the Python ecosystem.

Motivation