element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
In Reach! – Ultrasonic Sensor Sensing Challenge
  • Challenges & Projects
  • Design Challenges
  • In Reach! – Ultrasonic Sensor Sensing Challenge
  • More
  • Cancel
In Reach! – Ultrasonic Sensor Sensing Challenge
Forum SwishMaster - #4 - Ball trajectory
  • News
  • Forum
  • Projects
  • DC
  • Files
  • Members
  • More
  • Cancel
  • New
Join In Reach! – Ultrasonic Sensor Sensing Challenge to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 42 subscribers
  • Views 54 views
  • Users 0 members are here
  • ultrasonic sensor
  • design challenge
  • SwishMaster
  • tdk
  • TDK waterproof sensors
  • In Reach!
  • Ultrasonic Sensor Sensing Challenge
  • In Reach
  • TDK USSM Plus-FM
  • TDK USSM1.0 PLUS-FS
Related

SwishMaster - #4 - Ball trajectory

amgalbu
amgalbu 4 days ago

In this post, I will talk about some of the relevant features of the firmware I am developing.

Reading ball height

I explained how to measure the distance between the ball and the SwishMaster in a previous post. Basically, I am leveraging the TDK USSM Arduino Library and, in particular, the GetDistanceCm() function.

Computing the ball trajectory

The main task of the firmware is to reconstruct the ball trajectory from the ball height readings. The process involves the following steps

  • Get an approximation of the horizontal coordinate. USSM does not provide a reading for the horizontal position of the object -just the time of flight of reflected sound waves
  • Correct measurement depending on horizontal position. Given the estimated horizontal position, the real distance between the ball and the sensor (i.e the distance measured along the sensor axis) can be calculated
  • Align the axes: sensors measure distances in two different reference systems, which have to be aligned to make all the readings refer to a common reference system
  • Compute the parameters of the parabola that best matches the points
  • Compute the ball entry angle

1. Estimate ball horizontal position

As the basketball travels across the area covered by the USSM, we need to correct the measured distance to take into account the horizontal offset of the actual position of the ball from the sensor vertical axis. The sensor does not provide such an information, but it’s possible to estimate the ball horizontal position under the following conditions

  • The ball speed is constant
  • The ball distances are read at a fixed rate

In this scenario, the following algorithm works with a good precision

  • Compute the average height of the ball
  • Calculate the width of the covered area at the computed height
  • The horizontal distance between samples is given by the area width divided by the number of sample


The area where the sensor can detect the basketball is approximated by a six-edges polygon, shown in the following picture

image


For example, the formula to compute the width of the covered area at a given height “C” is

image

image

Where “Y” is the measured distance, and X is the width of the covered area. Solving the equation, we get

image

2. Correct measurements for horizontal position

Given the estimation of the horizontal position and the distance returned by the USSM, we can calculate the distance along the sensor axis using the Pitagora theorem

image

3. Aligning the axis

Samples are taken in two different reference systems, whose axis are 50 degrees apart. To align the axis, we need to rotate the axis 25 degrees clockwise and 25 degrees counterclockwise, as shown in the following picture

image

To rotate a point (x, y) around the origin by an angle θ (in degrees), the standard 2D rotation formulas are:

image

Finally, a translation is applied to make the origins overlap

4. Parabola fitting

This is essentially performing a quadratic regression to find coefficients a,b,c for:

image

Using the least squares method for n points, the system of equations to solve is:

image

This 3×3 system can be solved using Cramer's rule. 

Cramer's Rule says that we can find the value of a given variable by dividing that variable's determinant by the regular coefficient-determinant's value. That is, Cramer's Rule specifies this relationship:

image

where D is the matrix determinant and Da Db, Dc are the matrix where the 1st, 2nd and 3rd columns have been replaced by the determinant D. Showing the C code is probably simpler than explaining the Cramer’s rule…

Parabola SwishMasterParabola::fit()
{
  // Summations
  double Sx=0, Sx2=0, Sx3=0, Sx4=0;
  double Sy=0, Sxy=0, Sx2y=0;

  for (int i=0; i<n; i++) {
    double xi = x[i];
    double yi = y[i];
    double xi2 = xi*xi;

    Sx += xi;
    Sx2 += xi2;
    Sx3 += xi2*xi;
    Sx4 += xi2*xi2;
    Sy += yi;
    Sxy += xi*yi;
    Sx2y += xi2*yi;
  }

  // Build matrices for solving
  double denom = (Sx4*(Sx2*n - Sx*Sx)
    - Sx3*(Sx3*n - Sx*Sx2)
    + Sx2*(Sx3*Sx - Sx2*Sx2));

  double a = ( (Sx2y*(Sx2*n - Sx*Sx))
    - (Sxy*(Sx3*n - Sx*Sx2))
    + (Sy*(Sx3*Sx - Sx2*Sx2)) ) / denom;

  double b = ( (Sx4*(Sxy*n - Sy*Sx))
    - (Sx3*(Sx2y*n - Sy*Sx2))
    + (Sx2*(Sx2y*Sx - Sxy*Sx2)) ) / denom;

  double c = ( (Sx4*(Sx2*Sy - Sx*Sxy))
    - (Sx3*(Sx3*Sy - Sx2*Sxy))
    + (Sx2*(Sx3*Sx2y - Sx2*Sx2y)) ) / denom;

  Parabola p = { (float)a, (float)b, (float)c };
  Serial.print("Parabola parameters: ");
  Serial.print(a);
  Serial.print(", ");
  Serial.print(b);
  Serial.print(", ");
  Serial.println(c);

  return p;
}

5. Ball entry angle

We have the fitted parabola

image

The slope of the tangent at any point x_0is simply the derivative:

image


The angle with the horizontal is:

image

I just need to apply to formula to the last known point to get an estimate of the ball entry angle

And luckily...that's all

Sorry for the boring post full of formulas, but I think that some knowledge about the algorithm I implemented to computed the ball trajectory can make clearer how SwishMaster works. Next posts will focus on the case, the electronics and hopefully the first field test

 

  • Sign in to reply
  • Cancel
  • DAB
    DAB 1 day ago

    Math is fine, I am just not sure you are dealing with a parabola trajectory.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • amgalbu
    amgalbu 1 day ago in reply to DAB

    You are absolutely right, DAB . Parabola is just an approximation. Ball is not following a perfect ballistic trajectory, because of, among the others, the aerodynamic effects due to the rotation of the ball. Do you have any suggestion to improve trajectory calculation? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube