aboutsummaryrefslogtreecommitdiff
path: root/src/modules/uavcan/actuators/esc.cpp
diff options
context:
space:
mode:
authorPavel Kirienko <pavel.kirienko@gmail.com>2014-10-12 15:34:28 +0400
committerPavel Kirienko <pavel.kirienko@gmail.com>2014-10-12 15:34:28 +0400
commitced75deebe527581930419155fb0d73f18b7a5fe (patch)
tree9462a5df1dbd5f7328e9190ecdf8d363daa33880 /src/modules/uavcan/actuators/esc.cpp
parent835bab9115b49d90326a992917e8bd3e088e3fcd (diff)
downloadpx4-firmware-ced75deebe527581930419155fb0d73f18b7a5fe.tar.gz
px4-firmware-ced75deebe527581930419155fb0d73f18b7a5fe.tar.bz2
px4-firmware-ced75deebe527581930419155fb0d73f18b7a5fe.zip
ESC scaling fix
Diffstat (limited to 'src/modules/uavcan/actuators/esc.cpp')
-rw-r--r--src/modules/uavcan/actuators/esc.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/modules/uavcan/actuators/esc.cpp b/src/modules/uavcan/actuators/esc.cpp
index 223d94731..b516536c7 100644
--- a/src/modules/uavcan/actuators/esc.cpp
+++ b/src/modules/uavcan/actuators/esc.cpp
@@ -93,25 +93,22 @@ void UavcanEscController::update_outputs(float *outputs, unsigned num_outputs)
*/
uavcan::equipment::esc::RawCommand msg;
+ static const int cmd_max = uavcan::equipment::esc::RawCommand::FieldTypes::cmd::RawValueType::max();
+
if (_armed) {
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 * cmd_max;
if (scaled < 1.0F) {
scaled = 1.0F; // Since we're armed, we don't want to stop it completely
}
- if (scaled < uavcan::equipment::esc::RawCommand::CMD_MIN) {
- 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;
+ if (scaled > cmd_max) {
+ scaled = cmd_max;
perf_count(_perfcnt_scaling_error);
- } else {
- ; // Correct value
}
- msg.cmd.push_back(static_cast<unsigned>(scaled));
+ msg.cmd.push_back(static_cast<int>(scaled));
}
}