Robot won't stop even when speed set to 0


#1

For the CoderDojo (7-12y kids), I’m making a robot arena where two robots will fight.

  • They both have a balloon and a sharp stinger.
  • The robots cannot leave the arena (marked by black tape) and get a power-up (faster speed) when in bright light.
  • Every minute the players (humans) can move a object to block their opponent. If there’s an object in the arena, the will avoid it.
  • First ballon blown looses the game.

Problem is that I can’t get the basics right: controlling the speed of the robot.
For some reason the robot just keeps on running, even if I set the speed to zero.

You can find my script attached. I stripped it to the bare essentials for debugging.
Any help is appreciated…


#2

Hi, according to your description, I am afraid that we are unable to provide this kind of suggestion without any testing. Here a program for you, you can take a look at it.
You may search on our forum (http://forum.makeblock.com) and see if there are other users having similar personal projects.
LineFollower and Aviod object.zip (40.1 KB)


#3

I was unable to reproduce your problem with the code you have given (I removed the ‘wait until on board button pressed’ block, since that doesn’t seem to work in Scratch mode), but there are a few things to note. When running the robot in Scratch mode, the response time is slower. I had to hold the space bar down to get it to respond. I created the same program in Arduino mode, replacing the ‘space bar pressed’ condition with a ‘light sensor on board value less than 100’ condition and removing the ‘stop all’ block. When I placed my hand over the robot, it stopped immediately. One other thing to note is that the ‘Change Direction’ function will not allow your robot to run backwards since the program will instantaneously flow to the ‘turn right’ code block.


#4

THanks for your reply, debert.
I was looking more for answer like this. I got me thinking about the sequence.
Regarding the ‘instantaneously flow’: I remove too much code to simplify the program for this forum.

I managed to solve the problem by moving the “listerener” of the spacebar to another sprite.
On sprite 1 the main program is running.
On sprite 2 is changing speed when spacebar is clicked.

This seems to do the trick.

arena%202B


#5

Umpf, I think I stamped my triumph too early…

I tested the code with the blue pink: everything working fine. It turns when needed, I can easily control the speed and stop the bot with space or letter Q.

When I test it with the blue mBot: it doesn’t work. He drives around and turns when finding obstacles (just like the other one).
Controling speed doesn’t work though: the variables change, but he ignores the commands.
Even stopping the program with the red button doesn’t work: it keeps running.
Shutting off and back on: keeps running.

Any idea?

PS: pink robot = Bluetooth, blue robot = 2.4Ghz
PPS: tested separately, not both at once of course…


#6

Update: I switced blue & pink in my previous post: it’s correct now.
I updated the Blue mBot’s firmware, but still without success


#7

Sound like your robot is defect. You could switch the cables to the motors to find out if the motor is broken (unlikely, but cheap to replace) our your mainboard.


#8

Is there any reason why you are running in Scratch mode instead of Arduino mode? By compiling and loading the program onto the robot your robot will be much more responsive. Running it in Scratch mode means that it is sending the data gathered by the robot back to the computer for processing. The computer output must then be sent back to the robot before it will respond. If the program is uploaded to the robot, the data processing occurs on the robot. I have uploaded an image of the version of your program that I am running. I have circled where you need to click to run the program in Arduino mode. Note that you need to use the ‘mBot program’ start block. The other start blocks are not active in Arduino mode. Also note that I have used ‘set LED on board’ blocks to help troubleshoot. This tells me which part of the code is being used (or not being used). It doesn’t change the way your program runs.


#9

Thanks for your reply, David.

I use Scratch mode because I’m creating a game the kids can develop and play.
We need the keyboard to send to the mBot for changing speed:

  • Space = attack = speed 250 for 1 sec
  • Q = quit = speed 0
    (full description of the game in my first post)

I didn’t know of the Arduino mode btw: I’m just learning by doing.
I just tried it, but upload always fails. Will try some more.


#10

Update: I also found out why my IF-ELSE on the line follower isn’t working: the line follower only works well when there’s black-white contrast.
On my paper with black tape the program runs.
On a normal floor with tiles or wood or … the function always gives 3 as result.

This kills my ideas of creating some sort of an arena on a normal floor.


#11

Working in Scratch mode I think you will always have difficulties with responsiveness. Have a look at the line following video put out by MakeBlock (https://youtu.be/pTuiHjzWITc). This is actually one of series of videos on getting started with the mBot that I found invaluable. With regard to the upload failing there could be a couple of issues. One is that the robot isn’t connected to the computer.
connecting
The other possibility, if you are working in a school environment, is that restrictions placed on your network may block the upload. I don’t claim to understand it, but I had to talk to our network administrator to get it sorted out and he had to change some permissions.


#12

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.