Welcome to Cockpitbuilders.com. Please login or sign up.

May 01, 2024, 01:21:33 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
194 Guests, 1 User
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,641
  • Total Topics: 7,853
  • Online today: 222
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 1
Guests: 194
Total: 195

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

Real RMI Interface

Started by 727737Nut, September 24, 2015, 07:15:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

727737Nut

I haven't shown much of my interface projects for the 732 Sim so here you go. Started this this evening. It will drive the VOR1, VOR2, and ADF needles of the real RMI's i am using.  The steppers will be driven by DRV8825's controlled by a Teensy 3.2. 

The Heading input for the compass card is already in use and will tap into those signal wires.  So it takes 4 Synchro inputs to drive the gauge.  Actually 5 if you wanted ADF 2.

The hardware is all from servo city except the steppers and synchro's.  Ebay specials there. :) 

I am using this method also for the rest of the synchro driven instruments.

Feel free to ask if you have any questions.

Rob
737 Junkie

mickc

Awesome Rob!

Have done anything with the code yet?

I have an -800 series RMI that I converted to steppers (they don't run synchros in these, they are all digital) 
SIOC cant keep up with it very well, so I am converting to Arduino & X-board stepper drivers.  Yet to tackle the coding :)


727737Nut

Here is my code running some steppers for my ADI and Altimeter.  RMI will be similar.  The way X-plane set up it's datarefs, the RMI will be a breeze.  Dont even need to wire up the VOR ADF sw. 

Quote// Code for Course Dev Bar and GS + GS Flag on HSI, and VSI, Airspeed, Egt Gauge
#include <Servo.h>
#include <NonLinearGauge.h>
#include <AccelStepper.h>

const int homeButton = 11;
const int ledPin = 13;
const int PitchFD = A14;

byte hBval;
int val = 0;

AccelStepper stepper1(1, 0, 1);
AccelStepper stepper2(1, 6, 5);
AccelStepper stepper3(1, 2, 3);

// create servo object to control servo's
Servo airspeedServo;
Servo pitchfdServo;
Servo radioAltServo;
Servo myservo; // Coarse Altitude output

// Teensy specific variables
FlightSimFloat asp; //Air Speed gauge
FlightSimFloat ra; //Radio Altitude
FlightSimInteger toFrom;
FlightSimFloat adiroll;
FlightSimFloat adipitch;
FlightSimFloat FdPitch;
FlightSimInteger batt;

//FlightSimFloat gsFlag;
FlightSimFloat crsBar;  //-2.0 to 2.0 2 dot deflection
FlightSimFloat gsBar;  //-2.0 to 2.0 2 dot deflection
FlightSimFloat egt1; // in degrees celcius
FlightSimFloat Altitude;  //Alitude in Feet MSL
// Nonlinear Gauge setup for servo's
float raSet[] = {0, 500, 700, 1000, 1200, 1500, 2000, 2500, 2600}; //Gauge Face position
float raDeg[] = {35, 66, 75, 86, 92, 98, 106, 113, 118}; //Servo degrees
float aspFPM[] = {0, 60, 107, 164, 184, 205, 255, 357, 403}; //Gauge Face position
float aspDeg[] = {27, 27, 47, 72, 81, 90, 112, 158, 180}; //Servo degrees

NonLinearGauge airspeed {9, aspDeg, aspFPM};
NonLinearGauge radioAlt {9, raDeg, raSet};

#define CourseDeviation 10
#define GsDeviation 9
//#define Egt1Gauge 3

float cur_pos; // For stepper ADI Roll
float cur_pos2; // For stepper ADI Pitch
float cur_pos3; // Altimeter stepper

