My Teensy Aircraft Instrument Interface

Status
Not open for further replies.

raflyer

Well-known member
Well I can call this project complete now. In the pic below you will see my RMI interface which I use to drive my real RMI's and also my compass card on my HSI. Specs, Teensy 3.2, 6ea Pololu drv8825 stepper drivers set for 1/32 micro stepping. Servo city gears and hardware, ebay special 1.8deg 12-24v NEMA14 steppers. Optical sensors for setting home/0 position at start up. 26vac 400hz synchros which output the angle signal used by the RMI I have a few flights on it now and works great so i'm happy as a flying pig.
 

Attachments

  • RMI Interface.jpg
    RMI Interface.jpg
    154.4 KB · Views: 1,402
Wow, cool! So the white gear actually are analog gauges emulation?
Time ago I helped a friend of mine to create an analog simulation of a old analog altimeter, it has two arrows so was not so easy. At the end I dismantled a chinese clock and hacked with a motor controlled by I2C tangent sensor, I've used a magnet and hall sensor as well for the 0.
Bring to life analog gauges with digital tecnology it's a real challenge for an hobbist so you have all my attention! I will like to see a video of this...

A question, the blue/iron cilinders are actually encoders?
 
The blue cylinders are synchros

https://en.wikipedia.org/wiki/Synchro
https://en.wikipedia.org/wiki/Resolver_(electrical)

A really clever way to use angles in the days before digital computing was a thing and still something of a gold standard for angle sensing in aerospace and marine use. Have been wondering if a T3 plus a amplifier would be able to synthesis the 400hz ref and then adjust the gain of inverting and non inverting amplfiers to drive them directly. They need a bit of current normally, so require a robust electrical design.

Were the Synchros a salvage find, or brought new?
 
A synchro/resolver board for Teensy/Arduino would be a useful thing to have for us Sim builders, does anyone know of a low cost circuit for this? Seems like something I should try.
 
Wow, good to hear, Rob. I'm impressed. Seems you've made your way through the software jungle.

Kudos.

Thank you! Had some good help. :) I am having one issue that I haven't gotten figured out yet. The dreaded 0-359 or 359-0 crossing point of the compass card. When it crosses over this point, the stepper turns a full turn the opposite direction to get to either 359 or zero instead continuing around in the normal step by step way.

Rob
 
A synchro/resolver board for Teensy/Arduino would be a useful thing to have for us Sim builders, does anyone know of a low cost circuit for this? Seems like something I should try.

Myself and a few others would PAY for that! 10bit accuracy is plenty.
 
The synchros are used ebay finds. About 5 bucks each. They output the 3 phase signal that my aircraft instruments need to function correctly. I have 10 right now and need about 10-12 more to finish my cockpit setup. Here is a video I took a couple weeks ago, still tons of work to do but it is getting there.
 
I've been eyeing Resolver driver designs (2 channel vs syncro 3) and so far only way I've seen to easily do it is with a Teensy per channel, which seems a bit daft. One of those annoying 'I'm sure there is a clever way to do this' but the need to produce inverted phases has blocked my efforts so far.

What are you using to produce the 400hz reference? Fun way would be an aircraft APU, but stoking one of those up for every sim flight might crimp the fun a touch.
 
LOL That would be sweet to fire up a real APU but the neighbors would hate me. :) I am using an industrial 26Vac 400Hz power supply, For the 115Vac needs I am just using a step up transformer. The nice thing about all this is that other than the lighting, it is all designed to work on very very small current use.
 
For the 360 -> 0 transition on the compass, there's a simple solution. There are always two ways to get from a current position to a target position: clockwise (positive) and counterclockwise (negative). Every time you have a difference between the target position and the actual position, calculate BOTH angles. So, if your target position is 10 degrees and your current position is 350 degrees, a counterclockwise rotation (negative) would take 340 degrees. A clockwise rotation would take only 20 degrees, as 10 deg = 370 deg and 370-350=20.

Let's see if I can draft the algorithm here (just typing blindly, haven't compiled):

Code:
int cwAngle;
int ccwAngle;
if (target > currentPosition) {
  cwAngle = target-currentPosition;
  ccwAngle = currentPosition-target+360;
} else {
  ccwAngle = currentPosition-target;
  cwAngle = target-currentPosition+360;
}

