RoboticsGeneral

Maqueen Plus and Gamepad - Communication Lag

userHead david.lincourt 2020-06-18 23:44:32 2837 Views5 Replies
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?
2020-06-23 22:05:11 Hello Nana - A little over a second... less than 1.5 seconds. userHeadPic david.lincourt
2020-06-20 01: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 () {

})
userHeadPic david.lincourt