Skip to content

Commit

Permalink
add uav lights node
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Dec 25, 2023
1 parent 5d9ea66 commit a078965
Show file tree
Hide file tree
Showing 26 changed files with 362 additions and 387 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/build_dronecan.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
url = [email protected]:PonomarevDA/tools.git
[submodule "Libs/stm32-cube-project"]
path = Libs/stm32-cube-project
url = https://github.com/RaccoonLabHardware/mini-v2-software.git
url = https://github.com/RaccoonLabHardware/lights-v0-software.git
2 changes: 1 addition & 1 deletion Libs/stm32-cube-project
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Mini v2 node custom application
# UAV Lights node custom application

This repository introduces a simple Cyphal application written for the [RL Mini v2](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_mini_v2.html) and [RL Micro](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_micro.html) nodes. Based on this project you can write your custom application if the original CAN-PWM convertor application doesn't suit your requirements.
This repository introduces a simple Cyphal application written for the [UAV Lights](https://docs.raccoonlab.co/guide/ui_leds/) node. Based on this project you can write your custom application if the original application doesn't suit your requirements.

| View | Top view | Bot view |
| ---- | --- | ------ |
| <img src="https://docs.raccoonlab.co/assets/img/view.bbf1e631.png" alt="drawing" width="150"> | <img src="https://docs.raccoonlab.co/assets/img/view_top.6b0ef99e.png" alt="drawing" width="150"> | <img src="https://docs.raccoonlab.co/assets/img/view_bottom.ee41f6d5.png" alt="drawing" width="150">|
| <img src="https://docs.raccoonlab.co/assets/img/t-view.42a0bfba.png" alt="drawing" width="225"> | <img src="https://docs.raccoonlab.co/assets/img/t-view-top.39aeaa81.png" alt="drawing" width="225"> | <img src="https://docs.raccoonlab.co/assets/img/t-view-bottom.e9a28e7d.png" alt="drawing" width="225">|

The default capabilities of the node are shown on the picture below:

Expand All @@ -14,17 +14,17 @@ The default capabilities of the node are shown on the picture below:

The node has 6 user pins. By default 4 of them are configured as PWM and 2 of them as UART RX, but you can change the configuration to support I2C, ADC, GPIO or something else.

Please, refer to the [Mini v2 hardware](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_mini_v2.html#pinout) page for the details.
Please, refer to the [UAV Lights hardware](https://docs.raccoonlab.co/guide/ui_leds/hardware.html) page for the details.

Below you can see a brief description of hardware capabilities:

<img src="https://docs.raccoonlab.co/assets/img/pinout.c14a3021.png" alt="drawing">
<img src="https://docs.raccoonlab.co/assets/img/pinout.3edfaf8e.png" alt="drawing">

## 2. STM32CubeMX

The pinout configuration is based on the [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) generated project: [Libs/mini_v2](https://github.com/RaccoonLabHardware/mini_v2_ioc) with the following configuration:
The pinout configuration is based on the [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) generated project: [Libs/stm32-cube-project](https://github.com/RaccoonLabHardware/lights-v0-software) with the following configuration:

<img src="https://raw.githubusercontent.com/RaccoonLabHardware/mini_v2_stm32cubemx_project/main/Assets/stm32cubemx.png" alt="drawing">
<img src="https://github.com/RaccoonLabHardware/lights-v0-software/raw/main/Assets/stm32cubemx.png" alt="drawing">

If you need to use custom pinout configuration, it is recommended to use either [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) or [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html) to modify .ioc file and regenerate your custom project.

Expand All @@ -36,7 +36,7 @@ You are expected to use the following software:
- [gui_tool](https://dronecan.github.io/GUI_Tool/Overview/) for DroneCAN.

Hardware requirements:
- Mini v2 or Micro node
- UAV Lights node
- STM32 programmer and CAN-sniffer (for example [RL sniffer and programmer](https://docs.raccoonlab.co/guide/programmer_sniffer/))

## 4. Usage
Expand All @@ -46,16 +46,16 @@ The project is based on the CMake build system, but it is suggested to interract
**Step 1. Clone the repository with submodules**

```bash
git clone https://github.com/RaccoonlabDev/mini_v2_node --recursive
cd mini_v2_node
git clone https://github.com/RaccoonlabDev/uav_lights_node --recursive
cd uav_lights_node
git submodule update --init --recursive
```

**Step 2. Connect Sniffer and Programmer to Mini v2 node.**
**Step 2. Connect Sniffer and Programmer to UAV Lights node.**

An example of connection scheme suitable for bench test for Mini v2 node and RL Programmer-Sniffer is shown below:
An example of connection scheme suitable for bench test for UAV Lights node and RL Programmer-Sniffer is shown below:

<img src="assets/connection.png" alt="drawing">
<img src="https://docs.raccoonlab.co/assets/img/bench_test_molex.7b3ab4e3.png" alt="drawing">

You can also use other sniffer and programmers. For details refer to: [Programmer usage](https://docs.raccoonlab.co/guide/programmer_sniffer/programmer.html) and [Sniffer usage](https://docs.raccoonlab.co/guide/programmer_sniffer/sniffer.html#_4-1-cyphal-usage) pages.

Expand Down Expand Up @@ -90,7 +90,7 @@ source scripts/init.sh
~/Download/Yukon
```

Please, refer to the [Mini node docs](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_cyphal.html).
Please, refer to the [UAV Lights docs](https://docs.raccoonlab.co/guide/ui_leds/cyphal.html).
It has a detailed steps about how to perform bench testing of the node.

**Q&A**
Expand All @@ -99,7 +99,7 @@ If you are strugguling with the software building, please refer to the build wor

## 5. Customization

The peripherals are initialised in [Libs/stm32-cube-project/Core/Src/main.c](https://github.com/RaccoonLabHardware/mini-v2-software/blob/main/Core/Src/main.c), which are automatically generated based on the configuratation file [can_pwm_v2.ioc](https://github.com/RaccoonLabHardware/mini-v2-software/blob/main/can_pwm_v2.ioc) file. If you want to use a different peripheral configuration, you should update can_pwm_v2.ioc with STM32CubeIDE or STM32CubeMX.
The peripherals are initialised in [Libs/stm32-cube-project/Core/Src/main.c](https://github.com/RaccoonLabHardware/lights-v0-software/blob/main/Core/Src/main.c), which are automatically generated based on the configuratation file [project.ioc](https://github.com/RaccoonLabHardware/lights-v0-software/blob/main/can_pwm_v2.ioc) file. If you want to use a different peripheral configuration, you should update can_pwm_v2.ioc with STM32CubeIDE or STM32CubeMX.

The main application is started in [Src/cyphal_application/application.cpp](Src/cyphal_application/application.cpp).
By default it just blinks the RGB LED, subscribes to the setpoint topic to control PWM1 and publishes a feedback with the latest applied setpoint. Note, that the application is as simple as possible: it controls only a single PWM and doesn't have safety features like TTL, but you are free to extend it as you want.
Expand All @@ -114,7 +114,6 @@ You can also easily create custom Integer and String registers. An example is sh

The project has a few dependencies which are attached to the repository as submodules. They are:

- [Libs/mini_v2](https://github.com/RaccoonLabHardware/mini_v2_ioc) is a project generated with the STM32CubeMX. It is based on .ioc file corresponded to the default firmware of the Mini v2 node. You may only need to change it if you want to use an a different peripheral configuration.
- [Libs/stm32-cube-project](https://github.com/RaccoonLabHardware/lights-v0-software) is a project generated with the STM32CubeMX. It is based on .ioc file corresponded to the default firmware of the UAV Lights node. You may only need to change it if you want to use an a different peripheral configuration.
- [Libs/Cyphal](https://github.com/RaccoonlabDev/libcanard_cyphal_application) is a general-purpose application based on the [Cyphal libcanard](https://github.com/OpenCyphal/libcanard), [o1heap](https://github.com/pavel-kirienko/o1heap) and other libraries with minimal required features to start and some features related to UDRAL/DS015.
- [Src/libparams](https://github.com/PonomarevDA/libparams) is a simple library with ROM driver implementation that allows to store configuration parameters in persistent memory.
- [not yet] Src/libsqcan is a general-purpose application based on [DroneCAN libcanard](https://github.com/dronecan/libcanard) with minimal required features to start. The DroneCAN part is not publically released yet.
10 changes: 5 additions & 5 deletions Src/cyphal_application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
set(applicationSourceCode
Src/periphery/pwm/pwm.cpp
Src/periphery/adc/adc.cpp
Src/periphery/led/led.cpp
Src/periphery/ws2812/ws2812.c

Src/cyphal_application/setpoint/setpoint.cpp
Src/cyphal_application/feedback/feedback.cpp
Src/cyphal_application/lights/lights.cpp
Src/cyphal_application/application.cpp
Libs/Cyphal/Udral/rgbled.cpp
)
set(applicationHeaders
Src
Expand All @@ -14,6 +15,5 @@ set(applicationHeaders

list(APPEND cyphalRegisters
${CMAKE_CURRENT_LIST_DIR}/params.yaml
${CMAKE_CURRENT_LIST_DIR}/setpoint/params.yaml
${CMAKE_CURRENT_LIST_DIR}/feedback/params.yaml
${CMAKE_CURRENT_LIST_DIR}/lights/params.yaml
)
3 changes: 1 addition & 2 deletions Src/cyphal_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ The node has the following interface:

|| Type | Message | Topic name |
| -- | ---- | ------- | ----------- |
| 1 | sub | reg.udral.service.actuator.common.sp.Vector31 | setpoint | {'type': 'Port', 'data_type': 'reg.udral.service.actuator.common.sp.Vector31', 'enum_base': 'PARAM_SUB_SETPOINT'}|
| 2 | pub | reg.udral.service.actuator.common.Feedback.0.1 | feedback | {'type': 'Port', 'data_type': 'reg.udral.service.actuator.common.Feedback.0.1', 'enum_base': 'PARAM_PUB_FEEDBACK_1'}|
| 1 | sub | reg.udral.physics.optics.HighColor.0.1 | lights | {'type': 'Port', 'data_type': 'reg.udral.physics.optics.HighColor.0.1', 'enum_base': 'RGBLED'}|

The node has the following registers:

Expand Down
20 changes: 7 additions & 13 deletions Src/cyphal_application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#include "main.h"
#include "string_params.hpp"
#include "params.hpp"
#include "setpoint/setpoint.hpp"
#include "feedback/feedback.hpp"
#include "lights/lights.hpp"
#include "periphery/led/led.hpp"


void init_persistent_storage() {
paramsInit(static_cast<uint8_t>(IntParamsIndexes::INTEGER_PARAMS_AMOUNT), NUM_OF_STR_PARAMS);
paramsLoadFromFlash();

auto node_name_param_idx = static_cast<ParamIndex_t>(IntParamsIndexes::INTEGER_PARAMS_AMOUNT);
paramsSetStringValue(node_name_param_idx, 19, (const uint8_t*)"co.raccoonlab.mini");
paramsSetStringValue(node_name_param_idx, 21, (const uint8_t*)"co.raccoonlab.lights");
}

void application_entry_point() {
Expand All @@ -28,19 +28,13 @@ void application_entry_point() {
cyphal::Cyphal cyphal;
int init_res = cyphal.init();

SetpointSubscriber setpoint(&cyphal);
init_res |= setpoint.init();

FeedbackPublisher feedback(&cyphal);
init_res |= feedback.init();
RgbLights lights(&cyphal);
init_res |= lights.init();

while (true) {
auto led_color = (init_res >= 0) ? LedColor::BLUE_COLOR : LedColor::RED_COLOR;
LedPeriphery::toggle(led_color);
LedPeriphery::toggle();

cyphal.process();

auto crnt_time_ms = HAL_GetTick();
feedback.process(crnt_time_ms);
lights.update();
}
}
43 changes: 0 additions & 43 deletions Src/cyphal_application/feedback/feedback.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions Src/cyphal_application/feedback/feedback.hpp

This file was deleted.

9 changes: 0 additions & 9 deletions Src/cyphal_application/feedback/params.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions Src/cyphal_application/lights/lights.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// This software is distributed under the terms of the MIT License.
/// Copyright (c) 2023 Dmitry Ponomarev.
/// Author: Dmitry Ponomarev <[email protected]>

#include "lights.hpp"
#include <algorithm>
#include "cyphal.hpp"
#include "params.hpp"
#include "main.h"
#include "periphery/ws2812/ws2812.h"
#include "periphery/adc/adc.hpp"

extern TIM_HandleTypeDef htim2;

static constexpr uint8_t RED_SCALE = 256 / (reg_udral_physics_optics_HighColor_0_1_MAX_RED + 1);
static constexpr uint8_t GREEN_SCALE = 256 / (reg_udral_physics_optics_HighColor_0_1_MAX_GREEN + 1);
static constexpr uint8_t BLUE_SCALE = 256 / (reg_udral_physics_optics_HighColor_0_1_MAX_BLUE + 1);


int8_t RgbLights::init() {
int8_t res;

res = ws2812bInit(32, &htim2, TIM_CHANNEL_3);
if (res < 0) {
return res;
}

res = _rgbled_sub.init();
if (res < 0) {
return res;
}

res = AdcPeriphery::init();
if (res < 0) {
return res;
}

return 0;
};

void RgbLights::update() {
static uint32_t next_time_ms = 0;
if (HAL_GetTick() < next_time_ms) {
return;
}
next_time_ms = HAL_GetTick() + 10;

auto color = _rgbled_sub.get();
static Leds_Color_t leds;

// static uint8_t counter = 0;
// leds.colors[counter].shades.red = color.red * RED_SCALE;
// leds.colors[counter].shades.green = color.green * GREEN_SCALE;
// leds.colors[counter].shades.blue = color.blue * BLUE_SCALE;
// counter = (counter + 1) % 32;

for (uint_fast8_t led_idx = 0; led_idx < 32; led_idx++) {
leds.colors[led_idx].shades.red = color.red * RED_SCALE;
leds.colors[led_idx].shades.green = color.green * GREEN_SCALE;
leds.colors[led_idx].shades.blue = color.blue * BLUE_SCALE;
}
ws2812bSetColors(&leds);
ws2812bStartOnce();
}
23 changes: 23 additions & 0 deletions Src/cyphal_application/lights/lights.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// This software is distributed under the terms of the MIT License.
/// Copyright (c) 2023 Dmitry Ponomarev.
/// Author: Dmitry Ponomarev <[email protected]>

#ifndef SRC_CYPHAL_APPLICATION_LIGHTS_LIGHTS_HPP_
#define SRC_CYPHAL_APPLICATION_LIGHTS_LIGHTS_HPP_

#include "cyphal_subscribers.hpp"
#include "Udral/rgbled.hpp"
#include "Udral/circuit_status.hpp"

class RgbLights {
public:
RgbLights(cyphal::Cyphal* driver) : _rgbled_sub(driver), _temp_pub(driver, 0) {};
int8_t init();
void update();
private:

cyphal::HighColorSubscriber _rgbled_sub;
RaccoonLab::CircuitStatusTemperaturePublisher _temp_pub;
};

#endif // SRC_CYPHAL_APPLICATION_LIGHTS_LIGHTS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - String register with name `uavcan.pub.setpoint.type`
# The generated registers have proper flags, data type and min, max and default values.
# They correspond the standard: https://github.com/OpenCyphal/public_regulated_data_types/blob/master/uavcan/register/384.Access.1.0.dsdl
uavcan.sub.setpoint:
uavcan.sub.lights:
type: Port
data_type: reg.udral.service.actuator.common.sp.Vector31
enum_base: PARAM_SUB_SETPOINT
data_type: reg.udral.physics.optics.HighColor.0.1
enum_base: RGBLED
Loading

0 comments on commit a078965

Please sign in to comment.