if (cwAngle < ccwAngle) {
  // rotate cwAngle degrees clockwise
  ...
} else {
  // rotate ccwAngle degrees counterclockwise
  ...
}

Examples:

currentPositiontargetcwAngleccwAngle
105040 [used]320
350515 [used]345
10200190170 [used]
27018027090 [used]

Hope that helps...
 
Last edited:
I tried this code but it didn't work, It just kept turning. The part that is confusing me is how the accel stepper controls the stepper. If I command -8000 as a position, it goes to 90deg, If i put 8000, it goes back to zero, 8000 again, goes to 270 The second code I posted works perfect as far as tracking with the Sim except the zero - 359 line. Frustrating as I feel i'm close to understanding it.

Test code Just the stepper part in the loop,

Code:
currentPosition = currentPosition / 88.889; //convert steps(32000) to degrees(360)
  if (magHdg > currentPosition) {
    cwAngle = magHdg - currentPosition;
    ccwAngle = currentPosition - magHdg + 360;
  } else {
    ccwAngle = currentPosition - magHdg;
    cwAngle = currentPosition + 360;
  }
  if (cwAngle < ccwAngle) {
    stepper4.move(+88.889); //88.889 steps = 1 deg
    stepper4.run();  //ToPosition
  } else {
    stepper4.move(-88.889);
    stepper4.run();  //ToPosition
    }
}


Code that works well other than the 0-359 crossing

Code:
cur_pos4 = magHdg * 88.889;
  stepper4.moveTo(cur_pos4);
  stepper4.run();  //ToPosition
 
Rob, some comments:


  1. Your code doesn't show how and where the currentPosition variable gets its value from. However, the first line of the code above converts currentPosition from steps to degrees. and overwrites the old value. If you don't reload that value in steps somewhere into the currentPosition variable, on the next pass you would divide the value (already in degrees) by 88.889 again, producing a bogus value.
  2. The second line that calculates cwAngle is wrong in your code. Instead of cwAngle = currentPosition + 360, it should be cwAngle = magHdg - currentPosition + 360.

If my analysis is correct, things would work like this

Code:
currentPosition = stepper.currentPosition() / 88.889 // get current stepper position and convert it to degrees
  if (magHdg > currentPosition) {
    cwAngle = magHdg - currentPosition;
    ccwAngle = currentPosition - magHdg + 360;
  } else {
    ccwAngle = currentPosition - magHdg;
    cwAngle = magHdg - currentPosition + 360;
  }
  if (cwAngle < ccwAngle) {
    stepper4.move((long) (cwAngle * 88.889)); //88.889 steps = 1 deg
    stepper4.run();  //ToPosition
  } else {
    stepper4.move((long) (-ccwAngle *88.889));
    stepper4.run();  //ToPosition
    }

Furthermore, we can get rid of all the floating point arithmetics if we just do all the calculations in steps instead of in degrees:

Code:
long currentPosition = stepper.currentPosition();
long targetPosition = (long) (magHdg * 88.889); // 1 deg = 88.889 steps - but is the magHdg range really 0-359?
long cwSteps;
long ccwSteps;
  if (targetPosition > currentPosition) {
    cwSteps = targetPosition - currentPosition;
    ccwSteps = currentPosition - targetPosition + 320000;
  } else {
    ccwSteps = currentPosition - targetPosition;
    cwSteps = targetPosition - currentPosition + 360;
  }
  if (cwAngle < ccwAngle) {
    stepper4.move(cwAngle);
  } else {
    stepper4.move(-ccwAngle);
  }
  stepper4.run();  //ToPosition

Can you give it a try?

Jorg
 
Thanks Jorg! I will try tomorrow as it is late here now. Just so you know where my thought process was, currentPosition is in the accellstepper library which gives back the current step position of the stepper from the 0 ref point. That is what I thought you meant therefore I went down that road. :) I thought I needed to convert back to degrees to play well with the the magHdg data. In my head I was trying to figure a way to use steps all along which is what your 2nd sketch does.

To answer your question does it really need 0-359? Yes, it is driving the compass card or Azimuth dial as some call it on the HSI and RMI and they both must turn 360 degrees. I also need the code for the RMI needles as they have the same behavior. So to make the RMI gauge work I needed 4 synchro inputs capable of 360 rotation with .5deg accuracy and smooth movement. This setup accomplish this mechanically perfect, now to fine tune the software side. :) For anyone interested, The RMI has a compass card and 2 needles and is used to show the relative bearing to a tuned navigation radio aid relative to the path of the aircraft. Amazingly complex instrument for a small 3" gauge. :)
Rob
 
I just tried the code and the stepper never moves. Tried tweaking the section in this part to no avail, i tried all 3 Sould it be cwSteps and ccwSteps instead?

Code:
if (cwAngle < ccwAngle) {
    stepper4.move((long) (cwAngle * 88.889)); //88.889 steps = 1 deg
    stepper4.run();  //ToPosition
  } else {
    stepper4.move((long) (-ccwAngle *88.889));
    stepper4.run();  //ToPosition

Code:
 if (cwAngle < ccwAngle) {
    stepper4.move(cwAngle);
  } else {
    stepper4.move(-ccwAngle);
  }
  stepper4.run();  //ToPosition

Code:
if (cwAngle < ccwAngle) {
    stepper4.move(cwAngle * 88.889); //88.889 steps = 1 deg
    stepper4.run();  //ToPosition
  } else {
    stepper4.move(-ccwAngle * 88.889);
    stepper4.run();  //ToPosition
    }
 
Last edited:
Sorry, Rob, first there were several typing error on my behalf.

It was late and I didn't look close. Yes, it should have been cwSteps and ccwSteps. The code shouldn't even have compiled, as cwAngle and ccwAngle weren't declared. Did you check if there were any error messages in Arduino? Furthermore, the constants used to compensate negative values were wrong (320000 and 360 instead of 32000).

The fact that we're just looking at snippets of your code and not at the whole sketch complicates things. We might be missing something here and right now, I can't tell what it is. Can you post ALL of your sketch?

The other thing is that I really encourage you to try to understand what's happening. Add some debug statements with Serial.print and watch what happens. Output the current position and the target position. Converting from floating point variables to integer (long) also isn't always trivial. Try to see what you are actually sending to the stepper.

It doesn't make any difference if you put the stepper4.run() statement in both branches of an if-then-else statement or just unconditionally execute it outside of the if-then-else, but it's easier to read and maintain if you have it only once.

Code:
long currentPosition = stepper.currentPosition();
long targetPosition = (long) (magHdg * 88.889); // 1 deg = 88.889 steps - but is the magHdg range really 0-359?
long cwSteps;
long ccwSteps;
if (targetPosition > currentPosition) {
  cwSteps = targetPosition - currentPosition;
  ccwSteps = currentPosition - targetPosition + 32000;
} else {
  ccwSteps = currentPosition - targetPosition;
  cwSteps = targetPosition - currentPosition + 32000;
}
Serial.print("Current position in steps:");
Serial.println(currentPosition);
Serial.print("Target position in degrees: ");
Serial.print(magHdg);
Serial.print(", in steps: ");
Serial.println(targetPosition);
Serial.print("Steps for rotation: clockwise: ");
Serial.print(cwSteps);
Serial.print(", counterclockwise: ");
Serial.println(ccwSteps);
if (cwSteps < ccwSteps) {
    Serial.print("Moving clockwise, number of steps: ");
    Serial.println(cwSteps);
    stepper4.move(cwSteps);
} else {
    Serial.print("Moving counterclockwise, number of steps: ");
    Serial.println(ccwSteps);
    stepper4.move(-ccwSteps);
}
stepper4.run();  //ToPosition
 
Myself and a few others would PAY for that! 10bit accuracy is plenty.

Roger that, I've got some trim indicators that should take in synchro signals but I'm directly driving the internal motor instead.

Do you need synchro transmitters or receivers? (or both?) Any need for resolver transmit/receive?

By the way, if you need any ARINC 429 (transmit or receive), I've got a teensy board for that so get in touch if needed.
 
Aaaand, we have another problem. Thinking about it, the negative and positive moves will take the currentPosition out of the valid range when the compass crosses zero. Easy to see: start with a zero position and move to 350. It will start a 10 degrees left turn and currentPosition gets negative. So, we must put that variable into a valid range (0-32000) when it gets above or below the bounds.

One additional line gets this done (check http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain) to see why. After this, currentPosition will always be in the range 0-32000:

Code:
long currentPosition = stepper.currentPosition();
currentPosition = (currentPosition % 32000 + 32000) % 32000; // positive modulo, see http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain
long targetPosition = (long) (magHdg * 88.889); // 1 deg = 88.889 steps - but is the magHdg range really 0-359?
...

Try it with and without this patch to see the difference.
 
Jorg,
Thank you, It was late for me as well LOL I will try tonight and report back. Learning is always rewarding :)

