arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Operate APA102 LED Board via ROS2 on NavQPlus over UCANS32K1 Board

Objective: publish messages from ROS2, subscribe on UCANS32K1 and drive the APA102 LED Board connected to UCANS32K1.

hashtag
Introduction

This tutorial explains how to operate APA102 LED Board via NavQPlus with ROS2 over UCANS32K1 Board. NavQPlus and UCANS32K1 boards will communicate via CAN-FD. UCANS32K1 and APA102 boards will communicate via SPI.

hashtag
Items Needed

  • NavQPlus Board

  • USB-UART serial debugger cable

  • 2 CAN Termination Resistor network

hashtag
Hardware Procedure

hashtag
APA102 LED Board

Refer the 'connections' and 'network' for 3-LED APA102 Board .

Note: we will be using three 3-LED APA102 Boards in this tutorial, each containing three RGB LEDs. The boards will be connected in daisy-chain network.

hashtag
NavQPlus Board

hashtag
UCANS32K1 Board

hashtag
Software Procedure

hashtag
UCANS32K1

hashtag
Software Setup

Enable 'apa102 led' driver and 'apa102 led' example in the menu. Note: You may search for their location in the menu by typing / followed by the name of the option. Ex: "/apa102" + enter.

Change the value of 'NUM_LEDS' macro in 'examples/apa102/apa102_main.c' to 3.

hashtag
Building PX4

Note: if you get error in the following line: snerr("ERROR: Each LED uses 4 bytes, so (buflen % 4)", apply the following patch in the 'platforms/nuttx/NuttX/nuttx' sub-directory.

hashtag
Flashing PX4

Note: You may flash the attached file (configured for a 3-LED APA102 board), to skip the above steps.

hashtag
NavQPlus

hashtag
NavQPlus WIC Image Clone & Setup

Clone and extract 'navqplus-image-22.04-230127.wic.bz2' from .

Flash the WIC image on the SD Card, using HxD.

  • Set the on the NavQPlus Board to 'sdcard mode' (i.e. both switches should be on), then reset the board (by turning it off and on).

  • Credentials:

    • username: user.

hashtag
Receive heartbeat from UCANS32K1

Note: you may see the output using the 'ifconfig' command.

hashtag
ROS2 Setup

Note: if you get 'server certificate verification failed', you may run 'git config --global http.sslverify false' to turn off this check, or add the necessary certificate to the trust store of your operating system. Please note that the former method is only for testing purposes.

Replace the config.json file in ros2_orchestrator with the config.json attached below.

Set the 'max_leds' parameter in config.json equal to the number of LEDs in your APA102 board.

Note: if you get 'clock skew' warning, running 'find . -type f | xargs -n 5 touch' should resolve it. Otherwise reset the system clock.

  • Note: you may be prompted after successful execution to run further commands.

  • ROS2 launcher may block the shell so you may need to open another shell via ssh on the ethernet ip to run your tests.

  • If you get 'could not read from remote repository', replace 'git@' with 'https://' in clone links in config.json. also, replace ':' with '/'. ex: 'git@github.com:rudislabs/opencyphal_led.git' would become 'https://github.com/rudislabs/opencyphal_led.git'.

hashtag
Demonstration

Commands for publishing colors according to the number of leds in our setup: (Ex: we ran the command for 9-leds because we are using three 3-LED APA102 boards cascaded together.)

  • 3-leds: ros2 topic pub /led_image sensor_msgs/msg/Image "{height: 1, width: 3, encoding: "rgb8", step: 9, data: [61,255,0, 255,255,61, 255,61,127]}".

  • 6-leds: ros2 topic pub /led_image sensor_msgs/msg/Image "{height: 1, width: 6, encoding: "rgb8", step: 18, data: [0,0,255, 0,255,0, 255,0,0, 127,127,0, 127,0,127, 0,127,127]}".

  • 9-leds: ros2 topic pub /led_image sensor_msgs/msg/Image "{height: 1, width: 9, encoding: "rgb8", step: 27, data: [0,0,255, 0,255,0, 255,0,0, 127,127,0, 127,0,127, 0,127,127, 61,255,31, 255,31,61, 61,31,255]}".

CAN connector cable
  • Micro SD Card

  • An APA102 based RGB LED board

  • UCANS32K146 or UCANS32K1SIC

  • Jumper wires

  • STEMMA QT / Qwiic JST SH 4-pin Cable

  • Segger J-Link debugger or similar debugger

  • password: user.

    If you get error related to usb0/mlan0 (which happens when these devices are not connected), comment out their tags in the '~/CycloneDDSConfig.xml' file.

    12-leds: ros2 topic pub /led_image sensor_msgs/msg/Image "{height: 1, width: 12, encoding: "rgb8", step: 36, data: [0,0,255, 0,255,0, 255,0,0, 128,128,0, 128,0,128, 0,128,128, 0,0,255, 0,255,0, 255,0,0, 128,128,0, 128,0,128, 0,128,128]}".

    file-download
    465B
    unknown_conversion_type_character.patch
    arrow-up-right-from-squareOpen
    unknown_conversion_type_character patch
    file-download
    392KB
    34.bin
    arrow-up-right-from-squareOpen
    PX4 Firmware
    herearrow-up-right
    boot switches
    file-download
    1KB
    config.json
    arrow-up-right-from-squareOpen
    config.json
    Complete Hardware Setup
    Block Diagram
    NavQPlus Connections
    UCANS32K1 Connections
    Demo: Three 3-LED APA102 Daisy Chained
    git clone -b pr-ucan-pca9685 https://github.com/px4/px4-autopilot.git --recursive PX4-Autopilot-pr-ucan-pca9685.
    cd PX4-Autopilot-pr-ucan-pca9685
    git pull
    make nxp_ucans32k146_pca9685 menuconfig
    make nxp_ucans32k146_pca9685
        // output: build/nxp_ucans32k146_default/deploy/34.bin
    // start jlink.exe.
    connect
    // specify the following:
        // device: s32k146;
        // target interface: s (which stands for swd);
        // interface speed: 1000 khz (recommended);
    loadbin <path to 34.bin> 0x6000
    // quit jlink tools by typing 'q'.
    sudo ip link set can0 down
    sudo ip link set can0 up type can bitrate 1000000 dbitrate 4000000 loopback off fd on fd-non-iso off restart-ms 100
    mkdir -p ~/git/ros2/src
    cd ~/git/ros2/src
    git clone https://github.com/NXPHoverGames/ros2_orchestrator.git -b NavQPlusPX4Demo
    cd ~/git/ros2
    colcon build --symlink-install
    echo "source /home/user/git/ros2/install/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    ros2 launch ros2_orchestrator orchestrate.launch.py
    here