Skip to content

Commit

Permalink
add crct.temperaturegs
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Dec 25, 2023
1 parent 37f232d commit bdc98ce
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Src/cyphal_application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set(applicationSourceCode

Src/cyphal_application/lights/lights.cpp
Src/cyphal_application/application.cpp

Libs/Cyphal/Udral/rgbled.cpp
Libs/Cyphal/Udral/circuit_status.cpp
)
set(applicationHeaders
Src
Expand Down
1 change: 1 addition & 0 deletions Src/cyphal_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ The node has the following interface:
|| Type | Message | Topic name |
| -- | ---- | ------- | ----------- |
| 1 | sub | reg.udral.physics.optics.HighColor.0.1 | lights | {'type': 'Port', 'data_type': 'reg.udral.physics.optics.HighColor.0.1', 'enum_base': 'RGBLED'}|
| 2 | pub | uavcan.si.sample.temperature.Scalar.1.0 | crct.temp | {'type': 'Port', 'data_type': 'uavcan.si.sample.temperature.Scalar.1.0', 'enum_base': 'PARAM_CRCT_TEMPERATURE'}|

The node has the following registers:

Expand Down
19 changes: 13 additions & 6 deletions Src/cyphal_application/lights/lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ void RgbLights::update() {
}
next_time_ms = HAL_GetTick() + 10;

// Temperature
static const uint16_t TEMP_REF = 25;
static const uint16_t ADC_REF = 1750; ///< v_ref / 3.3 * 4095
static const uint16_t AVG_SLOPE = 5; ///< avg_slope/(3.3/4096)
_temp_pub.setPortId(paramsGetIntegerValue(PARAM_CRCT_TEMPERATURE_ID));
if (_temp_pub.isEnabled()) {
uint16_t adc_measurement = AdcPeriphery::get(AdcChannel::ADC_TEMPERATURE);
uavcan_si_sample_temperature_Scalar_1_0 msg;
msg.kelvin = (ADC_REF - adc_measurement) / AVG_SLOPE + TEMP_REF + 273;
_temp_pub.publish(msg);
}

// Lights
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;
Expand Down
5 changes: 5 additions & 0 deletions Src/cyphal_application/lights/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ uavcan.sub.lights:
type: Port
data_type: reg.udral.physics.optics.HighColor.0.1
enum_base: RGBLED

uavcan.pub.crct.temp:
type: Port
data_type: uavcan.si.sample.temperature.Scalar.1.0
enum_base: PARAM_CRCT_TEMPERATURE

0 comments on commit bdc98ce

Please sign in to comment.