diff --git a/conf/autopilot/subsystems/fixedwing/radio_control_datalink.makefile b/conf/autopilot/subsystems/fixedwing/radio_control_datalink.makefile
index e33a41c25e..dc36fad956 100644
--- a/conf/autopilot/subsystems/fixedwing/radio_control_datalink.makefile
+++ b/conf/autopilot/subsystems/fixedwing/radio_control_datalink.makefile
@@ -15,5 +15,5 @@ ifeq ($(NORADIO), False)
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control.c
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control/rc_datalink.c
# arch only with sim target for compatibility (empty functions)
- sim.srcs += $(SRC_ARCH)/radio_control/rc_datalink.c
+ sim.srcs += $(SRC_ARCH)/subsystems/radio_control/rc_datalink.c
endif
diff --git a/conf/joystick/cockpit_sx.xml b/conf/joystick/cockpit_sx.xml
index d94603ceb1..8bfa250d4d 100644
--- a/conf/joystick/cockpit_sx.xml
+++ b/conf/joystick/cockpit_sx.xml
@@ -12,10 +12,10 @@
-
+
-
+
diff --git a/conf/joystick/ikarus_usb.xml b/conf/joystick/ikarus_usb.xml
index 6134a9da82..1f5bb2a379 100644
--- a/conf/joystick/ikarus_usb.xml
+++ b/conf/joystick/ikarus_usb.xml
@@ -12,8 +12,8 @@
-
+
diff --git a/conf/messages.xml b/conf/messages.xml
index 45a085f936..4c58df1c40 100644
--- a/conf/messages.xml
+++ b/conf/messages.xml
@@ -1959,8 +1959,8 @@
-
+
diff --git a/sw/airborne/firmwares/fixedwing/datalink.c b/sw/airborne/firmwares/fixedwing/datalink.c
index 1178a0ef0b..d94abb5d1d 100644
--- a/sw/airborne/firmwares/fixedwing/datalink.c
+++ b/sw/airborne/firmwares/fixedwing/datalink.c
@@ -185,15 +185,15 @@ void dl_parse_msg(void) {
#if defined RADIO_CONTROL && defined RADIO_CONTROL_TYPE_DATALINK
if (msg_id == DL_RC_3CH /*&& DL_RC_3CH_ac_id(dl_buffer) == TX_ID*/) {
LED_TOGGLE(3);
- parse_rc_datalink(
+ parse_rc_3ch_datalink(
DL_RC_3CH_throttle_mode(dl_buffer),
DL_RC_3CH_roll(dl_buffer),
DL_RC_3CH_pitch(dl_buffer));
} else
- if (msg_id == DL_RC_4CH /*&& DL_RC_3CH_ac_id(dl_buffer) == TX_ID*/) {
+ if (msg_id == DL_RC_4CH && DL_RC_4CH_ac_id(dl_buffer) == AC_ID) {
LED_TOGGLE(3);
parse_rc_4ch_datalink(
- DL_RC_4CH_joystick_id(dl_buffer),
+ DL_RC_4CH_mode(dl_buffer),
DL_RC_4CH_throttle(dl_buffer),
DL_RC_4CH_roll(dl_buffer),
DL_RC_4CH_pitch(dl_buffer),
diff --git a/sw/airborne/subsystems/radio_control/rc_datalink.c b/sw/airborne/subsystems/radio_control/rc_datalink.c
index 662a6b5ccd..1d7a39ccb5 100644
--- a/sw/airborne/subsystems/radio_control/rc_datalink.c
+++ b/sw/airborne/subsystems/radio_control/rc_datalink.c
@@ -21,7 +21,7 @@
* Boston, MA 02111-1307, USA.
*/
-#include "radio_control/rc_datalink.h"
+#include "subsystems/radio_control/rc_datalink.h"
#include "subsystems/radio_control.h"
int8_t rc_dl_values[ RC_DL_NB_CHANNEL ];
@@ -33,11 +33,11 @@ void radio_control_impl_init(void) {
}
-void parse_rc_datalink( uint8_t throttle_mode,
+void parse_rc_3ch_datalink( uint8_t throttle_mode,
int8_t roll,
int8_t pitch)
{
- uint8_t throttle = throttle_mode & 0xFC;
+ uint8_t throttle = ((throttle_mode & 0xFC)>>2)*(128/64);
uint8_t mode = throttle_mode & 0x03;
rc_dl_values[RADIO_ROLL] = roll;
@@ -47,3 +47,20 @@ void parse_rc_datalink( uint8_t throttle_mode,
rc_dl_frame_available = TRUE;
}
+
+void parse_rc_4ch_datalink(
+ uint8_t mode,
+ uint8_t throttle,
+ int8_t roll,
+ int8_t pitch,
+ int8_t yaw)
+{
+ rc_dl_values[RADIO_MODE] = (int8_t)mode;
+ rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
+ rc_dl_values[RADIO_ROLL] = roll;
+ rc_dl_values[RADIO_PITCH] = pitch;
+ rc_dl_values[RADIO_YAW] = yaw;
+
+ rc_dl_frame_available = TRUE;
+}
+
diff --git a/sw/airborne/subsystems/radio_control/rc_datalink.h b/sw/airborne/subsystems/radio_control/rc_datalink.h
index d10170febb..ca72750480 100644
--- a/sw/airborne/subsystems/radio_control/rc_datalink.h
+++ b/sw/airborne/subsystems/radio_control/rc_datalink.h
@@ -43,13 +43,24 @@ extern int8_t rc_dl_values[ RC_DL_NB_CHANNEL ];
extern volatile bool_t rc_dl_frame_available;
/**
- * Decode datalink message to get rc values
+ * Decode datalink message to get rc values with RC_3CH message
+ * Mode and throttle are merge in the same byte
*/
-extern void parse_rc_datalink(
+extern void parse_rc_3ch_datalink(
uint8_t throttle_mode,
int8_t roll,
int8_t pitch);
+/**
+ * Decode datalink message to get rc values with RC_4CH message
+ */
+extern void parse_rc_4ch_datalink(
+ uint8_t mode,
+ uint8_t throttle,
+ int8_t roll,
+ int8_t pitch,
+ int8_t yaw);
+
/**
* Macro that normalize rc_dl_values to radio values
*/
@@ -60,7 +71,7 @@ extern void parse_rc_datalink(
Bound(_out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ); \
_out[RADIO_YAW] = 0; \
Bound(_out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ); \
- _out[RADIO_THROTTLE] = ((MAX_PPRZ/64) * _in[RADIO_THROTTLE]); \
+ _out[RADIO_THROTTLE] = ((MAX_PPRZ/128) * _in[RADIO_THROTTLE]); \
Bound(_out[RADIO_THROTTLE], 0, MAX_PPRZ); \
_out[RADIO_MODE] = MAX_PPRZ * (_in[RADIO_MODE] - 1); \
Bound(_out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ); \
diff --git a/sw/ground_segment/joystick/input2ivy.ml b/sw/ground_segment/joystick/input2ivy.ml
index 61b0af2f1c..594275b14c 100644
--- a/sw/ground_segment/joystick/input2ivy.ml
+++ b/sw/ground_segment/joystick/input2ivy.ml
@@ -350,7 +350,7 @@ let scale = fun x min max ->
min + ((x - min_input) * (max - min)) / (max_input - min_input)
(** Fit a given interval of value into [min_input; max_input] *)
-let fit = fun x min max ->
+let fit = fun x min max min_input max_input ->
min_input + ((x - min) * (max_input - min_input)) / (max - min)
(** Scale a value in the given bounds *)
@@ -380,7 +380,7 @@ let eval_call = fun f args ->
| "<", [a1; a2] -> if a1 < a2 then 1 else 0
| ">", [a1; a2] -> if a1 > a2 then 1 else 0
| "Scale", [x; min; max] -> scale (x) (min) (max)
- | "Fit", [x; min; max] -> fit (x) (min) (max)
+ | "Fit", [x; min; max; min_input; max_input] -> fit (x) (min) (max) (min_input) (max_input)
| "Bound", [x; min; max] -> bound (x) (min) (max)
| "PprzMode", [x] -> pprz_mode (x)
| "JoystickID", [] -> !joystick_id