简体   繁体   English

约翰尼5步进移动(循环)

[英]johnny-five stepper move in (for-loop)

i'm relatively new in node.js resp. 我在node.js中相对较新。 johnny-five. 约翰尼五世。 I'm trying to move a Stepper for (example) 5 times with 1000 Steps. 我正在尝试以1000个步进将(例如)步进器移动5次。

So: 所以:

   do 1000 Steps in cw ; 
   console.log('ready); 
   do 1000 steps;
   console.log('ready')
   ...

it would be nice to make this in a for loop . 最好在for循环中进行设置。 Example: for 5 times make 1000 steps. 示例:5次,进行1000步。 I try to do this with the following Code: 我尝试使用以下代码执行此操作:

  for (var i = 0; i < 5; i++) {
    stepper.direction(1).step(1000, function() {
    console.log("Done stepping!");
    });
  }

The Output in my cmd is 我的cmd中的输出是

Done stepping!
Done stepping!
Done stepping!
Done stepping!
Done stepping!

But the Motor moves only once. 但是电机只运动一次。 I don't really understand why!? 我真的不明白为什么!

Hope someone can give a tip, Thanks! 希望有人能给个小费,谢谢!

Without wiring one up myself, I think that your problem is this: direction(1) . 如果不自己动手,我想您的问题是: direction(1) It seems like direction makes the motor point at a certain direction; direction似乎使电机指向某个方向。 thus your loop tells the motor to point at the same direction 5 times. 因此,您的回路告诉电机指向同一方向5次。

Try setting some different values inside stepper() , or replacing 1 with i in your loop: 尝试在stepper()内设置一些不同的值,或在循环中用i替换1

for (var i = 0; i < 5; i++) {
   stepper.direction(i).step(1000, function() {
   console.log("Done stepping!");
   });
 }

If this doesn't help, does your stepper motor have an external power source? 如果这没有帮助,您的步进电机是否具有外部电源? Can you provide a wiring diagram and the code for a simple test case? 您能提供一个简单测试用例的接线图和代码吗?

I am just starting to get back into writing code. 我才刚开始重新编写代码。 It's been 30 years so I am more than rusty. 已经30年了,所以我不只是生锈。

Try removing 'var in your 'for' loop. 尝试在“ for”循环中删除“ var”。

 for (i = 0; i < 5; i++) {
    stepper.direction(1).step(1000, function() {
    console.log("Done stepping!");
    });
  }

var I think would need to be defined earlier in the code. var我认为需要在代码的前面定义。

If you found the reason why please post it so I can learn from it too. 如果您找到原因,请发布它,以便我也可以从中学习。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM