vscson
Posts: 2
Joined: Fri Sep 20, 2019 5:25 pm

pigpio capabilities?

Fri Sep 20, 2019 5:52 pm

I am trying to replace the software on my UCTRONICS K0073 robotic car. The original C code is controlling the pan/tilt servos with simple bit bang and raspbian gettimeofday() timer which is not very accurate. I tried the servo_demo from pigpio and it works great.
What I can't find is whether it supports different DMA and PWM controls simultaneously on other pins.
The servos are on gpio 4 & 25.
The car code runs a string of ws2811 LED modules using PWM and DMA on gpio 18
Ultrasonic HC-SR04 is on 26 & 23, Trig & Echo and more gettimeofday() timing.
Will pigpio support the servos and LEDs at the same time?

Scott

User avatar
neilgl
Posts: 2078
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: pigpio capabilities?

Fri Sep 20, 2019 8:58 pm

Probably it will. pigpio by @joan can do "hardware timed PWM on any of GPIO 0-31" see the docs at:
[url]http://abyz.me.uk/rpi/pigpio/index.html[/url]

vscson
Posts: 2
Joined: Fri Sep 20, 2019 5:25 pm

Re: pigpio capabilities?

Mon Oct 14, 2019 10:53 pm

Forgot to post that this worked great. It was easy to convert from a kluge wiringPi/mixed-gpio to PIGpio.

User avatar
HermannSW
Posts: 2559
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio capabilities?

Tue Oct 15, 2019 12:02 am

vscson wrote:
Mon Oct 14, 2019 10:53 pm
Forgot to post that this worked great.
Even under load?
Did you power the two PT servos from two Raspberry 5V pins?
I read that you should not drive more than two SG90 from a Pi.

Without load two SG90s powered directly by Pi are no problem:
https://www.raspberrypi.org/forums/view ... 7&t=254180
Image

Yesterday I did try to control 4 servos from a Pi (powered by constant voltage power supply with 5V/2A).
Although I used pigpio command to change the gripper servo only, after some time all servos go crazy for some time.
What can be an explanation for that?
https://twitter.com/HermannSW/status/11 ... 7031124996
https://twitter.com/HermannSW/status/11 ... 1369725952
https://twitter.com/HermannSW/status/11 ... 9112682496
Image
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

User avatar
HermannSW
Posts: 2559
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio capabilities?

Tue Oct 15, 2019 4:21 pm

In a twitter discussion I provided connection diagram, which might make answering the questions easier:
https://twitter.com/HermannSW/status/11 ... 8222300160
GraphvizFiddle share link
Image
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

pootle
Posts: 374
Joined: Wed Sep 04, 2013 10:20 am
Location: Staffordshire
Contact: Website

Re: pigpio capabilities?

Wed Oct 16, 2019 6:53 am

HermannSW wrote:
Tue Oct 15, 2019 12:02 am

Yesterday I did try to control 4 servos from a Pi (powered by constant voltage power supply with 5V/2A).
Although I used pigpio command to change the gripper servo only, after some time all servos go crazy for some time.
What can be an explanation for that?
The servos themselves generate a lot of noise on the power supply rail, additional decoupling capacitors across the power wires right beside the servos should fix the problem as long as your power supply is not drooping under load.

User avatar
HermannSW
Posts: 2559
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio capabilities?

Thu Oct 17, 2019 6:06 pm

I discussed your proposal with a colleague.
pootle wrote:
Wed Oct 16, 2019 6:53 am
The servos themselves generate a lot of noise on the power supply rail,
He agreed on that.
additional decoupling capacitors across the power wires right beside the servos should fix the problem as long as your power supply is not drooping under load.
He disagreed, and even found an inner diagram of an SG90 showing that they contain capacitor -- I tried again and again, but I cannot find that.

He pointed to the GND connection between yellow and white mini breardboards, and asked me to connect the Pi GND exactly where the other were connected. I used power rails of a long breadboard and did exactly that. This is new diagram:
GraphvizFiddle Share link
Image


I tried it, and it does work quite well. Quickly moving all 4 servos simultaneously from 1000 (45°) to 1500(90°) and 2000(135°), and then repeat. First with 0.6s delay between moves, then with 0.3s delay -- quite impressive. I really like this servo sound in the video -- with 4 servos moving simultaneously, like a choir ;-)
https://youtu.be/qc0d_gW480I
Image


Now that this is resolved, it is time to create a new thread on this 4DoF robot arm (I plan to add a small camera near the gripper, control with joysticks, make automatic grip using live video analysis, ...).