Robz
 
Jorg,
Here is my code with your latest changes. Still no movement. Serial Print reported the magHdg at 47 and current position at 0 Target position also 0

Code:
#include <AccelStepper.h>

const int homeButton = 0;
const int homeButton2 = 1;
const int homeButton3 = 2;
const int homeButton4 = 3;

byte hBval;
byte hB2val;
byte hB3val;
byte hB4val;

AccelStepper stepper(1, 21, 20);  //21=Step 20=Dir #31
AccelStepper stepper2(1, 19, 18); //19=Step 18=Dir #32
AccelStepper stepper3(1, 17, 16); //17=Step 16=Dir #33
AccelStepper stepper4(1, 15, 14); //15=Step 14=Dir #34

FlightSimFloat nav1;
FlightSimFloat nav2;
FlightSimFloat adf1;
FlightSimFloat magHdg;

float cur_pos;
float cur_pos2;
float cur_pos3;
float cur_pos4;

long currentPosition = stepper.currentPosition();

long targetPosition = (long) (magHdg * 88.889); // 1 deg = 88.889 steps - but is the magHdg range really 0-359?
long cwSteps;
long ccwSteps;

void setup() {
  Serial.begin(38400);

  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(3000);
  stepper2.setMaxSpeed(3000);
  stepper2.setAcceleration(3000);
  stepper3.setMaxSpeed(3000);
  stepper3.setAcceleration(3000);
  stepper4.setMaxSpeed(2500);
  stepper4.setAcceleration(3000);

  nav1    = XPlaneRef("sim/cockpit2/radios/indicators/nav1_relative_bearing_deg");
  nav2    = XPlaneRef("sim/cockpit2/radios/indicators/nav2_relative_bearing_deg");
  adf1    = XPlaneRef("sim/cockpit2/radios/indicators/adf1_relative_bearing_deg");
  magHdg  = XPlaneRef("sim/cockpit2/gauges/indicators/heading_electric_deg_mag_pilot");

  pinMode(homeButton, INPUT_PULLUP);
  pinMode(homeButton2, INPUT_PULLUP);
  pinMode(homeButton3, INPUT_PULLUP);
  pinMode(homeButton4, INPUT_PULLUP);

  stepperHome(); //runs routine to home motors
}

void loop() {
  FlightSim.update();

  cur_pos = nav1 * 88.889;
  stepper.moveTo(cur_pos);
  stepper.run();  //ToPosition

  cur_pos2 = nav2 * 88.889;
  stepper2.moveTo(cur_pos2);
  stepper2.run();  //ToPosition

  cur_pos3 = adf1 * -88.889;
  stepper3.moveTo(cur_pos3);
  stepper3.run();  //ToPosition
  
  currentPosition = (currentPosition % 32000 + 32000) % 32000; // positive modulo, see http://stackoverflow.com/questions/1082917/mod-of-negative-number-is-melting-my-brain
  if (targetPosition > currentPosition) {
    cwSteps = targetPosition - currentPosition;
    ccwSteps = currentPosition - targetPosition + 32000;
  } else {
    ccwSteps = currentPosition - targetPosition;
    cwSteps = targetPosition - currentPosition + 32000;
  }
  Serial.print("Current position in steps:");
  Serial.println(currentPosition);
  Serial.print("Target position in degrees: ");
  Serial.print(magHdg);
  Serial.print(", in steps: ");
  Serial.println(targetPosition);
  Serial.print("Steps for rotation: clockwise: ");
  Serial.print(cwSteps);
  Serial.print(", counterclockwise: ");
  Serial.println(ccwSteps);
  if (cwSteps < ccwSteps) {
    Serial.print("Moving clockwise, number of steps: ");
    Serial.println(cwSteps);
    stepper4.move(cwSteps);
  } else {
    Serial.print("Moving counterclockwise, number of steps: ");
    Serial.println(ccwSteps);
    stepper4.move(-ccwSteps);
  }
  stepper4.run();  //ToPositio

}

void stepperHome() { //this routine should run the motor
  delay(100);
  hBval = digitalRead(homeButton);
  while (hBval == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper.moveTo(33000);
    stepper.run();
    hBval = digitalRead(homeButton);
  }
  stepper.setCurrentPosition(0); //should set motor position to zero and go back to main routine

  delay(50);
  hB2val = digitalRead(homeButton2);
  while (hB2val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper2.moveTo(33000);
    stepper2.run();
    hB2val = digitalRead(homeButton2);

  }
  stepper2.setCurrentPosition(0); //should set motor position to zero and go back to main routine

  delay(50);
  hB3val = digitalRead(homeButton3);
  while (hB3val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper3.moveTo(33000);
    stepper3.run();
    hB3val = digitalRead(homeButton3);

  }
  stepper3.setCurrentPosition(0); //should set motor position to zero and go back to main routine

  delay(50);
  hB4val = digitalRead(homeButton4);
  while (hB4val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper4.moveTo(33000);
    stepper4.run();
    hB4val = digitalRead(homeButton4);
  }
  stepper4.setCurrentPosition(0); //should set motor position to zero and go back to main routine

}
 
See, that's what I said about looking at the whole sketch. This definitely won't move. It's about local and global variables. Maybe, you don't know that concept yet.

Some variables need to be declared GLOBALLY, as you need to maintain their values over longer periods of time or read and write them from different locations in your program. All FlightSimFloats (nav1, nav2, adf1 and magHdg) are of this type, as well as the AccelSteppers (stepper1-4). That means, you can read and write them from anywhere within your program.

In contrast, the variables currentPosition, targetPosition, cwSteps and ccwSteps are NOT of this type. You only need them for a brief period of time, when you calculate how much the stepper should move. So, you actually can DECLARE them right in the middle of your loop() function, which makes them LOCAL within this scope. If you try to read or write them in the setup() function or from within stepperHome(), your compiler will report them as unknown there.

Check here for further explanations: http://ftp.tuwien.ac.at/languages/c/programming-bbrown/c_046.htm

Now, when I posted that first sketch, my idea was that those four local variables are declared and used within the loop() function. That would update them on every loop pass. In your current sketch, currentPosition and targetPosition are declared globally and set only once, when the program starts. Never again. That won't move anything.

Actually, you could do the same with some of the other variables you use as well: hBval, hB2val, hB3val and hB4val, as well as cur_pos, cur_pos2, cur_pos3 and cur_pos4. I'll leave it as an exercise for you.

Another suggestion is to substitute the fixed numbers by declared constants. Makes your code more readable and easier to maintain. And, of course, instead of

Code:
long currentPosition = stepper.currentPosition();

it must be

Code:
long currentPosition = stepper4.currentPosition();

So, here's the modified sketch (and, this time I've compiled it, so at least syntactically it's correct).

Ah, another question: My son just asked "How much did this guy spend on parts for his simulator until now?" Actually, I'd like to know as well. :)

Jorg

Code:
#include <AccelStepper.h>


const int homeButton = 0;
const int homeButton2 = 1;
const int homeButton3 = 2;
const int homeButton4 = 3;


byte hBval;
byte hB2val;
byte hB3val;
byte hB4val;


AccelStepper stepper(1, 21, 20);  //21=Step 20=Dir #31
AccelStepper stepper2(1, 19, 18); //19=Step 18=Dir #32
AccelStepper stepper3(1, 17, 16); //17=Step 16=Dir #33
AccelStepper stepper4(1, 15, 14); //15=Step 14=Dir #34


FlightSimFloat nav1;
FlightSimFloat nav2;
FlightSimFloat adf1;
FlightSimFloat magHdg;


float cur_pos;
float cur_pos2;
float cur_pos3;
float cur_pos4;


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


void setup() {
  Serial.begin(38400);
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(3000);
  stepper2.setMaxSpeed(3000);
  stepper2.setAcceleration(3000);
  stepper3.setMaxSpeed(3000);
  stepper3.setAcceleration(3000);
  stepper4.setMaxSpeed(2500);
  stepper4.setAcceleration(3000);


  nav1    = XPlaneRef("sim/cockpit2/radios/indicators/nav1_relative_bearing_deg");
  nav2    = XPlaneRef("sim/cockpit2/radios/indicators/nav2_relative_bearing_deg");
  adf1    = XPlaneRef("sim/cockpit2/radios/indicators/adf1_relative_bearing_deg");
  magHdg  = XPlaneRef("sim/cockpit2/gauges/indicators/heading_electric_deg_mag_pilot");


  pinMode(homeButton, INPUT_PULLUP);
  pinMode(homeButton2, INPUT_PULLUP);
  pinMode(homeButton3, INPUT_PULLUP);
  pinMode(homeButton4, INPUT_PULLUP);


  stepperHome(); //runs routine to home motors
}


