RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Torque control in servo motor

Sat Apr 08, 2017 4:13 am

Hello everyone.

The problem I am facing is that I am able to rotate servo motor to the desired position with my code, but I am unable to control the speed of rotation. I need to slow down the rotation so that it slowly rotates from one position to another. Also there is some jitter when the servo moves to a particular position.

I am using 180 degree positional servo.

The following is the code snippet.

Code: Select all


P.start (2.5)  #giving PWM signal in pin P

def servo_motion ():
 try:
   while True:
      if GPIO.event_detected (Pin1):
        P.ChangeDutyCycle (7.5)
        time.sleep (0.2)
      time.sleep (0.1)

 except KeyboardInterrupt :
    P.stop ()
    GPIO.cleanup ()

servo_motion ()



Sorry for the indentation problems. I wrote the code from my cellphone.

Can anyone help me in this code to slow down the servo rotation ??? Thanks in advance.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Torque control in servo motor

Sat Apr 08, 2017 7:51 am

If you don't want jitter you need to use hardware timed pulses, e.g. pigpio, servoblaster, RPIO.GPIO (not RPi.GPIO).

To slow down you will have to move the servo in smaller steps. Rather than going from 1000µs pulses straight to 2000µs pulses go to 1100, 1200, 1300, ..., 1900, 2000 and stop briefly at each intermediate point. That is the programming part of programming.

RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Re: Torque control in servo motor

Sat Apr 08, 2017 7:54 am

Thanks a lot. I will try that thing and will post here later.

RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Re: Torque control in servo motor

Sat Apr 08, 2017 8:02 am

One more thing i want to ask. In 180 degree servo if I give pulse more than 1.5ms it will directly move to 180 position. Also any pulse less than 1.5ms will take it to 0 position.

So if I take dutycycle(2.5) as my neutral position and by putting dutycycle (7.5) it moves to 180 position, what duty cycle values should I put between these values to move the servo in small steps and hence slowing down the speed of rotation ???

Please clarify me in this regard.

Thanks

ghp
Posts: 1498
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Torque control in servo motor

Sat Apr 08, 2017 3:06 pm


RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Re: Torque control in servo motor

Sat Apr 08, 2017 3:08 pm

How can Linear equation help me in this ???

RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Re: Torque control in servo motor

Tue Apr 18, 2017 6:40 am

Hello eveyone. I was trying with this and found out a solution, but it makes the servo a bit unstable.

Code: Select all


p.start(12)   //assuming servo is connected to pin p

def slow():
  for i in range(2,7,1):
    p.ChangeDutyCycle(i)
    time.sleep(0.1)

while True:
  try:
    if GPIO.event_detected(PIR1):   //assuming rising edge detected at GPIO pin where PIR sensor is connected
      p.ChangeDutyCycle(2)
      slow()
    time.sleep(0.2)

  except KeyboardInterrupt:
    //cleanup GPIO pins

I can make the servo motion slower with this. But there is a problem. Whenver any motion is detected in a PIR sensor, the servo motor rotates multiple times (in my case 2 times) before stopping to the required position. Is there any way to stop the servo at the required place after one such rotation whenever a particular sensor is activated. Help would be appreciated. Thanks !!

User avatar
Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

Re: Torque control in servo motor

Tue Apr 18, 2017 7:15 am

Whenver any motion is detected in a PIR sensor, the servo motor rotates multiple times (in my case 2 times)
Huh! what type of servo do you have?
A normal RC servo never has continuous rotation.
Only continuous rotation servos can go all the way around, normally used as robot wheel motors.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

RGhosh99
Posts: 25
Joined: Tue Mar 21, 2017 6:57 am

Re: Torque control in servo motor

Tue Apr 18, 2017 7:18 am

Its not continuous rotation. When a sensor is activated, from the initial position it moves to the desired position, and again it moves to the initial position and comes back again to the desired position. Its type of like back and forth movement.

I have 180 degree positional control servo.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Torque control in servo motor

Tue Apr 18, 2017 7:46 am

The servo is doing what you tell it to do. You need to work through a Python tutorial and perhaps a tutorial about servo control.

User avatar
Gavinmc42
Posts: 4526
Joined: Wed Aug 28, 2013 3:31 am

Re: Torque control in servo motor

Tue Apr 18, 2017 7:53 am

You might want to grab Joan's piscope software and actually see the signal your code is doing.
http://abyz.co.uk/rpi/pigpio/piscope.html

If you have a PC and soundcard you can turn it into a simple scope.
https://www.zeitnitz.eu/scope_en

Without looking at the signal I agree with Joan and would say your code is wrong and the servo is doing exactly what it is told.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Python”