Hi,
i am trying to get a stepper motor (Nema 17, CL42T closed loop driver), to move to a positition defined by an integer using AccelStepper. This works just fine with this code:
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include "AccelStepper.h"
AccelStepper stepper(1,2,3);
unsigned int POS = 0;
void onPltAltimeterNeedleChange(unsigned int newValue) {
POS = map(newValue, 0, 65535, 0, 800);
}
DcsBios::IntegerBuffer pltAltimeterNeedleBuffer(0x133c, 0xffff, 0, onPltAltimeterNeedleChange);
void setup() {
stepper.setMaxSpeed(2000);
stepper.setAcceleration(10000);
DcsBios::setup();
}
void loop() {
DcsBios::loop();
stepper.moveTo(POS);
stepper.run();
}
The "newValue" integer is provided by a flight sim and corresponds to the position of a cockpit gauge, ie 0 is the 12oclock position, 32.767 is the 6ocklock position, and 65535 is 0,005° CCW of the first position.
The issue is that when the newValue crosses 0, the stepper will do a 359° turn to reach its new position, see the attached video.
In the past i tried this code, provided by another forum user, which did fix the issue, but introduced major positional error.
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include "AccelStepper.h"
AccelStepper stepper(1,3,4);
int val = 0;
int AltNeedle = 0;
void onPltAltimeterNeedleChange(unsigned int newValue) {
static unsigned int oldValue = 0;
int change = (int)(newValue - oldValue);
AltNeedle += map(change,-32768,32767,-400,400);
oldValue = newValue;
}
DcsBios::IntegerBuffer pltAltimeterNeedleBuffer(0x133c, 0xffff, 0, onPltAltimeterNeedleChange);
void setup() {
DcsBios::setup();
stepper.setMaxSpeed(1000);
stepper.setAcceleration(1000);
}
void loop() {
DcsBios::loop();
stepper.moveTo(AltNeedle);
stepper.run();
}
So, im basically looking for a way to tell Accelstepper to go from position 65535 to 0 by going 0,005° CW, and not 359.995° CCW, and the other way round.
Any advice would be appreciated