91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何通過(guò)代碼HodgePodging加快最大步進(jìn)速度

454398 ? 來(lái)源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2019-11-18 09:03 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

第1步:

我使用了很多單詞來(lái)描述我的方法,但是我也尊重每個(gè)人都會(huì)從另一個(gè)地方來(lái)處理這個(gè)問(wèn)題。如果您有經(jīng)驗(yàn),請(qǐng)多說(shuō)些抱歉,但是,如果您不熟悉arduino,并且想以比當(dāng)前使用accelstepper更快的速度運(yùn)行步進(jìn)電機(jī),那么請(qǐng)問(wèn)所有問(wèn)題。

計(jì)劃:

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

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

//做東西

//做更多東西

stepper.run();

}

只要“填充”時(shí)間不長(zhǎng),stepper.run()就會(huì)非常頻繁地運(yùn)行,并且步進(jìn)操作。但是stepper.run()并不是一個(gè)非??焖俚暮瘮?shù),在某些時(shí)候它是限制因素!然后,此while循環(huán)會(huì)花費(fèi)太長(zhǎng)時(shí)間。

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

//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

這有意義嗎?下一步,讓我們深入研究同樣冗長(zhǎng)的注釋代碼,如果有任何問(wèn)題,請(qǐng)返回。

步驟2:哇,代碼!

我從我的項(xiàng)目中提取了一個(gè)完整的程序,并在保留大部分表單的同時(shí)將其剝離了下來(lái)。 “功能”模式。我可以說(shuō)原始代碼有效,但是我只測(cè)試了新代碼可以編譯。

此代碼是否完美?否。

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

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

它最初是作為函數(shù)調(diào)用編寫(xiě)的,在我的程序中可以使用幾個(gè)不同的馬達(dá)(調(diào)用accellstepper的不同實(shí)例),但在此示例中我將其簡(jiǎn)化了一些。

建議:如果簽出附帶的.ino,則可以在您喜歡的文本編輯器中查看代碼。它的顯示效果會(huì)好得多,我不建議整體復(fù)制此代碼塊,因?yàn)樗赡軙?huì)稍微變形。

