Jump to content

DCS bios Multiple steppers-one arduino


Recommended Posts

Hi Guys,

I have already finished construction of 8 gauges for my pit, all of them are already fine tuned (steps, speed...) running one gauge on one arduino (for tunning/testing). Now I am trying to implement 4-5 to one arduino by changing of well know code for Vid29, so i can use Tekxx ICB pcb for RS485 communication. This is what I have tried but always only one motor is working (I have added one stepper config and one motor instance) please help:helpsmilie::helpsmilie::helpsmilie:

 

/*
 The following #define tells DCS-BIOS that this is a RS-485 slave device.
 It also sets the address of this slave device. The slave address should be
 between 1 and 126 and must be unique among all devices on the same bus.
*/
#define DCSBIOS_RS485_SLAVE 6

/*
 The Arduino pin that is connected to the
 /RE and DE pins on the RS-485 transceiver.
*/
#define TXENABLE_PIN 2

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

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


class Vid29Stepper : public DcsBios::Int16Buffer {
 private:
   AccelStepper& stepper;
   StepperConfig& stepperConfig;
   unsigned int (*map_function)(unsigned int);
   unsigned char initState;
 public:
   Vid29Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned int (*map_function)(unsigned int))
   : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), map_function(map_function), initState(0) {
   }

   virtual void loop() {
     if (initState == 0) { // not initialized yet
       stepper.setMaxSpeed(stepperConfig.maxSpeed/4);
       stepper.setAcceleration(stepperConfig.acceleration/4);
       stepper.moveTo(-((long)stepperConfig.maxSteps));
       initState = 1;
     }
     if (initState == 1) { // zeroing
       stepper.run();
       if (stepper.currentPosition() <= -((long)stepperConfig.maxSteps)) {
         stepper.setCurrentPosition(0);
         initState = 2;
         stepper.moveTo(stepperConfig.maxSteps/2);
       }
     }
     if (initState == 2) { // running normally
       if (hasUpdatedData()) {
         unsigned int newPosition = map_function(getData());
         newPosition = constrain(newPosition, 0, stepperConfig.maxSteps);
         stepper.moveTo(newPosition);
       }
       stepper.run();
     }
   }
};

/* modify below this line */

/* define stepper parameters
  multiple Vid29Stepper instances can share the same StepperConfig object */
struct StepperConfig stepperConfig = {
4320,  // maxSteps
7000, // maxSpeed
5250// acceleration
 };

struct StepperConfig stepperConfig2 = {
4320,  // maxSteps
7000, // maxSpeed
5250// acceleration
 };


// define AccelStepper instance
AccelStepper stepper(AccelStepper::DRIVER, 6, 7);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper verticalspeed(0x3450, stepper, stepperConfig, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 0, 65535, 0, stepperConfig.maxSteps-1);

AccelStepper stepper(AccelStepper::DRIVER, 4, 5);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper IAS(0x344e, stepper, stepperConfig2, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 0, 65535, 0, stepperConfig2.maxSteps-1);
}); 

}); 
void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to post
Share on other sites

What about the master. You talk about the slaves but you haven't included the master in your description.

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to post
Share on other sites

Master is standard code:

/*
 Tell DCS-BIOS this is a RS-485 Master.
 You will need to flash this to a Mega 2560.
*/
#define DCSBIOS_RS485_MASTER

/*
 Define where the TX_ENABLE signals are connected.
 You can connect up to three half-duplex RS-485 transceivers.
 
 Arduino Pin             RS-485 Transceiver Pin
 TXn ------------------- DI (driver input)
 RXn ------------------- RO (Receiver Output)
 UARTn_TXENABLE_PIN ---- /RE, DE (active low receiver enable, driver enable)
 
 If you have less than three transceivers connected, comment out the corresponding
 #define UARTn_TEXENABLE_PIN lines for receivers that are not present.
*/
#define UART1_TXENABLE_PIN 2
#define UART2_TXENABLE_PIN 3
#define UART3_TXENABLE_PIN 4

#include "DcsBios.h"

void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

Code form my first post is working but only for first motor, second one will not even do zeroing. So the part of code added by me for second stepper is wrong but I don't know why, I have just copy stepperconfig and rename it to stepperconfig2 and copied motor instance and changed pin numbers and addressing of instrument. Separately for each motor it was working but together two motors in one arduino not.... :helpsmilie::helpsmilie::helpsmilie:

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to post
Share on other sites

Take out stepper config 2 struct and change 2nd stepper to use 1st config struct, I think as both steppers use same struct data.

 

maybe !!

AMD A8-5600K @ 4GHz, Radeon 7970 6Gig, 16 Gig Ram, Win 10 , 250 gig SSD, 40" Screen + 22 inch below, Track Ir, TMWH, Saitek combat pedals & a loose nut behind the stick :thumbup:

