Board index FlightGear Support Interfacing

Generic socket input issues

Connecting two computers, using generic protocol, connecting with Matlab?

Generic socket input issues

Postby nkGerd » Sun May 04, 2014 3:09 am

Hello everyone,
I am trying to send aileron, elevator, rudder and throttle commands to FlighGear from a C++ program via the "--generic=socket=in" -option. I am just trying to control the airplane while it flies (so I can't disable the flight models). I have been trying to get this to work for the past two days, but nothing that I implement seems to be working. I was hoping that you could help me troubleshoot.

I run FlightGear 3.0.0 on Windows 7 on the same computer as the C++ program with the following command line options:
Code: Select all
C:\Program Files\FlightGear v2.10\bin\Win64\fgfs.exe
  --fg-root=C:\Program Files\FlightGear v2.10\data
  --fg-scenery=C:\Program Files\FlightGear v2.10\data\Scenery;C:\Program Files\FlightGear v2.10\scenery;C:\Program Files\FlightGear v2.10\terrasync
  --terrasync-dir=0
  --aircraft=Rascal110-JSBSim
  --control=keyboard
  --console
  --disable-random-objects
  --disable-specular-highlight
  --enable-ai-models
  --disable-ai-traffic
  --in-air
  --disable-real-weather-fetch
  --geometry=800x600
  --bpp=32
  --timeofday=noon
  --disable-terrasync
  --httpd=5500
  --props=5501
  --disable-fgcom
  --generic=socket,in,10,,5010,udp,custom_inputs_abs
  --log-level=warn


I have defined a custom_input_abs.xml in the Protocols folder (It only has the aileron and elevator for now):
Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
   <input>
      <line_separator>newline</line_separator>
      <var_separator>,</var_separator>
      <chunk>
         <name>aileron</name>
         <node>/controls/flight/aileron</node>
         <type>float</type>
         <format>%f</format>
      </chunk>
      <chunk>
         <name>elevator</name>
         <node>/controls/flight/elevator</node>
         <type>float</type>
         <format>%f</format>
      </chunk>
   </input>   
</generic>
</PropertyList>


I send the packets in the proper format and have the program running and sending when I start FlightGear. I can't see the udp packets on Windows when I send them to localhost. I have tested the packets on wireshark when sending them to a different computer and they arrived fine and the data was 18 bytes long (16 for the variables and 2 for the comma and newline). The packets are sent via the following C++ program:

Code: Select all
// udp_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <winsock2.h>
#include <iostream>
#pragma comment( lib, "wsock32.lib" )

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   //initialize WsaData
   WSADATA WsaData;
   if ((WSAStartup( MAKEWORD(2,2), &WsaData ) == NO_ERROR)<0){
      cout << "Broken";
      return -1;
   }

   //create socket
   int handle = socket( AF_INET, SOCK_DGRAM, 0);
   
   if ( handle <= 0 )
   {
      printf( "failed to create socket\n" );
      return -1;
   }

   //Destination:
   unsigned int a = 127;//206;
   unsigned int b =0;//87;
   unsigned int c =0;//11;
   unsigned int d = 1;//38;
   unsigned short port = 5010;
   unsigned int destination = ( a << 24 ) | ( b << 16 ) | ( c << 8  ) | d;
   //FGpacket.
   //bind socket
   sockaddr_in address;
   address.sin_family = AF_INET;
   address.sin_addr.s_addr = htonl(destination);
   address.sin_port = htons( (unsigned short) port );

   
   Sleep(10);
      
   if (bind( handle, (const sockaddr*) &address, sizeof(sockaddr_in))< 0)
   {
      printf( "failed to bind socket\n" );
      //return -1;
   }

   float an=0.13;
   float bn=0.8;
   char packet_data[1024];

   sprintf(packet_data, "%f,%f\n", an, bn);

   cout << packet_data;

   //Send Data
   while (1) {
      Sleep(20);
      int sent_bytes = sendto( handle, (const char*)packet_data, strlen(packet_data),0, (sockaddr*)&address, sizeof(sockaddr_in) );
      if ( sent_bytes != strlen(packet_data) )
      {
         printf( "failed to send packet\t" );
         return -1;
         closesocket(handle);
      }else{
         cout<<sent_bytes<<endl;
      }
   }

   WSACleanup();
   cout<<"Success";
   return 0;
}


The log outputs the following information, which says nothing really about a failed connection (or a successful one for that matter):
Code: Select all
Enabling ATI viewport hack
Skipping bad material entry params
Httpd server started on port 5500
Reading deprecated xml electrical system model from
    C:/Program Files/FlightGear v2.10/data/Aircraft/Rascal/Systems/electrical.xm
l
Duplicate autopilot component Pitch hold, renamed to Pitch hold_0
Duplicate autopilot component Altitude Hold (Altimeter based) Stage 2, renamed t
o Altitude Hold (Altimeter based) Stage 2_0
Duplicate autopilot component Speed hold (vary elevator), renamed to Speed hold
(vary elevator)_0
environment init
Failed to tie property /ai[0]/models[0]/carrier[0]/controls[0]/constants[0]/rudd
er[0]
Failed to tie property /ai[0]/models[0]/carrier[1]/controls[0]/constants[0]/rudd
er[0]
  Sorry, qdot doesn't appear to be trimmable
  Sorry, pdot doesn't appear to be trimmable
  Trim Results:
          Altitude AGL:    1.3  wdot: -2.83e+000 Tolerance: 1.000000e-003  Faile
d
           Pitch Angle: -0.071  qdot: 1.58e+000 Tolerance: 1.000000e-004  Failed

            Roll Angle:  -0.16  pdot: -4.98e+000 Tolerance: 1.000000e-004  Faile
d

  Trim Statistics:
    Total Iterations: 2
    Sub-iterations:
    wdot: 3 average: 1.5  successful:  1  stability: 2
    qdot: 0 average: 0  successful:  0  stability: 12.1
    pdot: 8 average: 4  successful:  2  stability: 2
    Run Count: 173

I have previously tried to get it to work on FLighgear version 2.0.0, but that one stops responding if I add the "--generic=socket,in,10,,5010,udp,custom_inputs_abs" command into the command line.
The issue may have possibly to do with the tied properties of the Property Tree, but there does not seem to be much information about them. When I Ctrl click the "." in the Property Browser after FlighGear has started, it shows me that the aileron and elevator is of type (double, AT). To be honest I am quite stuck at the moment and don't even know where to proceed from here.

Any help from you will be appreciated. Thank you.
nkGerd
 
Posts: 1
Joined: Sun May 04, 2014 2:33 am

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests

cron