Help out a highschool student

Hello! I’m a sophomore taking a PLTW class and we’re currently working on the famous Marble Sorter project. We’re using ROBOTC 4.X for VEX to code our program and I honestly have no idea what I’m doing. I never got the hang of coding throughout the course. We’re trying to get our machine to: 1. Read the light value detected when the lightsensor is covered by the marble in queue* Move the categorized cup to move into place 2. Have the motor move a gear and allow the marble to pass through and into the cup 3. The axle holding the cup moves back to its original position 4. The program repeats a certain amount of times until the sorting is complete
I was hoping the experienced and people more seasoned than I could help me with my project?

I can try and help you. I did this project last year in my POE class very successfully. Can you post your code, so I can see what you have programmed so far?

We just finished construction and entered the motor and sensor setup. I haven’t done any actual coding yet.

[PHP]#pragma config(Sensor, in2, lightsensor, sensorReflection)
#pragma config(Motor, port2, motor1, tmotorVex393_MC29, openLoop) //turns gear
#pragma config(Motor, port8, motor2, tmotorVex269_MC29, openLoop) //turns cup axle
#pragma config(Motor, port10, flashlight, tmotorVexFlashlight, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()


You will need some type of sensor on the motor2 which has the cups. Otherwise you will not be able to accurately move the cups in place.

Having an IME encoder or Quad encoder on motor1 is also advisable. This way you can count the clicks required to push just one marble out. Timing may work but it won’t always work.

First turn on the flashlight.

Then start a while loop.

Detect the color from the light sensor. I am not sure what the values will be so run the debugger with the flashlight on and see the different values of the light sensor.

Set up some if statements to find the color and set a variable.

You will want to count the range of values for each cup and move the motor until the cup is in range. Then stop that motor2. So figure out where you are now and where you want to be. Run the motor2 fairly slow until the cup is in place. Stop motor2 when it is close.

Now run the other motor as long as it takes to shoot one marble. Again go slow.

end the while loop iteration and do the next marble until you see no more.

You might also find it helpful to make a flowchart before starting to program. Once you think it through, it is actually not too complex of a program. Team80_Giraffes provided an excellent summary of what the program will need to do.

To figure out the values for each colour marble, open the debugger window for sensors and take the readings for each colour. Keep in mind that you want to use ranges and not exact values for each colour, as the marbles will vary slightly.

Here is my code using a light sensor (or some other sensor, I can’t remember) to sort the marbles. I hope this helps.
Marble Sorter Project.c (3.75 KB)

This stuff was REALLY helpful, guys :slight_smile:
All your recommendations alongside some old class notes helped me figure out the coding. All I neec to do is experiment and find the values I need. Thanks a ton!! :smiley: I’ll get back to you guys on my final product when I figure the rest out on my own.

On a side not you can also use the line tracker to sense colors. Or at least red, blue, and yellow. It’s useful in VRC make your robot aware of what alliance your on.

Another trick, I saw somebody did with a LEGO sorter, is to attach a sample marble to each cup and put two light sensors on your sorter.

Then you just keep moving to the next cup until both light sensor values match withing some predefined tolerances. This way your code works with any color as long as you have an extra sample marble and is less dependent on the external lighting conditions.

i am doing the same project and i cant seem to program the light sensor with the servo.