More advice/recommendations requested for flight sim project

EAL727Capt

Well-known member
Greetings, all!

Recently, I've been experimenting and familiarizing myself with the ins and outs of Teensys and the incredible PJRC Flight Sim Controls and am having fun learning something which is still very new to me.

Some background...I'm interfacing old OEM instruments, gauges and indicators for a Boeing 727-200 in X-Plane. I have a few (less than 10) instruments interfaced and the process is slow and on-going.

Currently, I'm attempting to interface a pair of flap gauges and am 'stuck.' These flap gauges have eight (8) settings, 0-degrees, 2-degrees, 5-degrees, 15-degrees, 20-degrees, 25-degrees, 30-degrees and 40-degrees. These represent the various degrees of flaps deployed in the various stages of aircraft operation.

I'm using a Teensy 3.2, DRV8825 stepper drivers and NEMA17 steppers with 92 teeth gearing meshed with synchro transmitters to drive the needles, as I've done this set-up with other instruments I've previously interfaced successfully.

With the sketch I've developed/hacked-up/tweaked (attached), all works well at the 0, 2 and 5-degree settings--the speed and needles move in precise concert with what the sim's gauges show.
When 'Flaps 15' (and beyond) is selected, the stepper motor speeds up and races past the selected setting. On the actual gauge, it slows down.
I'm using the AccelStepper library as I've found this works great (usually) and am now thinking that perhaps I need to MAP my settings/readings instead...which is something I've been trying to avoid.
Another thought I have: Abandon the AccelStepper library and use the Stepper.h library instead.

In my sketch, I've adjusted the speed, acceleration, steps-per-revolution, etc., all without success. In short, I cannot get these motors to slow down and behave!

Am also thinking that I might need to include the actual X-Plane datarefs for each of the eight (8) flap settings but think that this might have something to do with mapping....again, trying to avoid...but will if I have to.
I mention this because during operation, there are two (2) datarefs which caught my attention almost immediately during flap operation. One appears to be a 'target' setting and the other is the 'current' setting (which changes until it matches the 'target' setting.

Flaps 0 = 0.
Flaps 2 = 0.142857
Flaps 5 = 0.285714
Flaps 15 = 0.428571
Flaps 20 = 0.571429
Flaps 25 = 0.714286
Flaps 30 = 0.857143
Flaps 40 = 1.

When Flaps 2 is selected, the dataref entitled "sim/cockpit2/controls/flap_ratio" immediately shows 0.142857 whereas the dataref entitled "sim/cockpit2/controls/flap_handle_desplay_ratio" increases from 0. until it reaches 0.142857. Likewise, when Flaps 15 is selected, the 1st dataref immediately shows 0.428571 and the 2nd dataref increases until that value is reached. I'm thinking I need to incorporate these readings into my sketch.

Code:
//      FLAPS GAUGES     TESTING
//      

//   208000 steps/revolution
//   1/32 micro-stepping


//   Stepper motor.. 92 teeth
//   Transmitter.... 92 teeth


#include <AccelStepper.h>

AccelStepper FLAPSobL(1, 16, 17);  //1=Library function, 16=Step, 17=Dir   Outboard Left flaps position
AccelStepper FLAPSobR(1, 14, 15);  //1=Library function, 14=Step, 15=Dir   Outboard Right flaps position

FlightSimFloat FlapOBleft;
FlightSimFloat FlapOBright;

float FLAPSobL_pos; //   Outboard LEFT
float FLAPSobR_pos; //   Outboard RIGHT

const long STEPS_PER_REVOLUTION = 208000;
const float STEPS_PER_DEGREE = ((float) STEPS_PER_REVOLUTION) / 360.0;

void setup() {
 Serial.begin(9600);
 FLAPSobL.setMaxSpeed(2000);
 FLAPSobL.setAcceleration(500);
 FLAPSobR.setMaxSpeed(2000);
 FLAPSobR.setAcceleration(500);
    
  FlapOBleft = XPlaneRef("sim/flightmodel2/wing/flap2_deg[2]");
  FlapOBright = XPlaneRef("sim/flightmodel2/wing/flap2_deg[3]");    
  }

void loop() {
  FlightSim.update();

  FLAPSobL_pos = FlapOBleft * STEPS_PER_DEGREE;
  FLAPSobL.moveTo(FLAPSobL_pos);
  FLAPSobL.run();
  FLAPSobR_pos = FlapOBright * STEPS_PER_DEGREE;
  FLAPSobR.moveTo(FLAPSobR_pos);
  FLAPSobR.run();
  
  }



I'm anxious to hear the expert's opinions on this latest challenge and if further explanation is required, please let me know.

Stay well and thank you in advance.

Jay
 
Last edited:
Back
Top