aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-03-26 09:56:15 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-03-26 09:56:15 +0100
commitbd290c65f843a81b180fc15c881b7481f52b570a (patch)
treecd47f23224053a8d1d858bff7a653ea645919720
parentf35ea50c927c283e2929b8415a981880ee4fafa6 (diff)
parent506c16f12a8420991a0e64c616bbf5833ce1845c (diff)
downloadpx4-firmware-bd290c65f843a81b180fc15c881b7481f52b570a.tar.gz
px4-firmware-bd290c65f843a81b180fc15c881b7481f52b570a.tar.bz2
px4-firmware-bd290c65f843a81b180fc15c881b7481f52b570a.zip
Merge pull request #770 from PX4/hil_range_fix
Fixed the HIL actuator range to what it should be
-rw-r--r--ROMFS/px4fmu_common/init.d/rc.usb3
-rw-r--r--src/modules/mavlink/mavlink_messages.cpp93
2 files changed, 65 insertions, 31 deletions
diff --git a/ROMFS/px4fmu_common/init.d/rc.usb b/ROMFS/px4fmu_common/init.d/rc.usb
index 2aeea5cbe..9f80219b1 100644
--- a/ROMFS/px4fmu_common/init.d/rc.usb
+++ b/ROMFS/px4fmu_common/init.d/rc.usb
@@ -10,6 +10,7 @@ mavlink start -r 10000 -d /dev/ttyACM0
mavlink stream -d /dev/ttyACM0 -s NAMED_VALUE_FLOAT -r 10
mavlink stream -d /dev/ttyACM0 -s OPTICAL_FLOW -r 10
mavlink stream -d /dev/ttyACM0 -s ATTITUDE_CONTROLS -r 30
+mavlink stream -d /dev/ttyACM0 -s SERVO_OUTPUT_RAW_0 -r 10
# Exit shell to make it available to MAVLink
-exit
+exit
diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp
index 037999af7..4ca3840d4 100644
--- a/src/modules/mavlink/mavlink_messages.cpp
+++ b/src/modules/mavlink/mavlink_messages.cpp
@@ -71,6 +71,7 @@
#include <uORB/topics/battery_status.h>
#include <uORB/topics/navigation_capabilities.h>
#include <drivers/drv_rc_input.h>
+#include <drivers/drv_pwm_output.h>
#include "mavlink_messages.h"
@@ -788,47 +789,79 @@ protected:
uint32_t mavlink_custom_mode;
get_mavlink_mode_state(status, pos_sp_triplet, &mavlink_state, &mavlink_base_mode, &mavlink_custom_mode);
- /* set number of valid outputs depending on vehicle type */
- unsigned n;
+ if (mavlink_system.type == MAV_TYPE_QUADROTOR ||
+ mavlink_system.type == MAV_TYPE_HEXAROTOR ||
+ mavlink_system.type == MAV_TYPE_OCTOROTOR) {
+ /* set number of valid outputs depending on vehicle type */
+ unsigned n;
- switch (mavlink_system.type) {
- case MAV_TYPE_QUADROTOR:
- n = 4;
- break;
+ switch (mavlink_system.type) {
+ case MAV_TYPE_QUADROTOR:
+ n = 4;
+ break;
- case MAV_TYPE_HEXAROTOR:
- n = 6;
- break;
+ case MAV_TYPE_HEXAROTOR:
+ n = 6;
+ break;
- default:
- n = 8;
- break;
- }
+ default:
+ n = 8;
+ break;
+ }
- /* scale / assign outputs depending on system type */
- float out[8];
+ /* scale / assign outputs depending on system type */
+ float out[8];
- for (unsigned i = 0; i < 8; i++) {
- if (i < n) {
- if (mavlink_base_mode & MAV_MODE_FLAG_SAFETY_ARMED) {
- /* scale fake PWM out 900..1200 us to 0..1*/
- out[i] = (act->output[i] - 900.0f) / 1200.0f;
+ for (unsigned i = 0; i < 8; i++) {
+ if (i < n) {
+ if (mavlink_base_mode & MAV_MODE_FLAG_SAFETY_ARMED) {
+ /* scale fake PWM out 900..2100 us to 0..1 for normal multirotors */
+ out[i] = (act->output[i] - PWM_LOWEST_MIN) / (PWM_HIGHEST_MAX - PWM_LOWEST_MIN);
+
+ } else {
+ /* send 0 when disarmed */
+ out[i] = 0.0f;
+ }
} else {
- /* send 0 when disarmed */
- out[i] = 0.0f;
+ out[i] = -1.0f;
+ }
+ }
+
+ mavlink_msg_hil_controls_send(_channel,
+ hrt_absolute_time(),
+ out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
+ mavlink_base_mode,
+ 0);
+ } else {
+
+ /* fixed wing: scale all channels except throttle -1 .. 1
+ * because we know that we set the mixers up this way
+ */
+
+ float out[8];
+
+ const float pwm_center = (PWM_HIGHEST_MAX + PWM_LOWEST_MIN) / 2;
+
+ for (unsigned i = 0; i < 8; i++) {
+ if (i != 3) {
+ /* scale fake PWM out 900..2100 us to -1..+1 for normal channels */
+ out[i] = (act->output[i] - pwm_center) / ((PWM_HIGHEST_MAX - PWM_LOWEST_MIN) / 2);
+
+ } else {
+
+ /* scale fake PWM out 900..2100 us to 0..1 for throttle */
+ out[i] = (act->output[i] - PWM_LOWEST_MIN) / (PWM_HIGHEST_MAX - PWM_LOWEST_MIN);
}
- } else {
- out[i] = -1.0f;
}
- }
- mavlink_msg_hil_controls_send(_channel,
- hrt_absolute_time(),
- out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
- mavlink_base_mode,
- 0);
+ mavlink_msg_hil_controls_send(_channel,
+ hrt_absolute_time(),
+ out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
+ mavlink_base_mode,
+ 0);
+ }
}
}
};