The online racing simulator
Motion platform interface in Visual C++ V6.0
Hello,

I need your help....

I am looking for the source code of a program in visual c++ V6.0 which is capable of extracting from LFS, in real time at aroud 20 times per second, the acceleration in x, y and z direction (longitudinal, lateral and vertical).

I would update this source code in order to convert these acceleration data and sent them via RS232 (I have the according serial library as I am allready doing this in rFactor) to my home made motion platform (2 DOF) which works really well with rFactor and which I now would like to use with LFS!.



I suppose that such program would need to connect to LFS via a UDP(?) port and read/decode the UDP data (messages). For that it probably would need to be linked to a library...

Does anybody know if such program and libraries is available and if yes, where I can get it ? It would be nice if it would be prepacaged in a Microsoft visual c++ V6.0 workspace (I know... I am dreaming... lol)

Sorry if I seem a bit lazy here. But I am a LFS "beginner"... I believe that I'll need outsim (is this a library? a program ?) I would really like to go staight to the essentials and not program such program myselves.

Thanks a lot!
Outsim is an interface. You 'connect' to it via udp with some simple settings and then LFS will send data to you. It's up to you to interpret the data to suit your needs.

From the Insim.txt file in your LFS/docs folder :

Quote :OutSim - Motion Simulator Support
=================================

The user's car in multiplayer or the viewed car in single player or
single player replay can output information to a motion system while
viewed from an internal view.

This can be controlled by 5 lines in the cfg.txt file :

OutSim Mode 0 :0-off 1-driving 2-driving+replay
OutSim Delay 1 :minimum delay between packets (100ths of a sec)
OutSim IP 0.0.0.0 :IP address to send the UDP packet
OutSim Port 0 :IP port
OutSim ID 0 :if not zero, adds an identifier to the packet

Each update sends the following UDP packet :

unsigned int :time in milliseconds (to check order)
Angular Velocity :3 floats
Orientation :3 floats Heading, Pitch, Roll
Acceleration :3 floats X, Y, Z
Velocity :3 floats X, Y, Z
Position :3 ints X, Y, Z (metres x 65536)
Game ID :1 int (optional ID - if specified in cfg.txt)

Note 1 : X and Y axes are on the ground, Z is up.

Note 2 : Motion simulators can be dangerous. The developers of the
Live for Speed racing simulator do not support any motion systems in
particular and cannot accept responsibility for any injuries or death
connected with the use of such machinery.

Quote from Victor :Outsim is an interface. You 'connect' to it via udp with some simple settings and then LFS will send data to you. It's up to you to interpret the data to suit your needs.

From the Insim.txt file in your LFS/docs folder :

Thanks for your patience Victor! I suppose I am not the only one asking this kind of questions over time!

Would it be possible for you to tell me where to find a little example of a Visual C++ V6.0 application (source code) which reads and interprets this data send by LFS? I then would adapt this programm for my needs....

Thanks very much!
Disclaimer:
This was written in about 5 minutes, wasn't compiled, probably won't compile (you'll need to link wsock32 libraries for a start), is full of things I wouldn't advise doing (I'd add a second struct for x, y, z for instance), assumes that you don't init OutSim via InSim (i.e. you configure OutSim to talk directly via the cfg file), and is written as inline C rather than the OOP and streams approach you should take with C++.

But you should get the vague idea.

#include <stdio.h>
#include <stdlib.h>

#include <windows.h>

struct outsim_packet_t
{
unsigned int time;
float velocity1;
float velocity2;
float velocity3;
float heading;
float pitch;
float roll;
float accX;
float accY;
float accZ;
float velX;
float vely;
float velz;
int posx;
int posy;
int posz;
};

int main(int argc, char *argv[])
{
struct sockaddr_in saddr;
WSADATA wsadata;
short listenport;
int g = 1;
listenport = 7500;

if (WSAStartup(0x202, &wsadata) == SOCKET_ERROR)
{
printf("WSAStartup failed\n");
WSACleanup();
return 0;
}

s = socket(AF_INET, SOCK_DGRAM, 0);

if (s == INVALID_SOCKET)
{
printf("Error opening listen socket\n");
WSACleanup();
return 0;
}

// make our socket non-blocking, this allows us to timeout the connection
// gracefully, and potentially do other things
unsigned long smode = 1;
ioctlsocket(s, FIONBIO, &smode);

saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = INADDR_ANY;
saddr.sin_port = htons(listenport);

if (bind(s,(struct sockaddr *)&saddr, sizeof(saddr)) == SOCKET_ERROR)
{
printf("Bind failed\n");
closesocket(s);
s = INVALID_SOCKET;
WSACleanup();
return 0;
}

while (g)
{
// ideally you should check to see when LFS last sent something to
// us. I'd say 20 seconds. You'd then set g = 0 if its not, which would
// kill the loop
// I couldn't be arsed to do this

// read socket for data
// consider using a more sensible size buffer
char buf[512];
int retval = recv(s, buf, 512, 0);
// consider checking the packet size is what you'd expect (i.e. compare with the sizeof(struct outsim_packet_t))
if (retval > 0)
{
// memcpy buf into a vari
struct outsim_packet_t packet;
memcpy(&packet, buf, sizeof(struct outsim_packet_t));

// do stuff with the packet - tell your motion platform
}

// Dont hammer the system
sleep(20);
}

closesocket(s);
WSACleanup();

return 0;
}

Thanks angry angel !

I'll try your code and report back! Great starting point.
Hey, gadaga!
Can you tell me how did you build your platform? Any documentation available?
Thanks in advance
Quote from gadaga :Thanks angry angel !

I'll try your code and report back! Great starting point.

OK I've coded the little program with input from "angry angel" and it perfectly works (with some minor adaptations)!

Now the next challenge. I need to extract from all this outsim packet data the g-forces (acceleration) in lateral, longitudinal and vertical directions.

In the outsim data there is the velocity and acceleration in x, y and z directions (I suppose that there is an area around the tracks with x, y coordinates in the flat plane and a z factor for vertical movement) and a so called velocity 1, 2 and 3 (I don't know to what that corresponds) and alos there is heading (which I suppose is deduced from the velocity x and y data ?).

All in all I would need some mathematical know how (formulas with a lot of sinus, cosinus, tan, atan, ...) to transform all this data.

Would anybody dispose of such formulas to deduce the lateral, longitudinal (wrt to the body of the car) and vertical (allthough here I suppose I can directly use the z components from outsim ?) acceleration data.

Many thanks!
gadada,

Great idea for this interface.
Please what is a link for the complete system for rfactor?

Thanks,
JS
RayOK already made an example interface in VB6 that grabs all this data, I then tweaked it to show exactly what it is you're looking for. Search the programmers forum for that thread, download the source code, open it with a text editor (if you don't have VB6 installed) and you'll have your equations. Rewrite for C++ and you're away.

Edit: Here, I even found the thread for you: link
Thanks a lot Bob (Smith)

Finally I've reused RayOK's VB code and I did the supplementarry coding in VB 6 in order to interface to my DIY motion platform (simulating lateral and longitudinal acceleration). It works like a charm now! LFS feels so good now !
Perhaps you could post some pictures? Any info on the motion platform itself?

FGED GREDG RDFGDR GSFDG