bon_vieira
Posts: 3
Joined: Wed Apr 11, 2018 10:20 pm

Servo control degree by degree

Wed Apr 11, 2018 11:08 pm

Hi everyone.

I'm trying to build an IV infusion (saline solution) controller using the Raspberry Pi. I have a system in place that uses IR beams to detect the falling liquid drips inside the drip chamber and at every new drip calculates the current DPM (drips per minute). I want to feed that information into a controller that can squeeze or release the little hose, always comparing the current DPM to a set initial one determined by the user, constantly adjusting the DPM to its desired value.

I've tried to use a couple different stepper motors coupled with an eccentric shaft for the control part, pressing the hose against a fixed plane surface (clockwise squeezes, counterclockwise releases) but I found them unrealiable and some of them even weak.

I went and bought a servo motor with 13kgf/cm of torque which should be more than I what need to completely squeeze the hose and stop the fluid flow.

I'm using Joan's pigpio library to control it but I can't move the motor by smaller increments. All I can do is go from increments of a 100 (e.g. set_servo_pulsewidth(pin, 1100); set_servo_pulsewidth(pin, 1200))

My servo doesn't change its position from the two previous examples if I do for instance set_servo_pulsewidth(pin, 1150)

For this type of control I'd like to change the servo's position by degree, even less if possible.

Is it my servo that just can't do that?
Is there another way that could maybe work?

Sorry for the long post, I thought that adding some context would be helpful.

Thanks in advance.
Attachments
Webp.net-compress-image.jpg
Webp.net-compress-image.jpg (157 KiB) Viewed 1019 times

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

Re: Servo control degree by degree

Thu Apr 12, 2018 8:25 am

Perhaps that is the resolution of the servo?

As a test connect the servo control wire to a hardware PWM GPIO (one of 12/13/18/19) then use the pigs HP command to send hardware pulses. You will be able to achieve sub-microsecond pulse time resolution.

For example if you connect the servo to GPIO 19 (expansion header pin 35).

pigs hp 19 50 75000 # 50Hz 7.5% duty = 1500 us

pigs hp 19 50 75005 # 50Hz 7.5005% duty =1500.1 us

Play around and check the servo resolution at various positions

For safety keep the duty cycle value fed to HP to between 50000 (1000us) and 100000 (2000us).

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Servo control degree by degree

Thu Apr 12, 2018 11:16 am

gpiozero has an angular servo class but I'm not usre if it has the resolution you desire.
Arguing with strangers on the internet since 1993.

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

Re: Servo control degree by degree

Thu Apr 12, 2018 11:53 am

thagrol wrote:
Thu Apr 12, 2018 11:16 am
gpiozero has an angular servo class but I'm not usre if it has the resolution you desire.
By default pigpio servo pulses have a resolution of 5µs, far better than the 100µs steps which the servo seems to be responding to. I expect there is something wrong in the set-up. My cheap servos have a much better resolution than 100µs, probably 10µs or less.

bon_vieira
Posts: 3
Joined: Wed Apr 11, 2018 10:20 pm

Re: Servo control degree by degree

Thu Apr 12, 2018 1:12 pm

joan wrote:
Thu Apr 12, 2018 8:25 am
Perhaps that is the resolution of the servo?

As a test connect the servo control wire to a hardware PWM GPIO (one of 12/13/18/19) then use the pigs HP command to send hardware pulses. You will be able to achieve sub-microsecond pulse time resolution.

For example if you connect the servo to GPIO 19 (expansion header pin 35).

pigs hp 19 50 75000 # 50Hz 7.5% duty = 1500 us

pigs hp 19 50 75005 # 50Hz 7.5005% duty =1500.1 us

Play around and check the servo resolution at various positions

For safety keep the duty cycle value fed to HP to between 50000 (1000us) and 100000 (2000us).
Thanks for the tip Joan.

So, the results are somewhat weird.

When I put it all the way to 100000, going to 99000 moves it, then to 98000 also moves, I can move down all the way to 50000 by those small increments of a thousand but I can't move up by increments of a thousand (going from 92000 to 93000 doesn't do anything for instance). In sum, to increase the duty cycle the increments have to be at least of 5000, to decrease it 1000 works.

The servo is a Towerpro MG995.

bon_vieira
Posts: 3
Joined: Wed Apr 11, 2018 10:20 pm

Re: Servo control degree by degree

Thu Apr 12, 2018 1:21 pm

joan wrote:
Thu Apr 12, 2018 11:53 am
thagrol wrote:
Thu Apr 12, 2018 11:16 am
gpiozero has an angular servo class but I'm not usre if it has the resolution you desire.
By default pigpio servo pulses have a resolution of 5µs, far better than the 100µs steps which the servo seems to be responding to. I expect there is something wrong in the set-up. My cheap servos have a much better resolution than 100µs, probably 10µs or less.
The setup: 6V 1A max power supply to servo, servo signal into GPIO BCM 12, Pi GND and power supply ground joined together.

I intend to put the servo in the same system that I had the stepper in (pic from original post).

Return to “Automation, sensing and robotics”