/*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,您注意到了嗎?

我的“線性斜坡”實(shí)際上不是線性斜坡。我每128步(大約每20mS)減少1uS步之間的延遲。最初,步進(jìn)延遲為250mS,步進(jìn)增加的速率為每32mS 1uS。到我的驅(qū)動(dòng)結(jié)束時(shí),每11.5mS的增加速率為1uS。這是一個(gè)非線性的斜坡,在接近終點(diǎn)時(shí)加速度增加??赡苡泻芏嗪芎玫姆椒梢允勾司€性化,或更改執(zhí)行速度增加的方法。但是我的執(zhí)行器已經(jīng)運(yùn)行了好幾個(gè)月,所以我認(rèn)為該方法已經(jīng)足夠好了。

事實(shí)是,直到我編寫(xiě)此可指導(dǎo)的代碼并梳理我的代碼之前,我才注意到它。

責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    步進(jìn)電機(jī)的位置控制與速度控制

    步進(jìn)電機(jī)是一種將電脈沖信號(hào)轉(zhuǎn)換為角位移或線位移的執(zhí)行元件,其 位置控制 與 速度控制 是兩大核心應(yīng)用。雖然兩者在實(shí)現(xiàn)上緊密相關(guān),但控制目標(biāo)和策略有本質(zhì)區(qū)別。 一、 核心原理回顧 步進(jìn)電機(jī)的運(yùn)動(dòng)由
    的頭像 發(fā)表于 03-23 15:37 ?668次閱讀
    <b class='flag-5'>步進(jìn)</b>電機(jī)的位置控制與<b class='flag-5'>速度</b>控制

    步進(jìn)電機(jī)驅(qū)動(dòng)器的作用介紹

    步進(jìn)電機(jī)驅(qū)動(dòng)器是現(xiàn)代工業(yè)自動(dòng)化、精密控制設(shè)備中的核心組件之一,其作用遠(yuǎn)不止簡(jiǎn)單的“驅(qū)動(dòng)電機(jī)轉(zhuǎn)動(dòng)”,而是通過(guò)精確控制電流、細(xì)分步距角以及動(dòng)態(tài)響應(yīng),實(shí)現(xiàn)高精度定位和速度調(diào)節(jié)。從3D打印機(jī)到數(shù)控機(jī)床,從醫(yī)
    的頭像 發(fā)表于 02-28 15:47 ?212次閱讀
    <b class='flag-5'>步進(jìn)</b>電機(jī)驅(qū)動(dòng)器的作用介紹

    DRV8811 步進(jìn)電機(jī)驅(qū)動(dòng)IC:特性、應(yīng)用與設(shè)計(jì)要點(diǎn)

    脈沖寬度調(diào)制(PWM)微步進(jìn)技術(shù),支持高達(dá) 1/8 步的微步進(jìn)索引器,通過(guò)簡(jiǎn)單的 STEP 和 DIR 接口就能輕松與控制器連接。它每相繞組最大
    的頭像 發(fā)表于 01-11 17:25 ?747次閱讀

    步進(jìn)電機(jī)的控制原理

    電機(jī)(簡(jiǎn)稱(chēng)HB)。 步進(jìn)電機(jī)區(qū)別于其他控制電機(jī)的最大特點(diǎn)是,它是通過(guò)輸入脈沖信號(hào)來(lái)進(jìn)行控制的,即電機(jī)的總轉(zhuǎn)動(dòng)角度由輸入脈沖數(shù)決定,而電機(jī)的轉(zhuǎn)速由脈沖信號(hào)頻率決定。 步進(jìn)電機(jī)的驅(qū)動(dòng)電路根
    發(fā)表于 01-04 08:25

    “點(diǎn)沙成金”的科技奇跡:深入解讀芯片制造三大階段與五大步

    芯片是如何“點(diǎn)沙成金”的?本文深度解析芯片制造的三大階段與五大步驟,從邏輯設(shè)計(jì)、晶圓拉制,到上百次的光刻-刻蝕循環(huán),揭秘驅(qū)動(dòng)數(shù)字世界的微觀奇跡。
    的頭像 發(fā)表于 10-31 10:34 ?1299次閱讀
    “點(diǎn)沙成金”的科技奇跡:深入解讀芯片制造三大階段與五<b class='flag-5'>大步</b>驟

    單片機(jī)怎么控制步進(jìn)電機(jī)的

    步進(jìn)電機(jī)作為一種將電脈沖信號(hào)轉(zhuǎn)化為角位移的執(zhí)行機(jī)構(gòu),其運(yùn)轉(zhuǎn)依賴(lài)于脈沖信號(hào)的控制,而單片機(jī)作為控制核心,通過(guò)輸出特定的脈沖信號(hào)和方向信號(hào),實(shí)現(xiàn)對(duì)步進(jìn)電機(jī)的步數(shù)、方向、轉(zhuǎn)速的精準(zhǔn)控制,整個(gè)過(guò)程需結(jié)合驅(qū)動(dòng)
    的頭像 發(fā)表于 07-24 13:41 ?778次閱讀

    STM32IDE如何設(shè)定代碼到ITCM中運(yùn)行?

    近期使用STM32MUX生成STM32IDE的代碼(MCU是STM32H743),目前希望可以將部分代碼定位到ITCM中運(yùn)行,加快處理速度,關(guān)于代碼
    發(fā)表于 06-24 06:45

    步進(jìn)電機(jī)和伺服電機(jī)的區(qū)別是什么?

    啟動(dòng)速度不同 步進(jìn)電機(jī)啟動(dòng)需要200-400毫秒而伺服電機(jī)只需要幾毫秒是步進(jìn)電機(jī)的上百倍 控制精度不同 步進(jìn)電機(jī)的精度取決于相數(shù)和驅(qū)動(dòng)器的細(xì)分設(shè)置;伺服電機(jī)的精度取決于編碼器的分辨率
    發(fā)表于 06-18 13:27

    ADI Trinamic TMC2210大電流步進(jìn)電機(jī)驅(qū)動(dòng)器IC數(shù)據(jù)手冊(cè)

    Analog Devices Inc.的TMC2210步進(jìn)電機(jī)驅(qū)動(dòng)器IC通過(guò)封裝引腳和附加診斷輸出提供配置選項(xiàng)。TMC2210集成了基于256微步進(jìn)內(nèi)置索引器的高級(jí)步進(jìn)電機(jī)驅(qū)動(dòng)器和兩個(gè)
    的頭像 發(fā)表于 06-04 10:42 ?1253次閱讀
    ADI Trinamic TMC2210大電流<b class='flag-5'>步進(jìn)</b>電機(jī)驅(qū)動(dòng)器IC數(shù)據(jù)手冊(cè)

    關(guān)于范例fifosync5bit在使用EP1-8共有16個(gè)通道時(shí),其最大速度能達(dá)到多少K?

    您好,我想問(wèn)一下關(guān)于范例fifosync5bit在使用EP1-8共有16個(gè)通道時(shí),其最大速度能達(dá)到多少K? 我使用官方的5bit配置完我的代碼后發(fā)現(xiàn)并不能使用streamer工具。因此想請(qǐng)問(wèn)當(dāng)5bit只有16個(gè)通道的時(shí)候,
    發(fā)表于 05-22 06:57

    實(shí)時(shí)生成步進(jìn)電機(jī)速度曲線

    一種用于步進(jìn)電機(jī)加速度的新算法可以實(shí)現(xiàn)速度曲線的實(shí)時(shí)參數(shù)化和計(jì)算。該算法可以在低端微控制器上運(yùn)行,只使用簡(jiǎn)單的定點(diǎn)算術(shù)運(yùn)算并且不使用數(shù)據(jù)表。它以恒定的加速度和減
    發(fā)表于 05-14 15:09

    HJ4205步進(jìn)電機(jī)驅(qū)動(dòng)電路詳解

    HJ4205是一款步進(jìn)電機(jī)驅(qū)動(dòng)電路。包含一個(gè)步進(jìn)電機(jī)控制器和內(nèi)部N溝道MOSFET,來(lái)驅(qū)動(dòng)一個(gè)雙極步進(jìn)電機(jī)或兩個(gè)刷式直流電機(jī)。HJ4205支持全步進(jìn)到1/256
    的頭像 發(fā)表于 05-07 16:19 ?1870次閱讀
    HJ4205<b class='flag-5'>步進(jìn)</b>電機(jī)驅(qū)動(dòng)電路詳解

    SlaveFifo 2bit sync模式下最大速度只有320Mbyte/s左右,還能更快一點(diǎn)嗎?

    你好!我測(cè)試了SlaveFifo 2bit sync32bitBus 模式,采用AN65974官方代碼,硬件芯片是Artix 7 , PCLK設(shè)置為100MHz的時(shí)鐘,目前只開(kāi)通單個(gè)讀線程 最大速度
    發(fā)表于 05-06 14:36

    剎車(chē)步進(jìn)電機(jī)的特點(diǎn)

    詳細(xì)分析。 一、技術(shù)原理與結(jié)構(gòu)設(shè)計(jì) 剎車(chē)步進(jìn)電機(jī)在傳統(tǒng)步進(jìn)電機(jī)的基礎(chǔ)上集成電磁制動(dòng)裝置,通常采用失電制動(dòng)原理。當(dāng)電機(jī)斷電時(shí),制動(dòng)器通過(guò)彈簧力或永磁體作用立即夾緊電機(jī)軸,實(shí)現(xiàn)瞬間停止;通電時(shí),電磁力克服彈簧阻
    的頭像 發(fā)表于 04-25 15:34 ?1580次閱讀
    剎車(chē)<b class='flag-5'>步進(jìn)</b>電機(jī)的特點(diǎn)

    步進(jìn)電機(jī)過(guò)載怎么處理

    步進(jìn)電機(jī)過(guò)載時(shí),可以采取以下措施進(jìn)行處理: 一、降低電機(jī)負(fù)載 1. 減少負(fù)載:通過(guò)增加傳動(dòng)比例、優(yōu)化機(jī)械設(shè)計(jì)等方式來(lái)減輕步進(jìn)電機(jī)的負(fù)載,確保其在額定負(fù)載范圍內(nèi)運(yùn)行。 2. 檢查機(jī)械部件:定期檢查
    的頭像 發(fā)表于 04-21 07:41 ?1547次閱讀