Accelstepper and VID-29 for DCS-BIOS

599 views
Skip to first unread message

Tore Riise

unread,
Oct 12, 2015, 2:41:55 AM10/12/15
to accelstepper
Hi,

I'm relatively new to Arduino programming and in the progress of building some instruments for my DCS A-10C simulator.
I have tried using the stepper.h library included in the Arduino with some luck, but can't get 12 steppers to work together. Someone suggested that I should try Accelstepper.
Now I've taken some code from different sources and tried to put them together into a working sketch for the left RPM gauge. But I have the following issues:

1. I can't get the pointer to move fast enough to keep up with the pointer in game.
2. It starts at zero, and if a select a mission where I start in the air with the motors running, I don't get it to go to the desired position.

Can anyone take a look at my sketch and see if there is some obvious errors?

// include AccelStepper library
#include <AccelStepper.h>
#include <DcsBios.h>
#include <Servo.h>

// DcsBios-related declarations
DcsBios::ProtocolParser parser;

#define STEPS_PER_REVOLUTION 630
#define ZERO_OFFSET 0

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int currentStepperPosition = 0; // current stepper position (in steps, from 0 to STEPS_PER_REVOLUTION+1)
signed long lastAccelStepperPosition;


void setup()
{
  stepper
.setMaxSpeed(1500.0);
  stepper
.setAcceleration(500.0);
  stepper
.setSpeed(1000);
  stepper
.runToNewPosition(630);  //backwards sweep to find hard stop
  stepper
.setCurrentPosition(0); //establishes the zero position



{  
   
Serial.begin(250000);

   
   
// 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(500);
   
}
}
int targetposLRPM = 0;
int posLRPM = 0;

void loop()
{
 
// handle DcsBios communication
 
while (Serial.available()) {
      parser
.processChar(Serial.read());
 
}
 
DcsBios::PollingInput::pollInputs();

}

void onDcsBiosWrite(unsigned int address, unsigned int value) {
 
 
//unsigned int LRPM = (value & 0xffff) >> 0;
 
if (address == 0x10a8) {
int     targetposLRPM = map(value, 0, 65535, 0, 600);

   
{
if(abs(targetposLRPM - posLRPM)> 2){         //if diference is greater than 2 steps.
     
if(targetposLRPM > posLRPM) {
          stepper
.move(-1);      // move one step to the left.
          posLRPM
++;
         
}
     
if(targetposLRPM < posLRPM){
          stepper
.move(1);       // move one step to the right.
          posLRPM
--;
         
}
   
}
 
 
// move stepper motor
  stepper
.run();
}
 
}
}


Any help will be very helpfull :)

gregor

unread,
Oct 12, 2015, 7:11:42 AM10/12/15
to accelstepper
Hi,

1) it seems to me that you only ever step your stepper motor once, after you have received a new value for the gauge. you should call stepper.run() as often as possible, for example at the end of your loop() function.
2) I think it will be better to use absolute stepper targets. using moveTo() instead of move() should fix 2).

this thread may be helpful: https://groups.google.com/forum/#!topic/accelstepper/j8QSG2T1nds


On Monday, October 12, 2015 at 8:41:55 AM UTC+2, Tore Riise wrote:
Hi,

I'm relatively new to Arduino programming and in the progress of building some instruments for my DCS A-10C simulator.
I have tried using the stepper.h library included in the Arduino with some luck, but can't get 12 steppers to work together. Someone suggested that I should try Accelstepper.
Now I've taken some code from different sources and tried to put them together into a working sketch for the left RPM gauge. But I have the following issues:

1. I can't get the pointer to move fast enough to keep up with the pointer in game.
2. It starts at zero, and if a select a mission where I start in the air with the motors running, I don't get it to go to the desired position.

Can anyone take a look at my sketch and see if there is some obvious errors?

void loop()
{
 
// handle DcsBios communication
 
while (Serial.available()) {
      parser
.processChar(Serial.read());
 
}
 
DcsBios::PollingInput::pollInputs();
}

void onDcsBiosWrite(unsigned int address, unsigned int value) {
 
 
//unsigned int LRPM = (value & 0xffff) >> 0;
 
if (address == 0x10a8) {
int     targetposLRPM = map(value, 0, 65535, 0, 600);

   
{
if(abs(targetposLRPM - posLRPM)> 2){         //if diference is greater than 2 steps.

      //
if(targetposLRPM > posLRPM) {
      //    stepper
.move(-1);      // move one step to the left.
      //    posLRPM
++;
      //   
}
     
//if(targetposLRPM < posLRPM){
      //    stepper
.move(1);       // move one step to the right.
      //    posLRPM
--;
      //   
}
      stepper.moveTo(targetposLRPM);     

targetposLRPM    

}

 
 
// move stepper motor
  stepper
.run();
}
 
}
}

gregor

unread,
Oct 12, 2015, 7:15:05 AM10/12/15
to accelstepper
sorry, i messed up while writing the last response.

void onDcsBiosWrite(unsigned int address, unsigned int value) {
 
 
//unsigned int LRPM = (value & 0xffff) >> 0;
 
if (address == 0x10a8) {
int     targetposLRPM = map(value, 0, 65535, 0, 600);

   
{
if(abs(targetposLRPM - stepper.currentPosition())> 2){         //if diference is greater than 2 steps.

      //
if(targetposLRPM > posLRPM) {
      //    stepper
.move(-1);      // move one step to the left.
      //    posLRPM
++;
      //   
}
     
//if(targetposLRPM < posLRPM){

      //    stepper
.move(1);       // move one step to the right.
      //    posLRPM
--;
      //   
}
      stepper.moveTo(targetposLRPM);    //set an absolute target
   
}

 
 
// move stepper motor
  stepper
.run();
}
 
}
}

Tore Riise

unread,
Oct 15, 2015, 1:54:28 AM10/15/15
to accelstepper
Ok, so I tried this.
Problem is that the stepper doesn't move fast enough to keep up with the in-game pointer. It doesn't matter which speed I set in the setup, it still moves at the same speed.
Also, If I start in-game with for example 60% rpm, the pointer goes to 0, then stays there. If I increase throttle to 80%, the pointer goes to 20%.

I'm pulling my hair out soon....

gregor

unread,
Oct 15, 2015, 4:18:07 PM10/15/15
to accelstepper
I think i see the problem. in your code stepper.run() will only be called *once* if you receive a new value for the gauge. Try the code below:
// include AccelStepper library
#include <AccelStepper.h>
#include <DcsBios.h>
#include <Servo.h>

// DcsBios-related declarations
DcsBios::ProtocolParser parser;

#define STEPS_PER_REVOLUTION 630
#define ZERO_OFFSET 0

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
int currentStepperPosition = 0; // current stepper position (in steps, from 0 to STEPS_PER_REVOLUTION+1)
signed long lastAccelStepperPosition;


void setup()
{
  stepper.setMaxSpeed(1500.0);
  stepper.setAcceleration(500.0);
  stepper.runToNewPosition(630);  //backwards sweep to find hard stop
  stepper.setCurrentPosition(0); //establishes the zero position
  stepper.setSpeed(1000); //set a constant speed. use this only if you use runSpeedToPosition() below

   Serial.begin(250000);


   // tell the AccelStepper library that we are at position zero
   //stepper.setCurrentPosition(0); //this line is not necessary, AccelStepper will always start at 0.
   lastAccelStepperPosition = 0;
   // set stepper acceleration in steps per second per second
   // (default is zero)
   //stepper.setAcceleration(500); //not necessary, you already set that before
   
}

int targetposLRPM = 0;
int posLRPM = 0;

void loop()
{
// handle DcsBios communication
while (Serial.available()) {
 parser.processChar(Serial.read());
}
DcsBios::PollingInput::pollInputs();
//stepper.run(); // move stepper motors (with acceleration)
stepper.runSpeedToPosition(); // move stepper motors (constant speed)
//more stepper motors, or use the multistepper class
//...
}

void onDcsBiosWrite(unsigned int address, unsigned int value) {
//unsigned int LRPM = (value & 0xffff) >> 0; 
if (address == 0x10a8) {
int targetposLRPM = map(value, 0, 65535, 0, 600);
Reply all
Reply to author
Forward
0 new messages