Autonomous Skills Sensor Programming

Hi Vex Forum members,

I am trying to program my robot for autonomous skills. Is it possible to have the robot automatically calculate the number of balls that have gone through the launcher in RobotC and then have the robot drive to the other side for preloads? I know how to do this in other languages by using event handlers, but C doesn’t have event handlers.

Thank You.

What event would you be looking for?

I qualified for Worlds, so I was hoping to do a few runs there.

I meant event in programming lol. What happens on the robot that you can detect that only happens once per ball shot and never otherwise.

I’ll give an example. This robot had a button that detected the ball. It then looked for the edge from when the ball transitioned from pressed to not pressed.

Ok, I think I get it. I could use a limit switch that only activates when a ball goes down the ramp.

Or ultrasonic sensor, then you would have to deal with button bouncing.

We use a line follow sensor mounted in our intake. When a ball is over the sensor, it decreases the amount of light the sensor can “see”.

You can also, depending on the type of launcher, detect either each full gear rotation (puncher/catapult), or each time you experience a significant slowdown (flywheel). The former is not always 100% accurate because you might notice that your shooter slips a little bit at the start of each draw (the gear doesn’t engage properly at first) or you decide to let the puncher dry fire (cycle without a ball) for some reason. The latter requires a stable velocity calculation because if the noise in your velocity matches the velocity lost in a shot, you will have many false positives (thinking the robot shot without actually shooting, or shooting without registering a shot). Your best bet is to add a button to detect the release of a ball. Light sensors might be affected by ambient lighting at a competition and even the position of the loaders, but I’m not sure. The light sensor also requires a little bit of testing that the button doesn’t.

I would advise using sonar sensors to detect a ball loaded then no longer there.

What type of launcher do you have? Different launchers already have very intuitive ways of detecting ball shots

I have a flywheel. I have both a double and single flywheel.

You can just use the spikes in flywheel velocity. It’s pretty simple on a flywheel.

Use a code like this:
Int ballcount=0;
While (ballcount<=32)
If (getMotorVelocity()<85)
You will have to tune all the numbers

Thank You
I understand now.

I’ve built a function into our PID controller so that it will react (in various ways) to balls being shot. But I find that the count we get from this won’t match the number of balls going through because when we shoot fast the flywheel does not recover to full speed. My plan right now is to use an ultrasonic sensor to count balls as they pass through. I considered a limit switch but didn’t like how it had to touch the balls and how the prong can break off if you move the intake backwards.

@Sunil, that’s a really interesting idea. I think it might be better than the ultrasonic sensor since I’ve found that the ultrasonic sensor readings have a lot of error in them. Have you had any issues with detecting balls in varying light conditions, or is there always a consistent drop in the reading regardless of the surrounding light conditions.

I want to try this with two sensors on opposite sides and color filters to detect only regular and only bonus balls. We won’t have time before Worlds, but if someone else is bored, you would basically use either green & orange or their complements to filter the light, I’m not familiar enough with the behavior of light passing through a semitransparent material to know which, and then program 3 buttons on the launcher for high, low, or no goal. It would automatically score your robot’s points, which would be really useful information for scouting teams (“In a match, we average scoring x number of points on our own, with y% accuracy.”) and impress most judges, which is always a plus.

We haven’t had any issues with different light conditions. The sensor always has a very clear difference (around 1500 with a ball and around 400 without).

OK, thanks! I tried it today and got results similar to what you described.