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();
}