kadda Posted June 2, 2017 Share Posted June 2, 2017 (edited) here s a basic sketch ispired by Ian;3092502']Here is a sketch that WarHog and I have written modified to make %360° instruments turn at higher speeds ( like Roll indication in my case ), AccelStepper kren(AccelStepper::DRIVER, step, dir); /************************************************************************************************************************************/ char flagroll; long currentrollStepperPosition = 0, diffposition; long lastAccelStepperPosition; long targetrollPosition,movementSinceLastUpdate ; long lastroll,krenvoulu; #define MAXROLLSPEED 500 #define MAXROLLACCEL 500 #define MAXROLLTOUR (931) // for my gear ratio correction #define MAXROLLTOURM10 (9300) // for my gear ration correction (in fact i m correcting because of the ratio i have 930.1 steps per revolution ) long delta; long poskren,lastkren; int corriger,cumul; short statekren,signcurr; long currentStepperPosition = 0; void onKpp1273kRollChange(unsigned int krenValue) { long targetPosition = map(krenValue, 0l, 65535l, 0l,MAXROLLTOURM10); targetPosition= targetPosition/10 + (targetPosition%10 >=6 ? 1 :0); poskren = kren.currentPosition(); movementSinceLastUpdate = poskren- lastAccelStepperPosition; currentStepperPosition += movementSinceLastUpdate; lastAccelStepperPosition = kren.currentPosition(); if (currentStepperPosition < 0) { currentStepperPosition = (-currentStepperPosition)%MAXROLLTOUR; currentStepperPosition = -(currentStepperPosition)+MAXROLLTOUR; signcurr=1; } currentStepperPosition %= MAXROLLTOUR; if(abs(poskren-lastkren)>=(10*MAXROLLTOUR)){ targetPosition= targetPosition + (poskren-lastkren >0 ? -1 : +1); lastkren = poskren; } delta = targetPosition - currentStepperPosition; if (delta < -(MAXROLLTOUR/2)) delta += MAXROLLTOUR; if (delta > (MAXROLLTOUR/2)) delta -= MAXROLLTOUR; if(delta!=0) { kren.move(delta); } } DcsBios::IntegerBuffer kpp1273kRollBuffer(0x320a, 0xffff, 0, onKpp1273kRollChange); Edited June 3, 2017 by kadda 1 With respect _________________ Kadda _________________ My works TL-39 (NewGen) project (Ру)/(EN) Link to comment Share on other sites More sharing options...
WhoMadeWho Posted June 4, 2017 Share Posted June 4, 2017 Thanks Kadda for the code. What brand / model are you using for a stepper? Link to comment Share on other sites More sharing options...
Hansolo Posted June 4, 2017 Share Posted June 4, 2017 +1 Thanks for sharing Kadda Cheers Hans 132nd Virtual Wing homepage & 132nd Virtual Wing YouTube channel My DCS-BIOS sketches & Cockpit Album Link to comment Share on other sites More sharing options...
kadda Posted June 4, 2017 Author Share Posted June 4, 2017 (edited) @WhoMadeWho , i m using different type of steppers, essentially because with some instruments i need tork but not speed, with others speed and no tork, unfortunatlly or fortunatlly ( i dont know because i learned many thing from that) with others i need both plus precision stepping, but one is commun for all the steppers, i get them all from old broken machinary ( printers, conditioners, ...), for the roll indicator in particular i m using "EM-462" from an old epson printer (i mean very old one :lol: ) @Hansolo , @WhoMadeWho you re welecome ps to all : i m very sorry for my " multilaguage sketch writing " Edited June 4, 2017 by kadda With respect _________________ Kadda _________________ My works TL-39 (NewGen) project (Ру)/(EN) Link to comment Share on other sites More sharing options...
kadda Posted June 10, 2017 Author Share Posted June 10, 2017 i ve to correct it a liiiiiiittle more, cuz after a long spinning i ve + - 5° of lag, will share the correction ... With respect _________________ Kadda _________________ My works TL-39 (NewGen) project (Ру)/(EN) Link to comment Share on other sites More sharing options...
Recommended Posts