M&M bot

Here it is…

The cube has a cutout where the M&M’s go. Holds a lot of them.

We are still playing with the # of colors to match and how quickly they flash on the screen.

See you at worlds. 73805T

47 Likes

Cool, but for some reason I thought it was a sorter and I could press the red button and only get the one true RED M&M.

18 Likes

Ha.

Probably going to have harder difficulty that gives a larger portion.

Or could take motor from 10% speed (currently) to 100% and spray m&m across the pit area.

14 Likes

“This is what you are doing instead of preparing for worlds? You’re fired.”

-Coach
You know who I am.

7 Likes

Trying to clean/refine the code somewhat.

In robotmesh… need to use an incremented list AND wait for bump sensor input INSIDE the list loop.

Ideas?

Got it figured out.

Also, thought the random # generator was broken. We are seeing a LOT of series of the same colors. Ran it 10 times, wrote down ALL the colors, added them up, divided by 3. The colors are ‘perfectly’ random… even in randomness, order emerges.

1 Like

the random function works by taking numbers from a “random” list of numbers and going through them so the numbers you get, and therfor the sequences, will overall be the same

Our data is not supporting this. What we were seeing were runs of 3 red in a set of 6 colors, or 3 greens/blues. Or even 4 of the same color.

huh… interesting. Maybe im wrong


what
i think i need this

It’s packed and w/ be at dallas tomorrow.

1 Like

Use srand(0). Then do %, followed by the max amount of numbers you want (like 3). Not sure if that’s how you’re doing it though

Well, we are back after a LONG week of world’s competition. Many mistakes were made. Very much NOT happy about the radio channel shortage in practice area.

On the m&m bot. Many, many bags of m&m made their way through the bot. I meant to printout the code and have it next to the bot but forgot.

We eventually moved the buttons in front of the screen so users could see the button confirmations.

Biggest problem was debouncing the bump switches. We had to ignore continued pressing (slow fingers), but this caused delays between accepting input.

Most of the coding was spent on logic and tightening up the code. Need to come back to button debouncing/input filtering. Probably “if pressed, wait until NOT pressed”.

Here’s a copy/paste screenshot of code. If someone knows how to paste entire thing at once, let me know.

image
image


image

4 Likes

Convert to text (20 char.)

1 Like

People had problems using the bot due to trying to hit the buttons too quickly, and not being able to remember 6 colors in a row… but that’s another matter.

If you look at the code, we have a delay after the button press. Otherwise the code ‘cycled’ back while the button was being released and ‘saw’ that it was pressed again.

This delay was the problem… edited the code to remove the ‘sleep .75’ line and replaced that with ‘wait until button NOT pressed’. Also, removed the .75 sleep where it displays a correct press.

Result is that it now will handle inputs as fast as you can enter them.

Now if mars/m&m will just respond to our sponsorship request…

4 Likes

The new ‘button checking’ code. Will take inputs as fast as you can hit them bump sensors.

import vex
import sys
import random

#region config
brain = vex.Brain()
conveyor_ = vex.Motor(vex.Ports.PORT4, vex.GearSetting.RATIO18_1, True)
bump_red = vex.Bumper(brain.three_wire_port.a)
bump_green = vex.Bumper(brain.three_wire_port.b)
bump_blue = vex.Bumper(brain.three_wire_port.c)
bump_newgame = vex.Bumper(brain.three_wire_port.d)
#endregion config

color_6 = None
color_1 = None
color_2 = None
color_3 = None
color_4 = None
color_5 = None
correct_count = None
gameover = None
color_pressed = None
color_checking = None
color_display = None

main thread

