EAL727Capt
Well-known member
Greetings!
For the past two (2) months, I have been attempting to write coding/sketch for a stepper motor to be interfaced with my home cockpit and am having zero success.
I am reaching-out for help as, at this point, I'm at a complete loss as to how to do the coding to get this one indicator to mimic what is happening in X-Plane 11.
I'm using a Teensy 3.2 with a DRV8825 stepper driver and a NEMA 17 stepper motor.
The goal is to operate an OEM flaps indicator gauge from a Boeing 727. There are two (2) gauges on the aircraft an show the flaps positions for each wing, both inboard and outboard.
Right now, I'm just working on the OUTBOARD LEFT indications; once I have a successful sketch, I can add the OUTBOARD RIGHT, INBOARD LEFT and INBOARD RIGHT, all based upon the various X-Plane data refs.
I have the Flight Sim Controls loaded onto my Teensy 3.2 and have become familiar with its operations. I have posted some videos on my YouTube.com channel...
www.youtube.com/eal727capt
Thus far, here is my code:
The number of steps (which I've previously confirmed for each flap setting) are as follows:
0..........0
2..........580
5..........1350
15........1650
20........1800
25........1900
30........2030
40........2400
Way back when, I had seen a similar project used for FSX and the video demonstrated the flaps gauge needle moving on a similar gauge but for a Boeing 737 and am convinced that this can be accomplished for my project.
In my sketch, nothing I've tried moves the stepper motor...not a single step, not a single micro-step, and I'm rapidly approaching a state of total frustration with this.
I could get the stepper to move (using a different sketch) from flaps 0 to flaps 2, to flaps 5, vice versa, but anything above flaps 5 and the stepper continuously spins.
It should be noted that 0 to 2 to 5 happens relatively quickly and from 5 to 15 and above and the indicator slows down...
Again, I have a video on my YouTube channel to demonstrate.
I would certainly appreciate and welcome any suggestions as to what I'm obviously missing here.
I'm new to coding and am trying my best to get it.
Thank you very much in advance.
Jay
For the past two (2) months, I have been attempting to write coding/sketch for a stepper motor to be interfaced with my home cockpit and am having zero success.
I am reaching-out for help as, at this point, I'm at a complete loss as to how to do the coding to get this one indicator to mimic what is happening in X-Plane 11.
I'm using a Teensy 3.2 with a DRV8825 stepper driver and a NEMA 17 stepper motor.
The goal is to operate an OEM flaps indicator gauge from a Boeing 727. There are two (2) gauges on the aircraft an show the flaps positions for each wing, both inboard and outboard.
Right now, I'm just working on the OUTBOARD LEFT indications; once I have a successful sketch, I can add the OUTBOARD RIGHT, INBOARD LEFT and INBOARD RIGHT, all based upon the various X-Plane data refs.
I have the Flight Sim Controls loaded onto my Teensy 3.2 and have become familiar with its operations. I have posted some videos on my YouTube.com channel...
www.youtube.com/eal727capt
Thus far, here is my code:
Code:
/* FLAPS GAUGE T E S T I N G WITH MAP AND RETURN MAP FUNCTIONS
Using Teensy 3.2, DRV8825 stepper driver board and NEMA 17 stepper motor
200 steps/revolution
1/16 micro-stepping
Stepper motor .. 78 teeth
Transmitter.... 78 teeth
*/
#include <AccelStepper.h>
AccelStepper FLAPSobL(1, 14, 15); //1=Library function, 14=Step, 15=Direction Outboard Left flaps position
FlightSimFloat FlapOBleft;
float FlapsOBleft_pos;
const long STEPS_PER_REVOLUTION = 200;
const float STEPS_PER_DEGREE = ((float) STEPS_PER_REVOLUTION) / 360.0;
void setup() {
Serial.begin(9600);
FLAPSobL.setMaxSpeed(3000);
FLAPSobL.setAcceleration(3000);
FlapOBleft = XPlaneRef("sim/flightmodel/parts/flap_def[8]");
}
void loop() {
FlightSim.update();
if (FlapOBleft == 0) { // Flaps 0
return (FlapsOBleft_pos, (0));
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapOBleft <= 2) { // Flaps 2
return (FlapsOBleft_pos, (580));
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapOBleft <= 5) { // Flaps 5
return (FlapsOBleft_pos, (1350));
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapsOBleft_pos <= 15) { // Flaps 15
return map(FlapsOBleft_pos, 5, 15, 1350, 1650);
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapsOBleft_pos <= 20) { // Flaps 20
return map(FlapsOBleft_pos, 15, 20, 1650, 1800);
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapsOBleft_pos <= 25) { // Flaps 25
return map(FlapsOBleft_pos, 20, 25, 1800, 1900);
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
if (FlapsOBleft_pos <= 30) { //Flaps 30
return map(FlapsOBleft_pos, 25, 30, 1900, 2030);
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
}
else {
return map(FlapsOBleft_pos, 30, 40, 2030, 2350);// Flaps 40
FLAPSobL.moveTo(FlapsOBleft_pos);
FLAPSobL.run();
long currentPosition = FLAPSobL.currentPosition();
currentPosition = (currentPosition % STEPS_PER_REVOLUTION + STEPS_PER_REVOLUTION) % STEPS_PER_REVOLUTION; // positive modulo
long targetPosition = (long)(FlapsOBleft_pos * 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;
}
}
}
The number of steps (which I've previously confirmed for each flap setting) are as follows:
0..........0
2..........580
5..........1350
15........1650
20........1800
25........1900
30........2030
40........2400
Way back when, I had seen a similar project used for FSX and the video demonstrated the flaps gauge needle moving on a similar gauge but for a Boeing 737 and am convinced that this can be accomplished for my project.
In my sketch, nothing I've tried moves the stepper motor...not a single step, not a single micro-step, and I'm rapidly approaching a state of total frustration with this.
I could get the stepper to move (using a different sketch) from flaps 0 to flaps 2, to flaps 5, vice versa, but anything above flaps 5 and the stepper continuously spins.
It should be noted that 0 to 2 to 5 happens relatively quickly and from 5 to 15 and above and the indicator slows down...
Again, I have a video on my YouTube channel to demonstrate.
I would certainly appreciate and welcome any suggestions as to what I'm obviously missing here.
I'm new to coding and am trying my best to get it.
Thank you very much in advance.
Jay