Jump to content

Recommended Posts

Posted

Hello,

I've run into an issue with my HSI stepper code that I just can't seem to figure out.  What happens is when it reaches a certain position (it will turn BACKWARDS then continue.  Anyone ever run into this?  I'm using a 360' VID motor. I feel like it can be solved with some glue code, but I can't figure it out..🫤.  Hopefully the video below will give a good visual on what I'm talking about.  I also inserted my Arduino/DCS BIOS code. 

Thanks for any help with this!

#define DCSBIOS_IRQ_SERIAL

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

// --- Define motor driver pins
#define MS1 2
#define MS2 3
#define EN 7
// ------------------------

// ---------- Stepper Motor Declarations ----------
#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 9, 8);

// ----------------------------------------------------------------------------
//     DCS Bios Stuff here
//-----------------------------------------------------------------------------

void onHsiHdgChange(unsigned int newValue) {
unsigned int stepperPosition = map(newValue, 0, 65535, 0, 2890);
  stepper.runToNewPosition(stepperPosition);
}
DcsBios::IntegerBuffer hsiHdgBuffer(0x104c, 0xffff, 0, onHsiHdgChange);

// ----------------------------------------------------------------------------
//     SETUP loop
//-----------------------------------------------------------------------------
void setup(void)
{
  DcsBios::setup();
    pinMode(MS1, OUTPUT);
    pinMode(MS2, OUTPUT);
    pinMode(EN, OUTPUT);
    digitalWrite(MS1, LOW);
    digitalWrite(MS2, HIGH);
    digitalWrite(EN, LOW);

// ----- Stepper init
    stepper.setMaxSpeed(1000);    //  maximum speed in steps per second. Must be > 0.
    stepper.setAcceleration(2800);  //  desired acceleration in steps per second per second. Must be > 0.0
    stepper.runToNewPosition(2890); // go to the upper end stop
    delay(250);
    stepper.setCurrentPosition(2890); // set max steps
    delay(1500);
    stepper.runToNewPosition(0);    // go to the lower end stop
    delay(250);
    stepper.setCurrentPosition(0);  // set steps to zero
    
}

// ----------------------------------------------------------------------------
//     LOOP loop - try to keep empty
//-----------------------------------------------------------------------------
void loop() {
  DcsBios::loop();
}

 

hsi.gif

Posted

A couple of questions - what aircraft (I always forget to say, assuming everyone already knows!)

Also, are you using a stepper that has a limited travel? I believe those 360 VID motors have an inbuilt 0 position sensor but am not certain, never having found one for sale

Les

Posted

I think what you're missing is called "zero crossing" code.

It needs to work out that going from 359 to 0, or 0 to 359, has to go the short way, or that 360 = 0 or -1 = 359.

Posted
6 hours ago, lesthegrngo said:

A couple of questions - what aircraft (I always forget to say, assuming everyone already knows!)

Also, are you using a stepper that has a limited travel? I believe those 360 VID motors have an inbuilt 0 position sensor but am not certain, never having found one for sale

Les

Hi Les,  This is for the A10C II module.  I'm using a VID29 stepper that had its travel limit stop removed, so it can spin freely 360 without stopping or any restrictions.  I'm not using a position sensor as I plan to use a knob to manually calibrate the HSI (like a real aircraft).  So... a dumb motor, without sensors.  🙂  

Posted (edited)

Even with the proposed correction you definitely need a zero detection sensor for the HSI. Else your disk may drift after a while. Have a look into the sketch for the Altimeter and the related postings. I think that the logic can be applied to your gauge. 

Btw. your hardware looks great so far 👍

Regerds, Vinc

Edited by Vinc_Vega

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted
1 hour ago, Vinc_Vega said:

Even with the proposed correction you definitely need a zero detection sensor for the HSI. Else your disk may drift after a while.

 

This is not necessarily so. The load on the stepper is light, not likely to loose steps. However, when you have optical zero reference, you can always use it in runtime to re-calibrate. If, e.g. you have an optical switch set to trip at 0°, everytime it trips you can check if your calculated position is indeed 0° or else update it

Posted
31 minutes ago, Nikolas_A said:

This is not necessarily so. The load on the stepper is light, not likely to loose steps. However, when you have optical zero reference, you can always use it in runtime to re-calibrate. If, e.g. you have an optical switch set to trip at 0°, everytime it trips you can check if your calculated position is indeed 0° or else update it

Its a whole disk and not a small pointer sitting on the stepper. Not sure if the load is that light. Try and find out if and how many steps it will loose. 

Regards, Vinc

Regards, Vinc

real life: Royal Bavarian Airforce

online: VJS-GermanKnights.de

[sIGPIC][/sIGPIC]

Posted

Load is very light on the motor and I haven't notice it drifting.  In a real aircraft it is standard procedure to calibrate the HSI with its knob by cross referencing the compass, so that's why I'm trying to do this without a zero sensor.  I'm still not having any luck finding any code samples without an IR or magnetic zero sensor where the indicator doesn't loop back around. 

 @No1sonuk  Thanks for the 'zero crossing' name reference - wasn't sure what it was called and was hard to describe. 

  • Recently Browsing   0 members

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