Forum >Maqueen Plus and Gamepad - Communication Lag
Maqueen Plus and Gamepad - Communication Lag

Hello I recently received my micro:Maqueen Plus with Mechanic, micro:bit and Gamepad and have been experimenting with controlling the robot with the gamepad using Microsoft MakeCode.
I can get the robot to respond to the commands that I send. However, there is a significant lag between a command (e.g. button press) and the reaction from the robot.
Any advice on how to make the communication faster with less lag?
I can get the robot to respond to the commands that I send. However, there is a significant lag between a command (e.g. button press) and the reaction from the robot.
Any advice on how to make the communication faster with less lag?
2020-06-20 09:09:19 Hello Nana - thanks for your help. Here is the Javascript code. I am using Microsoft MakeCode:
On the Robot:
radio.onReceivedString(function (receivedString) {
if (receivedString == "Open") {
basic.showIcon(IconNames.SmallHeart)
DFRobotMaqueenPluss.servoRun(Servos.S2, -150)
}
if (receivedString == "Close") {
basic.showIcon(IconNames.Heart)
DFRobotMaqueenPluss.servoRun(Servos.S2, 150)
}
if (receivedString == "Stop") {
basic.showIcon(IconNames.SmallHeart)
DFRobotMaqueenPluss.mototStop(Motors.ALL)
}
if (receivedString == "Left") {
basic.showArrow(ArrowNames.West)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CCW, 40)
}
if (receivedString == "Right") {
basic.showArrow(ArrowNames.East)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CCW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CW, 40)
}
if (receivedString == "Up") {
basic.showArrow(ArrowNames.North)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CW, 40)
}
if (receivedString == "Down") {
basic.showArrow(ArrowNames.South)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CCW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CCW, 40)
}
})
basic.showIcon(IconNames.SmallHeart)
radio.setGroup(1)
DFRobotMaqueenPluss.servoRun(Servos.S2, -150)
DFRobotMaqueenPluss.mototStop(Motors.ALL)
basic.forever(function () {
})
On the Gamepad
gamePad.onEvent(GamerBitPin.P15, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P14, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P14, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.West)
radio.sendString("Left")
})
gamePad.onEvent(GamerBitPin.P15, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.East)
radio.sendString("Right")
})
gamePad.onEvent(GamerBitPin.P13, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.South)
radio.sendString("Down")
})
gamePad.onEvent(GamerBitPin.P8, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P1, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Open")
})
gamePad.onEvent(GamerBitPin.P8, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.North)
radio.sendString("Up")
})
gamePad.onEvent(GamerBitPin.P1, GamerBitEvent.Down, function () {
basic.showIcon(IconNames.Heart)
radio.sendString("Close")
})
gamePad.onEvent(GamerBitPin.P13, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
basic.showIcon(IconNames.SmallHeart)
radio.setGroup(1)
radio.sendString("Open")
basic.forever(function () {
})
david.lincourt
On the Robot:
radio.onReceivedString(function (receivedString) {
if (receivedString == "Open") {
basic.showIcon(IconNames.SmallHeart)
DFRobotMaqueenPluss.servoRun(Servos.S2, -150)
}
if (receivedString == "Close") {
basic.showIcon(IconNames.Heart)
DFRobotMaqueenPluss.servoRun(Servos.S2, 150)
}
if (receivedString == "Stop") {
basic.showIcon(IconNames.SmallHeart)
DFRobotMaqueenPluss.mototStop(Motors.ALL)
}
if (receivedString == "Left") {
basic.showArrow(ArrowNames.West)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CCW, 40)
}
if (receivedString == "Right") {
basic.showArrow(ArrowNames.East)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CCW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CW, 40)
}
if (receivedString == "Up") {
basic.showArrow(ArrowNames.North)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CW, 40)
}
if (receivedString == "Down") {
basic.showArrow(ArrowNames.South)
DFRobotMaqueenPluss.mototRun(Motors.M2, Dir.CCW, 40)
DFRobotMaqueenPluss.mototRun(Motors.M1, Dir.CCW, 40)
}
})
basic.showIcon(IconNames.SmallHeart)
radio.setGroup(1)
DFRobotMaqueenPluss.servoRun(Servos.S2, -150)
DFRobotMaqueenPluss.mototStop(Motors.ALL)
basic.forever(function () {
})
On the Gamepad
gamePad.onEvent(GamerBitPin.P15, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P14, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P14, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.West)
radio.sendString("Left")
})
gamePad.onEvent(GamerBitPin.P15, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.East)
radio.sendString("Right")
})
gamePad.onEvent(GamerBitPin.P13, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.South)
radio.sendString("Down")
})
gamePad.onEvent(GamerBitPin.P8, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
gamePad.onEvent(GamerBitPin.P1, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Open")
})
gamePad.onEvent(GamerBitPin.P8, GamerBitEvent.Down, function () {
basic.showArrow(ArrowNames.North)
radio.sendString("Up")
})
gamePad.onEvent(GamerBitPin.P1, GamerBitEvent.Down, function () {
basic.showIcon(IconNames.Heart)
radio.sendString("Close")
})
gamePad.onEvent(GamerBitPin.P13, GamerBitEvent.Up, function () {
basic.showIcon(IconNames.SmallHeart)
radio.sendString("Stop")
})
basic.showIcon(IconNames.SmallHeart)
radio.setGroup(1)
radio.sendString("Open")
basic.forever(function () {
})
