NUNUG / scary-gadgets-1

Scripts from YouTube video series relating to our first annual Scary Gadgets meeting, October 2013.
MIT License
6 stars 10 forks source link

Servo goes too far (click) #1

Open mrlunk opened 7 years ago

mrlunk commented 7 years ago

Hi there...

To start out with, I am pretty noob on this stuff :)

I used your video instructions to hook up a 'Tamia TSU-02' servo from an old RC-car. But when I use your script the servo clicks on one side pretty hard as if it wants to go too far...

Q: 'Please tell me what I need to adjust to make this servo work like it should....'

What I know a bout the servo: Control System: Pulse width control Operating Angle: One side more than 45 degrees Current Consumption: 8mA (using 6.0V battery) Output Torque: 3.3kg*cm (using 6V battery) Operating Speed: 0.14sec/60 degrees (using 6V battery) Power Supply: 4.8~6.0V Domensions: 32x16x34.5mm Weight: 26g

Thanks a lot for your help in advance.

Greets, Peter Lunk

spgilmore commented 7 years ago

That does sound like typical behavior when you send a servo motor to a position which is beyond its operational range.

The servos that I use have close to 180 degree operating angles. These are common and their typical pulse times are between 0.50 ms and 2.5 ms with 1.5 ms in the center. With a 45 degree or 90 degree operating angle, your pulse times will be different and you'll have to determine what they should be. However, it probably still moves to the center with 1.5 ms pulses. You could easily modify the program to cycle through a range of pulse times, output the current pulse time to the screen so that you can observe the motor behavior at different pulse times to get an idea what the correct range is for your motor. I would start at 1.5 ms and move backward by .05 ms at a time to determine the left limit and then a second test to start at 1.5 ms and move forward by 0.5 ms at a time to determine the right limit.

Maybe something like this (modification of the original program):

    # Move in 0.05 increments from 1.5 down to 0.5.
    for step in range(20):
        # Start in the center and move left a little at a time.
        position = 1.5 - (step * 0.05)
        # Comment-out the line above and use this one instead to test the other direction up to 2.5.
        #position = 1.5 + (step * 0.05)
        duty_cycle_percentage = position * 100 / ms_per_cycle
        print("Pulse: " + str(position))
        pwm.start(duty_cycle_percentage)
        time.sleep(.5)

If your motor doesn't center at 1.5 ms, I would just start at 0.10 ms and increase pulse times to 3 ms in increments of 0.1 or 0.2 to determine a course range, then reduce the steps and the range to get a finer measurement.

Once you've determined the pulse range for your motor, obviously you could take the original program and just modify the left-position and right-position variables to properly represent the pulse time limits for your motor.

mrlunk commented 7 years ago

Wow hanks for your quick and clear reply... I will be trying this tomorrow and let you know how it went :) Greetz, Peter Lunk