freddythunder
Posts: 2
Joined: Fri Dec 12, 2014 5:21 am

Robot programming :: your 2 cents

Fri Dec 12, 2014 5:46 am

Hello,

I am planning to build a robot for my home for fun, security and home automation (also a moving sound system, few other things). I have been a programmer for quite a long time and program for a living, but haven't done much with robotics at all.

I started playing with sketches in Arduino playing with PWM for speed control of a high torque motor for experimenting. I recently got a pi and am looking into what language to use to control the robot. I've noticed that python is used frequently for robotics programming and know the benchmark is still on the faster sides of things, perl is optimized more. I work as a PHP programmer and since perl is where PHP originally started, I am opting to use a while(1) loop to work kind of like a daemon that would make class calls to other included perl scripts for various controls and readings. Whew. First question: what do you think?

I've installed wiringpi so I have gpio on the command line. Second question: Anyone have any opinion on installing the perl wrapper for wiringpi to use calls inside perl vs. using system() calls directly to gpio?

And third question: In my brain I see the robot accelerating and decelerating on a curve so it isn't just GO!.....STOP! My original idea is to use PWM to put movement on a curve by turning up the PWM value slowly in the beginning of the travel, and turning down the PWM as it approches it's destination. Is PWM a good way to go?

Thanks!

:D

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Robot programming :: your 2 cents

Fri Dec 12, 2014 10:17 am

Warning; this can be a big project. I have my half finished "trolley" which has been around for years and been mechanically rebuilt at least twice. (I drag it out for a few days every now and then but can never finish it; I have commitment issues in general :))

Don't know about Perl, etc but the permanent loop is right - continually getting instructions about the movement that is needed, and sending PWM signals to the motors. In my case I did this on arduino though (eventual plan is to get the raspi sending commands to it over serial or maybe i2c).

I think the "usual" programming language to use on a raspi would be C or Python though. (No idea about the execution speed of Perl.)

On mine I have motors with encoders built in. The arduino reads the encoders and increases/decreases the PWM to get the speed I have set. And yes, I try to ramp the speed that is set up or down neatly to prevent sudden jerking starts or stops. (My trolley is ultimately meant to be a small moving coffee-table.) I have simple dead reckoning navigation by counting the encoder ticks, though that's massively inaccurate - a few turns and it loses track of which direction it's facing. I think some people don't use encoders at all - just a little compass/IMU for direction and speed - but I have no idea if that works well enough.

I am sure this could all be done more neatly on the raspi though. Mine is currently a maze, both in the physical wiring and in the arduino code. It'll be even worse if I ever get the raspi on there controlling it.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Robot programming :: your 2 cents

Fri Dec 12, 2014 10:55 am

The infinite loop is the basis for all real-time control.
Another pattern that is useful is foreground and background tasks. Here all your time-critical stuff is handled on time-triggered interrupts. Those are foreground. The less time-critical stuff is done in the normal infinite loop, which is the background.

Generally, you can't wait for anything, because then you will not be doing stuff that you need to be doing. So another pattern that can be vital is the Finite State Automaton.

freddythunder
Posts: 2
Joined: Fri Dec 12, 2014 5:21 am

Re: Robot programming :: your 2 cents

Sat Dec 13, 2014 12:14 am

Thank you for your replies!
Yes, I need to remind myself often that it's going to take a really long time; even thought I want it done quick. I made a police light bar that probably only took about 80 hours total, but took me a year and a half to find the 80 hours so I know what you mean.

I found this (and a couple other) articles that talk about benchmarks between the different programming languages.
http://raid6.com.au/~onlyjob/posts/arena/
I have not read the whole thing, skimmed and looked at the graphs, but pretty promising in C and perl. Although the guy that heads up wiringpi said the perl wrapper is not very fast so that worries me. I wrote a while(1) loop in perl to do facial detection on an ip camera stream and that did work pretty quickly.

I'm planning on going with the 2nd suggestion.. I'll have the while(1) loop running taking care of main robot functions, then I'll have either background processes called by that on the pi or even call other processes on the linux server upstairs to do anything cpu intensive so the robot can be it's own thing.

I think I'll start by experimenting in perl and using tickmarks or system calls to the command line gpio interface to see if that's quick enough. If not I'll use python as my contingency plan.
Thanks!

Dutch_Master
Posts: 360
Joined: Sat Jul 27, 2013 11:36 am

Re: Robot programming :: your 2 cents

Sat Dec 13, 2014 12:33 am

Another good way to smooth out speed curves is a G-sensor. Actually, a 3G sensor, that measures acceleration (positive and negative) in 3 axis.

These guys do an affordable kit: http://www.codemercs.com Look in their shop for the Quake Catcher Kit

BrendonShaw
Posts: 89
Joined: Sat Jun 30, 2012 7:53 am

Re: Robot programming :: your 2 cents

Sun Dec 14, 2014 9:10 am

I have built a couple of robots, as the previous mail were do you start? You can use DC motors or servo motors, both have advantages and disadvanges i.e. cost Vs accuracy. We built a 4 AWD bot using mini DC motors and encoders to measure distance.

If you want DC motor speed control, the RPi will not be good enough I know there is a PWM pin but we have found if you do something like take a picture the timing goes out. I would recommend using a Ardunio micro really cheap and hook via the RPi virutal USB port. Depending on your construction buy a DC motor controller board, size & type will depend on your motors. RPi does not have an interupt triggered GPIO, so you cannot hook up encoders to the RPi. Again the Ardunio will manage that for you, but not sure what encoders you want to use.

As a recommdation check out the yellow DC motors and chassis, you can get dual shaft motors and encoder wheels & sensors. Really small and we have these running on a mini robot chassis.

https://www.tindie.com/products/upgrade ... -800-g-cm/

Using Ardunio means you can get some example code and control via RPi serial comms, I also think Python will do the good and also allows good control of the GPIO, camera etc

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

Re: Robot programming :: your 2 cents

Sun Dec 14, 2014 9:26 am

BrendonShaw wrote: ...
If you want DC motor speed control, the RPi will not be good enough I know there is a PWM pin but we have found if you do something like take a picture the timing goes out. I would recommend using a Ardunio micro really cheap and hook via the RPi virutal USB port. Depending on your construction buy a DC motor controller board, size & type will depend on your motors. RPi does not have an interupt triggered GPIO, so you cannot hook up encoders to the RPi. Again the Ardunio will manage that for you, but not sure what encoders you want to use.
...
Have you tried? The Pi is more than good enough to control servos, and provide PWM to control LED brightness and motor speed from any of the gpios on the expansion header.

Plenty of people have successfully read rotary encoders without problems.

What problems did you actually have with the code you were using?

BrendonShaw
Posts: 89
Joined: Sat Jun 30, 2012 7:53 am

Re: Robot programming :: your 2 cents

Sun Dec 14, 2014 9:30 am

We had four dc motors and wannted indepent speed control on each motor, we found the RPi could not manage accurate speed control on four PWM pins. I will admit I need to see if the B+ is better.

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

Re: Robot programming :: your 2 cents

Sun Dec 14, 2014 9:53 am

BrendonShaw wrote:We had four dc motors and wannted indepent speed control on each motor, we found the RPi could not manage accurate speed control on four PWM pins. I will admit I need to see if the B+ is better.
There are software modules like servoblaster, RPIO.GPIO and my pigpio library which do accurate PWM on multiple gpios.

Return to “Automation, sensing and robotics”