color_1 = 0
color_2 = 0
color_3 = 0
color_4 = 0
color_5 = 0
color_6 = 0
correct_count = 0
gameover = 0
color_pressed = 0
brain.screen.set_font(vex.Font.MONO_60)
brain.screen.print_line(2, ’ To Play, Press’)
brain.screen.print_line(3, ’ “New Game”’)
while True:
if bump_newgame.pressing():
# reset variables
color_pressed = 0
correct_count = 0
gameover = 0
# generate colors
color_1 = random.randint(1, 3)
color_2 = random.randint(1, 3)
color_3 = random.randint(1, 3)
color_4 = random.randint(1, 3)
brain.screen.clear_screen(0x000000)
brain.screen.print_line(2, ’ Ready!’)
sys.sleep(1)
for color_display in [color_1, color_2, color_3, color_4]:
if color_display == 1:
brain.screen.clear_screen(0x000000)
brain.screen.set_fill_color(0xFF0000)
brain.screen.draw_rectangle(0, 0, 500, 250)
sys.sleep(0.5)
brain.screen.clear_screen(0x000000)
sys.sleep(0.5)
elif color_display == 2:
brain.screen.clear_screen(0x000000)
brain.screen.set_fill_color(0x33CC00)
brain.screen.draw_rectangle(0, 0, 500, 250)
sys.sleep(0.5)
brain.screen.clear_screen(0x000000)
sys.sleep(0.5)
elif color_display == 3:
brain.screen.clear_screen(0x000000)
brain.screen.set_fill_color(0x000099)
brain.screen.draw_rectangle(0, 0, 500, 250)
sys.sleep(0.5)
brain.screen.clear_screen(0x000000)
sys.sleep(0.5)
brain.screen.clear_screen(0x000000)
brain.screen.set_fill_color(0x000000)
brain.screen.print_line(2, ‘Your turn!’)
brain.screen.print_line(3, ‘Press the colors…’)
if gameover == 0:
for color_checking in [color_1, color_2, color_3, color_4]:
# record presses
sys.wait_for(lambda: bump_red.pressing() or bump_green.pressing() or bump_blue.pressing())
if bump_red.pressing():
sys.wait_for(lambda: not bump_red.pressing())
color_pressed = 1
elif bump_green.pressing():
sys.wait_for(lambda: not bump_green.pressing())
color_pressed = 2
elif bump_blue.pressing():
sys.wait_for(lambda: not bump_blue.pressing())
color_pressed = 3
# check presses
if color_pressed == color_checking:
color_pressed = 0
correct_count = correct_count + 1
brain.screen.clear_screen(0x000000)
brain.screen.print_line(2, (’’.join([str(x) for x in ['Color ‘, correct_count, ’ correct!’]])))
sys.sleep(0.01)
else:
gameover = 1
break

game lost

if gameover == 1:
brain.screen.clear_screen(0x000000)
brain.screen.set_fill_color(0x000000)
brain.screen.print_line(1, ‘Wrong Color!’)
brain.screen.print_line(2, ‘To Play Again,’)
brain.screen.print_line(3, ‘Press “New Game”’)
gameover = 2
sys.sleep(0.1)

game won

if gameover == 0:
brain.screen.clear_screen(0x33CC00)
brain.screen.set_fill_color(0x33CC00)
brain.screen.print_line(2, ‘You Win!!!’)
brain.screen.print_line(3, ‘To Play Again,’)
brain.screen.print_line(4, ‘Press “New Game”’)
conveyor_.spin(vex.DirectionType.FWD, 10, vex.VelocityUnits.PCT)
sys.sleep(2.5)
conveyor_.spin(vex.DirectionType.REV, 10, vex.VelocityUnits.PCT)
sys.sleep(0.75)
conveyor_.stop(vex.BrakeType.BRAKE)
gameover = 2

color_6

2 Likes

Wait, what, all this complexity in BLOCKS? Dude, we were all told that anything past a squarebot has to be programmed in PROS.

7 Likes

Ha. I see that blocks (and this was actually robotmesh DESKTOP edition) is seriously underused and underappreciated.

We’ve got a PID written in blocks also, much easier for new programmers to follow… wider base of influence.

I’ve not seen anything so far that could not be done in blocks. Wish robotmesh desktop would release an updated version. The new vex v5 blocks looks good though: scroll wheel supported, subroutines!

2 Likes