Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 5.61 KB

tcp-version.md

File metadata and controls

71 lines (56 loc) · 5.61 KB

Piracer_py Application with TCP/IP Socket

!!!! DOCUMENTATION IN PROGRESS !!!!

We decided to build two versions of the Piracer Application - the V1 TCP-Version and V2 DBUS-Version.
The following documentation narrows down the details on V1 TCP-Version.

Introduction

Multiprocessing

Multiprocessing is a technique that enables concurrent execution of multiple processes, allowing programs to utilize multiple CPU cores for improved performance. It provides a way to create and manage separate processes, each with its own memory space and resources, allowing them to run independently. This is particularly useful for CPU-bound tasks, such as data processing and intensive computations, as it can significantly reduce execution time. Python's multiprocessing module offers a high-level interface for creating and managing processes, with features like the Pool class for parallelizing function calls and tools for inter-process communication like pipes and queues. It is a powerful tool for optimizing multi-core systems and achieving faster program execution in Python.

Queues

Queues in Python's multiprocessing module enable secure communication between concurrent processes by preventing data corruption and race conditions.
Processes can use the put() and get() methods to add and retrieve items from the queue, maintaining synchronization.
The FIFO queues are used to provide values from Process 1-3 on Process 4.

Monitoring

See Execption.md

Software Architecture

Processes

This python application runs four Processes which are responsible for the follwoing tasks:

Process Task
ℹ️
Car_Info
Display ip address & battery information on the on-board OLED display
🚗
Remote_Controll
Throttle and steering controll via Gamepad-Remotecontrol
➡️
Recieve_Data
Recieve data from CAN-Bus
📡
Send_Data
Send send via TCPS socket.

Process 1 - Display Car Info

ℹ️ car_info.py
The function utilizes the PiRacerStandard class to access the vehicle's battery data and the socket module to retrieve the local IP address.
The earned information includes battery voltage, current, power consumption, local IP address, and current time.

Process 2 - Remote Controll

🚗car_control.py
This Python script allows remote control of a PiRacerStandard vehicle using the ShanWanGamepad module.
The car_control function takes input from the gamepad's analog sticks for throttle and steering.
The vehicle's throttle and steering angles are then set based on these inputs to drive the car.
The script runs in an infinite loop until interrupted by the user, and upon interruption, the car's throttle and steering are set to 0 for safety.

!!! Insert picture of Gamepad & Gif of driving Piracer here !!!

Process 3 - Recieve Data

➡️recieve_data.py
This Python script utilizes the can library to communicate with CAN (Controller Area Network) devices and extract data from sensors. It employs the socketcan bus interface for communication and handles the reception of data from a specific CAN ID. The received data is processed to calculate the speed of a wheel based on RPM and wheel diameter. The calculated speed and RPM values are then stored in a queue, ensuring efficient data storage even when the queue is full. The script provides a robust mechanism for extracting and processing sensor data, while the KeyboardInterrupt is supported for graceful termination.

Process 4 - Send Data

📡send_data.py
While using inter-process-communication (IPC), we have to decide which method we want to use. An overview of the different methods can be found in Inter-Process-Communication.md.

In terms of IPC, sockets provide good performance and flexibility for inter-process communication (IPC), especially when using binary data serialization.
🤔 But what socket type should we use? TCP/IP or Unix domain sockets?

  • Unix domain sockets are used for communication between processes on the same machine by using the local file system as their address space.
    They are relatively efficient because they avoid the overhead of the network protocol.
  • TCP/IP sockets are generally used for communication between processes on different machines, but can also been used for the communication between processes on the same machine. 🤯 We made the decision to try both TCP/IP socket (V1) and DBus (V2) like mentioned ealier.

This Python script establishes a socket server that communicates with a client, sending real-time data from a vehicle.
The received information from the can bus like speed and RPM are merged with car control and other car-related information data from queues.
The script uses queues to collect real-time data from different sources, facilitating safe inter-process communication.

References

[1], [2], [3], [4]