davis422
Posts: 4
Joined: Tue May 05, 2020 12:23 am

Need help measuring the speed of a small ball

Tue May 05, 2020 12:29 am

Hello all. Very new to actually doing something creative with the raspi. But here is the project I would like to accomplish. I'm hoping someone can help me with it.

I am a foosball player and I would like to be able to use the raspi with some type of sensor to determine how fast the ball is traveling when someone shoots it. I assume the best way would be to let the ball pass two different sensors (laser or IR) and do the calculations from the time it breaks the first beam to the time it breaks the second beam to determine the ft/sec.

I'm just not sure what sensors I should be using for this. They will need to be roughly 12 inches apart. If someone could get me started with a parts list it would be much appreciated.

Thanks!

User avatar
Botspot
Posts: 1241
Joined: Thu Jan 17, 2019 9:47 pm
Location: Texas
Contact: Website

Re: Need help measuring the speed of a small ball

Tue May 05, 2020 1:52 am

I play foosball once in a while too.
davis422 wrote:
Tue May 05, 2020 12:29 am
I assume the best way would be to let the ball pass two different sensors (laser or IR) and do the calculations from the time it breaks the first beam to the time it breaks the second beam to determine the ft/sec.
You could certainly go the light interrupt route. Potential problems:
  • what if the ball is not going straight down the field? For example, if the ball is going 142 ft/sec, but at 45 degrees, the sensors will only register 100 ft/sec.
  • The ball rarely goes down a long, unobstructed path. Ok, maybe yours does, but a good competitive game will have the ball bouncing around like popcorn! So, to register all those small movements, you will need many small sensors, spaced maybe an inch apart. Which leads to the next problem:
  • How will these sensors determine if they saw a ball, or the feet of the little hitter men? Or somebody's hand?
  • Also, Raspberry Pi is not designed for high-speed GPIO. It can't even determine what voltage it's seeing. It can only register a I or a O, one or a zero, 3.3v or 0v. So calibrating these sensors will be tough.
Want to make your own Raspbian image?
  • Hard way: Mess with confusing terminal commands.
  • Easy way: Let Pi-Power-Tools do it all for you!
Boot your image in a VM, Flash from the Internet at top speed, Mount (to drop files in), Edit partitions, Shrink/Expand, Repair, and more. Enjoy! :)
https://github.com/Botspot/Pi-Power-Tools

davis422
Posts: 4
Joined: Tue May 05, 2020 12:23 am

Re: Need help measuring the speed of a small ball

Tue May 05, 2020 2:52 am

I just want it for controlled shots from the forward shooting 3 rod. the ball will be placed and then shot directly into the goal. Sort of like a fastest shot contest. So we can control the environment to make sure the sensor only sees the ball and not the men. And I found a video where a kid used an Arduino to measure the velocity of a paintball shot and thats way faster than a foosball shot I would assume.


here is a link to the video
https://www.youtube.com/watch?v=V_2JUTnXn6I

I would try his method, but I need the sensors spaced a lot further apart.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Need help measuring the speed of a small ball

Tue May 05, 2020 10:57 am

Place the ball on a selected spot ,Just IN front of the ball place a portable IR transmitter witch will record when the beam is broken

Between the goal post have a IR receiver ( Beam Curtain) ,similar to used on Lift Door Ways . Now you have the time the ball passes the IR transmitter
And the time the ball passes the IR receiver ( Beam Curtain)

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

Heater
Posts: 15838
Joined: Tue Jul 17, 2012 3:02 pm

Re: Need help measuring the speed of a small ball

Wed May 06, 2020 6:25 am

Curiously according to wikipedia the fastest football kicks are about 80mph.

That is about 36 meters per second. I don't know anything about football but it seems a penalty kick is 12 yards. Let's call it 12 meters. So 333ms flight time.

Setting up IR LEDs and detectors around the place is going to be a pain, what with all those cables to run around the place.

I would consider doing it with the Pi camera and video object detection/motion detection. Then all you need to do is set the Pi on a tripod and let it run.

This might sound like a horribly complicated thing to do software wise but with the OpenCV library it can be done in a few pages of Python code.

Processing speed might be an issue. At even at only 10 frames per second we have 120 frames of video in 12 meters, usually more, so we know we can get at least 1% accuracy this way. That is in real time of course. If the Pi is not fast enough for that record some video and post process it.

Paul McWhorter has a brilliant series on YouTube showing how to do this in detail.
https://www.youtube.com/watch?v=5INy0Fv ... ERFFPkOuP4_

There he does everything on a Jetson Nano (With a Pi camera) but most of the OpenCV stuff should run on the Pi just fine. The series is quite long but you can ignore a lot of stuff about learning Linux commands and setting up the Nano. There are many gems of OpenCV in there.
Memory in C++ is a leaky abstraction .

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Need help measuring the speed of a small ball

Wed May 06, 2020 9:29 am

