servo/controller/fw/embed/test
2025-04-17 15:53:03 +03:00
..
python_can.py Add Python test scripts for CAN communication 2025-01-18 18:34:05 +03:00
python_enable_motor.py Enhance CAN bus scripts with argparse and error handling 2025-02-04 13:41:05 +03:00
python_send_angle.py Enhance CAN bus scripts with argparse and error handling 2025-02-04 13:41:05 +03:00
python_send_velocity.py New PID coefficients; remove legacy 2025-02-12 21:57:27 +08:00
python_test_id.py fix work with float type of angle 2025-04-17 15:53:03 +03:00
README.md Add README file with instructions for CAN communication scripts 2025-01-18 18:40:23 +03:00
send_velocity_impulses.py Enhance CAN bus scripts with argparse and error handling 2025-02-04 13:41:05 +03:00

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:
    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:

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:

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:

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:

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:
      sudo ip link set can0 up type can bitrate 1000000