Link to post
Share on other sites
Take out stepper config 2 struct and change 2nd stepper to use 1st config struct, I think as both steppers use same struct data.

 

maybe !!

 

Already tried, it didn't help...And due the different adjustment for acceleration and speed for each gauge I need more then one stepperconfig....:dunno:

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to post
Share on other sites
Already tried, it didn't help...And due the different adjustment for acceleration and speed for each gauge I need more then one stepperconfig....:dunno:

 

Sorry Draken but I don,t think I read your first post properly. So you are you trying to run more than one stepper motor on a single Arduino board? If that’s the case my recommendation is...don't. The Arduino boards, with exception of the more powerful 32 bit boards will not run several steppers. In my cockpit, I run one pro mini plus one Easy Driver board for each stepper motor I have. If you want to use a much more powerful processor, I’m sure you can do it but not with these little Arduino boards.

 

One stepper motor = one Arduino board + Driver board.

 

BTW Draken, what are you using to drive your stepper motors. Any pictures of your gauges you could post?

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to post
Share on other sites

Hi Warhog,

if it is like you have wrote I am really in the troubles :mad:.... I have chose concept using Tekkx boards with Arduino nano due the easy RS485 connectivity. And plan was connect 4 motors to one nano. If this will be not working I have wasted lot of money and time :music_whistling: You can see upper instrumental panel on the pictures no secret, I am using same drivers like you.

But still there must be a way how to update original vid29 code for more then one stepper in arduino. Even in original code for vid 29 is writen

multiple Vid29Stepper instances can share the same StepperConfig object

...

Before I will give up with my concept I need to drink some whisky and also test and prove it is not working:) So if somebody know how to update code please help....

1979714557_Upperpanelfronside.thumb.jpg.6a1e1be0bf18b74c7af9e274410a45ef.jpg

669608659_Upperpanelbackside.thumb.jpg.decb019acd5c70b8eb4fdc9713f73ca4.jpg

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to post
Share on other sites
Hi Warhog,

if it is like you have wrote I am really in the troubles :mad:.... I have chose concept using Tekkx boards with Arduino nano due the easy RS485 connectivity. And plan was connect 4 motors to one nano. If this will be not working I have wasted lot of money and time :music_whistling: You can see upper instrumental panel on the pictures no secret, I am using same drivers like you.

But still there must be a way how to update original vid29 code for more then one stepper in arduino. Even in original code for vid 29 is writen

multiple Vid29Stepper instances can share the same StepperConfig object

...

Before I will give up with my concept I need to drink some whisky and also test and prove it is not working:) So if somebody know how to update code please help....

 

Hi Draken

You definitely cannot connect 4 stepper motors to one Arduino board. It just won't be powerful enough. Maybe 2 motors. I used one Arduino with 2 motors on the Accelerometer for the A10. It works but just barely because one of the motors rarely has to do anything. This is the code I used.

 


#define DCSBIOS_IRQ_SERIAL
//#define DCSBIOS_RS485_SLAVE 20
//#define TXENABLE_PIN 2


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

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


class Vid29Stepper : public DcsBios::Int16Buffer {
 private:
   AccelStepper& stepper;
   StepperConfig& stepperConfig;
   unsigned int (*map_function)(unsigned int);
   unsigned char initState;
 public:
   Vid29Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned int (*map_function)(unsigned int))
   : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), map_function(map_function), initState(0) {
   }

   virtual void loop() {
     if (initState == 0) { // not initialized yet
       stepper.setMaxSpeed(stepperConfig.maxSpeed);
       stepper.setAcceleration(stepperConfig.acceleration);
       stepper.moveTo(-((long)stepperConfig.maxSteps));
       initState = 1;
     }
     if (initState == 1) { // zeroing
       stepper.run();
       if (stepper.currentPosition() <= -((long)stepperConfig.maxSteps)) {
         stepper.setCurrentPosition(0);
         initState = 2;
         stepper.moveTo(stepperConfig.maxSteps/2);
       }
     }
     if (initState == 2) { // running normally
       if (hasUpdatedData()) {
         unsigned int newPosition = map_function(getData());
         newPosition = constrain(newPosition, 0, stepperConfig.maxSteps);
         stepper.moveTo(newPosition);
       }
       stepper.run();
     }
   }
};



/* define stepper parameters
  multiple Vid29Stepper instances can share the same StepperConfig object */
struct StepperConfig vid28_1 = {
 1260,  // maxSteps
 2500, // maxSpeed
 10000 // acceleration
 };
struct StepperConfig vid28_2 = {
 1260,  // maxSteps
 2500, // maxSpeed
 10000 // acceleration
 };

