女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

如何通過代碼HodgePodging加快最大步進速度

454398 ? 來源:網絡整理 ? 作者:網絡整理 ? 2019-11-18 09:03 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

第1步:

我使用了很多單詞來描述我的方法,但是我也尊重每個人都會從另一個地方來處理這個問題。如果您有經驗,請多說些抱歉,但是,如果您不熟悉arduino,并且想以比當前使用accelstepper更快的速度運行步進電機,那么請問所有問題。

計劃:

Accelstepper使用非線性加速度曲線,以逐漸增加步進電機的步進率。它在stepper.run()調用期間以非常抽象的方式執行此操作,這是一個(粗略的想法)函數,用于檢查您是否應進行新步驟,如果是,則步進驅動程序并計算下一次執行的時間步驟已到。您需要經常調用它,但是您可以在控制循環中執行其他操作。因此,例如,在這里您可能會看到:

同時(digitalRead(someSensor)== high){

//做東西

//做更多東西

stepper.run();

}

只要“填充”時間不長,stepper.run()就會非常頻繁地運行,并且步進操作。但是stepper.run()并不是一個非常快速的函數,在某些時候它是限制因素!然后,此while循環會花費太長時間。

所以我的建議和方法是執行以下操作:

//starting from the non-moving position

while(condition){

//do stuff

stepper.run();

if (stepper.Speed()==maxAccelstepperSpeed){

//Extrafast mode is a simple linear acceleration program. Not as nice as stepper.run(), but much faster.

break; //let‘s get out of this while loop!

}

//extraFastMode()偽代碼:

//calculate a starting stepdelay based on what speed you’re transitioning away from the accelstepper library.

The new method of stepping will just be:

“While(condition){

”Do stuff/ check extra if statements

Take a step

wait manually with a delay

add to a counter

//if the counter hits a trigger number, and you‘re not at your final target speed,

then decrease your delay [which increases your motor speed“

}//loop back to the top

這有意義嗎?下一步,讓我們深入研究同樣冗長的注釋代碼,如果有任何問題,請返回。

步驟2:哇,代碼!

我從我的項目中提取了一個完整的程序,并在保留大部分表單的同時將其剝離了下來。 “功能”模式。我可以說原始代碼有效,但是我只測試了新代碼可以編譯。

此代碼是否完美?否。

此代碼是執行此操作的最佳還是最快方法?否。

但這行得通嗎?是。我希望我已使其功能盡可能透明。

它最初是作為函數調用編寫的,在我的程序中可以使用幾個不同的馬達(調用accellstepper的不同實例),但在此示例中我將其簡化了一些。

建議:如果簽出附帶的.ino,則可以在您喜歡的文本編輯器中查看代碼。它的顯示效果會好得多,我不建議整體復制此代碼塊,因為它可能會稍微變形。

/*This document should end up as a short introduction to one particular method of

sidestepping Accelstepper’s somewhat low step-rate limit using default stepper.run()

protocol. It is not the only and certainly not the best method. But it works.*/

//Extra note about the purpose: This lets you use the nice accelstepper acceleration

algorithm for the initial acceleration and then a much cruder linear ramp thereafter.

#include

const int stepPin=23;

const int directionPin=14;

/*Accelstepper SetMotorIdentifier(TYPE, STEP, DIRECTION) We are using type 1 because I‘m using a classic STEP/DIR stepper Driver.

Different types might ask for things other than step&direction [see Accelsteppr documentation]*/

AccelStepper stepper(1,stepPin,directionPin);

long actuatorDistance = 158400; //This varies depending on your purpose. I wanted to go 158,400 steps. That corresponded with 99 rotations of my 1.8 deg stepper motor with 1/8th microstepping.

int actuatorSpeed=3900; //This corresponded to 487.5 steps/second, or 2.47 revs/second, which for me corresponding to about 40 seconds for my actuator.

unsigned long actuatorTimeout =19000; //This might not be used in the tutorial, but it’s good to have a timeout threshold if you think your actuator might stall out and you want some backup timeout.

int actuatorAcceleration=8500; //This acceleration value was chosen by experimentation, and only corresponds to the initial actuatorSpeed trigger point - after that your linear acceleration takes over.

const byte programOverhead=26; //measured in mS.

//During the fast-stepping function you may want to check a few sensors (in my case, for an end-stop)。 The thing is you want your initial linear step-delay to be pretty close to whatever step rate the accelstepper actuatorSpeed was. For this to work, you need to know roughly how much time your control loop takes excluding the step delay. If your sketch is similar to mine in what it‘s checking, you can start with my numbers.

const byte minPulseWidth=3; //different drivers require different minimum step pulses to register a line change.。.The basic reprap drivers are 1-2mS, this is sort of an unnecessary variable I used for extra fluff, you can probably do without it.

//FINAL STEP RATE VALUE

byte stepDelayTarget=90-minPulseWidth-programOverhead; // This should never add up to 《0. Check manually.

//This number, here shown as 90, relates to your target final step max speed. 90 is in uS, so I went up to 1000,000/90 = 11,111.1.。 steps/second. That’s an improvement over the default max of 3900 steps/seconds and was rate limited in my application by the physical system. I don‘t know how high you can expect an arduino to go. I would guess around 30uS for the mega with my specific code (ergo 33,000 steps/s)

const int systemEndstop=24;

const int enablePin=53; //This is another extra variable I kept in the example code. You can ignore it, but it refers to a pin that is controlling the enable pin of my DRV8825 driver. Because it’s 53 you can see I wrote this probably for an arduino mega.

//Global variables as part of the program functions.

unsigned long timeStart; //We want to be able to reset timeStart in different parts of the program. It‘s a global variable redeclared by a number of functions. Be aware. Another ’extra variable‘ I kept in the example code.

void setup(){ //Void setup runs once during initial boot of microprocessor, but not after.

stepper.setPinsInverted(false,false,true); // setPinsInverted(bool Dir,bool Step,bool Enable) Bool enable is == true because my enable pin is OFF when HIGH and ON when LOW. This is opposite of the default, so we enable the invert function. I believe the default is set for an A4988 driver, and this use case is for the Pololu DRV8825 breakout.

//the following should be familiar if you’ve used the accelstepper program before.

stepper.setMaxSpeed(actuatorSpeed);

stepper.setAcceleration(actuatorAcceleration);

stepper.setEnablePin(enablePin);

stepper.setMinPulseWidth(3); //Remember the minPulseWidth variable from before? This is the accelstepper version.

// declare pinmodes

pinMode(systemEndstop,INPUT);

digitalWrite(systemEndstop,HIGH); //This sets internal 20k pull-up resistor. It is usually necessary for a hall sensor to have a pull-up resistor, and in this case I was using a hall-sensor endstop.

} //end of void setup

void fastSteppingFunction(){ //This function will be used later as the linear-ramp portion of the code.

//Ok! StepDelay needs to be set so that it creates a stepping speed approximately equal to the stepping speed that accelstepper leaves off at. Much different, and you will have caused an instantaneous acceleration that the stepper motor will fail to keep up with.

byte stepDelay=((1000000/actuatorSpeed)-minPulseWidth-programOverhead);

//IMPORTANT NOTE: If your actuatorSpeed is less than 3900steps/s, you might want to change stepDelay to a uint_16t or otherwise ”uint.“ Bytes are less overhead to work with, but can‘t be 》255

//In my original code, I actually hard coded the stepDelay start at 250 instead of (100000/actuatorSpeed)。 The math for my values would put 1,000,000/actuatorSpeed at 256 steps/second, and for some reason I chose 250. But this math step allows for you to change your actuatorSpeed without needing to change the value here.

byte counter = 0;

//counter is used as a way to make a very quick conditional statement that overflows every 256 digits. There are other ways to implement the linear ramp. This is the way I chose. I thought it would be fast although it’s no longer clear to me why I chose exactly this method.

while(digitalRead(systemEndstop)==HIGH){ //remember this is our ending condition. In my code we are not relying on our steps to be counted. You can count steps too, by setting your condition to be when a bigger counter reaches a certain number. Then you need to implement a counter that increments during each step.

digitalWrite(stepPin,HIGH);

delayMicroseconds(minPulseWidth);

digitalWrite(stepPin,LOW);

delayMicroseconds(stepDelay);

if (actuatorTimeout《(millis()-timeStart)){ //Did you notice we said ”timeStart=millis()“ at the start of actuation? This is because I recommend your system has a timeout in case your motor stalls out and you never reach your endstop.

//make an error function and call it here.

//make a function to get back up to speed, assuming you want to do that after you resolve the error. Optional not included.

//recursively return to the fastSteppingFunction();

}

/*Next step is to increment the counter. This will run each time you repeat the loop.

My method is not very adjustable to changing the slope of the ramp, and if I were to rewrite

this code today I would probably choose something else. Consider this when implementing

your code.

*/

counter=counter+2; /*always manipulate this counter so that you understand when your

counter will reach the condition in the if statement below. In my case, it will reach the

the condition every 256/2 steps, i.e, every 128 steps. If I chose a number like ”3“ instead

of ”2“ I would have a problem because the counter would not reach 0 until a third overflow

of the byte counter, so I would be decreasing the slope of my linear ramp six times.

Meanwhile I can also decrease the slope by half by changing the number to 1. Or, I can double

the slope by saying 4. This lack of flexibility in changing the linear ramp slope is why

I suggest considering other methods to make a linear ramp. Try to implement your method with

minimum math. Ideally do not include multiplication in the loop, and especially not division.

*/

if (stepDelay》stepDelayTarget && counter==0){ //So this condition is looking to see if you‘re reached your max speed target, and if you haven’t yet and the counter has reached its trigger point [0], then it decreases the delay.

stepDelay--; //Stepdelay-- is a fast way of saying ”stepdelay=stepdelay-1“, i.e, your decreasing the step delay. By decreasing the step delay, you are increasing the frequency of steps/ the speed of your motor.

}

}

}

}

void moveActuatorForward(){

//Hey! You‘re about to start moving a motor. In a lot of cases that means you should make some safety check. The following commented if statement is a filler for that.

/*if ([insert errorCondition]){

//stepper.disableOutputs();

//error();

}*/

stepper.enableOutputs(); //This is redundant, in fact. It’s already been called.

stepper.move(actuatorDistance); //You need to tell accelstepper how far you‘re going!

timeStart = millis(); //I used a global variable in other parts of the code, maybe you want to use a local variable.

//Hey we’re finally starting!!

while(1){ //Title: ”Basic Moving While Loop“

if (digitalRead(systemEndstop)==LOW){ //checks if we hit the endstop before reaching the accelstepper max speed

//This never happened for my application, but maybe does for yours.

break; //break removes you from the while loop called ”Basic Moving While loop“

}

stepper.run(); //this makes your initial acceleration completely abstract.

if(stepper.speed() fastSteppingFunction();

break;

}

}

stepper.DisableOutputs();

//Hey we‘re done!

}

void loop(){

//do stuff other than moving your motors, if you have other stuff to do.

stepper.disableOutputs(); //I tend to add extra disableOutputs in case I made mistakes in the code, because my stepper motors were set to a high current that would eventually make those little motors overheat. For simple programs this isn’t a big deal, but once you start running around with more program states you want to be sure you don‘t let your motor overheat while you’re doing something else.

if (1){ //Here I‘m just suggesting that you probably want to run the actuator based on some condition.

//Now this is a stripped version of the code. Let’s just look at it as a goal to ”actuate“ a linear actuator. There are two endstops for this device but we‘re only looking at moving the actuator from ”home“ to ”endstop“

stepper.enableOutputs();

stepper.setCurrentPosition(0); //My physical system had a lot of friction, so I never decelerated my load. This meant that when I start the motor, accelstepper sometimes wants to ”slow down“ before it accelerates again. This is even if it was in fact not running. SetCurrentPosition(0) acts as a reset to the accelstepper code.

moveActuatorForward();

stepper.disableOutputs();

}

}

步驟3:PS,您注意到了嗎?

我的“線性斜坡”實際上不是線性斜坡。我每128步(大約每20mS)減少1uS步之間的延遲。最初,步進延遲為250mS,步進增加的速率為每32mS 1uS。到我的驅動結束時,每11.5mS的增加速率為1uS。這是一個非線性的斜坡,在接近終點時加速度增加。可能有很多很好的方法可以使此線性化,或更改執行速度增加的方法。但是我的執行器已經運行了好幾個月,所以我認為該方法已經足夠好了。

事實是,直到我編寫此可指導的代碼并梳理我的代碼之前,我才注意到它。

責任編輯:wv

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 步進電機
    +關注

    關注

    152

    文章

    3166

    瀏覽量

    149733
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    實時生成步進電機速度曲線

    一種用于步進電機加速度的新算法可以實現速度曲線的實時參數化和計算。該算法可以在低端微控制器上運行,只使用簡單的定點算術運算并且不使用數據表。它以恒定的加速度和減
    發表于 05-14 15:09

    網絡筆記分享-實時生成步進電機速度曲線

    一種用于步進電機加速度的新算法可以實現速度曲線的實時參數化和計算。該算法可以在低端微控制器上運行,只使用簡單的定點算術運算并且不使用數據表。它以恒定的加速度和減
    發表于 03-04 21:17

    步進電機的控制實現方法

    電機能夠實現高精度的位置控制和速度控制。本文將詳細介紹步進電機的控制實現方法,包括基本的控制原理、常見的控制策略以及實際應用中的注意事項。 ? ? ? 一、步進電機的基本控制原理 ? ? ?
    的頭像 發表于 01-21 16:43 ?1353次閱讀
    <b class='flag-5'>步進</b>電機的控制實現方法

    通過具體案例,選擇合適的步進電機

    選型原則,并通過具體實例加以說明,幫助讀者更好地理解和應用步進電機的選型方法。 ? ? ? 步進電機選型的基本要素 ? ? ? 步進電機選型主要依據三大要素:步距角、靜力矩和電流。 ?
    的頭像 發表于 12-13 07:34 ?1526次閱讀
    <b class='flag-5'>通過</b>具體案例,選擇合適的<b class='flag-5'>步進</b>電機

    行星減速步進電機與步進電機的區別

    步進電機是一種將電脈沖信號轉變為角位移或線位移的開環控制電機。其工作原理是通過電子電路將直流電分為多相序控制電流,使用這種電流給步進電機供電,步進電機才能正常工作。每輸入一個電脈沖,
    的頭像 發表于 11-16 15:11 ?844次閱讀
    行星減速<b class='flag-5'>步進</b>電機與<b class='flag-5'>步進</b>電機的區別

    LMK05318在TICS Pro中怎樣設置,可以加快同步的速度,實現幾分鐘之內相位同步?

    同步可能需要數小時。請問在TICS Pro中怎樣設置,可以加快同步的速度,實現幾分鐘之內相位同步?可以接受同步過程中輸出頻率的偏差,但要求相位快速同步。附件是我這次的使用的配置文件,請問這樣的配置是否有問題?
    發表于 11-12 06:46

    步進電機驅動器的主要工作原理是什么?

    步進電機驅動器的主要工作原理是通過精確控制電機的步進角度,實現對電機位置和速度的精確控制。步進電機驅動器通常由微處理器、功率放大器、驅動電路
    的頭像 發表于 10-24 13:40 ?2257次閱讀

    步進電機的控制技術及發展概況有哪些?

    電脈沖信號時,步進電機的定子繞組會產生磁場,使轉子產生扭矩,從而實現轉動。步進電機的轉動角度與輸入的電脈沖數成正比,因此可以通過控制電脈沖的數量來實現精確的定位和速度控制。
    的頭像 發表于 10-22 11:50 ?682次閱讀

    最大限度地提高MSP430? FRAM的寫入速度

    電子發燒友網站提供《最大限度地提高MSP430? FRAM的寫入速度.pdf》資料免費下載
    發表于 10-18 10:09 ?1次下載
    <b class='flag-5'>最大</b>限度地提高MSP430? FRAM的寫入<b class='flag-5'>速度</b>

    PLC控制步進電動機的基本原理

    “步距角”。通過精確控制脈沖的數量,可以實現對步進電動機角位移量的精細調控,從而實現高精度的定位任務。 除了位置控制外,步進電動機的速度和加速度
    的頭像 發表于 09-24 11:28 ?875次閱讀

    步進電機的伺服控制方法有哪些

    和脈沖序列,使電機準確移動到目標位置。這種控制模式適用于需要精確定位的應用場景。 2. 速度模式 定義 :在速度模式下,步進伺服電機根據輸入的速度指令,
    的頭像 發表于 09-04 09:48 ?1167次閱讀

    步進電機伺服控制系統的作用

    步進電機伺服控制系統是一種精密的電機控制系統,它通過精確控制電機的步進角度來實現對機械運動的精確控制。這種系統廣泛應用于自動化設備、機器人、精密儀器等領域。 步進電機伺服控制系統的作用
    的頭像 發表于 09-04 09:46 ?1221次閱讀

    AM625SIP處理器如何透過整合LPDDR4,加快開發速度

    電子發燒友網站提供《AM625SIP處理器如何透過整合LPDDR4,加快開發速度.pdf》資料免費下載
    發表于 08-28 10:47 ?0次下載
    AM625SIP處理器如何透過整合LPDDR4,<b class='flag-5'>加快</b>開發<b class='flag-5'>速度</b>

    步進電機型號與步進電機命名規則

    混合式步進電機代碼:SM。 系列代碼:H、高性能二相步進電機;C、三相步進電機;E、五相步進
    的頭像 發表于 08-26 09:42 ?1025次閱讀
    <b class='flag-5'>步進</b>電機型號與<b class='flag-5'>步進</b>電機命名規則

    國內低代碼平臺推薦--萬界星空科技低代碼平臺

    代碼平臺是一種應用程序,它為編程提供圖形用戶界面,從而以極快的速度開發代碼,減少傳統編程工作。 這些工具有助于快速開發代碼最大限度
    的頭像 發表于 07-18 15:39 ?568次閱讀
    國內低<b class='flag-5'>代碼</b>平臺推薦--萬界星空科技低<b class='flag-5'>代碼</b>平臺