Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
nps_radio_control_joystick.c File Reference

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>
+ Include dependency graph for nps_radio_control_joystick.c:

Go to the source code of this file.


#define NPS_JS_AXIS_ROLL   0
#define NPS_JS_AXIS_PITCH   1
#define NPS_JS_AXIS_YAW   2
#define JS_NB_AXIS   4
#define JS_NB_BUTTONS   3


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...


struct NpsJoystick nps_joystick
SDL_Joystick * sdl_joystick
SDL_Event sdl_event

Detailed Description

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:

  • 4 axes and 3 buttons, or
  • 5 axes

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.

Macro Definition Documentation


#define JS_NB_AXIS   4

Definition at line 95 of file nps_radio_control_joystick.c.


#define JS_NB_BUTTONS   3

Definition at line 112 of file nps_radio_control_joystick.c.


#define NPS_JS_AXIS_PITCH   1

Definition at line 85 of file nps_radio_control_joystick.c.


#define NPS_JS_AXIS_ROLL   0

Definition at line 82 of file nps_radio_control_joystick.c.



Definition at line 91 of file nps_radio_control_joystick.c.


#define NPS_JS_AXIS_YAW   2

Definition at line 88 of file nps_radio_control_joystick.c.



Definition at line 105 of file nps_radio_control_joystick.c.



Definition at line 108 of file nps_radio_control_joystick.c.



Definition at line 102 of file nps_radio_control_joystick.c.

Function Documentation

◆ nps_radio_control_joystick_init()

int nps_radio_control_joystick_init ( const char *  device)

Initializes SDL and the joystick.

Function exits with -1 if fails

devicestring integer of desired joystick device
0 on success

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().

+ Here is the caller graph for this function:

◆ nps_radio_control_joystick_update()

void nps_radio_control_joystick_update ( void  )

Variable Documentation

◆ nps_joystick

◆ sdl_event

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* sdl_joystick