diff --git a/conf/abi.xml b/conf/abi.xml index a907ecf687..c7c2e578af 100644 --- a/conf/abi.xml +++ b/conf/abi.xml @@ -191,6 +191,13 @@ Extra field for options like detector source etc + + + + + + + diff --git a/conf/flight_plans/joystick.xml b/conf/flight_plans/joystick.xml index d09754fab7..454c2ad372 100644 --- a/conf/flight_plans/joystick.xml +++ b/conf/flight_plans/joystick.xml @@ -3,7 +3,18 @@
#include "subsystems/datalink/datalink.h" -#include "firmwares/fixedwing/joystick.h" + +#ifdef NAV_C +#include "firmwares/fixedwing/stabilization/stabilization_attitude.h" +#include "autopilot.h" +void joystick_handler(void) { + if (And(autopilot_get_mode() == AP_MODE_AUTO2, nav_block == joystick_block)) { + h_ctl_roll_setpoint = AUTO1_MAX_ROLL * joystick.roll / MAX_PPRZ; + h_ctl_pitch_setpoint = AUTO1_MAX_PITCH * joystick.pitch / MAX_PPRZ; + v_ctl_throttle_setpoint = joystick.throttle; + } +} +#endif
@@ -18,6 +29,12 @@ + + + + + + @@ -77,7 +94,7 @@ - + diff --git a/conf/flight_plans/rotorcraft_joystick_enac.xml b/conf/flight_plans/rotorcraft_joystick_enac.xml new file mode 100644 index 0000000000..e4b23e403c --- /dev/null +++ b/conf/flight_plans/rotorcraft_joystick_enac.xml @@ -0,0 +1,116 @@ + + + +
+#ifdef NAV_C +#include "firmwares/rotorcraft/stabilization/stabilization_attitude.h" +#include "autopilot.h" +static inline void joystick_handler(uint8_t sender_id __attribute__((unused)), int16_t roll, int16_t pitch, int16_t yaw, int16_t throttle) { + if (And(autopilot_get_mode() == AP_MODE_NAV, nav_block == joystick_block)) { + nav_roll = ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_PHI * roll / MAX_PPRZ); + nav_pitch = ANGLE_BFP_OF_REAL(STABILIZATION_ATTITUDE_SP_MAX_THETA * pitch / MAX_PPRZ); + nav_heading = ANGLE_BFP_OF_REAL(3.1416f * yaw / MAX_PPRZ); + nav_throttle = throttle; + } +} +#endif +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/conf/modules/joystick.xml b/conf/modules/joystick.xml new file mode 100644 index 0000000000..cb1995908c --- /dev/null +++ b/conf/modules/joystick.xml @@ -0,0 +1,22 @@ + + + + + + Handle JOYSTICK_RAW messages + + Each new message is parsed and stored into the joystick structure. + An ABI message JOYSTICK is sent and can be used for control or payload + depending on the application. + + +
+ +
+ + + + + +
+ diff --git a/sw/airborne/firmwares/fixedwing/fixedwing_datalink.c b/sw/airborne/firmwares/fixedwing/fixedwing_datalink.c index ec1bc94693..e28fa4d39d 100644 --- a/sw/airborne/firmwares/fixedwing/fixedwing_datalink.c +++ b/sw/airborne/firmwares/fixedwing/fixedwing_datalink.c @@ -47,19 +47,6 @@ #define MOfMM(_x) (((float)(_x))/1000.) -#if USE_JOYSTICK -#include "firmwares/fixedwing/stabilization/stabilization_attitude.h" -#include "autopilot.h" -uint8_t joystick_block; -#define JoystickHandeDatalink(_roll_int8, _pitch_int8, _throttle_int8) { \ - if (autopilot_get_mode() == AP_MODE_AUTO2 && nav_block == joystick_block) { \ - h_ctl_roll_setpoint = _roll_int8 * (AUTO1_MAX_ROLL / 0x7f); \ - h_ctl_pitch_setpoint = _pitch_int8 * (AUTO1_MAX_PITCH / 0x7f); \ - v_ctl_throttle_setpoint = (MAX_PPRZ/0x7f) * _throttle_int8; \ - } \ - } -#endif - void firmware_parse_msg(struct link_device *dev __attribute__((unused)), struct transport_tx *trans __attribute__((unused)), uint8_t *buf) { uint8_t msg_id = IdOfPprzMsg(buf); @@ -152,16 +139,6 @@ void firmware_parse_msg(struct link_device *dev __attribute__((unused)), struct break; #endif /* HITL */ -#if USE_JOYSTICK - case DL_JOYSTICK_RAW: { - if (DL_JOYSTICK_RAW_ac_id(buf) == AC_ID) { - JoystickHandeDatalink(DL_JOYSTICK_RAW_roll(buf), - DL_JOYSTICK_RAW_pitch(buf), - DL_JOYSTICK_RAW_throttle(buf)); - } - } - break; -#endif // USE_JOYSTICK default: break; } diff --git a/sw/airborne/firmwares/fixedwing/joystick.h b/sw/airborne/firmwares/fixedwing/joystick.h deleted file mode 100644 index 9a5f32bd60..0000000000 --- a/sw/airborne/firmwares/fixedwing/joystick.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef JOYSTICK_H -#define JOYSTICK_H - -extern uint8_t joystick_block; - -#endif diff --git a/sw/airborne/modules/joystick/joystick.c b/sw/airborne/modules/joystick/joystick.c new file mode 100644 index 0000000000..3fabe327cf --- /dev/null +++ b/sw/airborne/modules/joystick/joystick.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 Gautier Hattenberger + * + * This file is part of paparazzi + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, see + * . + */ +/** + * @file "modules/joystick/joystick.c" + * @author Gautier Hattenberger + * Handle JOYSTICK_RAW messages + */ + +#include "modules/joystick/joystick.h" +#include "subsystems/datalink/datalink.h" +#include "subsystems/abi.h" +#include "pprzlink/dl_protocol.h" +#include "generated/airframe.h" + +struct Joystick joystick; + +void joystick_init(void) +{ + joystick.roll = 0; + joystick.pitch = 0; + joystick.yaw = 0; + joystick.throttle = 0; +} + +void joystick_parse(void) +{ + if (DL_JOYSTICK_RAW_ac_id(dl_buffer) == AC_ID) { + joystick.roll = DL_JOYSTICK_RAW_roll(dl_buffer); + joystick.pitch = DL_JOYSTICK_RAW_pitch(dl_buffer); + joystick.yaw = DL_JOYSTICK_RAW_yaw(dl_buffer); + joystick.throttle = DL_JOYSTICK_RAW_throttle(dl_buffer); + AbiSendMsgJOYSTICK(JOYSTICK_ID, joystick.roll, joystick.pitch, joystick.yaw, joystick.throttle); + } +} + diff --git a/sw/airborne/modules/joystick/joystick.h b/sw/airborne/modules/joystick/joystick.h new file mode 100644 index 0000000000..d21e73ad89 --- /dev/null +++ b/sw/airborne/modules/joystick/joystick.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Gautier Hattenberger + * + * This file is part of paparazzi + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, see + * . + */ +/** + * @file "modules/joystick/joystick.h" + * @author Gautier Hattenberger + * Handle JOYSTICK_RAW messages + */ + +#ifndef JOYSTICK_H +#define JOYSTICK_H + +#include "std.h" + +/** + * Joystick structure + */ +struct Joystick { + int32_t roll; ///< roll command + int32_t pitch; ///< pitch command + int32_t yaw; ///< yaw command + int32_t throttle; ///< throttle command +}; + +extern struct Joystick joystick; + +/** + * Init function + */ +extern void joystick_init(void); + +/** + * JOYSTICK_RAW message parser + * if valid, send a JOYSTICK ABI message + */ +extern void joystick_parse(void); + +#endif + diff --git a/sw/airborne/subsystems/abi_sender_ids.h b/sw/airborne/subsystems/abi_sender_ids.h index 6f8c62db51..a9ce33a2b4 100644 --- a/sw/airborne/subsystems/abi_sender_ids.h +++ b/sw/airborne/subsystems/abi_sender_ids.h @@ -425,4 +425,11 @@ #define DETECT_GATE_ABI_ID 33 #endif +/* + * JOYSTICK message (used for payload or control, but not as a RC) + */ +#ifndef JOYSTICK_ID +#define JOYSTICK_ID 1 +#endif + #endif /* ABI_SENDER_IDS_H */ diff --git a/sw/ext/pprzlink b/sw/ext/pprzlink index 1cf25d0406..9e26b7a1aa 160000 --- a/sw/ext/pprzlink +++ b/sw/ext/pprzlink @@ -1 +1 @@ -Subproject commit 1cf25d0406c160a7da145d9b0e7bc25b4db67845 +Subproject commit 9e26b7a1aae5493d7fe77e48814aa428e5d73479