PDA

View Full Version : [Discussion] Programming Languages for Robotics



LinuxGuy
04-30-2008, 03:39 PM
I thought I would create a place to discuss various programming languages used for Robotics, pros and cons of each, hardware usage, etc.

For instance, I use C and Python (http://www.python.org) at present. Python (http://www.python.org/) can interface with C/C++ modules for speed and to do things it can not do natively. This is how Python (http://www.python.org/) is extended. Python (http://www.python.org/) is an interpreted scripting language, so it won't be as fast as a compiled language such as C/C++. However, Python (http://www.python.org/) code can be easily modified on the fly and results can be seen instantly because there is no compile step as with C/C++ and other compiled languages.

I plan to use Python (http://www.python.org/) on W.A.L.T.E.R. because of its interpreted nature and the ability to login to the robot and change code, and then let it continue running. I will be able to optimize speed on critical modules by writing them in C/C++ and interfacing them to Python (http://www.python.org/). One other nice aspect of Python (http://www.python.org/) and other scripting languages, is they can be embedded within an application to allow customization and modification of behaviors.

Python (http://www.python.org/) also takes up much less space than having a native C/C++ toolchain on a robot, so would be better for a very storage limited system. Other interpreted languages, such as Ruby (http://www.ruby-lang.org/en/), TCL (http://www.tcl.tk/), PHP (http://www.php.net) (yes, I said PHP), and others, would have similar benefits.

8-Dale

JonHylands
04-30-2008, 04:42 PM
I use Squeak (http://www.squeak.org), which is a version of Smalltalk. Squeak (http://www.squeak.org/), like Python, is an interpreted language, and it has all the same benefits.

The main reason I use Squeak is because I have been programming in Smalltalk for 20 years now, and I can make it sing and dance quite nicely...

Some example Squeak robotics stuff I have written:

http://www.huv.com/roboMagellan (http://www.huv.com/roboMagellan/) - go to the bottom of the page to see my old mission editor

MicroRaptor GUIs (http://www.bioloid.info/tiki/tiki-index.php?page=MicroRaptor+Screenshots) - some user interface front-ends for my current "brain" system.

Of course, for both of those, all you are seeing there is the front end - there is a much larger "back end" that is actually doing all the interesting stuff.

- Jon

LinuxGuy
04-30-2008, 05:13 PM
I use Squeak (http://www.squeak.org), which is a version of Smalltalk. Squeak (http://www.squeak.org/), like Python, is an interpreted language, and it has all the same benefits.
I would also like to be able to use Squeak (http://www.squeak.org/), but it does not seem to have any facilities for low level access to devices using I2C or SPI. I need that for my robot because I will be using I2C as a communications medium for sensors and 'smart' modules. For Squeak (http://www.squeak.org/), I would probably want to use a small Seaside (http://www.seaside.st/) image, because I want my robot to have a web as well as IRC presence on the internet.


Some example Squeak robotics stuff I have written:

http://www.huv.com/roboMagellan (http://www.huv.com/roboMagellan/) - go to the bottom of the page to see my old mission editor

MicroRaptor GUIs (http://www.bioloid.info/tiki/tiki-index.php?page=MicroRaptor+Screenshots) - some user interface front-ends for my current "brain" system.
You software is beyond cool, Jon!


Of course, for both of those, all you are seeing there is the front end - there is a much larger "back end" that is actually doing all the interesting stuff.
I'd be very interested in seeing what is behind the Squeak (http://www.squeak.org/) doors, Jon, but that should be left for a new thread on "Squeak (http://www.squeak.org/) and Robotics." :veryhappy: I love the idea of using an AI type language for Robotics, because it opens up many more possibilities.

8-Dale

LinuxGuy
04-30-2008, 05:54 PM
<Crossposted>


The way I "translate" code from language to language is just understand the algorithm and the program flow and the data structures, and implement those with syntax of the other...
For the conversions I was doing, the new C software version had to spit out numbers just as close as possible to the original BASIC code. The documentation couldn't require more than the most minor of changes.


It's true that languages only differ only in syntax, but before choosing any language, one must consider what "level" the language sits at. The higher the level a language is, the further away you are from the hardware with layers of abstraction...
There are more differences than just syntax. The way a language does things comes into play also. It's not a matter of how high level a language is (all that are not assembly are high level, IMO), but whether the language allows you to get the job done you are trying to do. Some languges are meant for specific purposes, such as APL (http://www.dyalog.com/version11.htm) (Mathematics, might be great for IK/FK and complex navigation calculations, etc). There is also FORTH (http://www.forth.org/), ADA (http://en.wikibooks.org/wiki/Ada_Programming/Installing), JAVA (http://forums.trossenrobotics.com/www.javasoft.com), and others, in no particular order.


For every application, a developer must fully understand what their objectives are in the project. After you fully understand what your objectives are then you can choose which language/level you should develop in.
This is only true in an ideal situation, which most are not. You also have to look at the capabilities of the programming language(s) you are considering using, any OS you are going to use, etc. You do have to understand your objectives before going too far though, or you will almost always get into problems right away. You have to properly define what you want to accomplish overall, not just one part of your project. Some programming languages will be fine to start with but then start causing you problems further into implementation.


Please don't misconstrue "High Level" and "Low Level" as a measure of difficulty. A "Low Level" just means "closer to the hardware" and "High Level" means "further from the hardware."
Being closer to or further from the hardware just means having the right device driver or other device code available. It really hasn't got anything to do with the programming language itself. An OS can get in the way of accessing hardware. For instance, Windows makes it more difficult to access drivers and devices directly than Linux or UNIX does. Programming bare metal makes it the easiest to access the hardware because you don't have any OS to potentially get in the way. Even Linux, or any other OS, gets in the way of hardware access to varying degrees.

8-Dale

Wingzero01w
04-30-2008, 06:22 PM
And thats were i get confused... im always puzzled how other languages come out for microcontroller but dont work on others... For example the Propellor is programmed in Spin and Assembler but doesnt have Basic... The same as Basic stamp only has basic and doesnt have spin and assembler or other languages.

That kind of thing just really confuses me, and pretty much intimidates me from getting new chips like the dsPIC or the prop.

For some reason i guess i have it in my head that for every new controller i get im always almost going to have to learn a new language.

LinuxGuy
04-30-2008, 08:29 PM
And thats were i get confused... im always puzzled how other languages come out for microcontroller but dont work on others... For example the Propellor is programmed in Spin and Assembler but doesnt have Basic... The same as Basic stamp only has basic and doesnt have spin and assembler or other languages.
It has to do with what the manufacturer of the chip has in mind for it.

In the case of the Propeller Chip, Parallax no doube felt that a new language was needed for several reasons.

1) They didn't want the Propeller to be confused with other microcontrollers. The Propeller is a multitasking chip, very different from other current microcontrollers

2) The PBASIC dialect did not have the language constructs because the Basic STAMP has no capability to multitask at all.

3) The Propeller has a completely difference architecture from existing microcontrollers, such as the Basic STAMP, Basic Micro Atom/Atom PRO, etc. A new language was clearly needed to accomodate this new chip.

4) It was easier to create a brand new language rather than try extending an existing one. This way, all new features of the Propeller could be accommodated from the start.

I can't say any of these reasons influenced Parallax for sure, because they are just guesses and I don't have any inside information from Parallax and don't currently use the Propeller.


That kind of thing just really confuses me, and pretty much intimidates me from getting new chips like the dsPIC or the prop.
Welcome to the land of embedded computing! Other than C/C++ and similar languages, you won't likely find any standard amongst microcontrollers. Even with C, there will be different constructs for access to registers and other memory and I/O features based on the specific microcontroller. If you don't know C, then I strongly suggest you learn it because this will be as close to a language standard amongst microcontrollers as you will find. That is, at least until you get into the ARM9, Blackfin, Coldfire, i.MX21 (and other i.MX series controllers), and of course the x86 and other similar platforms, you won't have much of a choice of languages.


For some reason i guess i have it in my head that for every new controller i get im always almost going to have to learn a new language.
This will be true until you get away from the proprietary, closed door, microcontroller platforms. Once you get to the ARM9 and larger or faster platforms, you will be stuck learning a new variant of language for each microcontroller. You need to be into a C programmable microcontroller for this to change (Microchip PICs/dsPICs, Atmel AVRs, etc).

8-Dale

Wingzero01w
04-30-2008, 09:02 PM
Wow, thanks Robotguy that really really cleared things up.

For a starter in embedded computing, what would be a good way to learn about chips and programming them (dsPIC, C) that wont really intimidate the living daylights out of a newbie (and that wont totally demolish my robotics budget.) I really would like to learn this type of stuff so one day i could develop interface boards for robotics and such. My current project i want to work on is controlling a dynamixel bus, standard servo bus, and motor control all from some type of micro controller or two on the same board.

I also wouldn't mind learning C, i think it would be really beneficial for the type of job i want to get eventually. And well, what would be the best way of learning this?

LinuxGuy
04-30-2008, 09:50 PM
Wow, thanks Robotguy that really really cleared things up.
One is glad to be of service. :happy:


For a starter in embedded computing, what would be a good way to learn about chips and programming them (dsPIC, C) that wont really intimidate the living daylights out of a newbie (and that wont totally demolish my robotics budget.)
If you are really serious about getting into embedded computing, not just for robots, I suggest looking at the PICs/ds/PICs or AVRs. Microchip is happy to send you samples and you can place orders twice every 30 days. MPLAB and the Student Edition C compilers for both PIC and dsPIC are FREE even after the trial runs out - you just lose some compiler optimizations people tell me won't really be missed. You will be working in Windows for this development. I would start with the PIC18F2550, 18F2620, 18F4550, and 18F4620. Oricom Technologis (http://www.oricomtech.com) makes a board you can put the 18F4620, 18F4680, and any pin compatible PIC right on. The 18F4550 (40 pin) and 18F2550 (28 pin) have USB and can be bootloaded once you have flashed a bootloader to them. For programming/debugging, I strongly recommed the Olimex USB ICD2 (http://www.sparkfun.com/commerce/product_info.php?products_id=5) - I have and use one of these everytime I work with PICs/dsPICs.

For the Atmel AVRs like the Atmega168 (chips are inexpensive) and Atmega128 (Spark Fun has inexpensive breakout boards, programmers, etc) there are also free tools available such as AVRStudio (Windows) and free tools for Linux. I don't have a recommendation for a programmer/debugger for AVRs because I have not gotten into using them yet.


I really would like to learn this type of stuff so one day i could develop interface boards for robotics and such. My current project i want to work on is controlling a dynamixel bus, standard servo bus, and motor control all from some type of micro controller or two on the same board.
Start out by writing a program to blink one LED, then add more, then sequence them. This is how I started out with PICs, and it is a good and fun way to start out with any new microcontroller. Then you can learn to control the brightness of one LED using PWM, then several. Check your local bookstore for PIC programming and project books. There are some with an emphasis on robotics also. :veryhappy:


I also wouldn't mind learning C, i think it would be really beneficial for the type of job i want to get eventually. And well, what would be the best way of learning this?
Learning C (and C++) is a requirement for most of the really good jobs that have anything to do with software development. Learn it well! Learn about what goes on under the hood when your software project is being built. JAVA would also be a good one to learn, but I have not gotten much into it yet.

8-Dale

Alex
04-30-2008, 10:53 PM
Has anybody messed around with the OOPic? I've heard some really good things about them, but it's going back a number of years:

http://www.oopic.com/

For some reason they're using frames on their site, so the only way to link to the about page is to link to the page inside the frame:

http://www.oopic.com/about.htm

LinuxGuy
04-30-2008, 11:16 PM
[quote=Alex;9197]Has anybody messed around with the OOPic? I've heard some really good things about them, but it's going back a number of years:

http://www.oopic.com/[quote]

I had an ooPIC for awhile and was just starting to get into working with it when it ummm, well, let its magic smoke out. I heard later that the ooPIC-R boards are very prone to this sort of thing. When I can afford it, I want to get one of them (ooPIC II+, 40 pin version) on an Oricom Technology (http://www.oricomtech.com) ooBOT-II board - one of the same boards that will accept some 40 pin PICs. In fact, the ooPIC II+ is a programmed PIC16F877A! I also want to use the ooBOT-II board for PICs. :veryhappy:

I really like things that are object oriented and easy to use. :veryhappy:

8-Dale

Wingzero01w
04-30-2008, 11:27 PM
Thanks again,

I'm looking at the microchip sample place but i'm stuck with choosing the chips, im at the 2550 right now but i don't know which is the right choice.

PIC18F2550-I/SO SOIC 300mil
PIC18F2550-I/SP SPDIP
PIC18LF2550-I/SO SOIC 300mil
PIC18LF2550-I/SP SPDIP



Also what would i put these PIC's on? Oricom is sabbatical atm, not good =(. And which dsPIC is the best performance of the family, since they took away the mhz rating i get confused on MIPS.

Also, do you or anybody know of some good C/C++ books to learn from? Im taking a class during the summer on C++/JAVA but i think ill need refinement on the two after the course is done.

LinuxGuy
05-01-2008, 01:37 AM
I'm looking at the microchip sample place but i'm stuck with choosing the chips, im at the 2550 right now but i don't know which is the right choice.

PIC18F2550-I/SO SOIC 300mil
PIC18F2550-I/SP SPDIP
PIC18LF2550-I/SO SOIC 300mil
PIC18LF2550-I/SP SPDIP
You want the PDIPs. These are what you can use on a solderless or other breadboard.


Also what would i put these PIC's on? Oricom is sabbatical atm, not good =(. And which dsPIC is the best performance of the family, since they took away the mhz rating i get confused on MIPS.
The dsPIC30F series comes in DIP form. You'll want to invest in a GOOD solderless breadboard. Don't bother with anything that Radio Shack would carry. I have a Global Specialties (http://www.globalspecialties.com/proto_accessories.html) board I got through Mouser (http://www.mouser.com). The PB-103 would be good for starters. I have the PB-105. :veryhappy::veryhappy:

8-Dale

lnxfergy
05-01-2008, 10:57 PM
Ok, my two cents on AVRs and OOPics:

AVR - love 'em. I now use AVRs for all my projects, with AVR-GCC (WinAVR is the windows suite that includes AVR-GCC, the free C compiler). The $35 Atmel MKII programmer is probably the most standard one out there (I still use the original serial port version, but will eventually upgrade).

As for where to start with an AVR, check out the Seattle Robotics Society, their workshop robot uses an AVR (actually it uses the $40 AVR ROBOT CONTROLLER board, which is quite nice). They have all sorts of code and documentation for their robot, as well as some getting started projects. Their kit is actually available for about $100 for the whole robot (btw, I live on the East coast and have no affiliation with SRS, just a huge fan of the work they did). http://seattlerobotics.org/WorkshopRobot/index.php

OOPic - I have 2 or 3 of them, sitting on a shelf. They seemed great at first but... I found them to be pretty limited pretty fast. They are really good as co-processors or motor controllers, or other semi-simple, repetitive tasks, but I wouldn't recommend them as the main processor for a robot.

-Mike

lnxfergy
05-01-2008, 11:04 PM
Also, do you or anybody know of some good C/C++ books to learn from? Im taking a class during the summer on C++/JAVA but i think ill need refinement on the two after the course is done.

My favorite C/C++ intro book is one I picked up recently: Just Enough C/C++ Programming by Guy W. Lecky-Thompson. It isn't the most in-depth book, but it does cover all the basics in what I think is a very readable format.

Of course, it's important to note that many C/C++ compilers for microcontrollers aren't really C++ compilers (for instance AVR-GCC has the class keyword, but no new keyword, thus classes cannot be dynamically created at run time using C++, you have to revert to C-style malloc calls).

-Mike

Wingzero01w
05-02-2008, 06:17 AM
Thanks mike!

Ill be picking that book up pretty soon. I want to get started with the dsPIC's as soon as possible.

Droid Works
05-20-2008, 02:25 PM
Google排名吧聚集专业Google优化人才,为企业提供google排名 (http://www.google8.com.cn)优化服务,让您的目标客户轻松找到您,是企业Google推广领先 平台

?????

LinuxGuy
05-20-2008, 02:36 PM
OOPic - I have 2 or 3 of them, sitting on a shelf. They seemed great at first but... I found them to be pretty limited pretty fast. They are really good as co-processors or motor controllers, or other semi-simple, repetitive tasks, but I wouldn't recommend them as the main processor for a robot.
Which are they? Want to get rid of them and donate them to a worthy cause?

8-Dale

Alex
05-20-2008, 03:38 PM
yep, I just banned him;)

LinuxGuy
05-20-2008, 03:40 PM
I am also starting to look at other languages for possible use in robotics control - Prolog and Ada. Both are available for Linux. I want to learn an AI type language, so maybe I should look at getting a different implementation of Smalltalk, and also look at LISP too.

8-Dale

Adrenalynn
05-20-2008, 05:41 PM
ProLog - AHHHH! Man, take me back twenty years... I was sooo in love with Turbo ProLog for about three weeks. Then I woke up. ;)

http://www.fraber.de/university/prolog/tprolog.html

LinuxGuy
05-20-2008, 06:15 PM
ProLog - AHHHH! Man, take me back twenty years... I was sooo in love with Turbo ProLog for about three weeks. Then I woke up. ;)
I remember when Turbo Prolog came out. I almost bought it, but bought Turbo Pascal instead. Then I got Turbo C. I am probably not going to pick Prolog, but am going to give it a serious look anyway - have SWI Prolog and GProlog (GNU Prolog) installed. I have to find a good LISP implementation. I already have Squeak for Smalltalk at the moment but want to look at other implementations too. I'm also looking at ADA with real interest if there is a good Linux implementation that can compile or embedded systems and/or run on embedded systems like Hammer.

8-Dale

JonHylands
05-20-2008, 06:19 PM
In my fourth year AI project, me and another guy implemented Prolog in Smalltalk...

- Jon

metaform3d
05-20-2008, 07:46 PM
Lisp. God help me, is that still around? There are things I admire about the language: everything is the same -- the data structures, the algorithms, everything's a binary tree; the embodiment of lambda calculus. And yet, the maddening syntax. It's not called Lots of Irritating Single Parenthesis for nothing.

You could do much worse than Smalltalk.

LinuxGuy
05-20-2008, 08:41 PM
You could do much worse than Smalltalk.
I'm still in the process of learning Squeak (Smalltalk), but it does not have facilities for accessing low level functions like I2C, SPI, etc.

8-Dale

Adrenalynn
05-20-2008, 09:11 PM
I did commercial development in Turbo C. They had really fast integer math libraries... :)

LinuxGuy
05-24-2008, 07:41 PM
I'm looking seriously at Ada now. I am building gnat-gcc as I write this, which is the gcc-ada compiler. I bet some of you didn't even think gcc supported Ada, but it does. I am hoping I can find or build an Ada cross compiler for ARM. I'll have more to say on this as I make more progress with Ada. Ada was developed by the government for embedded systems, so there must be a way to build cross compilers for it.

I am also running Gentoo 2008 Linux now. ;)

8-Dale

Adrenalynn
05-25-2008, 12:33 AM
ADA was designed for government projects on mainframes...

LinuxGuy
05-25-2008, 01:16 AM
ADA was designed for government projects on mainframes...
Not according to what I read. It was also designed for embedded systems. It certainly has the features I want in a language, including concurrency.

8-Dale