Difference between revisions of "Input2Ivy"

From PaparazziUAV
Jump to navigation Jump to search
 
m (spelling)
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Input2Ivy''' is an [[Ivy]] agent written in Ocaml/C used to read inputs coming from joysticks or joypads and to send Ivy messages accordingly.
<categorytree style="float:right; clear:right; margin-left:1ex; border: 1px solid gray; padding: 0.7ex;" mode=pages>Tools</categorytree>
__TOC__
 
'''Input2Ivy''' is an [[Ivy]] agent written in Ocaml/C used to read inputs coming from [[Joystick|joysticks or joypads]] and to send Ivy messages accordingly.


= Compiling Input2Ivy =
= Compiling Input2Ivy =


The program is located in sw/ground_segment/joystick. In order to use it you need type 'make' in this folder after building the whole paparazzi sources (it will be added in the default set of compile program in the future).
The program is located in <tt>sw/ground_segment/joystick</tt>. It should already be compiled with the top level make, you also can explicitly build it with <tt>make</tt> in <tt>sw/ground_segment/joystick</tt>


The compiled programs are:
* the C library sdl_stick (using SDL)
* the C library usb_stick (we are planing to use gsl in the future for better cross-platform integration)
* input2ivy (ocaml main program that uses sdl_stick)
* input2ivy (ocaml main program that uses usb_stick)
* test_stick (a small C test program that display raw values of your joystick)
* test_stick (a small C test program that display raw values of your joystick)


Line 14: Line 16:
== Xml configuration file ==
== Xml configuration file ==


Input2Ivy reads the configuration of your input device in a Xml file located in conf/joystick. The format is as follow:
Input2Ivy reads the configuration of your input device in a xml file located in <tt>conf/joystick</tt>. The format is as follow:
 
<source lang="xml">
  <joystick>
  <joystick>
</source>
Start with the node 'joystick', no DTD yet.
Start with the node 'joystick', no DTD yet.


<source lang="xml">
   <input>
   <input>
   <axis index="0" name="roll"/>
   <axis index="0" name="roll"/>
Line 29: Line 33:
   ...
   ...
   </input>
   </input>
</source>
In this section, all the axis and buttons are described with an index and a name. Both have to be unique.
In this section, all the axis and buttons are described with an index and a name. Both have to be unique.
* the index is the actual axis or button number of your input device (you can use 'test_stick' to determine each index)
* the index is the actual axis or button number of your input device (you can use 'test_stick' to determine each index)
* the name is chosen by the user
* the name is chosen by the user


<source lang="xml">
   <variables>
   <variables>
   <var name="mode" default="0"/>
   <var name="mode" default="0"/>
Line 39: Line 46:
   ...
   ...
   </variables>
   </variables>
</source>
The section 'variables' allows to declare local variables to the program, those value can be changed based on inputs event. First you need to declare the variable with a default value (integer) and then each event is describe with the 'set' node. It is possible to use logical "C-like" expression for the event (&&, ||, <, >, ...).
The section 'variables' allows to declare local variables to the program, those value can be changed based on inputs event. First you need to declare the variable with a default value (integer) and then each event is describe with the 'set' node. It is possible to use logical "C-like" expression for the event (&&, ||, <, >, ...).


<source lang="xml">
   <messages period="0.1">
   <messages period="0.1">
  <message class="datalink" name="BOOZ_NAV_STICK">
    <message class="datalink" name="RC_4CH" send_always="true">
    <field name="vx_sp" value="-pitch"/>
      <field name="mode"        value="mode"/>
    <field name="vy_sp" value="roll"/>
      <field name="throttle"   value="Bound(0-ly,0,127)"/>
    <field name="vz_sp" value="(up-down)*127"/>
      <field name="roll"       value="roll"/>
    <field name="r_sp" value="(right-left)*127"/>
      <field name="yaw"         value="yaw"/>
  </message>
      <field name="pitch"       value="pitch"/>
    </message>
   <message class="ground" name="JUMP_TO_BLOCK" on_event="shoot && button1"/>
   <message class="ground" name="JUMP_TO_BLOCK" on_event="shoot && button1"/>
     <field name="block_id" value="IndexOfBlock('land')"/>
     <field name="block_id" value="IndexOfBlock('land')"/>
  </message>
  <message class="ground" name="DL_SETTING" on_event="button2">
    <field name="index" value="IndexOfSetting(kill_throttle)"/>
    <field name="value" value="1"/>
   </message>
   </message>
   ...
   ...
   </messages>
   </messages>
</source>
The 'messages' section describes the messages sent to [[Ivy]].
The 'messages' section describes the messages sent to [[Ivy]].
* the 'period' attribute define the period for sending the messages. A message is send only the at least one of its field has changed since last sending. Only messages with 'send_always="true"' are always sent.
* the 'period' attribute define the period for sending the messages. A message is send only the at least one of its field has changed since last sending. Only messages with 'send_always="true"' are always sent.
Line 63: Line 78:
** name: the name of the field (mandatory)
** name: the name of the field (mandatory)
** value: the value to be sent (here, expressions can be used, see below) (mandatory)
** value: the value to be sent (here, expressions can be used, see below) (mandatory)
 
<source lang="xml">
  </joystick>
  </joystick>
</source>
Close 'joystick' node.
Close 'joystick' node.


Line 80: Line 96:


== Trims ==
== Trims ==
First calibrate your joystick as described on the [[Joystick]] page.


TBD
In flight trimming is to be done...


= Usage =
= Usage =


./sw/ground_segment/joystick/input2ivy [options] config_file.xml
$ ./sw/ground_segment/joystick/input2ivy [options] config_file.xml


The options are:
The options are:
* -ac <AC name> the name of your aircraft (mandatory)
* -ac <AC name> the name of your aircraft (mandatory)
* -b <ivy_bus> the an ivy bus address (default address used if not set)
* -b <ivy_bus> the an ivy bus address (default address used if not set)
* -d <device_name> set the device name (default is /dev/input/js0)
* -d <device_index> set the SDL device index (default is 0)
** for paparazzi versions older than v4.2 use: -d <device_name> set the device name (default is /dev/input/js0))
* -v verbose mode (can also be used to identify the channels)
* -v verbose mode (can also be used to identify the channels)
* -id set the joystick ID (in range [0,255], a random value is chosen if not set)
* -id set the joystick ID (in range [0,255], a random value is chosen if not set)
Do not forget the configuration file name after the options.
Do not forget the configuration file name after the options.
Example invocation on Mac OS X using a SNES gamepad configuration as input:
$ ./sw/ground_segment/joystick/input2ivy  -b 224.255.255.255:2010 -ac Teensy_Fly_Quad_Elle0_v1_2_214 -d 0 snes_gamepad.xml


Input2Ivy can be launched from the Paparazzi Center if your conf/control_panel.xml have the correct 'program' entry. (See conf/control_panel.xml.example)
Input2Ivy can be launched from the Paparazzi Center if your conf/control_panel.xml have the correct 'program' entry. (See conf/control_panel.xml.example)
[[Category:Tools]]

Latest revision as of 10:00, 15 September 2016

Input2Ivy is an Ivy agent written in Ocaml/C used to read inputs coming from joysticks or joypads and to send Ivy messages accordingly.

Compiling Input2Ivy

The program is located in sw/ground_segment/joystick. It should already be compiled with the top level make, you also can explicitly build it with make in sw/ground_segment/joystick

  • the C library sdl_stick (using SDL)
  • input2ivy (ocaml main program that uses sdl_stick)
  • test_stick (a small C test program that display raw values of your joystick)

Configuration and use

Xml configuration file

Input2Ivy reads the configuration of your input device in a xml file located in conf/joystick. The format is as follow:

 <joystick>

Start with the node 'joystick', no DTD yet.

  <input>
   <axis index="0" name="roll"/>
   <axis index="1" name="pitch"/>
   <axis index="2" name="throttle"/>
   ...
   <button index="0" name="shoot"/>
   <button index="1" name="button1"/>
   <button index="2" name="button2"/>
   ...
  </input>

In this section, all the axis and buttons are described with an index and a name. Both have to be unique.

  • the index is the actual axis or button number of your input device (you can use 'test_stick' to determine each index)
  • the name is chosen by the user
  <variables>
   <var name="mode" default="0"/>
   <set var="mode" value="0" on_event="button1"/>
   <set var="mode" value="1" on_event="button2 && shoot"/>
   ...
  </variables>

The section 'variables' allows to declare local variables to the program, those value can be changed based on inputs event. First you need to declare the variable with a default value (integer) and then each event is describe with the 'set' node. It is possible to use logical "C-like" expression for the event (&&, ||, <, >, ...).

  <messages period="0.1">
    <message class="datalink" name="RC_4CH" send_always="true">
      <field name="mode"        value="mode"/>
      <field name="throttle"    value="Bound(0-ly,0,127)"/>
      <field name="roll"        value="roll"/>
      <field name="yaw"         value="yaw"/>
      <field name="pitch"       value="pitch"/>
    </message>
   <message class="ground" name="JUMP_TO_BLOCK" on_event="shoot && button1"/>
    <field name="block_id" value="IndexOfBlock('land')"/>
   </message>
   <message class="ground" name="DL_SETTING" on_event="button2">
     <field name="index" value="IndexOfSetting(kill_throttle)"/>
     <field name="value" value="1"/>
   </message>
   ...
  </messages>

The 'messages' section describes the messages sent to Ivy.

  • the 'period' attribute define the period for sending the messages. A message is send only the at least one of its field has changed since last sending. Only messages with 'send_always="true"' are always sent.
  • the 'message' node attributes are:
    • class: the class of the message (defined in conf/messages.xml) (mandatory)
    • name: the name of the message (defined in conf/messages.xml) (mandatory)
    • send_always: always send message the 'period' frequency if set to "true" (optional)
  • the 'messages' children are the field of the message as describe in conf/messages.xml, except for the field 'ac_id' that is automatically set if needed.
  • the 'field' node attributes are:
    • name: the name of the field (mandatory)
    • value: the value to be sent (here, expressions can be used, see below) (mandatory)
 </joystick>

Close 'joystick' node.

Expressions and functions

  • parenthesis: (, )
  • operators: +, -, *, % (divide, / is not allowed)
  • logical, comparator: &&, ||, <, >
  • functions:
    • Scale(x, min, max): scale the value in the given bounds (input bounds are [-127, 127]
    • Fit(x, min, max, min_input, max_input): some as 'Scale' with custom input bounds
    • Bound(x, min, max): bound the value between [min,max]
    • PprzMode(x): returns 0 if input is less than -127/2, 2 if greater than 127/2, 1 otherwise
    • JoystickId(): returns the joystick ID

Trims

First calibrate your joystick as described on the Joystick page.

In flight trimming is to be done...

Usage

$ ./sw/ground_segment/joystick/input2ivy [options] config_file.xml

The options are:

  • -ac <AC name> the name of your aircraft (mandatory)
  • -b <ivy_bus> the an ivy bus address (default address used if not set)
  • -d <device_index> set the SDL device index (default is 0)
    • for paparazzi versions older than v4.2 use: -d <device_name> set the device name (default is /dev/input/js0))
  • -v verbose mode (can also be used to identify the channels)
  • -id set the joystick ID (in range [0,255], a random value is chosen if not set)

Do not forget the configuration file name after the options.

Example invocation on Mac OS X using a SNES gamepad configuration as input:

$ ./sw/ground_segment/joystick/input2ivy  -b 224.255.255.255:2010 -ac Teensy_Fly_Quad_Elle0_v1_2_214 -d 0 snes_gamepad.xml 

Input2Ivy can be launched from the Paparazzi Center if your conf/control_panel.xml have the correct 'program' entry. (See conf/control_panel.xml.example)