void loop() {
  FlightSim.update();


  cur_pos = nav1 * STEPS_PER_DEGREE;
  stepper.moveTo(cur_pos);
  stepper.run();  //ToPosition


  cur_pos2 = nav2 * STEPS_PER_DEGREE;
  stepper2.moveTo(cur_pos2);
  stepper2.run();  //ToPosition


  cur_pos3 = adf1 * -STEPS_PER_DEGREE;
  stepper3.moveTo(cur_pos3);
  stepper3.run();  //ToPosition


  long currentPosition = stepper4.currentPosition();
  currentPosition = (currentPosition % STEPS_PER_REVOLUTION + STEPS_PER_REVOLUTION) % STEPS_PER_REVOLUTION; // positive modulo
  long targetPosition = (long) (magHdg * STEPS_PER_DEGREE); 


  long cwSteps;
  long ccwSteps;
  if (targetPosition > currentPosition) {
    cwSteps = targetPosition - currentPosition;
    ccwSteps = currentPosition - targetPosition + STEPS_PER_REVOLUTION;
  } else {
    ccwSteps = currentPosition - targetPosition;
    cwSteps = targetPosition - currentPosition + STEPS_PER_REVOLUTION;
  }
  Serial.print("Current position in steps:");
  Serial.println(currentPosition);
  Serial.print("Target position in degrees: ");
  Serial.print(magHdg);
  Serial.print(", in steps: ");
  Serial.println(targetPosition);
  Serial.print("Steps for rotation: clockwise: ");
  Serial.print(cwSteps);
  Serial.print(", counterclockwise: ");
  Serial.println(ccwSteps);
  if (cwSteps < ccwSteps) {
    Serial.print("Moving clockwise, number of steps: ");
    Serial.println(cwSteps);
    stepper4.move(cwSteps);
  } else {
    Serial.print("Moving counterclockwise, number of steps: ");
    Serial.println(ccwSteps);
    stepper4.move(-ccwSteps);
  }
  stepper4.run();  


}


void stepperHome() { //this routine should run the motor
  delay(100);
  hBval = digitalRead(homeButton);
  while (hBval == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper.moveTo(33000);
    stepper.run();
    hBval = digitalRead(homeButton);
  }
  stepper.setCurrentPosition(0); //should set motor position to zero and go back to main routine


  delay(50);
  hB2val = digitalRead(homeButton2);
  while (hB2val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper2.moveTo(33000);
    stepper2.run();
    hB2val = digitalRead(homeButton2);


  }
  stepper2.setCurrentPosition(0); //should set motor position to zero and go back to main routine


  delay(50);
  hB3val = digitalRead(homeButton3);
  while (hB3val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper3.moveTo(33000);
    stepper3.run();
    hB3val = digitalRead(homeButton3);


  }
  stepper3.setCurrentPosition(0); //should set motor position to zero and go back to main routine


  delay(50);
  hB4val = digitalRead(homeButton4);
  while (hB4val == LOW)
  {
    //backwards slowly till it hits the switch and stops
    stepper4.moveTo(33000);
    stepper4.run();
    hB4val = digitalRead(homeButton4);
  }
  stepper4.setCurrentPosition(0); //should set motor position to zero and go back to main routine
}
 
Ah, another question: My son just asked "How much did this guy spend on parts for his simulator until now?" Actually, I'd like to know as well.

Good question, ;) I have around 1000.00 in the insrtuments so far. Probably 2500.00 total in the Sim. I have had some generous donations for which I am most grateful for!

I just tried the code, it worked! One caveat though, It turns to slow. It is ok if using standard turn rates in the air but when on the ground and more tight turns, it lags behind.
Thank for the link on the global vs local variables. I am familiar with the terminology and use in another programming language similar to C but not in arduino. This has been another good learning lesson so far. Thank you again. :)
Rob
 
That's what I was about to suggest, but you were faster than I :).

I have another exercise for you: right now, on startup the four instruments zero one after the other. First NAV1, then NAV2, then ADF then the compass. It's very easy to make them rotate at the same time and stop on zero. Try figuring out how.
 
Status
Not open for further replies.
Back
Top