rc_datalink working with RC_4CH message

This commit is contained in:
Gautier Hattenberger
2011-04-18 19:08:43 +02:00
parent 629ed9d9ce
commit 5bb3d894c2
8 changed files with 44 additions and 16 deletions
@@ -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
+2 -2
View File
@@ -12,10 +12,10 @@
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode + 1"/> <!-- only AUTO1 and AUTO2 available -->
<field name="throttle" value="Bound(Fit(throttle,0-100,100)+127,0,256)"/>
<field name="throttle" value="Fit(throttle,0-100,100,0,127)"/>
<field name="roll" value="roll"/>
<field name="yaw" value="yaw"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/>
</message>
</messages>
+1 -1
View File
@@ -12,8 +12,8 @@
<field name="mode" value="PprzMode(0-mode)"/>
<field name="throttle" value="127-throttle"/>
<field name="roll" value="roll"/>
<field name="yaw" value="0"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="0"/>
</message>
</messages>
+1 -1
View File
@@ -1959,8 +1959,8 @@
<field name="mode" type="uint8"/>
<field name="throttle" type="uint8"/>
<field name="roll" type="int8"/>
<field name="yaw" type="int8"/>
<field name="pitch" type="int8"/>
<field name="yaw" type="int8"/>
</message>
<message name="KITE_COMMAND" id="96">
+3 -3
View File
@@ -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),
@@ -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;
}
@@ -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); \
+2 -2
View File
@@ -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