Skip to content

Programming

I used an H-bridge and a potentiometer to program a Tetrix motor, which could adjust its speed. These motors are used to control the speed of the tennis ball and its spin. (STILL NEED TO EDIT ~ from week 9).

Gearbox Testing

I decided that the spin rate of my motors were too fast, and so I decided to build a simple lego gearbox to adjust for the correct torque.

It can either scale up the torque or scale it down.

I decided to build gear ratios with the lego box and 3D print attachments to the gears that fit with the Tetrix motor.

I went to this youtube video that was really helpful in understanding a gearbox.

Following the visual in the video:

video gearbox

I made my own lego gearbox. Later, I plan to buy metallic motors that have more defined edges and are stronger than the lego pieces.

My gearbox

Notice that the gearbox contains gears with smaller teeth interlocking their teeth with larger gears. Although this decreases the torque, it increases the speed of the gear. This is an inverse relationship.

Through my calculations, the first gear rotates about ⅕ for every time I spin the last gear. This means that when the Tetrix motor spins at 100 rpm, the last one will spin around 400-500 rpm. However, this also means that the last gear will have ¼-⅕ less torque.

T calc

Time to design the connector for the motor. This will have the joint for the tetrix motor on one end and a connector for the lego axle on the other.

2d connector

Fusion connector

When it was printed out however:

printed connector

I noticed that it was too loose when fitted with the tetrix motor’s shaft. As a result, I have to reduce the offset from the tetrix motor’s dimensions by 0.2mm on both sides.

Here is the current video for the tetrix motor turning the gears:

(A very quick note that this video was originally not working, and I updated it according to the format as described in week 18. In Terminal, I updated the ffmpeg tool by running brew install ffmpeg).

There was one problem, however. I noticed that the torque was way too low. With the slightest tap on the end motor, the tetrix motor would buckle under the torque pressure and it would stop spinning completely and start to turn itself.

According to its data sheet, the tetrix motor has 700 oz -in of torque, which translates to around 43.75 pounds. The smaller gears in the gear box have 17 teeth, while the larger one has 40. Since there are 5 levels of gears (I added another one), there are 4 reductions in torque, resulting in:

Numbers image

pound inch of torque.

This is clearly far from enough. My calculations could be off given that I probably used less than a pound of force with my finger and stopped the motor.

Choosing a motor

This was kind of a difficult process as there were not a lot of small DC motors that had high torque.

I have 2 options:

The first is to buy an extremely high torque tetrix motor and adapt it into the lego gear box to make the model. The second is to straight up by a high torque, high speed regular 12 volt DC motor that eliminates the use of the gear box.

After asking ChatGPT, it tells me the options for each one:

High torque tetrix motor alternatives High torque + high speed DC motor
AndyMark NeveRest Motors Torque = 8.75 oz in Faulhaber DC motor Torque = 2.688 oz in
REV Robotics HD Hex Motor Torque ≈ 600 oz in

I realized that the torques of these motors are still too small. The Falhaber motor has a top speed of 11000 rpm. I only needed the ball machine to spin at around 1000 rpm. So its torque would be increased to around 30 oz in, or less than 2 pounds, definitely not enough.

After a bit of searching, I found this motor from an official tennis ball machine replacement store. Although there is no official product description, I think it is worth a shot. After checking in with my parents, my dad (who has a degree in Industrial Automation) told me that since there was no official product description, it is not worth buying it. So I continued to look for a suitable motor on McMaster Carr.

After contacting the company via phone number, I was able to find 2 OK motors: the square face motor at 4200 rpm and 40 in-oz, and the brush motor at 3000 rpm and 21 in-oz.

When I discussed each option with my dad, we found that the torque is still too small.

Simple drawing

The above drawing shows my current plan. The wheels will be 5 inches in diameter, molded and made out of resin, with a coat of rubber around it. The tennis ball has a weight of 3 ounces, and a diameter of 3 inches approximately. So, the distance, R, from the center of the gear to the center of the tennis ball is around 4 inches, so in reality I would need to divided the torque of the motor by 4 in order to get the actual torque begin applied to the tennis ball.

After reviewing this video again, I realized that the motors they used are only 12 volt ones, and nothing more. So, I set out to find a motor with extreme speed, and I did find one. It is a RS550 motor. This data sheet shows that it has a torque of 551 g cm, which roughly translates to 7 in oz. However, its spin rate is 40000 RPM, meaning that if I made a gear box and changed that to 1000 RPM, I would get a resulting torque of 40 * 7 = 280 in oz of torque, which is around 17.5 lb in. (After a division of 4, resulting in a 4.25 pounds of force on the tennis ball).

This is far more than what I anticipated than the tetrix motor, leading me to believe that this design might actually work, it just requires the addition of a gear box, which I can either make or buy one.

