缺少`socket`上的错误处理程序TypeError:task不是函数 - node.js async.js

时间:2016-07-10 17:21:27

标签: javascript node.js socket.io async.js raspberry-pi3

我的网络服务器控制的机器人项目需要你的帮助。 我尝试通过网站控制两台电机。

很多东西已经在运作,所以我可以打开一个网站并点击" w"钥匙和两个汽车开始向前发展。 (MyControlls:w =前进,s =后退,a =左,d =右)

但是不再处理另一个命令。

在命令行上,我可以看到以下错误消息:

Missing error handler on `socket`.
TypeError: task is not a function
at /home/pi/tank/node_modules/async/dist/async.js:5285:13
at replenish (/home/pi/tank/node_modules/async/dist/async.js:871:21)
at /home/pi/tank/node_modules/async/dist/async.js:881:15
at _parallel (/home/pi/tank/node_modules/async/dist/async.js:5284:9)
at parallelLimit (/home/pi/tank/node_modules/async/dist/async.js:5317:14)
at Object.parallel (/home/pi/tank/node_modules/async/dist/async.js:930:20)
at Object.tank.moveForward (/home/pi/tank/app.js:46:9)
at Socket.<anonymous> (/home/pi/tank/app.js:87:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)

似乎问题出在 moveForward:function()和async.parallel周围 (其他Move函数也有同样的问题。)

var tank = {

//we create an object with the used pins
motors : {
    leftFront: 11,
    leftBack: 12,
    rightFront: 15,
    rightBack: 16
},

//we open the gpio pins and set the as outputs
init : function(){
    gpio.open(this.motors.leftFront, "output");
    gpio.open(this.motors.leftBack, "output");
    gpio.open(this.motors.rightFront, "output");
    gpio.open(this.motors.rightBack, "output");
},

//in order to move the tank forward, we supply both motors
moveForward : function(){
    async.parallel([
    gpio.write(this.motors.leftFront, 1),
    gpio.write(this.motors.rightFront, 1)
    ])
},

//in order to move the tank backwards, we supply both motors, but with inverse polarity
moveBackward : function(){
    async.parallel([
    gpio.write(this.motors.leftBack, 1),
    gpio.write(this.motors.rightBack, 1)
    ]);
},

//in order to turn right, we supply on the left
moveLeft : function(){
    gpio.write(this.motors.leftFront, 1);
},

//in order to turn left, we supply on the right
moveRight : function(){
    gpio.write(this.motors.rightFront, 1);
},

//in order to stop both motors, we set all pins to 0 value
stop : function(){
    async.parallel([
    gpio.write(this.motors.leftFront, 0),
    gpio.write(this.motors.leftBack, 0),
    gpio.write(this.motors.rightFront, 0),
    gpio.write(this.motors.rightBack, 0)
    ]);
}
};

请帮忙!

1 个答案:

答案 0 :(得分:1)

您未正确使用library(dplyr) grpD <- group_grid %>% mutate_if(is.factor, as.character) %>% #change to character class as joining mutate(income = as.character(income))#with same class columns are reqd. mydata %>% mutate_if(is.factor, as.character) %>% #change class here too left_join(., grpD, by= c("Country" = "state", "Age" = "age", "Income" = "income")) # Country Age Income val #1 FR 20 1 2 #2 UK 80 4 78 #3 UK 20 2 23 #4 IT 40 3 46 #5 DE 60 1 15 #6 ES 20 5 84 #7 FR 60 5 92 #8 DE 80 3 60 #9 IT 40 4 66 #10 UK 60 2 33 。它需要一系列函数,async.parallel()不返回函数。

你需要做这样的事情:

gpio.write()

为了避免额外的样板,您还可以将根据需要创建必要功能的函数分解出来:

var self = this;
async.parallel([
    function (callback) {
        gpio.write(self.motors.leftBack, 1, callback);
    },
    function (callback) {
        gpio.write(self.motors.rightBack, 1, callback);
    }
]);