// define AccelStepper instance
AccelStepper maxPointerStepper(AccelStepper::DRIVER, 5, 6);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           v-- arbitrary name
//           |   v-- Address of stepper data (from control reference)
//           |   |       v-- name of AccelStepper instance
//           |   |       |        v-- StepperConfig struct instance
Vid29Stepper maxPointer(0x1070, maxPointerStepper, vid28_1, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 4370, 65535, 0, vid28_1.maxSteps);
}); 

// define AccelStepper instance
AccelStepper minPointerStepper(AccelStepper::DRIVER, 8, 9);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           v-- arbitrary name
//           |   v-- Address of stepper data (from control reference)
//           |   |       v-- name of AccelStepper instance
//           |   |       |        v-- StepperConfig struct instance
Vid29Stepper minPntr(0x1074, minPointerStepper, vid28_2, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 4370, 65535, 0, vid28_2.maxSteps);
}); 


DcsBios::Switch2Pos accelPts("ACCEL_PTS", 7);

void setup() {
 DcsBios::setup();
 minPointerStepper.setPinsInverted (true,false,false); //This statement changes the direction pin
 maxPointerStepper.setPinsInverted (true,false,false); //This statement changes the direction pin
}

void loop() {
 DcsBios::loop();
}

 

Try it using a serial connection rather than an RS485 just to test it.

 

Just to clarify, the code above was originally written to control multiple stepper motors (12 in total) but it wasn't using an Arduino board. It was a 32 bit processor that uses the Arduino code which is C++. Its actually the base code for my EMI on the A10. I haven't tested it yet but it should run all 12 motors according to the developer of this 32 bit board. It better run, as the board was $75.00. I have tried using several motors but they do not function reliably with the Arduino boards. Thats why I scaled it back to one board = one motor. Its only $1.80 for a Pro Mini so adding one board for each motor was nothing compared to what I have already spent on the rest of the cockpit.


Edited by Warhog

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to post
Share on other sites

So I have compared your code to my and I have found my mistake in second stepper instance:

/*
 
AccelStepper stepper[color="Red"]2[/color](AccelStepper::DRIVER, 4, 5);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper IAS(0x344e, stepper[color="red"]2[/color], stepperConfig2, [](unsigned int newValue) -> unsigned int {
 /* this function needs to map newValue to the correct number of steps */
 return map(newValue, 0, 65535, 0, stepperConfig2.maxSteps-1);
}); 

}); 
void setup() {
 DcsBios::setup();
}

void loop() {
 DcsBios::loop();
}

 

Simply I have forgot to change instance name to different then in instance 1 :music_whistling:

 

Now it is everything working, I am currently running 4 stepper and it seems working without problems (just 10 min of flying).... I will keep testing this week and post video later on...

 

Thanks a lot for help Warhog....:worthy::worthy::worthy:

 

P.S.

Wasn't you problem with two steppers connected to acceleration of steppers, because I was not able to use 10000 in none of my gauges with vid29 each time I was loosing steps. Max I am using 5250, but this is probably connected also to arrow material(I am using 0.8mm polycarbonate ) and overall inertia of system... On some gauges I have also found if the data are fluctuating from + to - really fast (what is specific for some gauges for example RPM when you move with throttle forward and backward really fast few times ) I am also loosing steps with acceleration 5250 but with less acceleration is gauge running normally...


Edited by draken152

[sIGPIC][/sIGPIC]

Building FW190D pit ,,To Dora with love" http://forums.eagle.ru/showthread.php?t=132743

Link to post
Share on other sites

I'm so glad your gauges are working now.:thumbup: I know how frustrating it can be.

 

The loss of steps was my biggest problem when running more than two motors. Gauges were always getting out of sync. I didn't want to continually reset them to get them back into sync so I decided to keep it simple and use one motor one board. Just beware that whenever a motor has to react quickly, that is when you will probably lose steps or have issues in accuracy.

 

Best of luck Draken.

Regards

John W

aka WarHog.

 

My Cockpit Build Pictures...



John Wall

 

My Arduino Sketches ... https://drive.google.com/drive/folders/1-Dc0Wd9C5l3uY-cPj1iQD3iAEHY6EuHg?usp=sharing

 

 

WIN 10 Pro, i8-8700k @ 5.0ghz, ASUS Maximus x Code, 16GB Corsair Dominator Platinum Ram,



AIO Water Cooler, M.2 512GB NVMe,

500gb SSD, EVGA GTX 1080 ti (11gb), Sony 65” 4K Display

VPC MongoosT-50, TM Warthog Throttle, TRK IR 5.0, Slaw Viper Pedals

Link to post
Share on other sites
  • 2 years later...

I'm approaching this issue ... before to start i have two questions:
1 - how you sync/zeroed the gauges? 
2 - Why in some solution are you using a direct connection of the step motor to the gauges hands? is it for to speedup or down the hands or for to increase/decrease the step space?

 

Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...