我在试着让马达和强尼五号一起工作。我使用的是arduino,我从他们的网站上复制了代码和布线(大部分)。我在布线中唯一改变的是,我没有使用二极管来确保5V不会进入晶体管的发射极引脚,而是直接将其连接到电机,而不是使用电路板。问题是,我得到了一个奇怪的错误
C:\Users\simas\node_modules\johnny-five\lib\motor.js:721 this.speed({ ^
TypeError: this.speed不是Timeout.Motor.stop as _onTimeout at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10) PS C:\Users\simas\Desktop\motors>的函数
我一点也不明白为什么会发生这种情况,请帮帮忙。
(顺便说一下,我从网站上复制的代码是:
const {Board, Motor} = require("johnny-five");
const board = new Board();
board.on("ready", () => {
// Create a new `motor` hardware instance.
const motor = new Motor({
pin: 5
});
// Inject the `motor` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
motor
});
// Motor Event API
// "start" events fire when the motor is started.
motor.on("start", () => {
console.log(`start: ${Date.now()}`);
// Demonstrate motor stop in 2 seconds
board.wait(2000, motor.stop);
});
// "stop" events fire when the motor is stopped.
motor.on("stop", () => {
console.log(`stop: ${Date.now()}`);
});
// Motor API
// start([speed)
// Start the motor. `isOn` property set to |true|
// Takes an optional parameter `speed` [0-255]
// to define the motor speed if a PWM Pin is
// used to connect the motor.
motor.start();
// stop()
// Stop the motor. `isOn` property set to |false|
});)
发布于 2020-05-28 02:17:30
由于使用Adafruit Motor Shield V2 example code from the Johnny-Five documentation,我也遇到了同样的问题。
在将函数直接传递给board.wait时,这似乎是绑定到motor.stop调用的上下文的问题。
要解决此问题,请在电机实例上下文中声明您自己的函数,并将其传递给"start"事件处理程序中的board.wait调用:
// "start" event fires when the motor is started
motor.on("start", () => {
console.log(`start: ${Date.now()}`);
// Demonstrate motor stop in 2 seconds
board.wait(2000, () => {
motor.stop();
});
});https://stackoverflow.com/questions/58825674
复制相似问题