P.S:
Already made the robot arm do real stuff -- cool:
https://www.youtube.com/watch?v=iwZIn6fQfMk
Image
This is the script executed, GPIO8/9/10/11 is gripper/top/bottom/pan servo:
pi@raspberrypi3Bplus:~ $ cat doit
#!/bin/sh
pigs s 11 1500; pigs s 8 2100; sleep 0.5
pigs s 10 2500; pigs s 9 1900; sleep 0.5
pigs s 8 1500; sleep 0.5
pigs s 9 1500; pigs s 10 1500; sleep 0.5
pigs s 9 2500; pigs s 11 2500; sleep 0.5
pigs s 8 2200
pi@raspberrypi3Bplus:~ $
Last edited by HermannSW on Thu Oct 24, 2019 9:15 pm, edited 1 time in total.
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

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

Re: pigpio capabilities?

Thu Oct 17, 2019 7:51 pm

Just to be clear, are you saying the servo jitter mentioned in your earlier post was being caused by a ground problem?

That is an impressive gripper you have there. I'd have thought the code to pick and drop would be a lot more sophisticated! :oops:

User avatar
HermannSW
Posts: 2559
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio capabilities?

Thu Oct 17, 2019 8:37 pm

joan wrote:
Thu Oct 17, 2019 7:51 pm
Just to be clear, are you saying the servo jitter mentioned in your earlier post was being caused by a ground problem?
Yes.
My colleague explained to me that the previously slightly longer (thin) cable connection from Pi GND to constant current GND than the servo GND connections is likely to make the difference. The noise can lead to voltage drops and the PIs 3.3V on GPIO might drop below SG90 voltage detected as high.
That is an impressive gripper you have there. I'd have thought the code to pick and drop would be a lot more sophisticated! :oops:
Yes, its my first robot arm, only 14.99$ with free shipping on banggood.com:
https://twitter.com/HermannSW/status/11 ... 4921868290

I just tried the simple code, and was surprised as well that the movements were repeatable enough. I did place the die 8 times and robot arm did successfully take it 8 times.

I will add a small camera (only the sensor, not the board) at the gripper. I have two options for that: I hope that with camera this arm can do much nicer things, that are not even hardcoded (eg. by processing YUV images received by raspividyuv and looking at Y plane only for grey8 frame).

P.S:
Yesterday I was able to make successful test of Pan Tilt camera system with SG90 servos as well (for automatic airplane centered recording of approach for landing):
https://www.raspberrypi.org/forums/view ... 3#p1552893
With pigpio/pigs of course ;-)

Code: Select all

pi@raspberrypi2B:~ $ while true
> do
> for((i=1180; i<1450; ++i)); do pigs s 18 $i; done
> for((i=1450; i>1180; --i)); do pigs s 18 $i; done
> done
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

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

Re: pigpio capabilities?

Thu Oct 17, 2019 9:21 pm

Thanks for the info. It does make sense about the voltage drop but it's not something I would ever have thought of. I'll bear that in mind as I expect I'll see similar problems in the future.

Watching that robot arm spinning about reminded me of the considerably larger Foxhunter radar which also moved alarmingly fast.

User avatar
HermannSW
Posts: 2559
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: pigpio capabilities?

Mon Oct 28, 2019 1:23 am

Still have not created a new thread on 4DoF robot arm.
But I greatly improved the repo and its doc, here its table of contents:
https://github.com/Hermann-SW/4DoF_robo ... -robot-arm

Code: Select all

    Introduction
    Construction
    Wiring diagram
    Tools
        tools/gamepad
        pigpio pigs scripts
            die picker
            4 servos moving simultaneously
    Adding camera near gripper

The PT camera thread made progress:
https://www.raspberrypi.org/forums/view ... 2#p1558032

Tracking airplane in each frame (and marking it with 2x2 white marker) can be done with a simple heuristic. Depending on which task the 4DoF robot arm with camera added near gripper should do (eg. automatic die picking), an automatic solution might not be that difficult ...

The inverse kinematic for the 4DoF robot arm is simple.
The gripper servo is not involved by definition.
Next, the pan servo position for coordinate (x,y,z) is a simple function of x and y (cotangent).
For coordinate (x,y,z) the upper and lower servo have to be in a unique position, determined by simple functions on sqrt(x²+y²) and z.

The airplane is a bigger dot here, but this video was captured with smartphone camera and 640x480 resolution only,
Real airplane tracking will be done with 1920x1080 and a 70mm lens -- expected size of a 34m length A319 airbus is 300x60 pixels(!):
Image


P.S:
Simulating robot arm kinematics of two servos (of 4DoF robot arm) acting in same plane with two geogebra angle sliders and transformation; Ubuntu X11 screen recording done with "peek":
Image
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

Return to “Automation, sensing and robotics”