Any example code to send Orbiter values to Arduino?

MarcT

New member
Joined
Aug 19, 2013
Messages
2
Reaction score
0
Points
0
Hi folks!

Hoping someone here can help point me to some sample code or the direction to go for what I'm trying to do.

I've been working on a full-scale Gemini space capsule simulator for the last year. Mechanical construction is about half done. All of the switches, dials, etc. are being duplicated. Not sure how I'm going to do the onboard computer yet but that's another story. I've made a joystick reproduction of the one found in the original capsules, and am using an Arduino Leonardo as a joystick simulator to provide those inputs to orbiter. I can also do keyboard emulation to send switch values to the program.

Where I'm having difficulty is in figuring out the best way to send values from Orbiter to the Arduino in order to drive mechanical dials. I've got dials (made using servos) for indicating altitude (during launch/reentry), acceleration, fuel levels, attitude, etc. Didn't want to use electronic MFD displays since those weren't authentic. Anyway, I've made good progress toward building all those instruments and they're controlled by Arduinos. But my weakness is in figuring out how to get the values sent over. I'm assuming I'll be using OrbConnect? Easiest thing for me would be if there is a way to send the values over a Com port since I'm familiar with Arduino serial comms. But I'm not as familiar with Windows programming. I can do VBA (like in Excel) and also C++ (as in Arduinos). I can figure out what I need to do if there is any sample code I can hack.

Has anyone seen anywhere an example of code that gets values from Orbiter and sends them over a serial interface? Really appreciate any advice that anyone can offer. Thanks!

Marc
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
Hello Marc,

I've done something very similar some time ago to connect NASSP to an Arduino-driven DSKY. So this might help.

It is not meant to be a generic class that can be used directly by you. It was highly specialized for the above mentioned project, but the general idea of how to operate Serial (COM) Connection is in there.

The idea behind this Serial class is as following:

  1. It is a kind of 'singleton', so I could get the one and only instance of it from any context via Serial::GetReference().
  2. It has knowledge of the data to be transmitted/received to detect if there is really a need for transmission or if nothing had changed.
  3. Periodically Serial::Transmit() would be called to transmit buffered data to the Arduino (if needed).
  4. Because of (2) Serial::Transmit() can be called in each Timestep. Real transmission will only start if the buffer contains changes.
For you to start, you should first ignore all the 'buffered' things that only make sense in the Apollo AGC/DSKY context (channel_010, channel_011, channel_013,...).
For the connection setup and transmission itself you should find enough hints on how to roll your own code. All the needed The WIN32-API calls (CreateFile, GetCommState, SetCommState, ClearCommError, ReadFile, WriteFile, CloseHandle) are in there.


Feel free to ask if you have questions,
Kuddel
 

Attachments

  • src_sys.zip
    3.9 KB · Views: 71

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
Hi again,

I found a simpler one (without any buffering) that makes it easier to understand the basics -I think.
 

Attachments

  • serial_io.zip
    2.4 KB · Views: 36

kamaz

Unicorn hunter
Addon Developer
Joined
Mar 31, 2012
Messages
2,298
Reaction score
4
Points
0
I'm assuming I'll be using OrbConnect?

If you want to use OrbConnect:

1. Start with this sketch http://arduino.cc/en/Tutorial/TelnetClient

2. Replace

Code:
if (client.connect(server, 10002)) {

with

Code:
if (client.connect(server, 37777)) {

3. Replace loop() with:

Code:
void loop()
{
  if (client.connected()) {
    // Set main engines to 50%
    client.println("SHIP:FOCUS:SetEngineGrpLevel:0:0.5");

    // if there are incoming bytes available 
    // from the server, read them and print them:
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }

  
}

NB the above code is untested, but it should get you started :)

...From another thread:

Connect to TCP port 37777. Send command followed by a newline character.

Orb::Connect will reply in the form <command>=<response> followed by a newline character.

The commands you need are ORB:SimTime and ORB:TimeAccel.

See the Orb::Connect manual for more information (it installs under Doc\OrbConnect).
 
Last edited:
Top