// setup runs once
void setup() {
  analogWriteResolution(12);
  setupCourseDeviation();
  setupGsDeviation();
  //setupEgt1Gauge();
  airspeedServo.attach(4);
  pitchfdServo.attach(20);
  radioAltServo.attach(23);
  myservo.attach(21); 

  stepper1.setMaxSpeed(700);
  stepper1.setAcceleration(700);
  stepper2.setMaxSpeed(1000);
  stepper2.setAcceleration(1000);
  stepper3.setMaxSpeed(500);
  stepper3.setAcceleration(300);

  toFrom      = XPlaneRef("sim/cockpit2/radios/indicators/nav1_flag_from_to_pilot"); //Nav-To-From indication, nav1, pilot, 0 is flag, 1 is to, 2 is from."
  asp         = XPlaneRef("sim/cockpit2/gauges/indicators/airspeed_kts_pilot");
  asp         = constrain(asp, 60, 400);
  adiroll     = XPlaneRef("sim/cockpit2/gauges/indicators/roll_electric_deg_pilot");
  adipitch    = XPlaneRef("sim/cockpit2/gauges/indicators/pitch_electric_deg_pilot");
  batt        = XPlaneRef("sim/cockpit2/electrical/battery_on[0]");
  Altitude    = XPlaneRef("sim/cockpit2/gauges/indicators/altitude_ft_pilot");
  FdPitch     = XPlaneRef("sim/cockpit2/autopilot/flight_director_pitch_deg");
  ra          = XPlaneRef("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot");
  pinMode(5, OUTPUT);
  //pinMode(19, OUTPUT);
  //pinMode(PitchFD, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(homeButton, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  stepperHome(); //runs routine to home motor

}

// loop runs repetitively, as long as power is on
void loop() {
  FlightSim.update(); // causes X-Plane's changes to be received
     
  cur_pos = adiroll * 13.33;
  stepper1.moveTo(cur_pos);
  stepper1.run();  //ToPosition

  cur_pos2 = adipitch * -40;
  stepper2.moveTo(cur_pos2);
   stepper2.run();  //ToPosition

  cur_pos3 = Altitude * -3.549; //-3.551
  stepper3.moveTo(cur_pos3);
  stepper3.run();  //ToPosition

  ra = constrain(ra, 0 , 2600);
 
  airspeedServo.write(airspeed.getAngle(asp));
  radioAltServo.write(radioAlt.getAngle(ra));
 
  val = Altitude;
  val = map(val, 0, 34000, 85, 26);     // 42000 lue between 0 and 180)
  val = constrain(val, 20 , 85 );
  myservo.write(val);                  // sets the servo position according to the scaled value

 
  int val = FdPitch - adipitch;
  val = map(val, -10, 10, 85, 130);
  val = constrain(val, 80, 140);
  pitchfdServo.write(val);
 

  updateCourseDeviation();
  updateGsDeviation();
  //updateEgt1Gauge();
}

    void setupCourseDeviation() {
    crsBar = XPlaneRef("sim/cockpit/radios/nav1_hdef_dot");
    pinMode(CourseDeviation, OUTPUT);  // PWM out
  }

  void updateCourseDeviation() {
    // crsBar -2.0 to 2.0 2 dot deflection
    int dev = (crsBar * 127); // dev = Deviation of course bar
    dev = map(dev, -254, 254, 0, 4095);
    analogWrite(CourseDeviation, dev);
  }

  void setupGsDeviation() {
    gsBar = XPlaneRef("sim/cockpit/radios/nav1_vdef_dot");
    pinMode(GsDeviation, OUTPUT);  // PWM out
  }

  void updateGsDeviation() {
    // crsBar -2.0 to 2.0 2 dot deflection
    int gsdev = (gsBar * 127); // dev = Deviation of course bar
    gsdev = map(gsdev, -254, 254, 0, 4095);
    analogWrite(GsDeviation, gsdev);
  }
   

   void stepperHome() { //this routine should run the motor
    hBval = digitalRead(homeButton);
    while (hBval == LOW)
    {
      //backwards slowly till it hits the switch and stops
      stepper1.moveTo(-2600);
      stepper1.run();
      digitalWrite(ledPin, HIGH); //indicates it's doing something
      hBval = digitalRead(homeButton);
      //      Serial.print("HomeButton is");
      //      Serial.println(hBval);
    }
    digitalWrite(ledPin, LOW); //indicates it's doing something
    stepper1.setCurrentPosition(0); //should set motor position to zero and go back to main routine
    //    Serial.print("Done with stepper Home");
  }



//void setupEgt1Gauge() {
//  egt1 = XPlaneRef("sim/cockpit2/engine/indicators/EGT_deg_C[0]");
//  pinMode(Egt1Gauge, OUTPUT);
//}

//void updateEgt1Gauge() {
//  int i;
//  i = (int) egt1;
//  i = map(i, 0, 600, 0, 3200);
//  analogWrite(Egt1Gauge, i);
//}









737 Junkie

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate