Jump to content

Recommended Posts

Posted

Hey guys,

 

for my Altimeter in the Hornet I need a stepper to drive the needle in front - I also found code but my question is how I can toggle and set up a endstop with a hall sensor or any other sensor so the code knows where 0 is…. Does anyone have an example for that?

 

 

thanks in advance 🙂 

Posted
8 hours ago, lesthegrngo said:

I used this site to show me how to do mine, remembering that you have to modify the X27 stepper by cutting off the little rotation limit pin - simple enough

Look for the part that says 'IR Positioning sensor'

https://realsimcontrol.com/io_step.html

Cheers

 

Les

Hey thanks for the answer. The wiring isn‘t the problem - but the code to implement into DCS BIOS - can I just use normal arduino code for „zeroing“? Is there a special way to get it work with DCS BIOS?

 

thanks 🙂

Posted

Hi, the site was unavailable to me yesterday, sorry for the delay - this is the sketch that is working with the IR sensor

#define DCSBIOS_IRQ_SERIAL

//#define DCSBIOS_RS485_SLAVE 49
//#define TXENABLE_PIN 2

#include <AccelStepper.h>
#include "DcsBios.h"

#include <Wire.h>




struct StepperConfig {
  unsigned int maxSteps;
  unsigned int acceleration;
  unsigned int maxSpeed;
};


class Vid29Stepper : public DcsBios::Int16Buffer {
  private:
    AccelStepper& stepper;
    StepperConfig& stepperConfig;
    inline bool zeroDetected() {
      return digitalRead(irDetectorPin) == 1;
    }
    unsigned int (*map_function)(unsigned int);
    unsigned char initState;
    long currentStepperPosition;
    long lastAccelStepperPosition;
    unsigned char irDetectorPin;
    long zeroOffset;
    bool movingForward;
    bool lastZeroDetectState;

    long normalizeStepperPosition(long pos) {
      if (pos < 0) return pos + stepperConfig.maxSteps;
      if (pos >= stepperConfig.maxSteps) return pos - stepperConfig.maxSteps;
      return pos;
    }

    void updateCurrentStepperPosition() {
      // adjust currentStepperPosition to include the distance our stepper motor
      // was moved since we last updated it
      long movementSinceLastUpdate = stepper.currentPosition() - lastAccelStepperPosition;
      currentStepperPosition = normalizeStepperPosition(currentStepperPosition + movementSinceLastUpdate);
      lastAccelStepperPosition = stepper.currentPosition();
    }
  public:
    Vid29Stepper(unsigned int address,
                 AccelStepper& stepper,
                 StepperConfig& stepperConfig,
                 unsigned char irDetectorPin,
                 long zeroOffset, unsigned int (*map_function)(unsigned int)): Int16Buffer(address),
      stepper(stepper),
      stepperConfig(stepperConfig),
      irDetectorPin(irDetectorPin),
      zeroOffset(zeroOffset),
      map_function(map_function),
      initState(0),
      currentStepperPosition(0),
      lastAccelStepperPosition(0)
    {
    }

    virtual void loop() {

      if (initState == 0) { // not initialized yet
        pinMode(irDetectorPin, INPUT);
        stepper.setMaxSpeed(stepperConfig.maxSpeed);
        stepper.setSpeed(1000);

        initState = 1;
      }
      if (initState == 1) {
        // move off zero if already there so we always get movement on reset
        // (to verify that the stepper is working)
        if (zeroDetected()) {
          stepper.runSpeed();
        } else {
          initState = 2;
        }
      }
      if (initState == 2) { // zeroing
        if (!zeroDetected()) {
          stepper.runSpeed();
        } else {
          stepper.setAcceleration(stepperConfig.acceleration);
          stepper.runToNewPosition(stepper.currentPosition() + zeroOffset);
          // tell the AccelStepper library that we are at position zero
          stepper.setCurrentPosition(0);
          lastAccelStepperPosition = 0;
          // set stepper acceleration in steps per second per second
          // (default is zero)
          stepper.setAcceleration(stepperConfig.acceleration);

          lastZeroDetectState = true;
          initState = 3;
        }
      }
      if (initState == 3) { // running normally

        // recalibrate when passing through zero position
        bool currentZeroDetectState = zeroDetected();
        if (!lastZeroDetectState && currentZeroDetectState && movingForward) {
          // we have moved from left to right into the 'zero detect window'
          // and are now at position 0
          lastAccelStepperPosition = stepper.currentPosition();
          currentStepperPosition = normalizeStepperPosition(zeroOffset);
        } else if (lastZeroDetectState && !currentZeroDetectState && !movingForward) {
          // we have moved from right to left out of the 'zero detect window'
          // and are now at position (maxSteps-1)
          lastAccelStepperPosition = stepper.currentPosition();
          currentStepperPosition = normalizeStepperPosition(stepperConfig.maxSteps + zeroOffset);
        }
        lastZeroDetectState = currentZeroDetectState;


        if (hasUpdatedData()) {
          // convert data from DCS to a target position expressed as a number of steps
          long targetPosition = (long)map_function(getData());

          updateCurrentStepperPosition();

          long delta = targetPosition - currentStepperPosition;

          // if we would move more than 180 degree counterclockwise, move clockwise instead
          if (delta < -((long)(stepperConfig.maxSteps / 2))) delta += stepperConfig.maxSteps;
          // if we would move more than 180 degree clockwise, move counterclockwise instead
          if (delta > (stepperConfig.maxSteps / 2)) delta -= (long)stepperConfig.maxSteps;

          movingForward = (delta >= 0);

          // tell AccelStepper to move relative to the current position
          stepper.move(delta);

        }
        stepper.run();
      }
    }
};

/* modify below this line */

/* define stepper parameters
   multiple Vid60Stepper instances can share the same StepperConfig object */
struct StepperConfig stepperConfig =
{
  730,  // maxSteps
  2200, // maxSpeed
  1000 // acceleration
};


// define AccelStepper instance
AccelStepper stepper(AccelStepper::DRIVER, 11, 10);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           v-- arbitrary name
Vid29Stepper alt100ftPointer(0x107e,          // address of stepper data
                             stepper,         // name of AccelStepper instance
                             stepperConfig,   // StepperConfig struct instance
                             6,              // IR Detector Pin (must be HIGH in zero position)
                             0,               // zero offset
[](unsigned int newValue) -> unsigned int {
  /* this function needs to map newValue to the correct number of steps */
  return map(newValue, 65535, 0, 0, stepperConfig.maxSteps - 1);
});


void setup() {

  DcsBios::setup();

}

void loop() {

  DcsBios::loop();
  
}

cheers

Les

  • Thanks 1
Posted
On 12/16/2022 at 10:51 AM, CYPHER11 said:

Hey guys,

 

for my Altimeter in the Hornet I need a stepper to drive the needle in front - I also found code but my question is how I can toggle and set up a endstop with a hall sensor or any other sensor so the code knows where 0 is…. Does anyone have an example for that?

 

 

thanks in advance 🙂 

Hey Cyphey11,

 

I too was trying to get the StandBy Altimeter Working by using Middlefart's Arduino's sketch in another thread and modify it to apply to F-18.

I just bought an hall effect sensor to do the same and get the needle to zero, I'll work on it for the next few days for my StandBy IAS.

The Thing I found is that the thousand feet in the digital OLED is not working neither on the OLED, the control reference in DCS-Bios or Fork, so I just bought the A-10C (Middlefart's code was built on this plane) and wanted to see if it worked good for me, and that I didn't have anything else not working, and it does work as it should on the A10C except for the OLED Baro I'll have to do a little homework on that too.  

My conclusion is that the address in DCS-Bios control Reference (Fork as the same Issue) is either not the good one or not working as iut should for the F-18 StandBy Gauge.

Is yours working on the thousands feet ? If yes could you please tell me what address do you used ?

 

Thanks in advance 

Lot2Learn

Posted

I did use that address but it does not return the thousands to DCS-Bios Fork, Does yours returns data ?

I bought A10-C module to see if Middlefart Arduino sketch was working on it (sending correct data to Altimeter's Oled) and it did, so I figured that the problem was coming from the address of the thousands in DCS-Bios, the ten thousands and hundreds are working fine. I don't know if there is a way to retrieve addresses from a Lua file in DCS somewhere ?

Thanks for you're answer No1sonuk

Posted

It is 100, 1000, 10000. Sorry for misleading you, My point here is only that I don't think the address for the 1000 is good. From what I learned it's not on the Hornet, I tried a code for the Altimeter on the Hornet and the 1000 is not sending data to the Arduino, even on DCS-Bios (fork) the data from 0x74f8 look erratic for the 1000. I'm trying to find out if there is a Lua file in DCS folders that I could have a look at to find the address.

Posted

I need to start getting my standby instruments setup in my home F/A-18C cockpit.  I was thinking of using this as my altimeter, but don't know how to get it interfacing with DCS.  Any suggestions?  I know that it is a little to big for the area, but I would make it work and look good.

https://www.flightillusion.com/military-vintage/other-gauges-mil/gsa-016g-digital-altimeter-green/

 

Wayne Wilson

AKA: hrnet940

Alienware Aurora R3, i7 3820 3.5GHz(4.2GHz setting) processor, EVGA Nvidia RTX 2070 8GB Graphics, 16GB Ram, 1TB SSD.

Posted

I had a look at them but 1) They are pretty expansive and 2) They work with a board that I know nothing about, so I decided to built my own (3D Printed). At the end the whole bunch of Standby gauges would have cost me around 2000 $ CDN, without knowing if they would work with DCS.

Also I'm trying to replicate the originals as much as I can, but the road to success with these things is a long one. I've been working on my cockpit for a year now, didn't play a lot for the past year...Still waiting for a 3D printer Prusa XL to get out in the market to complete the bigger parts, should be in soon now I hope.

Screenshot 2022-12-30 120838.jpg

Posted

Well I have a Creality CR-6 MAX and a Prusa MK3S+ already, thing is the MAX is not as reliable as Prusa is, I ordered the XL last February and they are about to ship, plan was (if not changed) to ship somewhere in January 2023. This gives me the chance to develop my skills with Electronics.  I just finished the IAS showed above, I worked on it for the past 2 weeks... I'm not good in Arduino programming, it's been a long learning process.

Now going on the Stand By Altimeter, more complex with the Oled's still have to go with the VSI to finish with the toughest one The Attitude Indicator. 

  • 2 months later...
Posted

Thanks everyone.

 

Wayne Wilson

AKA: hrnet940

Alienware Aurora R3, i7 3820 3.5GHz(4.2GHz setting) processor, EVGA Nvidia RTX 2070 8GB Graphics, 16GB Ram, 1TB SSD.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...