boyoh wrote:
Tue May 05, 2020 10:57 am
Place the ball on a selected spot ,Just IN front of the ball place a portable IR transmitter witch will record when the beam is broken

Between the goal post have a IR receiver ( Beam Curtain) ,similar to used on Lift Door Ways . Now you have the time the ball passes the IR transmitter
And the time the ball passes the IR receiver ( Beam Curtain)


[/

BoyOh
I could suggest it could be don just by using micro switches inter faced to the Pi system , Place the ball on a base , so when the
ball is kicked it will operate a Microswitch, From the goal post hang a thin sheet of wood or anything of your choice. this you can
experiment with , when the ball hit the sheet it will operate microswitches you could use more than one microswitch in series
To link the system you can use wire or Wi Fi. No complicated cameras and calculation's

The Pi would only need to record two pulses , the kick pulse and the hit pulse , The time between pules and distance will
give you the the calculation of ball speed We must realize we are not dealing with mathematicians

Just a Idea ,,,,,,,Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

JohnsUPS
Posts: 169
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: Need help measuring the speed of a small ball

Wed May 06, 2020 8:09 pm

Ahhhh....reminds me of times past - played my share of foos back in the day.....

If I get what you are describing correctly, you basically just want to measure the speed of the ball during a penalty kick or such as the ball enters the goal.

Because the ball won't loose any significant amount of speed between when it enters the goal and subsequently hits the backstop at the back of the goal, you could conceal and IR LED and receiver pair just inside of the goal, then another pair at the very back of of the goal by the backstop (all of this inside of the table). On the tables I have seen, there is a few inches of space between the two. The close proximity of the pairs of sensors might make calibration tricky, but once perfected it would be able to measure the speed of the ball shot from anywhere. The entrance angle (as was previously pointed out) would affect the reading, but is up to you to decide just how accurate you would like it to be.

Good luck!

davis422
Posts: 4
Joined: Tue May 05, 2020 12:23 am

Re: Need help measuring the speed of a small ball

Thu May 07, 2020 2:06 am

Heater - We are talking about foosball not football. :)

davis422
Posts: 4
Joined: Tue May 05, 2020 12:23 am

Re: Need help measuring the speed of a small ball

Thu May 07, 2020 2:09 am

boyoh wrote:
Wed May 06, 2020 9:29 am
boyoh wrote:
Tue May 05, 2020 10:57 am
Place the ball on a selected spot ,Just IN front of the ball place a portable IR transmitter witch will record when the beam is broken

Between the goal post have a IR receiver ( Beam Curtain) ,similar to used on Lift Door Ways . Now you have the time the ball passes the IR transmitter
And the time the ball passes the IR receiver ( Beam Curtain)


[/

BoyOh
I could suggest it could be don just by using micro switches inter faced to the Pi system , Place the ball on a base , so when the
ball is kicked it will operate a Microswitch, From the goal post hang a thin sheet of wood or anything of your choice. this you can
experiment with , when the ball hit the sheet it will operate microswitches you could use more than one microswitch in series
To link the system you can use wire or Wi Fi. No complicated cameras and calculation's

The Pi would only need to record two pulses , the kick pulse and the hit pulse , The time between pules and distance will
give you the the calculation of ball speed We must realize we are not dealing with mathematicians

Just a Idea ,,,,,,,Regards BoyOh
Unfortunately we won't be able to place anything under the ball. It will have to be sitting on the original playing surface. I'm thinking laser gates is going to be the way to go. I'm just going to need some help wiring it up, getting the pi to do the calculations, and getting it to display something on an LCD or similar.

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Need help measuring the speed of a small ball

Thu May 07, 2020 8:31 am

You seem to know what you want, But lack the ability to put it in to practice , Just to remind you that the forum will give you advice
but not design the circuit for you , When the Raspberry Pi was first put on the market , it was for learning coding and electronics.
so you have a lot to learn
There are people on the forum that could do the complete design for you , Just remember they spent years learning that skill.
So a course on basic electronics is what you need ,

If you are a foot baller , you could afford a design company to do it for you

Regards BoyOh Retired Electrical / Electronics Technician.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

User avatar
bensimmo
Posts: 4577
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Need help measuring the speed of a small ball

Thu May 07, 2020 11:35 am

Look up how to use Lightgates, there should be plenty of examples.
You can do it in Python3 using gpiozero in not to many lines of code.
each gate acts as a switch.
you can do it with just one gate too.

the problem you will face.
Balls are round, if it lifts the beam passes a shorter distance over the ball surface as it passes, you may have the advantage that you can keep the small ball mainly on the table so you can aim for the centre of the ball and try and keep it down.
Similar errors crop up when the ball goes through at a sideways angle, (distance traveled)

But that's just errors, once setup you can see if you can reduce them.as for the display, there are Python3 modules to aid add them in a few lines of code as well.
Pick a 1602 / hd44780 i2c style LCD or string some dot matrix led displays together.

Return to “Beginners”