From 47a87711d904525c78f9c095d1077cedc9689458 Mon Sep 17 00:00:00 2001 From: Bill Finger Date: Sat, 18 Jan 2025 18:40:23 +0300 Subject: [PATCH] Add README file with instructions for CAN communication scripts - Added a README file containing instructions for using the Python scripts to test and interact with a CAN bus system. - Included details on prerequisites, usage, configuration, and troubleshooting. - Provided step-by-step guidance for running each script, including arguments and behavior. --- controller/fw/embed/test/README | 11 ---- controller/fw/embed/test/README.md | 86 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 11 deletions(-) delete mode 100644 controller/fw/embed/test/README create mode 100644 controller/fw/embed/test/README.md diff --git a/controller/fw/embed/test/README b/controller/fw/embed/test/README deleted file mode 100644 index 9b1e87b..0000000 --- a/controller/fw/embed/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PlatformIO Test Runner and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PlatformIO Unit Testing: -- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html diff --git a/controller/fw/embed/test/README.md b/controller/fw/embed/test/README.md new file mode 100644 index 0000000..4ac995f --- /dev/null +++ b/controller/fw/embed/test/README.md @@ -0,0 +1,86 @@ +# CAN Communication Scripts + +This repository contains Python scripts for testing and interacting with a CAN bus system. These scripts enable sending and receiving CAN messages to control a motor, set angles, and adjust velocities. + +## Prerequisites + +1. **Python 3.7+** installed on your system. +2. **`python-can` library** installed. Install it via pip: + ```bash + pip install python-can + ``` +3. **SocketCAN interface** properly configured on your Linux system. The default channel is `can0`. + +## Usage + +### 1. Receiving CAN Messages + +The script `python_can.py` listens to the CAN bus and processes incoming messages. + +#### Run: +```bash +python3 python_can.py +``` + +#### Features: +- Processes messages with data length 5. +- Parses the first byte (`flag`) to determine the type: + - `'A'`: Angle (float). + - `'V'`: Velocity (float). + - `'E'`: Enable/disable status (boolean). + +### 2. Enabling or Disabling the Motor + +The script `python_enable_motor.py` sends commands to enable or disable the motor. + +#### Run: +```bash +python3 python_enable_motor.py <0|1> +``` + +#### Arguments: +- `0`: Disable the motor. +- `1`: Enable the motor. + +### 3. Sending Target Angle + +The script `python_send_angle.py` sends a target angle to the CAN bus. + +#### Run: +```bash +python3 python_send_angle.py +``` + +#### Behavior: +- Sends a message with a predefined target angle every second. +- Adjust the target angle in the script (`target_angle` variable). + +### 4. Sending Target Velocity + +The script `python_send_velocity.py` sends a target velocity to the CAN bus. + +#### Run: +```bash +python3 python_send_velocity.py +``` + +#### Behavior: +- Sends a message with a predefined target velocity every second. +- Adjust the target velocity in the script (`target_speed` variable). + +## Configuration + +### CAN Interface +The scripts use the following default CAN bus settings: +- **Channel**: `can0` +- **Bitrate**: `1 Mbps` + +If your configuration differs, update the `Bus()` initialization in the scripts. + +## Troubleshooting + +1. **"Error initializing CAN bus"**: + - Ensure your CAN interface is correctly configured and active: + ```bash + sudo ip link set can0 up type can bitrate 1000000 + ```