mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 07:31:36 +08:00
UAVCAN ESC perf counters
This commit is contained in:
@@ -48,6 +48,12 @@ UavcanEscController::UavcanEscController(uavcan::INode &node) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UavcanEscController::~UavcanEscController()
|
||||||
|
{
|
||||||
|
perf_free(_perfcnt_invalid_input);
|
||||||
|
perf_free(_perfcnt_scaling_error);
|
||||||
|
}
|
||||||
|
|
||||||
int UavcanEscController::init()
|
int UavcanEscController::init()
|
||||||
{
|
{
|
||||||
// ESC status subscription
|
// ESC status subscription
|
||||||
@@ -67,8 +73,10 @@ int UavcanEscController::init()
|
|||||||
|
|
||||||
void UavcanEscController::update_outputs(float *outputs, unsigned num_outputs)
|
void UavcanEscController::update_outputs(float *outputs, unsigned num_outputs)
|
||||||
{
|
{
|
||||||
assert(outputs != nullptr);
|
if ((outputs == nullptr) || (num_outputs > MAX_ESCS)) {
|
||||||
assert(num_outputs <= MAX_ESCS);
|
perf_count(_perfcnt_invalid_input);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rate limiting - we don't want to congest the bus
|
* Rate limiting - we don't want to congest the bus
|
||||||
@@ -89,13 +97,21 @@ void UavcanEscController::update_outputs(float *outputs, unsigned num_outputs)
|
|||||||
for (unsigned i = 0; i < num_outputs; i++) {
|
for (unsigned i = 0; i < num_outputs; i++) {
|
||||||
|
|
||||||
float scaled = (outputs[i] + 1.0F) * 0.5F * uavcan::equipment::esc::RawCommand::CMD_MAX;
|
float scaled = (outputs[i] + 1.0F) * 0.5F * uavcan::equipment::esc::RawCommand::CMD_MAX;
|
||||||
if (scaled < 1.0F)
|
if (scaled < 1.0F) {
|
||||||
scaled = 1.0F; // Since we're armed, we don't want to stop it completely
|
scaled = 1.0F; // Since we're armed, we don't want to stop it completely
|
||||||
|
}
|
||||||
|
|
||||||
assert(scaled >= uavcan::equipment::esc::RawCommand::CMD_MIN);
|
if (scaled < uavcan::equipment::esc::RawCommand::CMD_MIN) {
|
||||||
assert(scaled <= uavcan::equipment::esc::RawCommand::CMD_MAX);
|
scaled = uavcan::equipment::esc::RawCommand::CMD_MIN;
|
||||||
|
perf_count(_perfcnt_scaling_error);
|
||||||
|
} else if (scaled > uavcan::equipment::esc::RawCommand::CMD_MAX) {
|
||||||
|
scaled = uavcan::equipment::esc::RawCommand::CMD_MAX;
|
||||||
|
perf_count(_perfcnt_scaling_error);
|
||||||
|
} else {
|
||||||
|
; // Correct value
|
||||||
|
}
|
||||||
|
|
||||||
msg.cmd.push_back(scaled);
|
msg.cmd.push_back(static_cast<unsigned>(scaled));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,13 @@
|
|||||||
#include <uavcan/uavcan.hpp>
|
#include <uavcan/uavcan.hpp>
|
||||||
#include <uavcan/equipment/esc/RawCommand.hpp>
|
#include <uavcan/equipment/esc/RawCommand.hpp>
|
||||||
#include <uavcan/equipment/esc/Status.hpp>
|
#include <uavcan/equipment/esc/Status.hpp>
|
||||||
|
#include <systemlib/perf_counter.h>
|
||||||
|
|
||||||
class UavcanEscController
|
class UavcanEscController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UavcanEscController(uavcan::INode& node);
|
UavcanEscController(uavcan::INode& node);
|
||||||
|
~UavcanEscController();
|
||||||
|
|
||||||
int init();
|
int init();
|
||||||
|
|
||||||
@@ -96,4 +98,10 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool _armed = false;
|
bool _armed = false;
|
||||||
uavcan::equipment::esc::Status _states[MAX_ESCS];
|
uavcan::equipment::esc::Status _states[MAX_ESCS];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perf counters
|
||||||
|
*/
|
||||||
|
perf_counter_t _perfcnt_invalid_input = perf_alloc(PC_COUNT, "uavcan_esc_invalid_input");
|
||||||
|
perf_counter_t _perfcnt_scaling_error = perf_alloc(PC_COUNT, "uavcan_esc_scaling_error");
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user