I am new to mbot, i have access to it in college only I don’t have it home.
The teacher gave us some orders to do with mbot in home then try it in college the main problem is how can i know if my codes are going to work or not.
For example one of the orders say when mbot finds an obstacle it should moves backwards then Left then forward how can i know if my codes are Going to work or not.
And is it ok to post my codes and you guys will just tell me if it’s right or not.
Sorry if this question feels stupid I didn’t expect to get accepted in this college I don’t have alot of informations about these stuff.
I don't have my mBot but need to see if my codes work
@Buntaro Feel free to share your codes! We can test them and see if they’ll work, or help you fix them.
@CommandeR knows a lot about mBots, he can probably help you more than me.
Good luck!
Mbot should: (Move forward find an obstacle then moves backward) do this three times then turns right. Am not sure if it’s right
There is another thing the teacher wanted us to do but I didn’t know how.
It’s the same thing mbot should do but if the obstacle is gone the counter should reset to zero and keep moving to find another obstacle and count again then turn right. Hope you understand it
So the first code is supposed to make the mBot:
- Move forward if it sees no obstacle
- Move backward for 1 second three times (a total of 3 seconds) when it sees an obstacle
- When done moving backward, turn right
Is that right? Just want to make sure before I test it!
When it moves backward it will move forward again like this:
Forward obstacle backward forward obstacle backward forward obstacle backward turn right moves forward. It’s like trying 3 times to move forward just in case the obstacle is gone
It doesn’t go backward for 3 seconds straight
OK, I’ve almost got it! Choose A or B in step 2 below:
- Move forward if it sees no obstacle
- Move backward for one second, then move forward for one second when an obstacle is in range. A: Do this three times. Or B: Do this three times max, but stop doing this if the obstacle has disappeared.
- Turn right and continue (back at the start of the program)
Just to be extra clear.
B.
Mbot moves forward forever
It stops when it sees an obstacle and moves backward for one second ( the obstacle will be out of range ) that means it will go forward again, it will do this three times ( counter will reach 3 that will make mbot turn right ) and moves forward forever.
If the obstacle is gone and counter is on 2 only, sure it will go forward.
@Buntaro Got it!
I haven’t tested with my mBot yet, but I can see some issues with your code.
For example, the counter doesn’t reset if the obstacle moves before the third try, and there are a few things with the logic I would change. Here’s what I would do:
I’ll test both of our codes later today or tomorrow.
@Best_codes can’t wait to see the results!!
The important thing
Let’s say the obstacle is gone after two attempts ( counter will be 2 )
Mbot will move forward ( because obstacle is gone ) and counter will rest to zero right ?
And when it finds another obstacle it will count again from 0 to 3.
If that what’s going to happen then it’s 100% right.
@Best_codes I don’t know how to thank you
The sad thing we have upcoming project for mbot next week, and it will be the last week we study about mbot. And of course I don’t have any idea about what i should do if you have any suggestions it will be helpful
Again thank you very much
So sorry man. If you need any future help on coding the mbot, I will try to rebuild my mbot and test it for you And if you want to get one of your own, maybe I can share some of my programs if I can get my other account back.
Will make sure to ask if i need help and anything would help me alot .
Thank you so much
@Best_codes, your program made the arduino build fail.
Reason: You cannot have letters in the variable blocks. So, I changed “is obstacle there” false to zero,
and true to 1.
And I rebuilt my regular mbot.
That’s very strange, I’m pretty sure mBlock declares variables as a float
in the C code, and it should allow strings, but I fixed it in my screenshot.
Yeah, that is the part that made it error out. It didn’t support strings, atleast on the base mbot.