However, after further consideration, I decided to abandon the gear box idea as it contains a lot of moving parts. The amount of parts that it has increases the chance of the motors breaking down. Also, it would be difficult to remove or add gears to the gear box in order to adjust for the correct torque. Overall, I thought it was cumbersome and tedious to use a gear box.

Then, I found this video documenting a working tennis ball machine. The motor they used was a 775 motor spinning at 7,000 RPM at 24 volts, and it seemed that it had enough power to rotate a plastic wheel at high speed and can shoot the ball for 60 to 70 feet. I found the motor on amazon:

Good motor

I tested the motor using a power supply to measure the current of the motor:

power supply

The maximum current spike was around 4 amps when I put my finger against the motor, and when it rapidly accelerates. Although it is able to maintain a stable current of 0.4 amps when running regularly. The fact that the spike is far above the H-bridge’s upper limit of 2 amps means I needed a motor shield that has a limit of 20 amps or more.

The torque of the new motor seems fine, as stopping it with the finger was impossible.

Programming Phase 2

As seen in the previous 2.5 Design phase 2 section of this documentation, I am coming back from a long break on my project. This section will detail the rest of my work so far (as of 4/8/2024) on programming the motors.

Motor Details

The motor I am using, as described above, is a DC 775 motor, which has the following self-proclaimed voltage and current:

Next, I connected the DC motor up to a power supply, and saw the following values for its working voltage and current.

Then, I used this 43 amp motor shield to control the motor by putting everything in a circuit.

However, I was worried that this would be dangerous as I am working with a lot of voltage that is not contained.

Small Motor Control

So I decided to wire a small 5 volt DC motor first to the motor shield, using the same schematic as week 9.

At first, the motor didn’t spin because when I tested the voltage, it is always decreasing due to some reason. I was using a 12 volt power adaptor that is connected to the power pin on the motor shield. When I first measured the voltage difference between the power and ground pins, I got a voltage of 12.28v.

However, the voltage difference quickly dropped to 1.8v.

I had no idea why. I even tested it with many batteries connected together, but the voltage across all those batteries was still dropping continuously. I wondered if there was a problem with my multimeter, which was mostly likely the problem.

Then, I switched out the batteries for my multimeter and tested it again, to no avail.

Through out this whole process, even though the motor was plugged in, it was not spinning at all, and this was just the small 5 volt DC motor.

Working

So, I decided to take a step back and use the Arduino Uno instead of the Raspberry Pi to power the motor. I wired it and it worked!

Then, I wired the motor again using the Pi, and this time I tried another motor shield (43 A). This time, the 5v motor spun according to the example code shown below:

int enA = enA;
int in1 = pin1;
int in2 = pin2;

void setup() {
  // put your setup code here, to run once:

pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
Serial.begin(9600);
}


void demoOne(){
  // This will run the motor in both directions at a fixed speed.

  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW); // initiation, and spinning it clockwise
  analogWrite(enA, 200);

  delay(2000);

 digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH); // turn it the other way.
  delay(2000);
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
}

void demoTwo(){
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);

  for (int i = 0; i < 256; i++){
    analogWrite(enA, i);
    delay(20);
  }

  for (int i = 255; i>= 0; --i){
    analogWrite(enA, i);
    delay(20);
  }
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
}


void loop() {
  // put your main code here, to run repeatedly:
demoOne();
delay(1000);
demoTwo();
delay(1000);
}

Obviously, the pin numbers are substitutable.

Large motor Control

With the small motor working, I wired the large motor up to a giant power supply that provides a maximum of 25 volts and 20 amps. This power supply is the one I used.

This picture shows the wiring for the large motor. Notice that I am using heavy-duty copper wires that could withstand to a hundred amps instead of the unreliable jumper wires.

I didn’t fully solder the jumper wires copper core directly to the motor to allow room for error.

This time, I was able to get the motor to spin slowly, but it looks like that there is still not enough current for the motor. It now moves, but fairly slow.

Working

So, I increased amount of current applied to the motor, and tested it. The motor now works using the above testing code! It worked with the heavy duty motor shield that is directly controlled by the Raspberry Pi. Here is the working video:

Application

First, I connected the motor to the D-profile shaft via a coupling to see if it can be spun. The end of the shaft was connected to the flange.

Then, I installed both motors on to my front frame of the tennis ball machine, and spun the motor. The motor is attached to the wheel via a set screw, and it took some time to accelerate. Once it got up to speed, the wheel spun pretty powerfully, and the rubber felt strong enough to shoot a tennis ball. I think I will implement more screws and 3D printed parts in order to make sure that the centrifugal forces would not tear the frame apart.

Phase 3: Re-working

As of 4/8/24, I have not touched my project in couple of months, and my first step in programming is to make sure that I can get the 775 motor to work properly, then I will implement the potentiometer.


Last update: April 8, 2024