Paparazzi UAS
v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
|
Direct RC control for NPS with a standard joystick using SDL. More...
#include "nps_radio_control.h"
#include "nps_radio_control_joystick.h"
#include "generated/airframe.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <SDL/SDL.h>
Go to the source code of this file.
Macros | |
#define | NPS_JS_AXIS_ROLL 0 |
#define | NPS_JS_AXIS_PITCH 1 |
#define | NPS_JS_AXIS_YAW 2 |
#define | NPS_JS_AXIS_THROTTLE 3 |
#define | JS_NB_AXIS 4 |
#define | NPS_JS_BUTTON_MODE_MANUAL 1 |
#define | NPS_JS_BUTTON_MODE_AUTO1 2 |
#define | NPS_JS_BUTTON_MODE_AUTO2 3 |
#define | JS_NB_BUTTONS 3 |
Functions | |
int | nps_radio_control_joystick_init (const char *device) |
Initializes SDL and the joystick. More... | |
void | nps_radio_control_joystick_update (void) |
Updates joystick buttons from events, directly reads current axis positions. More... | |
Variables | |
struct NpsJoystick | nps_joystick |
SDL_Joystick * | sdl_joystick |
SDL_Event | sdl_event |
Direct RC control for NPS with a standard joystick using SDL.
Simple DirectMedia Layer library is used for cross-platform support. Joystick button and axes are mapped to RC commands directly with defines.
You must have a joystick with either:
First you should run sw/ground_segment/joystick/test_stick to determine the indices of the physical axes and buttons on your joystick (and to test that it actually works). Then you can assign each axis and button to a command in your airframe file.
The default axes are Roll = 0, Pitch = 1, Yaw = 2 and Throttle = 3. The default buttons are Manual = 0, Auto1 = 1, Auto2 = 2.
Example for 4 axes and 3 buttons using a joystick with 7 axes and 5 buttons:
* <section name="SIMULATOR" prefix="NPS_"> * ... * <define name="JS_AXIS_ROLL" value="2"/> <!-- Use joystick axis 2 for roll --> * <!-- Use joystick axis 1 for pitch (default) --> * <define name="JS_AXIS_YAW" value="3"/> <!-- Use joystick axis 3 for yaw --> * <define name="JS_AXIS_ROLL" value="6"/> <!-- Use joystick axis 6 for throttle --> * <define name="JS_BUTTON_MODE_MANUAL" value="3"/> <!-- Use joystick button 3 for manual --> * <!-- Use joystick button 1 for auto1 (default) --> * <!-- Use joystick button 2 for auto2 (default) --> * </section> *
One can define NPS_JS_AXIS_MODE to use an axis instead of buttons to change You will need a 5-axis joystick.
If you need to reverse the direction of any axis, simply use:
* <define name="JS_AXIS_PITCH_REVERSE" value="1"/> * <!-- value="1" is required, setting to zero or omitting disables reversing --> *
At this point, no other functionality or channels are supported for R/C control.
Definition in file nps_radio_control_joystick.c.
#define JS_NB_AXIS 4 |
Definition at line 95 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_init().
#define JS_NB_BUTTONS 3 |
Definition at line 112 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_init().
#define NPS_JS_AXIS_PITCH 1 |
Definition at line 85 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_AXIS_ROLL 0 |
Definition at line 82 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_AXIS_THROTTLE 3 |
Definition at line 91 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_AXIS_YAW 2 |
Definition at line 88 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_BUTTON_MODE_AUTO1 2 |
Definition at line 105 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_BUTTON_MODE_AUTO2 3 |
Definition at line 108 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
#define NPS_JS_BUTTON_MODE_MANUAL 1 |
Definition at line 102 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
int nps_radio_control_joystick_init | ( | const char * | device | ) |
Initializes SDL and the joystick.
Function exits with -1 if fails
device | string integer of desired joystick device |
Definition at line 130 of file nps_radio_control_joystick.c.
References JS_NB_AXIS, JS_NB_BUTTONS, NpsJoystick::mode, MODE_SWITCH_AUTO2, nps_joystick, NpsJoystick::pitch, NpsJoystick::roll, sdl_joystick, NpsJoystick::throttle, and NpsJoystick::yaw.
Referenced by nps_radio_control_init().
void nps_radio_control_joystick_update | ( | void | ) |
Updates joystick buttons from events, directly reads current axis positions.
Definition at line 201 of file nps_radio_control_joystick.c.
References NpsJoystick::mode, MODE_SWITCH_AUTO1, MODE_SWITCH_AUTO2, MODE_SWITCH_MANUAL, nps_joystick, NPS_JS_AXIS_PITCH, NPS_JS_AXIS_ROLL, NPS_JS_AXIS_THROTTLE, NPS_JS_AXIS_YAW, NPS_JS_BUTTON_MODE_AUTO1, NPS_JS_BUTTON_MODE_AUTO2, NPS_JS_BUTTON_MODE_MANUAL, NpsJoystick::pitch, NpsJoystick::roll, sdl_event, sdl_joystick, NpsJoystick::throttle, and NpsJoystick::yaw.
Referenced by nps_radio_control_available().
struct NpsJoystick nps_joystick |
Definition at line 117 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_available(), nps_radio_control_joystick_init(), and nps_radio_control_joystick_update().
SDL_Event sdl_event |
Definition at line 119 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_update().
SDL_Joystick* sdl_joystick |
Definition at line 118 of file nps_radio_control_joystick.c.
Referenced by nps_radio_control_joystick_init(), and nps_radio_control_joystick_update().