-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dabf4e0
commit 76b9160
Showing
7 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/// This software is distributed under the terms of the MIT License. | ||
/// Copyright (c) 2024 Dmitry Ponomarev. | ||
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#include "circuit_status.hpp" | ||
#include <algorithm> | ||
#include "cyphal.hpp" | ||
#include "params.hpp" | ||
#include "periphery/adc/adc.hpp" | ||
|
||
#include "uavcan/si/sample/electric_current/Scalar_1_0.h" | ||
#include "uavcan/si/sample/voltage/Scalar_1_0.h" | ||
#include "uavcan/si/sample/temperature/Scalar_1_0.h" | ||
|
||
#define ADC_RAW_TO_5V (3.3f * 2.0f / 4095.0f) | ||
#define ADC_RAW_TO_VIN (3.3f * 19.0f / 4095.0f) | ||
|
||
#ifdef STM32G0B1xx | ||
static const uint16_t TEMP_REF = 30; | ||
static const uint16_t ADC_REF = 943; ///< v_ref / 3.3 * 4095 | ||
static const uint16_t AVG_SLOPE = 3.1; ///< avg_slope/(3.3/4096) | ||
#else // STM32F103xB | ||
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) | ||
#endif | ||
|
||
int8_t CircuitStatus::init() { | ||
AdcPeriphery::init(); | ||
return 0; | ||
} | ||
|
||
void CircuitStatus::process(uint32_t crnt_time_ms) { | ||
if (_prev_pub_ts_ms + 500 > crnt_time_ms) { | ||
return; | ||
} | ||
_prev_pub_ts_ms = crnt_time_ms; | ||
|
||
{ | ||
voltage_5v_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_5V_ID)); | ||
if (voltage_5v_publisher.isEnabled()) { | ||
uavcan_si_sample_voltage_Scalar_1_0 msg{ | ||
0, | ||
AdcPeriphery::get(AdcChannel::ADC_5V) * ADC_RAW_TO_5V | ||
}; | ||
voltage_5v_publisher.publish(msg); | ||
} | ||
} | ||
|
||
{ | ||
voltage_vin_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_VIN_ID)); | ||
if (voltage_vin_publisher.isEnabled()) { | ||
uavcan_si_sample_voltage_Scalar_1_0 msg{ | ||
0, | ||
AdcPeriphery::get(AdcChannel::ADC_VIN) * ADC_RAW_TO_VIN | ||
}; | ||
voltage_vin_publisher.publish(msg); | ||
} | ||
} | ||
|
||
{ | ||
temperature_publisher.setPortId(paramsGetIntegerValue(PARAM_PUB_CRCT_TEMPERATURE_ID)); | ||
if (temperature_publisher.isEnabled()) { | ||
uint16_t raw_temperature = AdcPeriphery::get(AdcChannel::ADC_TEMPERATURE); | ||
float temperature = (ADC_REF - raw_temperature) / AVG_SLOPE + TEMP_REF + 273; | ||
uavcan_si_sample_temperature_Scalar_1_0 msg{ | ||
0, | ||
temperature | ||
}; | ||
temperature_publisher.publish(msg); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// This software is distributed under the terms of the MIT License. | ||
/// Copyright (c) 2024 Dmitry Ponomarev. | ||
/// Author: Dmitry Ponomarev <[email protected]> | ||
|
||
#ifndef SRC_CYPHAL_APPLICATION_CIRCUIT_STATUS_CIRCUIT_STATUS_HPP_ | ||
#define SRC_CYPHAL_APPLICATION_CIRCUIT_STATUS_CIRCUIT_STATUS_HPP_ | ||
|
||
#include "cyphal_publishers.hpp" | ||
#include "Udral/circuit_status.hpp" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
class CircuitStatus { | ||
public: | ||
explicit CircuitStatus(cyphal::Cyphal* driver) : voltage_5v_publisher(driver, 65535), | ||
voltage_vin_publisher(driver, 65535), | ||
temperature_publisher(driver, 65535) {}; | ||
int8_t init(); | ||
void process(uint32_t crnt_time_ms); | ||
private: | ||
RaccoonLab::CircuitStatusVoltagePublisher voltage_5v_publisher; | ||
RaccoonLab::CircuitStatusVoltagePublisher voltage_vin_publisher; | ||
RaccoonLab::CircuitStatusTemperaturePublisher temperature_publisher; | ||
uint32_t _prev_pub_ts_ms = 0; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // SRC_CYPHAL_APPLICATION_CIRCUIT_STATUS_CIRCUIT_STATUS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This is a short form that generates Integer & String registers related to the subscriber with PORT_NAME=feedback: | ||
# - Integer register with name `uavcan.pub.feedback.id` | ||
# - String register with name `uavcan.pub.feedback.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.pub.crct.5v: | ||
type: Port | ||
note: Voltage 5V | ||
data_type: uavcan.si.sample.voltage.Scalar.1.0 | ||
enum_base: PARAM_PUB_CRCT_5V | ||
|
||
uavcan.pub.crct.vin: | ||
type: Port | ||
note: Voltage Vin | ||
data_type: uavcan.si.sample.voltage.Scalar.1.0 | ||
enum_base: PARAM_PUB_CRCT_VIN | ||
|
||
uavcan.pub.crct.temperature: | ||
type: Port | ||
note: STM32 internal temperature | ||
data_type: uavcan.si.sample.temperature.Scalar.1.0 | ||
enum_base: PARAM_PUB_CRCT_TEMPERATURE |