telemetry-plugin problem - data stream to arduino

Discussion in 'Plugins' started by tommy42, Feb 11, 2015.

  1. tommy42

    tommy42 Registered

    Joined:
    Feb 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hi,
    I need some help with the telemetry-plugin.

    I've built a system with nine DC-Vibration-Motors in my racing seat (it works similar to the iVibe-System). The nine Motors should give some additional feedback of the tires and the chassis.
    The Vibration-Motors are connected via Arduino-Mega over serial port to the PC.

    The Arduino-code works as it should. But there is a problem with the data-stream between the telemetry-plugin and the arduino, that I couldn't fix for three month now.

    In practical it means: Motors are starting and stopping randomly without a reason. Sometimes the motors will start running while I'm in the garage-screen and the telemetry-plugin shouldn't be loaded anyway at this stage.

    I built a small tool in Visual Basic to start and stop the motors at different speeds. It does what it should do: Awaiting a Ten-Byte-Stream which starts with a Start-Byte („255“) at first, and then nine Bytes between „0“ and „254“for the nine Motors. Is the 10-Byte-Package processed, the Arduino ist awaiting the next Package. On this side everything should work properly.

    What I really need is a snippet for the rFactor2-telemetry-plugin, which will send the 10 Bytes continously to the Arduino on com3. It will be enough for my future work when the data stream is fixed like „255,100,100,100,100,100,100,100,100,100“.

    Thanx in advance

    tommy
     
  2. tommy42

    tommy42 Registered

    Joined:
    Feb 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hi,
    is really no one out there who played with the Internal-Plugin and an Arduino?

    My whole DIY-project stucks at the above described small issue with the 10-Byte-Stream. To make it clear: The connection between Arduino and Internals-Plugin is working. Additional Coding works as well (example: If the left rear wheel is offtrack, the vibration motor no. 4 is rumbling in the coded pattern. My problem is that the Internal-Plugin send more (unwanted) signals to all motors I could not explain.

    Any help will be really welcome

    tommy
     
  3. Marcel Offermans

    Marcel Offermans Registered

    Joined:
    Oct 4, 2010
    Messages:
    644
    Likes Received:
    2,926
    Maybe you should post some more details about how you coded this and what kind of "unwanted signals" you're talking about. Can you actually debug what data you are receiving on the arduino? Also you're saying the motors start running when you're in the garage. What data are you seeing on both sides of the connection in that case? There are so many things that could be wrong that it's hard to help (which is why people have not responded, I guess).
     
  4. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,345
    Likes Received:
    6,572
    Yeah, it's not really clear what your 'telemetry plugin' is actually doing.

    Also, UpdateTelemetry() is called when you're in the car and when you're at the monitor. It's up to you to check whether you're in realtime yet.
     
  5. fazed

    fazed Registered

    Joined:
    May 29, 2012
    Messages:
    6
    Likes Received:
    0
    When I wrote my plug-in for rF1 and the Arduino I soon realised that the SPI was by far the biggest bottle next both on the PC and the Arduino.

    My plug-in sounds like it did a very similar thing although I was controlling 6 linear actuators and a bank of LEDs.

    I eventually used an Ethernet shield and just fired the data in via UDP. Much more reliable with little to no buffering. The transfer rate is still slow, 20kbs but enough for what I was after.

    If you are firing out the data every update you can soon run into problems as you fill the SPI buffer.

    If you don't want to use an Ethernet, have a look at the Due board as it has a native USB port and can be address as a HID device. Much nicer way to do it.
     
  6. tommy42

    tommy42 Registered

    Joined:
    Feb 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hi Fazed,

    it seems so, that you described exactly my problem. I will make a try with less data to save bufferspace.

    This will take some time -> (I'm not a god like coder and my boss got a lot work for me these days). I will post my experience here as soon as possible.


    You talked about the Due-Board. Is it possible to stack my DIY-Motor-Shield (standard bread board size) on top of it like on the mega-board - the stack connectors looks pretty much the same? I ask, because I really don't want to solder this very tiny motorshield again.


    Thanx for the hints so far

    Tommy
     
  7. tommy42

    tommy42 Registered

    Joined:
    Feb 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hi,

    after a lot of hours try&error, I did a very small step to solve my problems.

    Now the unwanted signals starts when I'm in the cockpit and not in the garage screen. This was easy to find (thx Lazza). It was the difference between "Start

    session" and "EnterRealtime". The right point to put my code in, was "EnterRealtime".

    The other problem still exists. When I'm in the cockpit, some motors will start without a reason.

    As i told before, I am not a very good C+-Coder, and maybe a good soul will find the error in my coding below.

    In this simple version I've tried to send "0" signals to everyone of the nine motors. So the expected result should be, that no motor is running. But it didn't.

    Minimum two motors starts running (now at constant speed), when I enter the realtime. And they did not stop when I "ExitRealtime". Only solve for this: Leave the game, and reset the

    Arduino.

    If I put some additional code in it - something like Motor 4 start rumbling, when the left rear tire is loosing grip - will work. But without killing the

    unwanted signals it's pretty much useless. The idea of fazed with the buffering is for my C+-knowledge a few steps too high.

    Thx in advance
    (not native english speaking)
    Tommy


    SNIPPET ->


    void ExampleInternalsPlugin::ExampleInternalsPlugin() : m_hComm(INVALID_HANDLE_VALUE) {
    ...
    }


    void ExampleInternalsPlugin::EnterRealtime()
    {
    // start up timer every time we enter realtime
    WriteToAllExampleOutputFiles( "a", "---ENTERREALTIME---" );
    if ( this->m_hComm != INVALID_HANDLE_VALUE) {
    CloseHandle(this->m_hComm); //close the handle
    this->m_hComm = INVALID_HANDLE_VALUE;
    }
    m_hComm
    = CreateFile("COM3",
    GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    0,
    NULL
    );

    if (this->m_hComm == INVALID_HANDLE_VALUE)
    {
    // some error handling
    }
    }


    void ExampleInternalsPlugin::ExitRealtime()
    {
    WriteToAllExampleOutputFiles( "a", "---EXITREALTIME---" );
    if (m_hComm != INVALID_HANDLE_VALUE) {
    CloseHandle(m_hComm); //close the handle
    m_hComm = INVALID_HANDLE_VALUE;
    }
    }

    ...
    if ( hComm != INVALID_HANDLE_VALUE) {
    if (GetCommState(hComm, &dcb)) {
    dcb.BaudRate = CBR_115200;
    if ( SetCommState(hComm, &dcb) ) {
    bool retVal = WriteFile(hComm, data, 10, &byteswritten, NULL);
    }
    }
    }
    ...​

    <- END SNIPPET
     
  8. Curbfeeler

    Curbfeeler Registered

    Joined:
    Feb 15, 2012
    Messages:
    1
    Likes Received:
    0
    Cool, I actually want to connect my bike trainer to RFactor2. I'll be wanting to read slope data and if the car is pointing up a hill pull on a servo to tighten resistence and if downhill them loosen, etc. I'll be wanting to read the same type of thing (Telemetry data) as you and sending to a Rasperry Pi or Arduino. Ok if I reach out to you as I get started to see if we can pool resources? I am a software dev with 15 years experience.

    Dan
     
  9. tommy42

    tommy42 Registered

    Joined:
    Feb 11, 2015
    Messages:
    7
    Likes Received:
    0
    Hi Dan,

    your bike-trainer-sim sounds very interesting. I've got a Kettler-cycle-trainer with usb-PC-connect on my own. A sprint around the 25km-Nordschleife 2.01 with the heavy ups and downs will be a great workout. So it could be a motivating side-project of my own. In short: I'm on it and we can pool!

    But in my main project, I'm completely stucked. Next I will make a try in the arduino forum. Maybe someone there have experiences in "C++-vs.-Arduino". Until I can fix this, there is no hope to realize the cycle-race-track-sim with an arduino.

    If you will start your project, you should search in the example-plugin for the data of:

    Pos= (x,y,z)
    LocalAccel= (x,y,z)
    UnfilteredSteering= +-%
    Unfiltered Throttle= +%
    Speed= x kph, y mph
    and of course ;-)
    RPM= x

    The POS-Data will help you calculating the slope-angle. A good start to understand the data-ranges, is a simple txt-output of a warmup-lap. ISI got an easy to use example of exporting telemetry-data to txt included in the internal-plugins. You just have to uncomment the relevant lines in the plugin.


    I think you need an additional gamepad to steer your bike virtual around the track.

    Greetz

    Tommy
     

Share This Page